MarshalMsg encodes the message to the bytes.
(bytes []byte)
| 1017 | |
| 1018 | // MarshalMsg encodes the message to the bytes. |
| 1019 | func (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. |
| 1045 | func (s ByteSorted) AsSlice() []byte { |