On Tue, Mar 17, 2015 at 10:15 PM, Sayan Goswami <sayan.n...@gmail.com> wrote:
> Hi All,
>
> I am using CodedOutputStream and CodedInputStream to transfer messages
> across a network like so:
>
> Client requests:
>
> Socket serverSocket = new Socket(hosts, ports);
>
> CodedOutputStream outputStream =
> CodedOutputStream.newInstance(serverSocket.getOutputStream());
>
> outputStream.flush();
>
> CodedInputStream inputStream =
> CodedInputStream.newInstance(serverSocket.getInputStream());
>
>
> // the following happens inside a loop
>
>      Request request = Request.newBuilder()
>
> .setType(Request.RequestType.GET)
>
> .setKey(key)
>
> .build();
>
>
>      outputStream.writeRawVarint32(request.getSerializedSize());
>
>      request.writeTo(outputStream);
>
>      outputStream.flush();
>
>
> Server Processes Request:
>
>
> CodedOutputStream output =
> CodedOutputStream.newInstance(clientSocket.getOutputStream());
>
> output.flush();
>
> CodedInputStream input =
> CodedInputStream.newInstance(clientSocket.getInputStream());
>
>
> int length = input.readRawVarint32();
>
> byte[] message = input.readRawBytes(length);

Ew. You can just do a

limit = input.pushLimit(length)
request = Request.Builder.mergeFrom(input).build();
input.popLimit(limit);

>
> Request request = Request.parseFrom(message);
>
> // do things with request
>
>
> Now, each request of mine, has a serialized size of 56.. so I can send many
> messages up the stream, but what can I do when the size limit of 64MB is
> exceeded? Is there any way to reset the buffer? Following is the error
> message I am getting:
>
>
> Protocol message was too large.  May be malicious.  Use
> CodedInputStream.setSizeLimit() to increase the size limit.

>From the docs:

If you want to read several messages from a single CodedInputStream,
you could call resetSizeCounter() after each one to avoid hitting the
size limit.

Cheers,

  -ilia

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to