Forum Discussion

Guru2's avatar
Guru2
Occasional Contributor
3 years ago

How encoding/Decoding of Grpc proto parameters processed in ReadAPI during .proto file import

In our project we have requirement to test the grpc protocol using unary operation. Able to import .proto file successfully in readyapi, but when created the test case using the imported file, the original data of the unary request is mistmatched with the actual data of the proto file. 

 

For example:

Following is the request data we have got after importing the .proto file in readyapi. we are not sure how this encoding/decoding occurs in readyapi.

 

Request Data from readyapi:

{
"token1" : "c3RyaW5n",
"nonce" : "c3RyaW5n"
}

 

But in grpc server we have stored the same data as constants and comparing these constants with the readyapi request. Unfortunately the comparison is not matching with our implementation with the readyapi data received. Below is our two scenarios of comparision, but in none of the case its matching.

 

comparision 1: 

const test_token = "blablabla"

token := []byte(test_token)

"if bytes.Compare(token, in.GetToken1()) == 0"

 

comparision 2:

const test_token = "c3RyaW5n"

token := []byte(test_token)

"if bytes.Compare(token, in.GetToken1()) == 0"

  • TNeuschwanger's avatar
    TNeuschwanger
    Champion Level 1

    Hello Guru2 

     

    I am not familiar with grpc protocol, but your sample looks a little JSON ish...  I will just base this suggestion on what I am guessing is JSON request and response...  I could be completely off track so discard if this has nothing to do with JSON.  🙂

     

    I am pretty sure JSON has no specification for order.  If you provide original JSON and send it to any JSON interpreter, you might not get the same result in its output as originally consumed.  I have seen code samples to force JSON to keep order, but if I am on the wrong track here to begin with, I don't want to spend time continuing research on that.  If this is JSON related, you would need to sort both input and output to be consistent for comparison.

     

    Regards,

    Todd

    • richie's avatar
      richie
      Community Hero
      Hey TNeuschwanger,

      Just a follow up FYI for you regarding the json order/unorder (unorder....ia that even a word? Never mind...rhetorical!)

      The definition of a json object is an "unordered list of name/value pairs".
      If you want the contents of an object in a particular sequence, you have to do things like embed it in an array, etc.

      Cheers

      Rich
      • sonya_m's avatar
        sonya_m
        SmartBear Alumni (Retired)

        Thanks, Community!

        Guru2 please let us know if the advice helps!