vl4deee11
vl4deee11

Reputation: 81

Protobuf structure with bytes field

There is a protobuf structures

message A {
  bytes B = 1;
}

message B {
   int32 c = 1;
   int64 d = 2;
   string x = 3;
}

If we put the bytes of the same encoded proto-buffer in the A.B field and decode or encode

pseudocode: 
newA = &A{}
newB = &B{x:"123",c:1,d:3}
bytes_of_B = marshall(type(B), newB) 
newA.B = bytes_of_B
bytes_of_A = marshall(type(A), newA)

pseudocode: 
newA = unmarshall(bytes_of_A, type(A))
newB = unmarshall(newA.B, type(B))

how true is this and what may be the consequences of this

Upvotes: 1

Views: 1047

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1064194

At the wire/payload level, this scenario is 100% identical to

message A {
  B B = 1;
}

So: no consequences as such, but telling A to expect a B may be more convenient.

Upvotes: 2

Related Questions