github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/binary/bytes.go (about)

     1  package binary
     2  
     3  import hex "github.com/tmthrgd/go-hex"
     4  
     5  type HexBytes []byte
     6  
     7  func (hb *HexBytes) UnmarshalText(hexBytes []byte) error {
     8  	bs, err := hex.DecodeString(string(hexBytes))
     9  	if err != nil {
    10  		return err
    11  	}
    12  	*hb = bs
    13  	return nil
    14  }
    15  
    16  func (hb HexBytes) MarshalText() ([]byte, error) {
    17  	return []byte(hb.String()), nil
    18  }
    19  
    20  func (hb HexBytes) String() string {
    21  	return hex.EncodeUpperToString(hb)
    22  }
    23  
    24  // Protobuf support
    25  func (hb HexBytes) Marshal() ([]byte, error) {
    26  	return hb, nil
    27  }
    28  
    29  func (hb *HexBytes) Unmarshal(data []byte) error {
    30  	*hb = data
    31  	return nil
    32  }
    33  
    34  func (hb HexBytes) MarshalTo(data []byte) (int, error) {
    35  	return copy(data, hb), nil
    36  }
    37  
    38  func (hb HexBytes) Size() int {
    39  	return len(hb)
    40  }
    41  
    42  func (hb HexBytes) Bytes() []byte {
    43  	return hb
    44  }