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

Method MarshalMsg

msgp/setof/generated.go:172–190  ·  view source on GitHub ↗

MarshalMsg encodes the message to the bytes.

(bytes []byte)

Source from the content-addressed store, hash-verified

170
171// MarshalMsg encodes the message to the bytes.
172func (s StringSorted) MarshalMsg(bytes []byte) ([]byte, error) {
173 if s == nil {
174 return msgp.AppendNil(bytes), nil
175 }
176 if len(s) == 0 {
177 return msgp.AppendArrayHeader(bytes, 0), nil
178 }
179 bytes = ensure(bytes, s.Msgsize())
180 bytes = msgp.AppendArrayHeader(bytes, uint32(len(s)))
181 keys := make([]string, 0, len(s))
182 for k := range s {
183 keys = append(keys, k)
184 }
185 sort.Strings(keys)
186 for _, k := range keys {
187 bytes = msgp.AppendString(bytes, k)
188 }
189 return bytes, nil
190}
191
192// AsSlice returns the set as a sorted slice.
193func (s StringSorted) AsSlice() []string {

Callers 1

Calls 5

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

Tested by 1