Is protbuf Java's toByteArray() method same as python's SerializeToString()?

2,119 views
Skip to first unread message

S M

unread,
Apr 4, 2017, 5:34:18 PM4/4/17
to Protocol Buffers

I'm working on python protobuf and I need to convert a protobuf object to bytes. I know in Java, it can be done using toByteArray() method:  byte[] toByteArray(): serializes the message and returns a byte array containing its raw bytes.

In Python there is SerializeToString() method:  SerializeToString(): serializes the message and returns it as a string. Note that the bytes are binary, not text; we only use the str type as a convenient container.

Found here:https://developers.google.com/protocol-buffers/docs/pythontutorial

Just wanted to make sure they both are the same. 

Thank you in advance.

Feng Xiao

unread,
Apr 4, 2017, 5:50:12 PM4/4/17
to S M, Protocol Buffers
Yes, they both encode the message into protobuf binary format.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages