fullstorydev / grpcurl

Like cURL, but for gRPC: Command-line tool for interacting with gRPC servers
MIT License
10.36k stars 497 forks source link

protobuf type 'bytes' not supported #326

Closed allwicher closed 1 year ago

allwicher commented 1 year ago

When I call a service which expects a request with the parameter 'Buffer' of the type 'bytes', I get an error error getting request data: bad input: expecting string ; instead got {

When I use the same message in BloomRPC, the request is accepted and processed by the service.

Example proto message definition:

message UploadRequest {
  acme.service.version.Context context = 1;
  bytes buffer = 2;
}

gprcurl command:

grpcurl -format json -expand-headers -H 'Authorization: Bearer ${API_CALL_TOKEN}' -d '{
  "context": {
    ...
   },
  "buffer": {
        "type": "Buffer",
        "data": [   82,69,71,69,68,73,69,92,78,117,97,110 ]
  }
}' -proto protofiles/acme/service/version/data/data_service.proto -import-path ../protofiles/ <domain>  <service>/<method>
dragonsinth commented 1 year ago

Hi @allwicher, the JSON format for bytes is a base64 encoded string.

bytes base64 string "YWJjMTIzIT8kKiYoKSctPUB+" JSON value will be the data encoded as a string using standard base64 encoding with paddings. Either standard or URL-safe base64 encoding with/without paddings are accepted.