0

For example (golang):

type {
  Product struct {
    Name string
  }
  Customer struct {
    Name string
    Products []*Product
  }
}

Which is the correct behavior:

  1. GRPC honor the *Product pointer and transfer it only once.
  2. GRPC will transfer the same *Product as many times as it associated to different Customer.
michaelbn
  • 7,393
  • 3
  • 33
  • 46
  • 1
    [This answer](https://stackoverflow.com/a/6296006/751579) gives two pieces of information: First, that protobuf itself (the underlying serialization method) is a _tree serializer_ - thus it _does not_ handle repeated references to an object by serializing it only once, materializing a graph on the other end. But, second, that a particular .NET implementation of protobuf provides graph serialization as an option. Look for it as an option in the golang protobuf or the golang grpc implementation; it may be there. (Or maybe not.) – davidbak Jan 08 '21 at 17:06

1 Answers1

1

Michael, It is not clear on your message, but I am assuming that you will send a Customer as part of your request to a gRPC server.

Golang will marshal the struct into []byte (https://godoc.org/github.com/golang/protobuf/proto#Marshal), so the message will not have such thing as a pointer. It will be just an encoded message. (see https://github.com/golang/protobuf/blob/master/proto/wire.go#L22).

gRPC is not a Golang thing, so a pointer on a side (e.g. server) does not mean it must be a point on the other side (e.g. client).

Finally, answering your question, the expected behavior is 2. However, you may take a deeper look into proto buff serialization (https://developers.google.com/protocol-buffers/docs/encoding). I have no idea how it works, but maybe the message is compressed, so repeated []bytes maybe be discarded.

rubens21
  • 743
  • 5
  • 13