0
0

More than 3 years have passed since last update.

gRPC ruby の`Google::Rpc::Status.decode`の挙動

Last updated at Posted at 2021-08-16

この記事は手元でコードを動かしながら書いているわけではなく、ただ調べたことをざっとまとめているだけである。よって、何かミスってるかも。「スニペットでto_protoで、なぜわざわざprotoにリバースしてるんだ」的なツッコミもなしで。あくまで、Google::Rpc::Status.decode(シリアライズされたリクエスト)の挙動を見せるのがこの記事の目的だからリバースしてます。

gRPC ruby の クライアント側で、

      client = GetPostsService::Stub.new('localhost:5005')

      begin
        post_response = client.get_posts(
          GetPostsRequest.new(param)
        )
        puts(
          Google::Rpc::Status.decode(post_response.to_proto)    ## ここ
        )

      rescue GRPC::BadStatus => e  
        # Handle error here!
      end

case1. status=OK の場合、

=> <Google::Rpc::Status: code: 0, message: "", details: []>

なお、Google::Rpc::Status.decodeの引数に空配列を引数に渡してみると、この場合もstatus=0になった。

Google::Rpc::Status.decode('')
=> <Google::Rpc::Status: code: 0, message: "", details: []>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0