forked from TrueCloudLab/frostfs-sdk-go
[#317] api: Revert easyproto marshaler usage
It has caused a noticeable degradation in node. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
bab4d5a692
commit
328d214d2d
110 changed files with 47773 additions and 37555 deletions
|
@ -1,14 +1,17 @@
|
|||
package message
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/rpc/grpc"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// GRPCConvertedMessage is an interface
|
||||
// of the gRPC message that is used
|
||||
// for Message encoding/decoding.
|
||||
type GRPCConvertedMessage interface {
|
||||
UnmarshalProtobuf([]byte) error
|
||||
grpc.Message
|
||||
proto.Message
|
||||
}
|
||||
|
||||
// Unmarshal decodes m from its Protobuf binary representation
|
||||
|
@ -16,7 +19,7 @@ type GRPCConvertedMessage interface {
|
|||
//
|
||||
// gm should be tof the same type as the m.ToGRPCMessage() return.
|
||||
func Unmarshal(m Message, data []byte, gm GRPCConvertedMessage) error {
|
||||
if err := gm.UnmarshalProtobuf(data); err != nil {
|
||||
if err := proto.Unmarshal(data, gm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -25,16 +28,21 @@ func Unmarshal(m Message, data []byte, gm GRPCConvertedMessage) error {
|
|||
|
||||
// MarshalJSON encodes m to Protobuf JSON representation.
|
||||
func MarshalJSON(m Message) ([]byte, error) {
|
||||
return json.Marshal(m.ToGRPCMessage())
|
||||
return protojson.MarshalOptions{
|
||||
EmitUnpopulated: true,
|
||||
}.Marshal(
|
||||
m.ToGRPCMessage().(proto.Message),
|
||||
)
|
||||
}
|
||||
|
||||
// UnmarshalJSON decodes m from its Protobuf JSON representation
|
||||
// via related gRPC message.
|
||||
//
|
||||
// gm should be tof the same type as the m.ToGRPCMessage() return.
|
||||
func UnmarshalJSON(m Message, data []byte, gm any) error {
|
||||
if err := json.Unmarshal(data, gm); err != nil {
|
||||
func UnmarshalJSON(m Message, data []byte, gm GRPCConvertedMessage) error {
|
||||
if err := protojson.Unmarshal(data, gm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return m.FromGRPCMessage(gm)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue