X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=test%2Ftstodr.c;h=f2b8b3ab089b34d47fa21ce62060f0a5d007d6fb;hp=4c2ae053438f9e227cd4e52d75671f7af018ed73;hb=8356ea58313ee1f350226172cf99bfb0b7c5583c;hpb=6b76baf0fb5d0d437caedd8076f77f372d775758 diff --git a/test/tstodr.c b/test/tstodr.c index 4c2ae05..f2b8b3a 100644 --- a/test/tstodr.c +++ b/test/tstodr.c @@ -136,6 +136,44 @@ static void tst(void) odr_destroy(odr_decode); } +/* example from documentation.. 'Using Odr' */ +void do_nothing_useful(int value) +{ + ODR encode, decode; + Odr_int *valp, *resvalp; + char *bufferp; + int len; + + /* allocate streams */ + if (!(encode = odr_createmem(ODR_ENCODE))) + return; + if (!(decode = odr_createmem(ODR_DECODE))) + return; + + valp = &value; + if (odr_integer(encode, &valp, 0, 0) == 0) + { + printf("encoding went bad\n"); + return; + } + bufferp = odr_getbuf(encode, &len, 0); + printf("length of encoded data is %d\n", len); + + /* now let's decode the thing again */ + odr_setbuf(decode, bufferp, len, 0); + if (odr_integer(decode, &resvalp, 0, 0) == 0) + { + printf("decoding went bad\n"); + return; + } + /* ODR_INT_PRINTF format for printf (such as %d) */ + printf("the value is " ODR_INT_PRINTF "\n", *resvalp); + + /* clean up */ + odr_destroy(encode); + odr_destroy(decode); +} + int main(int argc, char **argv) { YAZ_CHECK_INIT(argc, argv);