GRPC 如何处理出现多次的指针?

How GRPC handle pointer that appear more then once?

例如(golang):

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

正确的行为是:

  1. GRPC 尊重 *Product 指针并仅传输一次。
  2. GRPC 会将相同的 *Product 传输多次,因为它关联到不同的 Customer

迈克尔, 您的消息并不清楚,但我假设您将发送 Customer 作为请求的一部分到 gRPC 服务器。

Golang 会将结构编组为 []byte (https://godoc.org/github.com/golang/protobuf/proto#Marshal),因此消息不会有指针之类的东西。这将只是一个编码的消息。 (看 https://github.com/golang/protobuf/blob/master/proto/wire.go#L22).

gRPC 不是 Golang 的东西,因此一侧(例如服务器)的指针并不意味着它必须是另一侧(例如客户端)的一个点。

最后,回答你的问题,预期的行为是 2但是,您可以更深入地了解 proto buff 序列化 (https://developers.google.com/protocol-buffers/docs/encoding)。我不知道它是如何工作的,但是可能消息被压缩了,所以重复[]bytes可能会被丢弃。