How to use "print_object"?

17 views
Skip to first unread message

natsumi hiroyama

unread,
May 7, 2015, 9:28:14 PM5/7/15
to asn1-develo...@googlegroups.com
i follow the getting started page and try the example code
i used the asn.1 C compiler to generate MyHTTP.c and MyHTTP.h, ...,and run test.c successfully.
i wanted to print the object,and added the code below 
print_object(&myRequest, &GETREQUEST_TYPE, &printer);
but the object was printed in the console ><
how can i print it in a file?
should i modify the definition of "printer"?

Zhiren Hu

unread,
May 17, 2015, 11:32:02 PM5/17/15
to asn1-develo...@googlegroups.com, natsu...@gmail.com
Hello natsumi hiroyama,

You just need to modify the print callback which is used to fill the value of printer, the example method is just print in console:

static int print(AsnPrinter* printer, const char* __format, ...) {
   va_list arg_ptr;
   int cnt;
   va_start(arg_ptr, __format);
   cnt = vprintf(__format, arg_ptr);
   va_end(arg_ptr);
   return cnt;
}

To print to file, you need to use the fd field in printer parameter of the print callback, usually fd can be use to store the file pointer, so you can use it to write to file.
Remember to open file prerior to call the print_object method, and close file after this method.


Regards,
Zhiren Hu
Reply all
Reply to author
Forward
0 new messages