dev@grizzly.java.net

Re: Questions about Protocol Buffer Implementation

From: Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
Date: Thu, 05 May 2011 21:05:53 +0200

Hi,

> Alright, so the second draft is up @
> https://github.com/cdollins/grizzly-google-protobufs
> grizzly-google-protobufs . The improvements that were made were to use the
> BufferInputStream and Protobuf mergeFrom InputStream variant as suggested by
> Oleksiy, also a unit test was added. Please take the time to review the code
> and make suggestions.
The Decoder looks very good!
IMO it would be great to improve Encoder the similar way, so it won't
perform the buffer copying.

Pls. check the BufferOutputStream (I've recently updated it a bit on
trunk), we can create the instance of BufferOutputStream, reserve 4
bytes for packet length and then let the message serialize its content
to the output stream. Once we know the length - we can put correct 4
bytes length into result buffer. So it will look like:

MemoryManager mm = obtainMemoryManager(...); // obtain memory manager

BufferOutputStream bos = new BufferOutputStream(mm); // create buffer
outputstream
bos.write(fourByteBuffer); // reserve 4 bytes which will
contain the length
message.writeTo(bos); // serialize the message
bos.close();
Buffer buffer = bos.getBuffer().flip(); // get the result buffer
from stream
int len = buffer.remaining() - 4; // calculate the message len
buffer.putInt(0, len); // put correct length to the buffer header

it's just my proposal, so feel free to change and improve it.

Thanks a lot!

WBR,
Alexey.

> --
> View this message in context: http://grizzly.1045725.n5.nabble.com/Questions-about-Protocol-Buffer-Implementation-tp4305806p4371922.html
> Sent from the Grizzly - Development mailing list archive at Nabble.com.