[#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:
Evgenii Stratonikov 2024-12-26 10:03:55 +03:00
parent bab4d5a692
commit 328d214d2d
Signed by: fyrchik
SSH key fingerprint: SHA256:m/TTwCzjnRkXgnzEx9X92ccxy1CcVeinOgDb3NPWWmg
110 changed files with 47773 additions and 37555 deletions

View file

@ -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)
}