MCPcopy
hub / github.com/tinylib/msgp / MarshalMsg

Method MarshalMsg

msgp/setof/generated.go:1019–1042  ·  view source on GitHub ↗

MarshalMsg encodes the message to the bytes.

(bytes []byte)

Source from the content-addressed store, hash-verified

1017
1018// MarshalMsg encodes the message to the bytes.
1019func (s ByteSorted) MarshalMsg(bytes []byte) ([]byte, error) {
1020 if s == nil {
1021 return msgp.AppendNil(bytes), nil
1022 }
1023 if len(s) == 0 {
1024 return msgp.AppendArrayHeader(bytes, 0), nil
1025 }
1026 bytes = ensure(bytes, s.Msgsize())
1027 bytes = msgp.AppendArrayHeader(bytes, uint32(len(s)))
1028 keys := make([]byte, 0, len(s))
1029 for k := range s {
1030 keys = append(keys, k)
1031 }
1032 slices.SortFunc(keys, func(a, b byte) int {
1033 if a < b {
1034 return -1
1035 }
1036 return 1
1037 })
1038 for _, k := range keys {
1039 bytes = msgp.AppendByte(bytes, k)
1040 }
1041 return bytes, nil
1042}
1043
1044// AsSlice returns the set as a sorted slice.
1045func (s ByteSorted) AsSlice() []byte {

Callers 1

Calls 5

MsgsizeMethod · 0.95
AppendNilFunction · 0.92
AppendArrayHeaderFunction · 0.92
AppendByteFunction · 0.92
ensureFunction · 0.70

Tested by 1