标签: protobuf-java

原始数据存储 jetpack compose - gradle 依赖项异常

我从 Android 开发者平台关注了这个 Codelab:https ://developer.android.com/codelabs/android-proto-datastore#4

添加了与 Codelab 中所示完全相同的依赖项,在尝试同步时出现以下 gradle 异常

A problem occurred configuring project ':app'.

Could not get unknown property 'source' for generate-proto-generateDebugProto of type org.gradle.api.internal.file.DefaultSourceDirectorySet.
  at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:125)
  at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:42)

Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'source' for generate-proto-generateDebugProto of type org.gradle.api.internal.file.DefaultSourceDirectorySet.
  at com.google.protobuf.gradle.ProtobufPlugin$_linkGenerateProtoTasksToSourceCompile_closure25$_closure39.doCall(ProtobufPlugin.groovy:472)
  at com.google.protobuf.gradle.ProtobufPlugin$_linkGenerateProtoTasksToSourceCompile_closure25.doCall(ProtobufPlugin.groovy:469)
  at com.google.protobuf.gradle.ProtobufPlugin.linkGenerateProtoTasksToSourceCompile(ProtobufPlugin.groovy:468)
  at com.google.protobuf.gradle.ProtobufPlugin$_doApply_closure5.doCall(ProtobufPlugin.groovy:153)
  at jdk.proxy1/jdk.proxy1.$Proxy56.afterEvaluate(Unknown Source)
  at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:125)
  at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:42)
Run Code Online (Sandbox Code Playgroud)

我不知道问题是什么,尝试升级 Codelab 中显示的版本,到处查找问题,但似乎找不到任何经历过同样事情的人。任何想法?

android-gradle-plugin protobuf-java android-jetpack-compose android-jetpack-datastore

14
推荐指数
1
解决办法
3425
查看次数

从 protobuf 消息中删除现有字段是否会导致问题?

我收到一条 protobuf 消息 -

message Sample{
    string field1 = 1;
    string field2 = 2;
    string field3 = 3;
}
Run Code Online (Sandbox Code Playgroud)

这些消息以二进制格式存储在数据存储中。因此,如果我想删除上述消息中的任何定义字段,是否会导致从数据存储区反序列化消息时出现任何问题?

serialization protocol-buffers binary-serialization deserialization protobuf-java

13
推荐指数
1
解决办法
2万
查看次数

将json转换为Java中动态生成的protobuf

鉴于以下json响应:

{
    "id" : "123456",
    "name" : "John Doe",
    "email" : "john.doe@example.com"
}
Run Code Online (Sandbox Code Playgroud)

以下user.proto文件:

message User {
    string id = 1;
    string name = 2;
    string email = 3;
}
Run Code Online (Sandbox Code Playgroud)

我想有可能动态创建protobuf消息类(在运行时编译.proto),这样如果json响应通过字段得到增强,"phone" : "+1234567890"我可以上传一个新版本的protobuf文件来包含string phone = 4并得到它protobuf响应中暴露的字段,没有重新启动服务.

如果我要从帽子中提取这些类,我希望能够在下面的代码中写一些东西.

import com.googlecode.protobuf.format.JsonFormat;
import com.googlecode.protobuf.Message;
import org.apache.commons.io.FileUtils;

...

public Message convertToProto(InputStream jsonInputStream){
    // get the latest user.proto file
    String userProtoFile = FileUtils.readFileToString("user.proto");

    Message userProtoMessage = com.acme.ProtobufUtils.compile(userProtoFile);
    Message.Builder builder = userProtoMessage.newBuilderForType(); 
    new JsonFormat().merge(inputStream, Charset.forName("UTF-8"), builder);
    return builder.build();
}
Run Code Online (Sandbox Code Playgroud)

是否存在com.acme.ProtobufUtils.compile(...)方法?或者如何实现一个?运行protoc …

java protocol-buffers protobuf-java google-protocol-buffer

