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

Method MarshalMsg

msgp/setof/generated.go:1874–1897  ·  view source on GitHub ↗

MarshalMsg encodes the message to the bytes.

(bytes []byte)

Source from the content-addressed store, hash-verified

1872
1873// MarshalMsg encodes the message to the bytes.
1874func (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.
1900func (s Int16Sorted) AsSlice() []int16 {

Callers 1

Calls 5

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

Tested by 1