MarshalMsg encodes the message to the bytes.
(bytes []byte)
| 170 | |
| 171 | // MarshalMsg encodes the message to the bytes. |
| 172 | func (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. |
| 193 | func (s StringSorted) AsSlice() []string { |