12
推荐指数
1
解决办法
1342
查看次数

String 构造函数中缺少边界检查消除?

查看 UTF8 解码性能,我注意到 protobuf 的性能UnsafeProcessor::decodeUtf8优于String(byte[] bytes, int offset, int length, Charset charset)以下非 ascii 字符串:"Quizdeltagerne spiste jordb\xc3\xa6r med fl\xc3\x98de, mens cirkusklovnen"

\n

我试图找出原因,所以我复制了相关代码,String并将数组访问替换为不安全的数组访问,与 相同UnsafeProcessor::decodeUtf8。\n以下是 JMH 基准测试结果:

\n
Benchmark                       Mode  Cnt    Score   Error  Units\nStringBenchmark.safeDecoding    avgt   10  127.107 \xc2\xb1 3.642  ns/op\nStringBenchmark.unsafeDecoding  avgt   10  100.915 \xc2\xb1 4.090  ns/op\n
Run Code Online (Sandbox Code Playgroud)\n

我认为差异是由于缺少边界检查消除而导致的,特别是因为checkBoundsOffCount(offset, length, bytes.length)String(byte[] bytes, int offset, int length, Charset charset).

\n

这个问题真的是缺少边界检查消除吗?

\n

这是我使用 OpenJDK 17 和 JMH 进行基准测试的代码。请注意,这只是String(byte[] bytes, …

performance jit jvm-hotspot bounds-check-elimination protobuf-java

11
推荐指数
1
解决办法
445
查看次数

解决 Firebase InApp Messasing 和 Dialogflow 依赖项

我有一个项目,我同时使用 FirebaseInAppMessaging 和 Dialogflow,但我很难解决依赖关系。添加 FirebaseInAppMessaging 和 Dialogflow 后,出现以下错误:

Duplicate class com.google.protobuf.AbstractMessageLite found in the following modules: jetified-protobuf-java-3.11.3.jar (com.google.protobuf:protobuf-java:3.11.3), jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in the following modules: jetified-protobuf-java-3.11.3.jar (com.google.protobuf:protobuf-java:3.11.3), jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream found in the following modules: jetified-protobuf-java-3.11.3.jar (com.google.protobuf:protobuf-java:3.11.3), jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractMessageLite$InternalOneOfEnum found in modules jetified-protobuf-java-3.11.3.jar (com.google.protobuf:protobuf-java:3.11.3) and jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0)
Duplicate class com.google.protobuf.AbstractParser found in the following modules: jetified-protobuf-java-3.11.3.jar (com.google.protobuf:protobuf-java:3.11.3), jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate …
Run Code Online (Sandbox Code Playgroud)

android firebase protobuf-java dialogflow-es firebase-in-app-messaging

8
推荐指数
1
解决办法
1228
查看次数

Java中如何处理未知的protobuf字段?

我有一个 Java 应用程序,它从另一台计算机读取一些 protobuf 数据,然后修改一些值并将其写回。用户很可能使用过时的 .proto 文件读取数据,因此在这种情况下会有一些字段无法理解。我最终希望在写回所做的更改时保留未知的数据;但是,我可以满足于仅检测到存在未知数据(以提示用户升级他/她的应用程序)。我不清楚如何处理 Java 中的未知字段。

如果有帮助,我正在使用版本 2 .proto 文件,因为我需要它与远程计算机上的 nanopb 兼容。

这个问题让我明白了一些,但我的问题与 JSON 无关。

java protocol-buffers protobuf-java

7
推荐指数
1
解决办法
8806
查看次数

使用Protobufs的批处理技术

是否有一种有效的技术可以通过HTTP发送批处理不同的Protobuf事件?

目标是在一个请求中列出多种类型的Protobuf消息。我的一个想法是将消息分成小数组,然后指定消息的类型,以便能够在服务器上反序列化它们。

serialization http protocol-buffers protobuf-net protobuf-java

