如何在 gRPC 中使用标量类型作为函数参数?
How to use scalar type as function argument in gRPC?
在 gRPC 中,它期望参数是 protobuf 消息。
假设我想发送一个int,我必须创建一个消息message Int { int32 value = 1; }
并使用这个消息发送一个int。
这里是一个函数定义的例子:rpc Range(Int) returns (stream Int) {}
但我不想为每个默认标量类型创建这样的消息结构,例如布尔、int32、int64、浮点数等
如何在 gRPC 函数参数中使用标量类型?
Protobuf 提供了wrapper 类型,你可以使用Int32Value
。
它应该是这样的
import "google/protobuf/wrappers.proto";
service YourSerice {
rpc Range(google.protobuf.Int32Value) returns (stream google.protobuf.Int32Value) {}
}
您可以检查 protobuf 上的其他原始包装器 github (wrappers.proto)。
在 gRPC 中,它期望参数是 protobuf 消息。
假设我想发送一个int,我必须创建一个消息message Int { int32 value = 1; }
并使用这个消息发送一个int。
这里是一个函数定义的例子:rpc Range(Int) returns (stream Int) {}
但我不想为每个默认标量类型创建这样的消息结构,例如布尔、int32、int64、浮点数等 如何在 gRPC 函数参数中使用标量类型?
Protobuf 提供了wrapper 类型,你可以使用Int32Value
。
它应该是这样的
import "google/protobuf/wrappers.proto";
service YourSerice {
rpc Range(google.protobuf.Int32Value) returns (stream google.protobuf.Int32Value) {}
}
您可以检查 protobuf 上的其他原始包装器 github (wrappers.proto)。