Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS import: othersrc/external/bsd/transit



Module Name:    othersrc
Committed By:   agc
Date:           Mon Feb 24 05:59:14 UTC 2014

Update of /cvsroot/othersrc/external/bsd/transit
In directory ivanova.netbsd.org:/tmp/cvs-serv13510

Log Message:
Initial import of transit-20140222 into othersrc

transit is a simple data serialisation library, in contrast to JSON or
CBOR (RFC 7049). It is much simplified from CBOR, and has none of the
binary string or escaped character issues that JSON faces.

There are two atomic types in the transit library 

+ a numeric value, encoded using the bottom 7 bits in a byte, and only
using the necessary number of bytes to fully represent the value. 

+ a string of bytes (which can be of any value). The bytes are preceded
by a numeric atom giving the length of the byte string. Byte strings do
not need to be NUL-terminated, nor do any characters need escaping
within the byte string.

As in JSON, there are two types of structured data based on top of these
two atoms:

+ a list of elements, and

+ a dictionary of pairs of elements

and each element in a list or dictionary can be any of the other
types, although the keys of dictionary pairs are usually represented
as strings.

A specific marker in the encoding represents the end of a list or
dictionary (similar to CBOR's indefinite length construction).

libtransit(3) gives a worked example of the data representation:

        to represent the abstract array "[1,["two",3],["four",5]]",
        the encoding would look like:

        03                    -- List follows
            01                -- Number follows
                01            -- 1
            03                -- List follows
                02            -- String follows
                    03        -- 3 bytes in string
                    74776f    -- "two"
                01            -- Number follows
                    03        -- 3
                05            -- End of list (inner list)
            03                -- List follows
                02            -- String follows
                    04        -- 4 bytes in string
                    666f7572  -- "four"
                01            -- Number follows
                    05        -- 5
                05            -- End of list (inner list)
            05                -- End of list (outer list)

        as can be seen from the following dump of the JSON conversion output

        % transit -j '[1,["two",3],["four",5]]' | hexdump -C
        00000000  03 01 01 03 02 03 74 77  6f 01 03 05 03 02 04 66  
|......two......f|
        00000010  6f 75 72 01 05 05 05                              |our....|
        00000017
        % transit -j '[1,["two",3],["four",5]]' | transit -d
        list
                number  1
                list
                        string  two
                        number  3
                list
                        string  four
                        number  5
        %

As can be seen above, there is a primitive provided to convert from
encoded JSON into the encoded transit representation.

When decoding transit-encoded streams, the transit_decode(3) function is
the main means of getting the individual parts into a parsed stream of
atoms. In addition, a number of accessor functions for the transit tree
as a whole, and the tree of atoms in particular, are provided. This can
be seen in the walk functions provided in the main transit program.

An additional walk function, from a different program, is shown below:

        static int
        walk(transit_t *t)
        {
                transit_atom_t  *list;
                transit_atom_t  *atom;
                uint64_t        *els;
                unsigned         i;

                /* the input is a list of dicts */
                list = transit_atom(t, 0);

                /* the indices of the elements are in the array in the "list" 
atom */
                els = transit_atom_ptr(list);

                for (i = 0 ; i < transit_atom_size(list) - 1 ; i++) {
                        /* add 1 field for the "name" key in the dict pair */
                        /* add 1 field for the "value" of the pair */
                        atom = transit_atom(t, els[i] + 1 + 1);
                        printf("name: %s\n", transit_atom_ptr(atom));
                }
                return 1;
        }


Status:

Vendor Tag:     CROOKS
Release Tags:   transit-20140222-base
                
N othersrc/external/bsd/transit/Makefile
N othersrc/external/bsd/transit/bin/1.expected
N othersrc/external/bsd/transit/bin/Makefile
N othersrc/external/bsd/transit/bin/2.expected
N othersrc/external/bsd/transit/bin/3.expected
N othersrc/external/bsd/transit/bin/4.expected
N othersrc/external/bsd/transit/bin/5.expected
N othersrc/external/bsd/transit/bin/6.expected
N othersrc/external/bsd/transit/bin/7.expected
N othersrc/external/bsd/transit/bin/12.expected
N othersrc/external/bsd/transit/bin/9.in
N othersrc/external/bsd/transit/bin/10.in
N othersrc/external/bsd/transit/bin/8.expected
N othersrc/external/bsd/transit/bin/9.expected
N othersrc/external/bsd/transit/bin/10.expected
N othersrc/external/bsd/transit/bin/11.expected
N othersrc/external/bsd/transit/dist/transit.1
N othersrc/external/bsd/transit/dist/Makefile
N othersrc/external/bsd/transit/dist/libtransit.3
N othersrc/external/bsd/transit/dist/main.c
N othersrc/external/bsd/transit/dist/transit.c
N othersrc/external/bsd/transit/dist/transit.h
N othersrc/external/bsd/transit/lib/shlib_version
N othersrc/external/bsd/transit/lib/Makefile

No conflicts created by this import




Home | Main Index | Thread Index | Old Index