dev@fi.java.net

Re: Encoding algorithms

From: Santiago Pericas-Geertsen <Santiago.Pericasgeertsen_at_Sun.COM>
Date: Fri, 11 Feb 2005 09:44:02 -0500

On Feb 11, 2005, at 6:12 AM, Paul Sandoz wrote:

> Santiago Pericas-Geertsen wrote:
>>> I was envisaging that encoding algorithms could be registered with
>>> multuple parsers instances (and types of parser) (so can external
>>> and initial vocabularies).
>> Ah, I see. Personally, I think that would be a bad idea since it
>> will require synchronization and will effectively create a "chicane"
>> in your system.
>>
>
> OK. Pondering some more.... perhaps the parser/serializer should
> maintain a registration of factories for each algorithm and do:
>
> algorithmFactory.getInstance().decodeFrom...
> algorithmFactory.getInstance().encodeTo...

  What's wrong with simply registering encoders on the parser/serializer
instance? In other words, why do we need the extra indirection via
factories?

> For encoding the serializer has a choice to use bytes or an
> OutputStream. The choice to use which is not so easy to determine as
> it would be based given the object on if there is enough room in the
> byte array to encode the object. In this respect it may only make
> sense to have:
>
> void encodeToOutputStream(Object data, OutputStream s) throws
> IOException;

  Will this work OK for those cases in which the serialized object must
be length prefixed? It seems that in many (most?) cases the serializer
will have to use a ByteArrayOutputStream to do the serialization
correctly. Am I missing something?

-- Santiago