Encoding/Decoding primitive types
By sandoz on Jun 02, 2006
A developer on the Fast Infoset user list was asking a question recently (see this thread) on how the Fast Infoset parsers/serializers can encode/decode binary data.
I promised to code some samples and also to blog about such support so... ...I find that questions/requests/issues/bugs are a great way of getting and focusing my attention on what developers/users find important :-)
For now i have created one sample in the fi/samples project, PrimitiveTypesWithElementContentSample.
This sample shows how primtive types, specifically arrays of byte, int and float can be encoded in binary form for element content when serializing a fast infoset document, and decoded as byte, int or float repectively when parsing the document. Further more, the sample shows that it is still possible to obtain the binary data in lexical form, which is important if the client does not desire or cannot process the primitive types.
I plan to add another sample soon that shows the same for attributes.
The Fast Infoset SAX serializers and parsers provide full support for what are known as the Fast Infoset encoding algorithms, which specify how various information may be encoded in binary form without any loss of lexical information. This is achieved by supprting as an extention to the Fast Infoset SAX API a PrimitiveTypeContentHandler which provides methods to write or access Java primitive types and arrays of.
Currently the StAX serializers and parsers only support the serializing/parsing of byte arrays. Work needs to be done to extend support for binary types that is compatible with the pull model (Derek has some good thoughts/experience on this). Any help on this area, coding/design, would be much appreciated!