MarshalMsg encodes the message to the bytes.
(bytes []byte)
| 1872 | |
| 1873 | // MarshalMsg encodes the message to the bytes. |
| 1874 | func (s Int16Sorted) MarshalMsg(bytes []byte) ([]byte, error) { |
| 1875 | if s == nil { |
| 1876 | return msgp.AppendNil(bytes), nil |
| 1877 | } |
| 1878 | if len(s) == 0 { |
| 1879 | return msgp.AppendArrayHeader(bytes, 0), nil |
| 1880 | } |
| 1881 | bytes = ensure(bytes, s.Msgsize()) |
| 1882 | bytes = msgp.AppendArrayHeader(bytes, uint32(len(s))) |
| 1883 | keys := make([]int16, 0, len(s)) |
| 1884 | for k := range s { |
| 1885 | keys = append(keys, k) |
| 1886 | } |
| 1887 | slices.SortFunc(keys, func(a, b int16) int { |
| 1888 | if a < b { |
| 1889 | return -1 |
| 1890 | } |
| 1891 | return 1 |
| 1892 | }) |
| 1893 | for _, k := range keys { |
| 1894 | bytes = msgp.AppendInt16(bytes, k) |
| 1895 | } |
| 1896 | return bytes, nil |
| 1897 | } |
| 1898 | |
| 1899 | // AsSlice returns the set as a sorted slice. |
| 1900 | func (s Int16Sorted) AsSlice() []int16 { |