github.com/annchain/OG@v0.0.9/og/protocol/ogmessage/archive/public_key.go (about) 1 package archive 2 3 import ( 4 "encoding/json" 5 "github.com/annchain/OG/common/hexutil" 6 "github.com/tinylib/msgp/msgp" 7 ) 8 9 ////no go:generate msgp 10 11 type PublicKey []byte 12 13 // DecodeMsg implements msgp.Decodable 14 func (z *PublicKey) DecodeMsg(dc *msgp.Reader) (err error) { 15 if CanRecoverPubFromSig { 16 return nil 17 } 18 { 19 var zb0001 []byte 20 zb0001, err = dc.ReadBytes([]byte((*z))) 21 if err != nil { 22 return 23 } 24 (*z) = PublicKey(zb0001) 25 } 26 return 27 } 28 29 // EncodeMsg implements msgp.Encodable 30 func (z PublicKey) EncodeMsg(en *msgp.Writer) (err error) { 31 if CanRecoverPubFromSig { 32 return nil 33 } 34 err = en.WriteBytes([]byte(z)) 35 if err != nil { 36 return 37 } 38 return 39 } 40 41 // MarshalMsg implements msgp.Marshaler 42 func (z PublicKey) MarshalMsg(b []byte) (o []byte, err error) { 43 if CanRecoverPubFromSig { 44 return nil, nil 45 } 46 o = msgp.Require(b, z.Msgsize()) 47 o = msgp.AppendBytes(o, []byte(z)) 48 return 49 } 50 51 // UnmarshalMsg implements msgp.Unmarshaler 52 func (z *PublicKey) UnmarshalMsg(bts []byte) (o []byte, err error) { 53 if CanRecoverPubFromSig { 54 return bts, nil 55 } 56 { 57 var zb0001 []byte 58 zb0001, bts, err = msgp.ReadBytesBytes(bts, []byte((*z))) 59 if err != nil { 60 return 61 } 62 (*z) = PublicKey(zb0001) 63 } 64 o = bts 65 return 66 } 67 68 // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message 69 func (z PublicKey) Msgsize() (s int) { 70 if CanRecoverPubFromSig { 71 return 0 72 } 73 s = msgp.BytesPrefixSize + len([]byte(z)) 74 return 75 } 76 77 func (z PublicKey) String() string { 78 return hexutil.Encode(z) 79 } 80 81 func (b PublicKey) MarshalJson() ([]byte, error) { 82 s := b.String() 83 return json.Marshal(&s) 84 }