Hi group,
I am trying to serialize/deserialize a sub message using Protobuf.
The reasons for this is signing. I want to be able to sign part of my
message. To be able to do that, I need to canonicalize it somehow.
If it matters, I use protbuf 3.0.0-alpha (With the proto2 language) with
Python3.4.
Example file: testp.proto
package my_package;
message my_mess {
message data {
optional uint64 x = 1;
optional uint64 y = 2;
optional uint64 z = 3;
}
optional bytes signature = 4;
}
In this example, I want to sign the data part of the message. Therefore I
want to serialize only my_mess.data, sign it, put the signature into
my_mess.signature, and then serialize the full message my_mess.
Compiling testp.proto:
$ protoc -I=. --python_out=. testp.proto
[libprotobuf WARNING google/protobuf/compiler/parser.cc:471] No syntax
specified for the proto file. Please use 'syntax = "proto2";' or 'syntax =
"proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)
I noticed that mm.data have the methods SerializeToString and
SerializePartialToString.
However, it seems like it is not possible to run them directly. Here are my
attempts:
$ ipython
In [1]: import testp_pb2
In [2]: mm = testp_pb2.my_mess()
In [3]: mm.data.x = 1
In [4]: mm.data.y = 2
In [5]: mm.data.z = 3
In [6]: mm.data.SerializeToString()
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
<ipython-input-6-faa8e25906ca> in <module>()
----> 1 mm.data.SerializeToString()
TypeError: SerializeToString() missing 1 required positional argument:
'self'
In [7]: mm.data.SerializePartialToString()
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
<ipython-input-7-4b2c1ff0b1c9> in <module>()
----> 1 mm.data.SerializePartialToString()
TypeError: SerializePartialToString() missing 1 required positional
argument: 'self'
I was wondering if there is some simple solution I'm missing. I am open to
other suggestions, if you have an idea of signing just a part of the
message in an elegant way.
Thank you for your help.
Note that this question was cross posted here:
http://stackoverflow.com/questions/27958571/serializing-part-of-a-message-with-protobuf
,
However, I didn't get any responses there.
Regards,
real.
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.