Retrieving data with field number and wire type

5 views
Skip to first unread message

rahul prasad

unread,
Nov 10, 2009, 9:25:49 AM11/10/09
to Protocol Buffers
Hi,

Is there a facility in protobuf library to retrieve data if the field numbers and wire types are known? If so how to go about this?

Regards,
Rahul

Evan Jones

unread,
Nov 10, 2009, 9:38:54 AM11/10/09
to rahul prasad, Protocol Buffers
On Nov 10, 2009, at 9:25 , rahul prasad wrote:
> Is there a facility in protobuf library to retrieve data if the
> field numbers and wire types are known? If so how to go about this?

If you don't want to use the generated code that handles this for you
for some reason, you want to look at CodedInputStream

C++:
http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.io.coded_stream.html

Java:
http://code.google.com/apis/protocolbuffers/docs/reference/java/index.html?com/google/protobuf/CodedInputStream.html

--
Evan Jones
http://evanjones.ca/

Kenton Varda

unread,
Nov 10, 2009, 2:39:45 PM11/10/09
to rahul prasad, Protocol Buffers
On Tue, Nov 10, 2009 at 6:25 AM, rahul prasad <rah...@gmail.com> wrote:
Hi,

Is there a facility in protobuf library to retrieve data if the field numbers and wire types are known?

Write a .proto file with that information.  Then you can compile it, or you can use protoc's --decode flag.

If you need something automated that runs as part of a larger app, you can construct a FileDescriptorProto at run-time, which is a structured representation of the contents of a .proto file.  You can then convert that to a FileDescriptor using DescriptorPool (C++) or Descriptors.FileDescriptor.buildFrom() (Java), and then construct a DynamicMessage from the descriptors (either language).
Reply all
Reply to author
Forward
0 new messages