protobuf3二进制数据转java对象  
   
所属分类 temporal
浏览量 1148
temporal server namespaces 表
select * from information_schema.columns where table_name='namespaces'
data字段  类型 bytea , 二进制类型
保存的是 persistencespb.NamespaceDetail 的 protobuf3 二进制数据
根据 .proto文件生成 java 对象
import 的 proto 文件必须存在 
//  来自 google protoc 工具的 include 目录
//  protoc-3.19.1-osx-x86_64/include/google/protobuf
//  protobuf-java-3.19.3.jar 里也有
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
//  https://github.com/gogo/protobuf/tree/master/gogoproto
import "dependencies/gogoproto/gogo.proto";
//  来自 temporal-serviceclient-1.8.1.jar
import "temporal/api/enums/v1/namespace.proto";
import "temporal/api/namespace/v1/message.proto";
temporal/proto
 internal
 dependencies
 temporal
 google
Temporal gRPC API and proto files compiled for Go
https://github.com/temporalio/api-go
实用 protoc ,根据 .proto文件 生成java文件 ,用于 java对象 和 protobuf3的序列化和反序列化
 
protoc --java_out=/OUTPUT_DIR  internal/temporal/server/api/persistence/v1/namespaces.proto
/Users/dugang/work/temporal/temporal/proto
protoc  --proto_path=. --proto_path=./internal --java_out=/Users/dugang/tmp/  internal/temporal/server/api/persistence/v1/executions.proto
--proto_path 指定搜索路径 ,可指定多个 
同时编译多个 
同时编译多个文件
path/to/xxx.proto 改为 path/to/*.proto
message NamespaceReplicationConfig {
    string active_cluster_name = 1;
    repeated string clusters = 2;
    // internal/temporal/server/api/persistence/v1/namespaces.proto:67:5: "temporal.api.enums.v1.ReplicationState" is not defined.
    // temporal.api.enums.v1.ReplicationState state = 3;
}
没找到 ReplicationState 对应的 .proto文件  ,先注释掉
生成java文件
temporal.server.api.persistence.v1.Namespaces
找不到的类和方法先注释掉
com.google.protobuf.GoGoProtos.getDescriptor()
registry.add(com.google.protobuf.GoGoProtos.stdduration);
registry.add(com.google.protobuf.GoGoProtos.stdtime);
com.google.protobuf.GoGoProtos.getDescriptor();
把 protobuf3 二进制数据转成java 对象
// read from namespaces 
byte[] bytes = ...
Namespaces.NamespaceDetail  namespaceDetail = Namespaces.NamespaceDetail.parseFrom(bytes);
System.out.println(namespaceDetail.toString());
		
 temporal namespace 创建和更新关键代码  
 protobuf 简介 及 java实例    
 上一篇  
   
 下一篇  
 temporal workflow 列表 关键代码 
 go 单引号 双引号 反引号 
 GO json 序列化与反序列化 
 PostgreSQL 连接信息查询 
 temporal 代码阅读记录 
 temporal namespace 信息获取 关键代码及堆栈信息