Take a look at
https://github.com/sijuv/protobuf-codec/blob/master/src/main/java/com/google/protobuf/codec/Codec.java

https://github.com/sijuv/protobuf-codec/blob/master/src/main/java/com/google/protobuf/codec/AbstractCodec.java

<https://github.com/sijuv/protobuf-codec/blob/master/src/main/java/com/google/protobuf/codec/AbstractCodec.java>
https://github.com/sijuv/protobuf-codec is a library which I plan to extend
to support other serialization schemes, currently supports JSON.

Regards,
Siju

On Sat, Dec 4, 2010 at 2:04 AM, Evan Jones <ev...@mit.edu> wrote:

> On Dec 3, 2010, at 14:21 , Koert Kuipers wrote:
>
>> public class ProtobufDeserializer<T extends Message> {
>>    public T fromByteBuffer(ByteBuffer byteBuffer) {
>>
>
> I don't *think* the generic type is going to be enough due to erasure, but
> I'm not a generics expert. I know something like the following works (I may
> be messing up the generics syntax since I'm not super familiar with it):
>
> <T extends MessageLite> public T fromByteBuffer(ByteBuffer byteBuffer, T
> defaultInstance) {
>  Builder b = defaultInstance.newBuilderForType();
>  b.mergeFrom(ByteString.copyFrom(byteBuffer));
>  return b.build();
> }
>
> You can get defaultInstance from ConcreteMessageType.getDefaultInstance();
>
> You may want to create a tiny InputStream wrapper around ByteBuffer to
> avoid an extra copy, or if you know it is a heap byte buffer, use the array
> mergeFrom().
>
> Hope that helps,
>
> Evan
>
> --
> Evan Jones
> http://evanjones.ca/
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to proto...@googlegroups.com.
> To unsubscribe from this group, send email to
> protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/protobuf?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to