MCPcopy
hub / github.com/gogf/gf / LeEncode

Function LeEncode

encoding/gbinary/gbinary_le.go:26–72  ·  view source on GitHub ↗

LeEncode encodes one or multiple `values` into bytes using LittleEndian. It uses type asserting checking the type of each value of `values` and internally calls corresponding converting function do the bytes converting. It supports common variable type asserting, and finally it uses fmt.Sprintf con

(values ...any)

Source from the content-addressed store, hash-verified

24// It supports common variable type asserting, and finally it uses fmt.Sprintf converting
25// value to string and then to bytes.
26func LeEncode(values ...any) []byte {
27 buf := new(bytes.Buffer)
28 for i := 0; i < len(values); i++ {
29 if values[i] == nil {
30 return buf.Bytes()
31 }
32 switch value := values[i].(type) {
33 case int:
34 buf.Write(LeEncodeInt(value))
35 case int8:
36 buf.Write(LeEncodeInt8(value))
37 case int16:
38 buf.Write(LeEncodeInt16(value))
39 case int32:
40 buf.Write(LeEncodeInt32(value))
41 case int64:
42 buf.Write(LeEncodeInt64(value))
43 case uint:
44 buf.Write(LeEncodeUint(value))
45 case uint8:
46 buf.Write(LeEncodeUint8(value))
47 case uint16:
48 buf.Write(LeEncodeUint16(value))
49 case uint32:
50 buf.Write(LeEncodeUint32(value))
51 case uint64:
52 buf.Write(LeEncodeUint64(value))
53 case bool:
54 buf.Write(LeEncodeBool(value))
55 case string:
56 buf.Write(LeEncodeString(value))
57 case []byte:
58 buf.Write(value)
59 case float32:
60 buf.Write(LeEncodeFloat32(value))
61 case float64:
62 buf.Write(LeEncodeFloat64(value))
63
64 default:
65 if err := binary.Write(buf, binary.LittleEndian, value); err != nil {
66 intlog.Errorf(context.TODO(), `%+v`, err)
67 buf.Write(LeEncodeString(fmt.Sprintf("%v", value)))
68 }
69 }
70 }
71 return buf.Bytes()
72}
73
74func LeEncodeByLength(length int, values ...any) []byte {
75 b := LeEncode(values...)

Callers 4

Test_LeEncodeAndLeDecodeFunction · 0.92
Test_LeEncodeStructFunction · 0.92
LeEncodeByLengthFunction · 0.85
EncodeFunction · 0.85

Calls 15

ErrorfFunction · 0.92
LeEncodeIntFunction · 0.85
LeEncodeInt8Function · 0.85
LeEncodeInt16Function · 0.85
LeEncodeInt32Function · 0.85
LeEncodeInt64Function · 0.85
LeEncodeUintFunction · 0.85
LeEncodeUint8Function · 0.85
LeEncodeUint16Function · 0.85
LeEncodeUint32Function · 0.85
LeEncodeUint64Function · 0.85
LeEncodeBoolFunction · 0.85

Tested by 2

Test_LeEncodeAndLeDecodeFunction · 0.74
Test_LeEncodeStructFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…