Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decode protobuf binary response

I have created a test app that can recognize some image using Goggle Goggles. It works for me, but I receive binaryt protobuf response. I have no proto-files, just binary response. How can I get data from it? (Have sent some image with bottle of bear and got the nex response):

A
TuborgLogo9 HoaniText���;�)b���2d8e991bff16229f6"�
+TR=T=AQBd6Cl4Kd8:X=OqSEi:S=_rSozFBgfKt5d9b0
+TR=T=6rLQxKE2xdA:X=OqSEi:S=gd6Aqb28X0ltBU9V
+TR=T=uGPf9zJDWe0:X=OqSEi:S=32zTfdIOdI6kuUTa
+TR=T=RLkVoGVd92I:X=OqSEi:S=P7yOhvSAOQW6SRHN
+TR=T=J1FMvNmcyMk:X=OqSEi:S=5Z631_rd2ijo_iuf�

need to get string "Tuborg" and if possible type - "Logo"

like image 904
Igor Avatar asked Oct 27 '11 09:10

Igor


People also ask

Is protobuf binary format?

A protocol buffer message is a series of key-value pairs. The binary version of a message just uses the field's number as the key -- the name and declared type for each field can only be determined on the decoding end by referencing the message type's definition (that is, the .

Is protobuf binary protocol?

Protobuf is a binary message format crafted by Google and is efficient compared to other message formats like JSON & XML.

How does protobuf encoding work?

Protobuf categorizes normally used data types into wire types which provides information to find the length of the value. For wire type 2, length is also encoded along with value. Zero values are not transmitted. 0, False, “”, does not take any bytes.


2 Answers

I'm going to assume the real question is how to decode protobufs and not how to read binary from the wire using Java.

The answer to your question can be found here

Briefly, on the wire, protobufs are encoded as 3-tuples of <key,type,value>, where:

  • the key is the field number assigned to the field in the .proto schema
  • the type is one of <Varint, int32, length-delimited, start-group, end-group,int64. It contains just enough information to decode the value of the 3-tuple, namely it tells you how long the value is.
like image 91
tgoodhart Avatar answered Sep 22 '22 13:09

tgoodhart


You can decode with protoc:

protoc --decode_raw < msg.bin
like image 20
To1ne Avatar answered Sep 18 '22 13:09

To1ne