github.com/okex/exchain@v1.8.0/libs/tendermint/types/encoding_helper.go (about)

     1  package types
     2  
     3  import (
     4  	//gogotypes "github.com/gogo/protobuf/types"
     5  	//"github.com/okex/exchain/libs/tendermint/libs/bytes"
     6  	gogotypes "github.com/gogo/protobuf/types"
     7  	"github.com/okex/exchain/libs/tendermint/libs/bytes"
     8  )
     9  
    10  // cdcEncode returns nil if the input is nil, otherwise returns
    11  // cdc.MustMarshalBinaryBare(item)
    12  func cdcEncode(item interface{}) []byte {
    13  	if item != nil && !isTypedNil(item) && !isEmpty(item) {
    14  		return cdc.MustMarshalBinaryBare(item)
    15  	}
    16  	return nil
    17  }
    18  
    19  func ibccdcEncode(item interface{}) []byte {
    20  	if item != nil && !isTypedNil(item) && !isEmpty(item) {
    21  		switch item := item.(type) {
    22  		case string:
    23  			i := gogotypes.StringValue{
    24  				Value: item,
    25  			}
    26  			bz, err := i.Marshal()
    27  			if err != nil {
    28  				return nil
    29  			}
    30  			return bz
    31  		case int64:
    32  			i := gogotypes.Int64Value{
    33  				Value: item,
    34  			}
    35  			bz, err := i.Marshal()
    36  			if err != nil {
    37  				return nil
    38  			}
    39  			return bz
    40  		case bytes.HexBytes:
    41  			i := gogotypes.BytesValue{
    42  				Value: item,
    43  			}
    44  			bz, err := i.Marshal()
    45  			if err != nil {
    46  				return nil
    47  			}
    48  			return bz
    49  		default:
    50  			return nil
    51  		}
    52  	}
    53  
    54  	return nil
    55  }