Ask a Question

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

Guru2
Occasional Contributor

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"

5 REPLIES 5
TNeuschwanger
Community Leader

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

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
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
sonya_m
SmartBear Alumni (Retired)

Thanks, Community!

@Guru2 please let us know if the advice helps!


Sonya Mihaljova
Community and Education Specialist

Guru2
Occasional Contributor

Hi Sonya,

 

Thanks for asking. My query was not solved because this is not a json request/response. Still could not understand how readyapi encodes the request data to server when the grpc request created using the unary call imported from .proto file.  So tried modifying the default request data in the grpc unary call based on how we implemented in our code. That modification did not helped, it throws "invalid input length" error after modifying. Any suggestions how to proceed further? How this request data is being set when creating grpc request using the imported API definition? Kindly let me know. 

 

 

Thanks,

Guru 

Guru2
Occasional Contributor

When sending request from readyapi to some server using grpc. Are some bytes getting padded in the json request or its re-ordered? How this encoding is happening in readyapi while sending request? Kindly let me know your thoughts on this.

 

 

Thanks,

Guru

cancel
Showing results for 
Search instead for 
Did you mean: