gbinary.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. // Package gbinary provides useful API for handling binary/bytes data.
  7. //
  8. // Note that package gbinary encodes the data using LittleEndian in default.
  9. package gbinary
  10. func Encode(values ...interface{}) []byte {
  11. return LeEncode(values...)
  12. }
  13. func EncodeByLength(length int, values ...interface{}) []byte {
  14. return LeEncodeByLength(length, values...)
  15. }
  16. func Decode(b []byte, values ...interface{}) error {
  17. return LeDecode(b, values...)
  18. }
  19. func EncodeString(s string) []byte {
  20. return LeEncodeString(s)
  21. }
  22. func DecodeToString(b []byte) string {
  23. return LeDecodeToString(b)
  24. }
  25. func EncodeBool(b bool) []byte {
  26. return LeEncodeBool(b)
  27. }
  28. func EncodeInt(i int) []byte {
  29. return LeEncodeInt(i)
  30. }
  31. func EncodeUint(i uint) []byte {
  32. return LeEncodeUint(i)
  33. }
  34. func EncodeInt8(i int8) []byte {
  35. return LeEncodeInt8(i)
  36. }
  37. func EncodeUint8(i uint8) []byte {
  38. return LeEncodeUint8(i)
  39. }
  40. func EncodeInt16(i int16) []byte {
  41. return LeEncodeInt16(i)
  42. }
  43. func EncodeUint16(i uint16) []byte {
  44. return LeEncodeUint16(i)
  45. }
  46. func EncodeInt32(i int32) []byte {
  47. return LeEncodeInt32(i)
  48. }
  49. func EncodeUint32(i uint32) []byte {
  50. return LeEncodeUint32(i)
  51. }
  52. func EncodeInt64(i int64) []byte {
  53. return LeEncodeInt64(i)
  54. }
  55. func EncodeUint64(i uint64) []byte {
  56. return LeEncodeUint64(i)
  57. }
  58. func EncodeFloat32(f float32) []byte {
  59. return LeEncodeFloat32(f)
  60. }
  61. func EncodeFloat64(f float64) []byte {
  62. return LeEncodeFloat64(f)
  63. }
  64. func DecodeToInt(b []byte) int {
  65. return LeDecodeToInt(b)
  66. }
  67. func DecodeToUint(b []byte) uint {
  68. return LeDecodeToUint(b)
  69. }
  70. func DecodeToBool(b []byte) bool {
  71. return LeDecodeToBool(b)
  72. }
  73. func DecodeToInt8(b []byte) int8 {
  74. return LeDecodeToInt8(b)
  75. }
  76. func DecodeToUint8(b []byte) uint8 {
  77. return LeDecodeToUint8(b)
  78. }
  79. func DecodeToInt16(b []byte) int16 {
  80. return LeDecodeToInt16(b)
  81. }
  82. func DecodeToUint16(b []byte) uint16 {
  83. return LeDecodeToUint16(b)
  84. }
  85. func DecodeToInt32(b []byte) int32 {
  86. return LeDecodeToInt32(b)
  87. }
  88. func DecodeToUint32(b []byte) uint32 {
  89. return LeDecodeToUint32(b)
  90. }
  91. func DecodeToInt64(b []byte) int64 {
  92. return LeDecodeToInt64(b)
  93. }
  94. func DecodeToUint64(b []byte) uint64 {
  95. return LeDecodeToUint64(b)
  96. }
  97. func DecodeToFloat32(b []byte) float32 {
  98. return LeDecodeToFloat32(b)
  99. }
  100. func DecodeToFloat64(b []byte) float64 {
  101. return LeDecodeToFloat64(b)
  102. }