Michael Ben-Nes
Michael Ben-Nes

Reputation: 7645

How GRPC handle pointer that appear more then once?

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.

Upvotes: 0

Views: 1187

Answers (1)

rubens21
rubens21

Reputation: 801

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.

Upvotes: 1

Related Questions