github.com/aergoio/aergo@v1.3.1/cmd/aergocli/util/encoding/encoding.go (about)

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package encoding defines interfaces shared by other packages that
     6  // convert data to and from byte-level and textual representations.
     7  // Packages that check for these interfaces include encoding/gob,
     8  // encoding/json, and encoding/xml. As a result, implementing an
     9  // interface once can make a type useful in multiple encodings.
    10  // Standard types that implement these interfaces include time.Time and net.IP.
    11  // The interfaces come in pairs that produce and consume encoded data.
    12  package encoding
    13  
    14  // BinaryMarshaler is the interface implemented by an object that can
    15  // marshal itself into a binary form.
    16  //
    17  // MarshalBinary encodes the receiver into a binary form and returns the result.
    18  type BinaryMarshaler interface {
    19  	MarshalBinary() (data []byte, err error)
    20  }
    21  
    22  // BinaryUnmarshaler is the interface implemented by an object that can
    23  // unmarshal a binary representation of itself.
    24  //
    25  // UnmarshalBinary must be able to decode the form generated by MarshalBinary.
    26  // UnmarshalBinary must copy the data if it wishes to retain the data
    27  // after returning.
    28  type BinaryUnmarshaler interface {
    29  	UnmarshalBinary(data []byte) error
    30  }
    31  
    32  // TextMarshaler is the interface implemented by an object that can
    33  // marshal itself into a textual form.
    34  //
    35  // MarshalText encodes the receiver into UTF-8-encoded text and returns the result.
    36  type TextMarshaler interface {
    37  	MarshalText() (text []byte, err error)
    38  }
    39  
    40  // TextUnmarshaler is the interface implemented by an object that can
    41  // unmarshal a textual representation of itself.
    42  //
    43  // UnmarshalText must be able to decode the form generated by MarshalText.
    44  // UnmarshalText must copy the text if it wishes to retain the text
    45  // after returning.
    46  type TextUnmarshaler interface {
    47  	UnmarshalText(text []byte) error
    48  }