dev@fi.java.net

EncodingAlgo.getPrimtiveLengthFromOctetLength

From: Alan Hudson <giles_at_yumetech.com>
Date: Wed, 02 Mar 2005 13:42:40 -0800

I'm not sure how to respond to this call. I have some algos which
cannot calculate the length just from the data length. An example is an
integer encoder which uses n bits to write each integer. Right now I
write out the number of bits used at the front of the stream. The call
to getPrimtiveLengthFromOctetLength does not provide the stream to decode.

Same issue with:
getOctetLengthFromPrimitiveLength when encoding. Ie I don't know the
length until after the encoding process has been run.

Obviously we want to avoid running over the data twice as well.

Lets take a really simple encoder. Scan the whole integer array,
determine smallest number of bits needed to encode min/max value.
Repeat through array to encode using #bits.

Perhaps we can solve this by requiring the first call to be a int
parseHeader(byte[]) , int parseHeader(InputStream). The algo could then
read any header its dropped to get params. It returns the number of
bytes read from the stream to later calls to decodeFromBytes could have
the correct start location.

This does make the encoders stateful and have thread issues. But I'm
not certain how else to crack this one.