The -genPrtToStr option causes functions to be generated that print the contents of variables of generated types to a given text buffer. This buffer can then be used to output the information to other mediums such as a file or window display.
It is possible to specify the name of a .c or .cpp file as an argument to this option to specify the name of the file to which these functions will be written. This is an optional argument. If not specified, the functions are written to separate files for each module in the source file. The format of the name of each file is <module>PrtToStr.c. If an output filename is specified after the –genPrtToStr qualifier, all functions are written to that file.
The calling sequence for each generated print-to-string function is as follows:
asn1PrtToStr_<name> (const char* name, <name>* pvalue, char* buffer, int bufSize)
The name and pvalue arguments are the same as they were in the -print case.
The buffer and bufSize arguments are used to describe the memory buffer the text is to be written into. These arguments specify a fixed-size buffer. If the generated text is larger than the given buffer size, as much text as possible is written to the buffer and a –1 status value is returned. If the buffer is large enough to hold the text output, all text is written to the buffer and a zero status is returned. If there is text already in the buffer, the function will append to this text, rather than overwrite it, starting at the first null character. So in this case there must be enough space in the buffer starting from the first null character to hold all of the generated text; otherwise, a status of -1 is returned. For this reason initializing a newly allocated buffer with zeroes before passing it to the function is a good idea.
For C++, two toString methods are generated in the control class that call the generated print-to-string function. With the first signature, in addition to the name argument, the method also takes a buffer and bufSize argument to describe the buffer to which the text is to be written. The second signature does not take a name argument; instead, the name of the item that the control class instance describes is defaulted.