7
推荐指数
1
解决办法
76
查看次数

R8 minify 上的问题

我安装了新版本的 Android Studio 并更新了我的项目(不更改依赖项),但遇到了以下问题:

Missing class com.google.protobuf.java_com_google_android_gmscore_sdk_target_granule__proguard_group_gtm_N1281923064GeneratedExtensionRegistryLite$Loader (referenced from: java.util.List kotlinx.coroutines.internal.FastServiceLoader.load(java.lang.Class, java.lang.ClassLoader))
Missing class org.bouncycastle.jsse.BCSSLParameters (referenced from: void okhttp3.internal.platform.BouncyCastlePlatform.configureTlsExtensions(javax.net.ssl.SSLSocket, java.lang.String, java.util.List) and 1 other context)
Missing class org.bouncycastle.jsse.BCSSLSocket (referenced from: void okhttp3.internal.platform.BouncyCastlePlatform.configureTlsExtensions(javax.net.ssl.SSLSocket, java.lang.String, java.util.List) and 5 other contexts)
Missing class org.bouncycastle.jsse.provider.BouncyCastleJsseProvider (referenced from: void okhttp3.internal.platform.BouncyCastlePlatform.<init>())
Missing class org.conscrypt.Conscrypt$Version (referenced from: boolean okhttp3.internal.platform.ConscryptPlatform$Companion.atLeastVersion(int, int, int))
Missing class org.conscrypt.Conscrypt (referenced from: boolean okhttp3.internal.platform.ConscryptPlatform$Companion.atLeastVersion(int, int, int) and 4 other contexts)
Missing class org.conscrypt.ConscryptHostnameVerifier (referenced from: okhttp3.internal.platform.ConscryptPlatform$DisabledHostnameVerifier)
Missing class org.openjsse.javax.net.ssl.SSLParameters (referenced from: void okhttp3.internal.platform.OpenJSSEPlatform.configureTlsExtensions(javax.net.ssl.SSLSocket, …
Run Code Online (Sandbox Code Playgroud)

android okhttp protobuf-java android-r8 kotlin-coroutines

7
推荐指数
1
解决办法
2454
查看次数

我应该将 gRPC protobuf 消息转换为 DTO 吗?- 最佳实践

最近,我开始使用 gRPC 消息与微服务交互。到目前为止,我一直在使用带有 DTO 的 REST API,并在代码本身中不断进行解耦和封装。

现在,我在使用 gRPC protobuf 消息时,我开始想知道什么 shell 是这里的最佳实践 - 在大声思考时,我会说,当在应用程序的入口点获取消息时,最好是将其转换从另一个角度来看,我只是将对象转换为对象,并想知道这些开销是否是强制性/必需的

期待您对此的想法:)

java design-patterns grpc protobuf-java

6
推荐指数
1
解决办法
4719
查看次数

拨 tcp 127.0.0.1:9091: 连接: 连接被拒绝

我正在使用 gRPC 应用程序并构建一个简单的应用程序。在文件下面。

syntax = "proto3";
option java_multiple_files = true;
package com.grpc;

message HelloRequest {
    string firstName = 1;
    string lastname = 2;
}
message HelloResponse {
    string greeting = 1;
}
service HelloService {
    rpc hello(HelloRequest) returns (HelloResponse);
}
Run Code Online (Sandbox Code Playgroud)

它正常生成文件

User.java -> generated from protoc compiler
userGrpc.java -> generated from protoc compiler
Run Code Online (Sandbox Code Playgroud)

GRPC服务.java

package GRPCService;

import java.io.IOException;

import io.grpc.Server;
import io.grpc.ServerBuilder;
import user.UserService;

public class GPRCService {
    public static void main(String[] args) throws IOException, InterruptedException {
        Server server = …
Run Code Online (Sandbox Code Playgroud)

ubuntu protocol-buffers grpc grpc-java protobuf-java

6
推荐指数
1
解决办法
1万
查看次数