I'm trying to parse some data into my Java proto class that's coming in
from OkHttp WebSocket connection
Below is what I have
@Override
public void onMessage(WebSocket webSocket, ByteString bytes) {
System.out.println("Alert notification");
byte[] alertNotificationByteArray = bytes.toByteArray();
try {
AlertIndicator alertIndicator = KeepAliveAlertIndicator.AlertIndicator
.parseFrom(alertNotificationByteArray);
Map < FieldDescriptor, Object > alertIndicatorMap =
alertIndicator.getAllFields();
System.out.println("Match Id: " + alertIndicator.getMatchId());
System.out.println("To Id: " + alertIndicator.getToUserId());
System.out.println("Timestamp: " + alertIndicator.getSentTime());
System.out.println("Match Id: " + alertIndicator.getMatchIdBytes());
System.out.println("To Id: " + alertIndicator.getToUserIdBytes());
System.out.println("Timestamp: " + alertIndicator.getSentTime());
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
But the results are empty. I was doing research and it looks like there is
also a Parser interface and a MessageLite interface. Are they things I need
to be using? Am I doing anything wrong in my code?
--
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.