天道酬勤,学无止境

protobuf-java

How to use protobuf message as java class without a java outer class?

I want to generate java class with My.proto: package com.my.test; option java_package = "com.my.test"; message MyError { optional string value = 11; optional string name = 12; } message MyRequest { optional string myid = 1; optional string yourid = 2; } After use protoc --java_out=./ My.proto, there will be: com.my.test.My.java package com.my.test; public class My { public static class MyError {} public static class MyRequest {} } How could I generate java class like: package com.my.test; public class MyError {} and package com.my.test; public class MyRequest {}

2022-04-30 19:35:35    分类:问答    java   protobuf-java

grpc/protobuffer ask for specific fields

GraphQL lets you ask for specific fields, the response contains only the fields that you had asked for. For example: a graphql query like: { hero { name } } will return: { "data": { "hero": { "name": "R2-D2" } } } where as a graphQl query like: { hero { name friends { name } } } would return: { "data": { "hero": { "name": "R2-D2", "friends": [ { "name": "Luke" }, { "name": "Han Solo" }, { "name": "Leia" } ] } } } Is there a similar mechanism/library/pattern that can be used in gRPC to achieve the same?

2022-04-16 21:52:55    分类:问答    protocol-buffers   grpc   grpc-java   protobuf-java

Release build fails

I'm trying to build a signed version (release version) and i got the following error Duplicate zip entry [com/google/protobuf/d$1.class == com/google/protobuf/Any$1.class] I tried to clean,invalidate,and delete gradle files and rebuild it. also updated to the latest version of the gRPC versions and protobuf. Tried this solution too but not working. Here is my build.gradle (app module) file apply plugin: 'com.android.application' apply plugin: 'com.google.protobuf' apply plugin: 'io.fabric' ext { supportLibraryVersion = '27.1.1' grpcVersion = '1.13.1' googlePlayVersion = '15.0.1'

2022-03-17 10:29:51    分类:问答    java   android   android-studio   grpc   protobuf-java

在原型中,如何将地图定义为自定义选项(In a proto, how can I define a map as a custom option)

问题 在我的 proto 文件中,我想将地图定义为自定义选项,尝试了一些方法,但都没有奏效。 我的元数据原型文件: 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; } 我的原型文件 syntax = "proto3"; package com.test; import "util/meta.proto"; import "google/protobuf/timestamp.proto"; message MyMeta { int32 id = 1 [(com.util.meta).needValidation = false, /*looking for a way to set a map (com.meta).tableOptions = {"t,raw_orders"}]*/; } 这可能吗?

2022-02-07 18:29:51    分类:技术分享    protocol-buffers   protobuf-net   proto   protobuf-java   protobuf.js

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

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/timestamp.proto"; message MyMeta { int32 id = 1 [(com.util.meta).needValidation = false, /*looking for a

2022-01-21 10:34:11    分类:问答    protocol-buffers   protobuf-net   proto   protobuf-java   protobuf.js

地图列表使用 Mapstruct 从 Java POJO 到 Protobuf (proto3)(Map List<String> with Mapstruct from Java POJO to Protobuf (proto3))

问题 我正在尝试将一些 POJO 从 Java 映射到 Protobuf (proto3)。 其中一些包含列表。 虽然使用 POJO(例如 List)映射列表没有问题,但我得到了 UnsupportedOperationException。 List<Product>示例(这工作正确): ProductProtobuf.Builder map(Product product); @Mapping(target = "productsList", source = "products") ResponseProtobuf.Builder map(Response response); List<String>示例(这不起作用): @Mapping(target = "usersList", source = "users") ResponseProtobuf.Builder map(Response response); 此外,我有一些用于构建器的 Mapper: public ResponseProtobuf.Builder responseBuilder() { return ResponseProtobuf.newBuilder(); } public ProductProtobuf build(ProductProtobuf.Builder builder) { return

2022-01-15 14:27:32    分类:技术分享    java   protocol-buffers   mapstruct   proto3   protobuf-java

Map List<String> with Mapstruct from Java POJO to Protobuf (proto3)

I'm trying to map some POJOs from Java to Protobuf (proto3). Some of them contain Lists. While mapping lists with POJOs (for example List) is no problem, I'm getting a UnsupportedOperationException. Example with List<Product> (this works corrctly): ProductProtobuf.Builder map(Product product); @Mapping(target = "productsList", source = "products") ResponseProtobuf.Builder map(Response response); Example with List<String> (this doesn't work): @Mapping(target = "usersList", source = "users") ResponseProtobuf.Builder map(Response response); Additionally, I have some Mapper for builder: public

2022-01-09 05:31:35    分类:问答    java   protocol-buffers   mapstruct   proto3   protobuf-java

如何以人类可读的方式在嵌套对象中记录 Protobuf 字符串?(How to log Protobuf string in nested objects in a human-readable way?)

问题 给定一个 proto 文件: syntax = "proto3"; package hello; message TopGreeting { NestedGreeting greeting = 1; } message NestedGreeting { Greeting greeting = 1; } message Greeting { string message = 1; } 和代码: 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()); } private static Hello.TopGreeting newGreeting(String message) { Hello.Greeting greeting = Hello.Greeting.newBuilder()

2021-12-23 23:37:53    分类:技术分享    serialization   protocol-buffers   protobuf-java

Protobuf InvalidProtocolBufferException with some strings

We using protobuf v.3 to transfer messages from C# client to Java server over HTTP. The message proto looks like this: message CLIENT_MESSAGE { string message = 1; } Both client and server uses UTF-8 character encoding for strings. Everything is fine whe we are using short string values like "abc", but when we trying to transfer string with 198 chars in it, we catchig an Exception: com.google.protobuf.InvalidProtocolBufferException: While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either that the input has been truncated or that an

2021-12-20 09:56:14    分类:问答    protocol-buffers   protobuf-csharp-port   protobuf-java

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

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()); } private static Hello.TopGreeting newGreeting(String message) { Hello.Greeting greeting = Hello.Greeting

2021-11-26 02:38:31    分类:问答    serialization   protocol-buffers   protobuf-java