protobuf-java

NullPointerException in ProtoBuf when Kryo serialization is used with Spark

别来无恙 提交于 2021-02-04 21:06:44
问题 I am getting the following error in my spark application when it is trying to serialize a protobuf field which is a map of key String and value float. Kryo serialization is being used in the spark app. Caused by: java.lang.NullPointerException at com.google.protobuf.UnmodifiableLazyStringList.size(UnmodifiableLazyStringList.java:68) at java.util.AbstractList.add(AbstractList.java:108) at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:134) at com

Protobuf-3: How to resolve missing method “getIdCase()” ? Classes generated with '--experimental_allow_proto3_optional '

北战南征 提交于 2020-12-13 03:04:53
问题 I used the proto3_optional, and getting this xxCase() method missing on field that are 'optional'. Is there a workaround for this? Generated message class "muni.model.Model$Person" missing method "getId Case " NoSuchMethodException: muni.model.Model$Person.getId Case() Note: I need to retain hasXX() method working for validating objects, and JsonFormat.printer(myproto) for deserializing. Proto object message Person{ //Output only optional string id = 3; // "muni.model.Model$Person" missing

Protobuf-3: How to resolve missing method “getIdCase()” ? Classes generated with '--experimental_allow_proto3_optional '

Deadly 提交于 2020-12-13 02:59:16
问题 I used the proto3_optional, and getting this xxCase() method missing on field that are 'optional'. Is there a workaround for this? Generated message class "muni.model.Model$Person" missing method "getId Case " NoSuchMethodException: muni.model.Model$Person.getId Case() Note: I need to retain hasXX() method working for validating objects, and JsonFormat.printer(myproto) for deserializing. Proto object message Person{ //Output only optional string id = 3; // "muni.model.Model$Person" missing

How to log Protobuf string in nested objects in a human-readable way?

不打扰是莪最后的温柔 提交于 2020-07-30 17:24:55
问题 Given a proto file: syntax = "proto3"; package hello; message TopGreeting { NestedGreeting greeting = 1; } message NestedGreeting { Greeting greeting = 1; } message Greeting { string message = 1; } and the code: public class Main { public static void main(String[] args) { System.out.printf("From top: %s%n", newGreeting("오늘은 무슨 요일입니까?")); System.out.printf("Directly: %s%n", "오늘은 무슨 요일입니까?"); System.out.printf("ByteString: %s", newGreeting("오늘은 무슨 요일입니까?").toByteString().toStringUtf8()); }

How to log Protobuf string in nested objects in a human-readable way?

荒凉一梦 提交于 2020-07-30 17:23:36
问题 Given a proto file: syntax = "proto3"; package hello; message TopGreeting { NestedGreeting greeting = 1; } message NestedGreeting { Greeting greeting = 1; } message Greeting { string message = 1; } and the code: public class Main { public static void main(String[] args) { System.out.printf("From top: %s%n", newGreeting("오늘은 무슨 요일입니까?")); System.out.printf("Directly: %s%n", "오늘은 무슨 요일입니까?"); System.out.printf("ByteString: %s", newGreeting("오늘은 무슨 요일입니까?").toByteString().toStringUtf8()); }

How to cast inner classes from Dynamic Message in Protobuf?

为君一笑 提交于 2020-06-29 03:37:54
问题 I am converting my protobuf response ( byte[] ) to Dynamic message by using following code block DynamicMessage message = DynamicMessage.parseFrom((Descriptors.Descriptor type, byte[] data) By using getField() , I am able to get field values in the form of java objects, FieldDescriptor fieldDescriptor = message.getDescriptorForType().findFieldByName("fieldXyz"); Object A = message.getField(fieldDescriptor); But I want to cast the value to original protobuf class. For example in this object A

How to deal with unknown protobuf fields in Java?

人盡茶涼 提交于 2020-06-27 13:08:29
问题 I have a Java application that reads some protobuf data from another computer and can then modify some values and write it back. It is very likely that a user could read the data using an outdated .proto file, so there would be some fields it doesn't understand in this case. I would ultimately like to preserve the uknown data when writing back the changes made; however, I could settle for just detecting that there is unknown data (to prompt the user to upgrade his/her application). It is not

In a proto, how can I define a map as a custom option

試著忘記壹切 提交于 2020-04-16 02:43:24
问题 In my proto file, I want to define a map as a custom option, tried a few things but none is working. my metadata proto file: syntax = "proto2"; import "google/protobuf/descriptor.proto"; package com.util; option java_package = "com.util"; message MyMeta { optional bool needValidation = 1; map<string, string> fileMap = 2; } extend google.protobuf.FieldOptions { optional MyMeta meta = 80412; } my proto file syntax = "proto3"; package com.test; import "util/meta.proto"; import "google/protobuf

The method emptyIntList() is undefined

被刻印的时光 ゝ 提交于 2019-12-24 10:24:42
问题 I am new to Google Protobuf . Tried to play with it using below student.proto file. syntax = "proto3"; package rld; option java_package = "com.rld"; option java_outer_classname = "StudentDTO"; message Student { string name = 1; int32 roll = 2; repeated int32 mark = 3; //Marks in various subjects } message StudentDatabase { repeated Student student = 1; } Then I tried to compile it using below Protobuf compiler command. From here, I downloaded the compiler. protoc -I=. --java_out=. ./student

How can I add my own code to JAVA generated classes from proto file?

牧云@^-^@ 提交于 2019-12-24 07:16:11
问题 I'm using protobuf and I'm generating JAVA classes from the following proto file. syntax = "proto3"; enum Greeting { NONE = 0; MR = 1; MRS = 2; MISS = 3; } message Hello { Greeting greeting = 1; string name = 2; } message Bye { string name = 1; } option java_multiple_files = true; Now I need to add some code to the generated files and I found that is possible using a custom plugin (https://developers.google.com/protocol-buffers/docs/reference/java-generated#plugins). I'm trying to generate