[#276] Merge repo with frostfs-api-go
Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
This commit is contained in:
parent
5361f0eceb
commit
6ce73790ea
337 changed files with 66666 additions and 283 deletions
40
api/rpc/message/encoding.go
Normal file
40
api/rpc/message/encoding.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package message
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// GRPCConvertedMessage is an interface
|
||||
// of the gRPC message that is used
|
||||
// for Message encoding/decoding.
|
||||
type GRPCConvertedMessage interface {
|
||||
UnmarshalProtobuf([]byte) error
|
||||
}
|
||||
|
||||
// Unmarshal decodes m from its Protobuf binary representation
|
||||
// via related gRPC message.
|
||||
//
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
|
||||
return m.FromGRPCMessage(gm)
|
||||
}
|
||||
|
||||
// MarshalJSON encodes m to Protobuf JSON representation.
|
||||
func MarshalJSON(m Message) ([]byte, error) {
|
||||
return json.Marshal(m.ToGRPCMessage())
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
return m.FromGRPCMessage(gm)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue