[xsde-users] custom binary encoding

Boris Kolpackov boris at codesynthesis.com
Tue Dec 30 09:54:16 EST 2014


Hi Jim,

Jim Dattolo <jdattolo at dekaresearch.com> writes:

> I want to encode my classes down to binary, however I want to strip off the
> attributes. [...] Is there any way to filter them out or add an option
> to the compiler to ignore attributes?

Customizing the XSD/e compiler is definitely possible but to me a much
easier way would be to strip the attributes from the schema (e.g., with
an XSLT transformation or some such). I may be wrong but from your
description it seems that the attributes in your schema are there
just for decoration. Their values are fixed and known to all the
parties involved.


> I see a lot of source for using the results of xsde, just not the
> source for the compiler itself? 

It is right here:

http://codesynthesis.com/projects/xsde/


> Any pointers to start down this path?

Uh, the trickiest part will be building it, especially if you are
on Windows. In fact, if you do want to go down this path, it will
probably be better for you to start with the current pre-release;
the build system has been improved there somewhat. Customizing
the source code itself will be fairly easy.


> Also I need to change the endian order for the binary for all
> datatypes. Not all data types are setup in the raw stream
> code, is it as simple as overriding for all of the missing
> data types and changing the stream type to little endian?

Yes, the way you would want to handle this is to implement your
own binary representation streams, just like the 'binary/custom'
example.

One last note: you said that the binary protocol is fixed and
cannot be changed. While you can change how XSD/e serializes
basic types (integers, string, etc.; via the binary stream),
you cannot change how or in which order it serializes higher-
level constructs, such as optional/sequences of elements,
etc. For example, for an optional element, XSD/e will first
write a boolean flag and then the element itself. For a
sequence of elements it will write the count first followed
by all the elements. Things get less "standard" for choice,
for example.

So unless all of this happens to match your binary format, you
will run into trouble that would require further, potentially
significant, customizations of the XSD/e compiler.

Boris



More information about the xsde-users mailing list