EncodeMsg encodes the message to the writer.
(writer *msgp.Writer)
| 988 | |
| 989 | // EncodeMsg encodes the message to the writer. |
| 990 | func (s ByteSorted) EncodeMsg(writer *msgp.Writer) error { |
| 991 | if s == nil { |
| 992 | return writer.WriteNil() |
| 993 | } |
| 994 | err := writer.WriteArrayHeader(uint32(len(s))) |
| 995 | if err != nil { |
| 996 | return err |
| 997 | } |
| 998 | keys := make([]byte, 0, len(s)) |
| 999 | for k := range s { |
| 1000 | keys = append(keys, k) |
| 1001 | } |
| 1002 | slices.SortFunc(keys, func(a, b byte) int { |
| 1003 | if a < b { |
| 1004 | return -1 |
| 1005 | } |
| 1006 | return 1 |
| 1007 | }) |
| 1008 | |
| 1009 | for _, k := range keys { |
| 1010 | err = writer.WriteByte(k) |
| 1011 | if err != nil { |
| 1012 | return err |
| 1013 | } |
| 1014 | } |
| 1015 | return nil |
| 1016 | } |
| 1017 | |
| 1018 | // MarshalMsg encodes the message to the bytes. |
| 1019 | func (s ByteSorted) MarshalMsg(bytes []byte) ([]byte, error) { |