forked from TrueCloudLab/frostfs-api-go
Merge pull request #68 from nspcc-dev/stringify-object-method
object: Stringily method
This commit is contained in:
commit
72a71e6a94
5 changed files with 362 additions and 61 deletions
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
||||||
PROTO_VERSION=v0.7.2
|
PROTO_VERSION=v0.7.3
|
||||||
PROTO_URL=https://github.com/nspcc-dev/neofs-api/archive/$(PROTO_VERSION).tar.gz
|
PROTO_URL=https://github.com/nspcc-dev/neofs-api/archive/$(PROTO_VERSION).tar.gz
|
||||||
|
|
||||||
B=\033[0;1m
|
B=\033[0;1m
|
||||||
|
|
118
object/types.go
118
object/types.go
|
@ -3,10 +3,14 @@ package object
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"github.com/nspcc-dev/neofs-api-go/internal"
|
"github.com/nspcc-dev/neofs-api-go/internal"
|
||||||
"github.com/nspcc-dev/neofs-api-go/refs"
|
"github.com/nspcc-dev/neofs-api-go/refs"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -262,3 +266,117 @@ func (m Object) Address() *refs.Address {
|
||||||
CID: m.SystemHeader.CID,
|
CID: m.SystemHeader.CID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m CreationPoint) String() string {
|
||||||
|
return fmt.Sprintf(`{UnixTime=%d Epoch=%d}`, m.UnixTime, m.Epoch)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stringify converts object into string format.
|
||||||
|
func Stringify(dst io.Writer, obj *Object) error {
|
||||||
|
// put empty line
|
||||||
|
if _, err := fmt.Fprintln(dst); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// put object line
|
||||||
|
if _, err := fmt.Fprintln(dst, "Object:"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// put system headers
|
||||||
|
if _, err := fmt.Fprintln(dst, "\tSystemHeader:"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
sysHeaders := []string{"ID", "CID", "OwnerID", "Version", "PayloadLength", "CreatedAt"}
|
||||||
|
v := reflect.ValueOf(obj.SystemHeader)
|
||||||
|
for _, key := range sysHeaders {
|
||||||
|
if !v.FieldByName(key).IsValid() {
|
||||||
|
return errors.Errorf("invalid system header key: %q", key)
|
||||||
|
}
|
||||||
|
|
||||||
|
val := v.FieldByName(key).Interface()
|
||||||
|
if _, err := fmt.Fprintf(dst, "\t\t- %s=%v\n", key, val); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// put user headers
|
||||||
|
if _, err := fmt.Fprintln(dst, "\tUserHeaders:"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, header := range obj.Headers {
|
||||||
|
var (
|
||||||
|
typ = reflect.ValueOf(header.Value)
|
||||||
|
key string
|
||||||
|
val interface{}
|
||||||
|
)
|
||||||
|
|
||||||
|
switch t := typ.Interface().(type) {
|
||||||
|
case *Header_Link:
|
||||||
|
key = "Link"
|
||||||
|
val = fmt.Sprintf(`{Type=%s ID=%s}`, t.Link.Type, t.Link.ID)
|
||||||
|
case *Header_Redirect:
|
||||||
|
key = "Redirect"
|
||||||
|
val = fmt.Sprintf(`{CID=%s OID=%s}`, t.Redirect.CID, t.Redirect.ObjectID)
|
||||||
|
case *Header_UserHeader:
|
||||||
|
key = "UserHeader"
|
||||||
|
val = fmt.Sprintf(`{Key=%s Val=%s}`, t.UserHeader.Key, t.UserHeader.Value)
|
||||||
|
case *Header_Transform:
|
||||||
|
key = "Transform"
|
||||||
|
val = t.Transform.Type.String()
|
||||||
|
case *Header_Tombstone:
|
||||||
|
key = "Tombstone"
|
||||||
|
val = "MARKED"
|
||||||
|
case *Header_Token:
|
||||||
|
key = "Token"
|
||||||
|
val = fmt.Sprintf("{"+
|
||||||
|
"ID=%s OwnerID=%s Verb=%s Address=%s Created=%d ValidUntil=%d SessionKey=%02x Signature=%02x"+
|
||||||
|
"}",
|
||||||
|
t.Token.Token_Info.ID,
|
||||||
|
t.Token.Token_Info.OwnerID,
|
||||||
|
t.Token.Token_Info.Verb,
|
||||||
|
t.Token.Token_Info.Address,
|
||||||
|
t.Token.Token_Info.Created,
|
||||||
|
t.Token.Token_Info.ValidUntil,
|
||||||
|
t.Token.Token_Info.SessionKey,
|
||||||
|
t.Token.Signature)
|
||||||
|
case *Header_HomoHash:
|
||||||
|
key = "HomoHash"
|
||||||
|
val = t.HomoHash
|
||||||
|
case *Header_PayloadChecksum:
|
||||||
|
key = "PayloadChecksum"
|
||||||
|
val = t.PayloadChecksum
|
||||||
|
case *Header_Integrity:
|
||||||
|
key = "Integrity"
|
||||||
|
val = fmt.Sprintf(`{Checksum=%02x Signature=%02x}`,
|
||||||
|
t.Integrity.HeadersChecksum,
|
||||||
|
t.Integrity.ChecksumSignature)
|
||||||
|
case *Header_StorageGroup:
|
||||||
|
key = "StorageGroup"
|
||||||
|
val = fmt.Sprintf(`{DataSize=%d Hash=%02x Lifetime={Unit=%s Value=%d}}`,
|
||||||
|
t.StorageGroup.ValidationDataSize,
|
||||||
|
t.StorageGroup.ValidationHash,
|
||||||
|
t.StorageGroup.Lifetime.Unit,
|
||||||
|
t.StorageGroup.Lifetime.Value)
|
||||||
|
case *Header_PublicKey:
|
||||||
|
key = "PublicKey"
|
||||||
|
val = t.PublicKey.Value
|
||||||
|
default:
|
||||||
|
key = "Unknown"
|
||||||
|
val = t
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := fmt.Fprintf(dst, "\t\t- Type=%s\n\t\t Value=%v\n", key, val); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// put payload
|
||||||
|
if _, err := fmt.Fprintf(dst, "\tPayload: %#v\n", obj.Payload); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -516,7 +516,6 @@ type CreationPoint struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *CreationPoint) Reset() { *m = CreationPoint{} }
|
func (m *CreationPoint) Reset() { *m = CreationPoint{} }
|
||||||
func (m *CreationPoint) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*CreationPoint) ProtoMessage() {}
|
func (*CreationPoint) ProtoMessage() {}
|
||||||
func (*CreationPoint) Descriptor() ([]byte, []int) {
|
func (*CreationPoint) Descriptor() ([]byte, []int) {
|
||||||
return fileDescriptor_02021a1d39b1aee0, []int{5}
|
return fileDescriptor_02021a1d39b1aee0, []int{5}
|
||||||
|
@ -826,64 +825,65 @@ func init() {
|
||||||
func init() { proto.RegisterFile("object/types.proto", fileDescriptor_02021a1d39b1aee0) }
|
func init() { proto.RegisterFile("object/types.proto", fileDescriptor_02021a1d39b1aee0) }
|
||||||
|
|
||||||
var fileDescriptor_02021a1d39b1aee0 = []byte{
|
var fileDescriptor_02021a1d39b1aee0 = []byte{
|
||||||
// 909 bytes of a gzipped FileDescriptorProto
|
// 916 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x55, 0x4f, 0x8f, 0xdb, 0x44,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x55, 0x4f, 0x8f, 0xdb, 0x44,
|
||||||
0x14, 0xb7, 0x13, 0xe7, 0xdf, 0x8b, 0xb7, 0xeb, 0x8e, 0x96, 0x62, 0xad, 0x44, 0x76, 0xb1, 0xa0,
|
0x14, 0xb7, 0x13, 0xe7, 0xdf, 0x8b, 0xb7, 0xeb, 0x8e, 0x96, 0x62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x42, 0x10, 0x1e, 0x90,
|
||||||
0x19, 0xe1, 0xc8, 0x81, 0xea, 0x8f, 0x64, 0xa3, 0xa5, 0x2d, 0xac, 0x96, 0xe8, 0x00, 0x6a, 0x2f,
|
0x70, 0x4a, 0x38, 0x72, 0xa0, 0xfc, 0x23, 0xd9, 0x68, 0x69, 0x03, 0xab, 0x25, 0x3a, 0x80, 0xca,
|
||||||
0xc2, 0x65, 0x42, 0xb4, 0xac, 0x85, 0xd3, 0xc0, 0xfb, 0xd3, 0x82, 0x7a, 0x26, 0xf1, 0xc0, 0x7a,
|
0xf3, 0x70, 0xb1, 0x26, 0x5a, 0xd6, 0xc0, 0x49, 0xe0, 0xfd, 0x69, 0x41, 0x35, 0x95, 0x78, 0x60,
|
||||||
0x16, 0xd3, 0x2b, 0xad, 0x69, 0x3f, 0xb6, 0xfd, 0xb4, 0x03, 0xbe, 0xca, 0x05, 0x06, 0xd6, 0x18,
|
0x3d, 0x8d, 0xe9, 0xa5, 0xd6, 0x34, 0x1f, 0xda, 0x7e, 0xd2, 0x01, 0x5f, 0xe5, 0x02, 0x03, 0x6b,
|
||||||
0xfa, 0x1c, 0x9a, 0x98, 0xcc, 0x62, 0x4e, 0xa6, 0x52, 0xef, 0xd3, 0x7e, 0xbc, 0xe7, 0xab, 0x0e,
|
0x0c, 0x7d, 0x0e, 0x75, 0x4c, 0xa6, 0x31, 0x27, 0x13, 0xa9, 0xf7, 0x69, 0x3e, 0xdc, 0xf3, 0x55,
|
||||||
0xf9, 0x67, 0xb3, 0x19, 0x27, 0x42, 0x04, 0x06, 0xde, 0x12, 0x50, 0xa9, 0x22, 0xb7, 0xaa, 0xe9,
|
0x87, 0xfc, 0xd3, 0xe9, 0x94, 0x13, 0x21, 0x02, 0x03, 0x6f, 0x09, 0xa8, 0x50, 0x91, 0x5b, 0xd6,
|
||||||
0x28, 0xdf, 0x76, 0x87, 0x04, 0x06, 0x2e, 0x56, 0xfe, 0x25, 0xb4, 0xc6, 0x3c, 0xa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0x99, 0x4e, 0x33, 0xfa, 0x14,
|
0x02, 0xee, 0x66, 0xeb, 0x61, 0x1c, 0xd1, 0x50, 0xae, 0x79, 0x72, 0xa3, 0x6d, 0xfc, 0x2e, 0xe0,
|
||||||
0x2c, 0xf5, 0x1a, 0xe9, 0x5d, 0xef, 0xed, 0x2e, 0x5b, 0x61, 0xfe, 0x78, 0xb3, 0x26, 0x58, 0xc3,
|
0xfd, 0x6e, 0x26, 0x77, 0x1a, 0x7d, 0x0a, 0x96, 0x7a, 0x93, 0xf4, 0xae, 0x77, 0x76, 0x23, 0x57,
|
||||||
0x59, 0xfb, 0x2b, 0xef, 0x6b, 0xbf, 0x37, 0x06, 0x4b, 0x31, 0x51, 0x1b, 0x1a, 0x97, 0xf4, 0x8a,
|
0x98, 0x3f, 0xda, 0xac, 0x08, 0xd6, 0x70, 0x3a, 0x84, 0xd2, 0xfb, 0x86, 0xe0, 0x8d, 0xc0, 0x52,
|
||||||
0xb2, 0x97, 0xd4, 0x31, 0x10, 0x40, 0x7d, 0x18, 0x72, 0x42, 0xa5, 0x63, 0x22, 0x1b, 0x9a, 0x43,
|
0x4c, 0xd4, 0x84, 0xda, 0x05, 0xbd, 0xa4, 0xec, 0x05, 0x75, 0x0c, 0x04, 0x50, 0x1d, 0x84, 0x9c,
|
||||||
0x4e, 0xae, 0x63, 0x96, 0x08, 0xa7, 0x82, 0x9a, 0x60, 0x3d, 0x27, 0xaf, 0xa4, 0x53, 0x45, 0x2d,
|
0x50, 0xe9, 0x98, 0xc8, 0x86, 0xfa, 0x80, 0x93, 0xab, 0x98, 0xad, 0x85, 0x53, 0x42, 0x75, 0xb0,
|
||||||
0xa8, 0x9d, 0x2f, 0xe2, 0xe5, 0xcc, 0xb1, 0x90, 0x53, 0xb6, 0xae, 0x53, 0xf3, 0x96, 0x85, 0x39,
|
0x9e, 0x91, 0x97, 0xd2, 0x29, 0xa3, 0x06, 0x54, 0xce, 0xe6, 0xf1, 0x62, 0xea, 0x58, 0xc8,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4e, 0xcb, 0xd2, 0xde,
|
||||||
|
0xfd, 0x06, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Range) Marshal() (dAtA []byte, err error) {
|
func (m *Range) Marshal() (dAtA []byte, err error) {
|
||||||
|
|
|
@ -70,6 +70,8 @@ message SystemHeader {
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreationPoint {
|
message CreationPoint {
|
||||||
|
option (gogoproto.goproto_stringer) = false;
|
||||||
|
|
||||||
// UnixTime is a date of creation in unixtime format
|
// UnixTime is a date of creation in unixtime format
|
||||||
int64 UnixTime = 1;
|
int64 UnixTime = 1;
|
||||||
// Epoch is a date of creation in NeoFS epochs
|
// Epoch is a date of creation in NeoFS epochs
|
||||||
|
|
181
object/types_test.go
Normal file
181
object/types_test.go
Normal file
|
@ -0,0 +1,181 @@
|
||||||
|
package object
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/refs"
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/service"
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/storagegroup"
|
||||||
|
"github.com/nspcc-dev/neofs-crypto/test"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStringify(t *testing.T) {
|
||||||
|
res := `
|
||||||
|
Object:
|
||||||
|
SystemHeader:
|
||||||
|
- ID=7e0b9c6c-aabc-4985-949e-2680e577b48b
|
||||||
|
- CID=11111111111111111111111111111111
|
||||||
|
- OwnerID=ALYeYC41emF6MrmUMc4a8obEPdgFhq9ran
|
||||||
|
- Version=1
|
||||||
|
- PayloadLength=1
|
||||||
|
- CreatedAt={UnixTime=1 Epoch=1}
|
||||||
|
UserHeaders:
|
||||||
|
- Type=Link
|
||||||
|
Value={Type=Child ID=7e0b9c6c-aabc-4985-949e-2680e577b48b}
|
||||||
|
- Type=Redirect
|
||||||
|
Value={CID=11111111111111111111111111111111 OID=7e0b9c6c-aabc-4985-949e-2680e577b48b}
|
||||||
|
- Type=UserHeader
|
||||||
|
Value={Key=test_key Val=test_value}
|
||||||
|
- Type=Transform
|
||||||
|
Value=Split
|
||||||
|
- Type=Tombstone
|
||||||
|
Value=MARKED
|
||||||
|
- Type=Token
|
||||||
|
Value={ID=7e0b9c6c-aabc-4985-949e-2680e577b48b OwnerID=ALYeYC41emF6MrmUMc4a8obEPdgFhq9ran Verb=Search Address=11111111111111111111111111111111/7e0b9c6c-aabc-4985-949e-2680e577b48b Created=1 ValidUntil=2 SessionKey=010203040506 Signature=010203040506}
|
||||||
|
- Type=HomoHash
|
||||||
|
Value=1111111111111111111111111111111111111111111111111111111111111111
|
||||||
|
- Type=PayloadChecksum
|
||||||
|
Value=[1 2 3 4 5 6]
|
||||||
|
- Type=Integrity
|
||||||
|
Value={Checksum=010203040506 Signature=010203040506}
|
||||||
|
- Type=StorageGroup
|
||||||
|
Value={DataSize=5 Hash=31313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131 Lifetime={Unit=UnixTime Value=555}}
|
||||||
|
- Type=PublicKey
|
||||||
|
Value=[1 2 3 4 5 6]
|
||||||
|
Payload: []byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7}
|
||||||
|
`
|
||||||
|
|
||||||
|
key := test.DecodeKey(0)
|
||||||
|
|
||||||
|
uid, err := refs.NewOwnerID(&key.PublicKey)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var oid refs.UUID
|
||||||
|
|
||||||
|
require.NoError(t, oid.Parse("7e0b9c6c-aabc-4985-949e-2680e577b48b"))
|
||||||
|
|
||||||
|
obj := &Object{
|
||||||
|
SystemHeader: SystemHeader{
|
||||||
|
Version: 1,
|
||||||
|
PayloadLength: 1,
|
||||||
|
ID: oid,
|
||||||
|
OwnerID: uid,
|
||||||
|
CID: CID{},
|
||||||
|
CreatedAt: CreationPoint{
|
||||||
|
UnixTime: 1,
|
||||||
|
Epoch: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Payload: []byte{1, 2, 3, 4, 5, 6, 7},
|
||||||
|
}
|
||||||
|
|
||||||
|
// *Header_Link
|
||||||
|
obj.Headers = append(obj.Headers, Header{
|
||||||
|
Value: &Header_Link{
|
||||||
|
Link: &Link{ID: oid, Type: Link_Child},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// *Header_Redirect
|
||||||
|
obj.Headers = append(obj.Headers, Header{
|
||||||
|
Value: &Header_Redirect{
|
||||||
|
Redirect: &Address{ObjectID: oid, CID: CID{}},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// *Header_UserHeader
|
||||||
|
obj.Headers = append(obj.Headers, Header{
|
||||||
|
Value: &Header_UserHeader{
|
||||||
|
UserHeader: &UserHeader{
|
||||||
|
Key: "test_key",
|
||||||
|
Value: "test_value",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// *Header_Transform
|
||||||
|
obj.Headers = append(obj.Headers, Header{
|
||||||
|
Value: &Header_Transform{
|
||||||
|
Transform: &Transform{
|
||||||
|
Type: Transform_Split,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// *Header_Tombstone
|
||||||
|
obj.Headers = append(obj.Headers, Header{
|
||||||
|
Value: &Header_Tombstone{
|
||||||
|
Tombstone: &Tombstone{},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// *Header_Token
|
||||||
|
obj.Headers = append(obj.Headers, Header{
|
||||||
|
Value: &Header_Token{
|
||||||
|
Token: &Token{
|
||||||
|
Signature: []byte{1, 2, 3, 4, 5, 6},
|
||||||
|
Token_Info: service.Token_Info{
|
||||||
|
ID: oid,
|
||||||
|
OwnerID: uid,
|
||||||
|
Verb: service.Token_Info_Search,
|
||||||
|
Address: service.Address{ObjectID: oid, CID: refs.CID{}},
|
||||||
|
Created: 1,
|
||||||
|
ValidUntil: 2,
|
||||||
|
SessionKey: []byte{1, 2, 3, 4, 5, 6},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// *Header_HomoHash
|
||||||
|
obj.Headers = append(obj.Headers, Header{
|
||||||
|
Value: &Header_HomoHash{
|
||||||
|
HomoHash: Hash{},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// *Header_PayloadChecksum
|
||||||
|
obj.Headers = append(obj.Headers, Header{
|
||||||
|
Value: &Header_PayloadChecksum{
|
||||||
|
PayloadChecksum: []byte{1, 2, 3, 4, 5, 6},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// *Header_Integrity
|
||||||
|
obj.Headers = append(obj.Headers, Header{
|
||||||
|
Value: &Header_Integrity{
|
||||||
|
Integrity: &IntegrityHeader{
|
||||||
|
HeadersChecksum: []byte{1, 2, 3, 4, 5, 6},
|
||||||
|
ChecksumSignature: []byte{1, 2, 3, 4, 5, 6},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// *Header_StorageGroup
|
||||||
|
obj.Headers = append(obj.Headers, Header{
|
||||||
|
Value: &Header_StorageGroup{
|
||||||
|
StorageGroup: &storagegroup.StorageGroup{
|
||||||
|
ValidationDataSize: 5,
|
||||||
|
ValidationHash: storagegroup.Hash{},
|
||||||
|
Lifetime: &storagegroup.StorageGroup_Lifetime{
|
||||||
|
Unit: storagegroup.StorageGroup_Lifetime_UnixTime,
|
||||||
|
Value: 555,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// *Header_PublicKey
|
||||||
|
obj.Headers = append(obj.Headers, Header{
|
||||||
|
Value: &Header_PublicKey{
|
||||||
|
PublicKey: &PublicKey{Value: []byte{1, 2, 3, 4, 5, 6}},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
|
||||||
|
require.NoError(t, Stringify(buf, obj))
|
||||||
|
require.Equal(t, res, buf.String())
|
||||||
|
}
|
Loading…
Reference in a new issue