Hi, 
I am writing backend service. The goal is to fetch proto-buf data from 
another API,  parse it and send back from my backend service. But I am 
getting some exceptions.

>From another API: proto-buf message is received after sending header: 
"Accept: application/x-protobuf" and json format is received after sending 
header: "Accept: application/json".

In my backend service, I have proto files and also created corresponding 
java files as well. I want to return the response in proto and json as per 
Accept header after calling another API. I am getting exceptions as 
follows:-

*Case-1*: As per protobuf documentation -> 
<GeneratedJavaFile>.parseFrom(okHttp3 httpResponse.body.bytes())
*Exception*: *com.google.protobuf.InvalidProtocolBufferException: While 
parsing a protocol message, the input ended unexpectedly in the middle of a 
field.  This could mean either that the input has been truncated or that an 
embedded message misreported its own length. *
*Remark: *Similar happened for inputStream as well If I try to convert 
response into byteStream().

*Case-2:*  
<GeneratedJavaFile>.Builder res = <GeneratedJavaFile>.newBuilder();
JsonFormat.parser().merge(okHttp3 httpResponse.body.string(), res);
Exception: Then also I am getting exception.

----
Kindly help as I have tried all other options available on net. Let me know 
if you need any other info.

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/9c4557db-922e-44b8-9628-81557a80cc76n%40googlegroups.com.

Reply via email to