I don't have .proto message created for these. Most of my APIs
takes .proto messages as parameters (as they represent my business
data objects) and in 1-2 APIs I need to pass only 2-3 primitive
parameters as arguments. In these cases I’m avoiding creation
of .proto messages (as these don’t represent my business data object).
As an alternative, I thought of using CodedOutputstream to pass
parameters along with tag so that retrieval is easy on the receiving
end using CodedInputStream but I don't see a way to retrieve parameter
using tags with CodedInputStream. Currently I've the below code and
thought the tag approach would make it simple but CodedInputStream
doesn't support parameter retrieval based on tags.

// Client Side code - which sends s1 & s2 strings to server
int s1Size = CodedOutputStream.computeStringSizeNoTag(s1);
codedOutputStream.writeRawVarint32(s1Size);
codedOutputStream.writeStringNoTag(s1);

int s2Size = CodedOutputStream.computeStringSizeNoTag(s2);
codedOutputStream.writeRawVarint32(s2Size);
codedOutputStream.writeStringNoTag(s2);

// Server side code - which reads s1 & s2 string
CodedInputStream codedInputStream =
CodedInputStream.newInstance(inputStream);
int s1Size = codedInputStream.readRawVarint32();
int s1SizeEntry = codedInputStream.pushLimit(s1Size);
String s1 = codedInputStream.readString();
codedInputStream.popLimit(s1SizeEntry);

int s2Size = codedInputStream.readRawVarint32();
int s2SizeEntry = codedInputStream.pushLimit(s2Size);
String s2 = codedInputStream.readString();
codedInputStream.popLimit(modifiedBySizeEntry);

Regards,
Prakash

On Aug 11, 9:17 pm, Jason Hsueh <jas...@google.com> wrote:
> Suppose those strings are all defined as optional fields in the message.
> They may not be present in the serialization, so the decoder needs to read a
> tag to determine the field number and type before handling the value.
>
> On Wed, Aug 11, 2010 at 8:37 AM, Prakash Rao <prakashrao1...@gmail.com>wrote:
>
>
>
> > Hi,
> > I was just looking at CodedInputStream class and there are APIs to
> > write primitives with or without tag (for example, writeString &
> > writeStringNoTag). I thought if we set unique tags for multiple
> > parameters then we would be able to retrieve these parameters using
> > tag numbers specified using CodedInputStream class. I don't see any
> > APIs to read values based on tags in CodedInputStream. Am I missing
> > something? For the time being I’m using pushLimit & popLimit APIs to
> > get different parameter values (based on serializedSize).
>
> > For example,
> > int test(String s1, String s2, String s3) {
> > }
>
> > CodedOutputStream out = CodedOutputStream.newIInstance("Some Output
> > Stream");
> > out.writeString(1, s1);
> > out.writeString(2, s2);
> > out.writeString(3, s3);
> > out.flush();
>
> > Why these are not possible?
> > CodedInputStream in = CodedInputStream.newIInstance("Some Input
> > Stream");
> > String s1 = in.readString(1);
> > String s2 = in.readString(2);
> > String s3 = in.readString(3);
>
> > Regards,
> > Prakash
>
> > --
> > 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.c­om>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/protobuf?hl=en.- Hide quoted text -
>
> - Show quoted text -

-- 
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