sofastack / sofa-jraft

A production-grade java implementation of RAFT consensus algorithm.
https://www.sofastack.tech/projects/sofa-jraft/
Apache License 2.0
3.56k stars 1.14k forks source link

计数器用grpc运行 #1015

Closed chenzhanpeng closed 2 weeks ago

chenzhanpeng commented 1 year ago

计数器这个demo 我通过spi配置成grpc,就能用了,有一点不明白的是,例子中反序列化数据 counterOperation = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( data.array(), CounterOperation.class.getName());,这外不是默认协议用的序列化方式吗,为啥grpc也能用

fengjiachun commented 1 year ago

这只是把 bytes 解析成 CounterOperation,gRPC 用的是 Protobuf,但是在 gRPC 的 Protobuf 中只看到了 bytes,大致是这个样子:

message CounterOperation {
  bytes data = 1;
}

上面的 data 字段使用 Hessian2 序列化成 bytes 的,Protobuf 只看到 bytes