You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
846 B

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