Thread
#serialization
    coolchandrakumar

    coolchandrakumar

    1 year ago
    Facing the exception while trying to convert json to protoBuf message using parseFrom() method
    com.google.protobuf.InvalidProtocolBufferException: While parsing a protocol message, the input ended unexpectedly in the middle of a field.
    at com.google.protobuf.GeneratedMessageLite.parsePartialFrom(GeneratedMessageLite.java:1563)
    Android Project using protobuf lite plugin
    try {
        //val stream = assets.open("JsonData.json")
        val jsonString = "{\"platform\":\"chan\"}"
        val chanData = ChanDataProto.ChanData.parseFrom(jsonString.encodeToByteArray())
        Log.d("ChanLog", "Value: ${chanData.platform}")
    } catch (ex: Exception) {
        ex.printStackTrace()
    }
    Proto
    syntax = "proto3";
    
    package tutorial;
    
    option java_package = "com.chan.chanprotobuf";
    option java_outer_classname = "ChanDataProto";
    
    message ChanData {
      string platform = 1;
    }
    Json
    {
      "platform": "chan"
    }