Module Name: othersrc Committed By: agc Date: Wed Mar 5 04:58:51 UTC 2014
Modified Files: othersrc/external/bsd/transit/bin: Makefile othersrc/external/bsd/transit/dist: libtransit.3 transit.c transit.h Added Files: othersrc/external/bsd/transit/bin: 16.expected Log Message: Changes to transit-20140304 + add 2 accessor functions for lists/dicts, one to get a field by its index, and the other for dicts to get the field value by name + bump version number to 20140304 To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 othersrc/external/bsd/transit/bin/16.expected cvs rdiff -u -r1.3 -r1.4 othersrc/external/bsd/transit/bin/Makefile cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/external/bsd/transit/dist/libtransit.3 cvs rdiff -u -r1.3 -r1.4 othersrc/external/bsd/transit/dist/transit.c \ othersrc/external/bsd/transit/dist/transit.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: othersrc/external/bsd/transit/bin/Makefile diff -u othersrc/external/bsd/transit/bin/Makefile:1.3 othersrc/external/bsd/transit/bin/Makefile:1.4 --- othersrc/external/bsd/transit/bin/Makefile:1.3 Tue Feb 25 08:54:43 2014 +++ othersrc/external/bsd/transit/bin/Makefile Wed Mar 5 04:58:51 2014 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.3 2014/02/25 08:54:43 agc Exp $ +# $NetBSD: Makefile,v 1.4 2014/03/05 04:58:51 agc Exp $ .include <bsd.own.mk> @@ -93,3 +93,8 @@ t: ${PROG} env LD_LIBRARY_PATH=${LIB_TRANSIT_DIR} ./${PROG} -d -j 15.enc > 15.out diff 15.expected 15.out rm -f 15.enc 15.out + @echo "16. json structured data as output" + env LD_LIBRARY_PATH=${LIB_TRANSIT_DIR} ./${PROG} -j '{"array":{"field1":1,"field2":"val2","field3":"string value 3","field4":"val4"},"array2":[1,2,3,4,5,6,7,8]}' > 16.enc + env LD_LIBRARY_PATH=${LIB_TRANSIT_DIR} ./${PROG} -d -j 16.enc > 16.out + diff 16.expected 16.out + rm -f 16.enc 16.out Index: othersrc/external/bsd/transit/dist/libtransit.3 diff -u othersrc/external/bsd/transit/dist/libtransit.3:1.1.1.1 othersrc/external/bsd/transit/dist/libtransit.3:1.2 --- othersrc/external/bsd/transit/dist/libtransit.3:1.1.1.1 Mon Feb 24 05:59:13 2014 +++ othersrc/external/bsd/transit/dist/libtransit.3 Wed Mar 5 04:58:51 2014 @@ -1,4 +1,4 @@ -.\" $NetBSD: libtransit.3,v 1.1.1.1 2014/02/24 05:59:13 agc Exp $ +.\" $NetBSD: libtransit.3,v 1.2 2014/03/05 04:58:51 agc Exp $ .\" .\" Copyright (c) 2014 Alistair Crooks <a...@netbsd.org> .\" All rights reserved. @@ -23,7 +23,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd February 22, 2014 +.Dd March 4, 2014 .Dt LIBTRANSIT 3 .Os .Sh NAME @@ -89,6 +89,16 @@ atoms, or fields of atoms. .Fo transit_size .Fa "transit_t *transit" .Fc +.Pp +Some dictionary and list access functions are also defined. +.Ft int +.Fo transit_field_by_index +.Fa "transit_t *transit" "uint32_t dictnum" "uint32_t fieldnum" "transit_atom_t *result" +.Fc +.Ft int +.Fo transit_field_by_name +.Fa "transit_t *transit" "uint32_t dictnum" "const char *fieldname" "transit_atom_t *result" +.Fc .Sh DESCRIPTION The .Nm Index: othersrc/external/bsd/transit/dist/transit.c diff -u othersrc/external/bsd/transit/dist/transit.c:1.3 othersrc/external/bsd/transit/dist/transit.c:1.4 --- othersrc/external/bsd/transit/dist/transit.c:1.3 Tue Feb 25 08:54:43 2014 +++ othersrc/external/bsd/transit/dist/transit.c Wed Mar 5 04:58:51 2014 @@ -421,3 +421,45 @@ transit_size(transit_t *trans) { return (trans) ? trans->c : 0; } + +/*****************************************************/ + +/* dictionary/list accessors */ + +/* return the contents of the list/dict field, accessed by number */ +int +transit_field_by_index(transit_t *t, uint32_t dict, uint32_t field, transit_atom_t *ret) +{ + transit_atom_t *atom; + transit_atom_t *el; + uint64_t *indices; + + atom = transit_atom(t, dict); + indices = transit_atom_ptr(atom); + el = transit_atom(t, indices[field]); + memcpy(ret, el, sizeof(*ret)); + return 1; +} + +/* return the contents of the dict value, accessed by name */ +int +transit_field_by_name(transit_t *t, uint32_t dict, const char *name, transit_atom_t *ret) +{ + transit_atom_t *atom; + transit_atom_t *el; + uint64_t *indices; + uint64_t i; + + atom = transit_atom(t, dict); + indices = transit_atom_ptr(atom); + for (i = 2 ; i < transit_atom_size(atom) ; i += 2) { + el = transit_atom(t, indices[i]); + if (el->type == TRANSIT_STRING && memcmp(name, el->v, el->n) == 0) { + el = transit_atom(t, indices[i + 1]); + memcpy(ret, el, sizeof(*ret)); + return 1; + } + } + return 0; +} + Index: othersrc/external/bsd/transit/dist/transit.h diff -u othersrc/external/bsd/transit/dist/transit.h:1.3 othersrc/external/bsd/transit/dist/transit.h:1.4 --- othersrc/external/bsd/transit/dist/transit.h:1.3 Tue Mar 4 02:14:15 2014 +++ othersrc/external/bsd/transit/dist/transit.h Wed Mar 5 04:58:51 2014 @@ -23,7 +23,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef TRANSIT_H_ -#define TRANSIT_H_ 20140303 +#define TRANSIT_H_ 20140304 #include <sys/types.h> @@ -82,6 +82,10 @@ transit_atom_t *transit_atom(transit_t * uint8_t *transit_encoded(transit_t */*trans*/); uint64_t transit_size(transit_t */*trans*/); +/* list/dict accessor functions */ +int transit_field_by_index(transit_t */*t*/, uint32_t /*dict*/, uint32_t /*field*/, transit_atom_t */*ret*/); +int transit_field_by_name(transit_t */*t*/, uint32_t /*dict*/, const char */*name*/, transit_atom_t */*ret*/); + __END_DECLS #endif Added files: Index: othersrc/external/bsd/transit/bin/16.expected diff -u /dev/null othersrc/external/bsd/transit/bin/16.expected:1.1 --- /dev/null Wed Mar 5 04:58:51 2014 +++ othersrc/external/bsd/transit/bin/16.expected Wed Mar 5 04:58:51 2014 @@ -0,0 +1 @@ +{"array":{"field1":1,"field2":"val2","field3":"string value 3","field4":"val4"},"array2":[1,2,3,4,5,6,7,8]}