forked from TrueCloudLab/frostfs-api-go
[#168] session: Implement binary/JSON encoders/decoders on ResponseVerify
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>support/v2.15
parent
edf6ec05b3
commit
6456fcf8fa
|
@ -164,3 +164,23 @@ func (r *ResponseMetaHeader) UnmarshalJSON(data []byte) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *ResponseVerificationHeader) MarshalJSON() ([]byte, error) {
|
||||
return protojson.MarshalOptions{
|
||||
EmitUnpopulated: true,
|
||||
}.Marshal(
|
||||
ResponseVerificationHeaderToGRPCMessage(r),
|
||||
)
|
||||
}
|
||||
|
||||
func (r *ResponseVerificationHeader) UnmarshalJSON(data []byte) error {
|
||||
msg := new(session.ResponseVerificationHeader)
|
||||
|
||||
if err := protojson.Unmarshal(data, msg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*r = *ResponseVerificationHeaderFromGRPCMessage(msg)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -102,3 +102,15 @@ func TestResponseMetaHeaderJSON(t *testing.T) {
|
|||
|
||||
require.Equal(t, r, r2)
|
||||
}
|
||||
|
||||
func TestResponseVerificationHeaderJSON(t *testing.T) {
|
||||
r := generateResponseVerificationHeader("key", "value")
|
||||
|
||||
data, err := r.MarshalJSON()
|
||||
require.NoError(t, err)
|
||||
|
||||
r2 := new(session.ResponseVerificationHeader)
|
||||
require.NoError(t, r2.UnmarshalJSON(data))
|
||||
|
||||
require.Equal(t, r, r2)
|
||||
}
|
||||
|
|
|
@ -745,3 +745,14 @@ func (r *ResponseVerificationHeader) StableSize() (size int) {
|
|||
|
||||
return size
|
||||
}
|
||||
|
||||
func (r *ResponseVerificationHeader) Unmarshal(data []byte) error {
|
||||
m := new(session.ResponseVerificationHeader)
|
||||
if err := goproto.Unmarshal(data, m); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*r = *ResponseVerificationHeaderFromGRPCMessage(m)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -166,16 +166,14 @@ func TestResponseVerificationHeader_StableMarshal(t *testing.T) {
|
|||
verifHeaderOrigin := generateResponseVerificationHeader("Key", "Inside")
|
||||
verifHeaderFrom := generateResponseVerificationHeader("Value", "Outside")
|
||||
verifHeaderFrom.SetOrigin(verifHeaderOrigin)
|
||||
transport := new(grpc.ResponseVerificationHeader)
|
||||
|
||||
t.Run("non empty", func(t *testing.T) {
|
||||
wire, err := verifHeaderFrom.StableMarshal(nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = goproto.Unmarshal(wire, transport)
|
||||
require.NoError(t, err)
|
||||
verifHeaderTo := new(session.ResponseVerificationHeader)
|
||||
require.NoError(t, verifHeaderTo.Unmarshal(wire))
|
||||
|
||||
verifHeaderTo := session.ResponseVerificationHeaderFromGRPCMessage(transport)
|
||||
require.Equal(t, verifHeaderFrom, verifHeaderTo)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue