天道酬勤,学无止境

protobuf-java

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

Question 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 "getIdCase" NoSuchMethodException: muni.model.Model$Person.getIdCase() 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 method "getIdCase" optional string firstName = 4; // optional added to test hasFirstName() optional

2021-10-30 16:04:08    分类:技术分享    protocol-buffers   protobuf-java

The method emptyIntList() is undefined

Question 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.proto It compiled successfully and generated StudentDTO.java, but with errors. There are two

2021-10-24 14:54:06    分类:技术分享    protobuf-java   google-protocol-buffer

Dependencies for Protoc Java plugin?

Question I'm trying to make working example at How to write a custom Protobuf CodeGenerator in Java . When I try to compile a file with import com.google.protobuf.compiler.PluginProtos; import java.io.IOException; public class MyPlugin { public static void main(String[] args) throws IOException { CodeGenerator gen = new CodeGenerator(); PluginProtos.CodeGeneratorRequest codeGeneratorRequest = PluginProtos.CodeGeneratorRequest.parseFrom(System.in); codeGeneratorRequest.getProtoFileList().forEach(gen::handleFile); // get the response and do something with it //PluginProtos.CodeGeneratorResponse

2021-10-23 22:27:49    分类:技术分享    java   protocol-buffers   protoc   protobuf-java

Protocol Buffers: How to parse a .proto file in Java

Question I am trying to dynamically parse a given .proto file in Java to decode a Protobuf-encoded binary. I have the following parsing method, in which the "proto" string contains the content of the .proto file: public static Descriptors.FileDescriptor parseProto (String proto) throws InvalidProtocolBufferException, Descriptors.DescriptorValidationException { DescriptorProtos.FileDescriptorProto descriptorProto = DescriptorProtos.FileDescriptorProto.parseFrom(proto.getBytes()); return Descriptors.FileDescriptor.buildFrom(descriptorProto, null); } Though, on execution the previous method

2021-10-20 15:04:24    分类:技术分享    java   protocol-buffers   protobuf-java