Here is the contents of the .proto file

syntax = "proto3";


package keepalive;


option go_package = "github.com/App/proto/keepalive";
option java_package = "com.app.proto.keepalive";
option java_outer_classname = "KeepAliveAlertIndicator";


import "google/protobuf/timestamp.proto";


// This is used for both: sending and receiving a alert heartbeat
message AlertIndicator {
   google.protobuf.Timestamp sent_time = 1;
   string match_id = 2;
   string to_user_id = 3;
}


On Saturday, January 5, 2019 at 3:43:13 PM UTC-5, [email protected] wrote:
>
> 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.

Reply via email to