2020-04-29 02:23:32 +00:00
|
|
|
package easyjson
|
|
|
|
|
|
|
|
import (
|
|
|
|
jlexer "github.com/mailru/easyjson/jlexer"
|
|
|
|
"github.com/mailru/easyjson/jwriter"
|
|
|
|
)
|
|
|
|
|
|
|
|
// UnknownFieldsProxy implemets UnknownsUnmarshaler and UnknownsMarshaler
|
|
|
|
// use it as embedded field in your structure to parse and then serialize unknown struct fields
|
|
|
|
type UnknownFieldsProxy struct {
|
2020-05-03 07:05:16 +00:00
|
|
|
unknownFields map[string][]byte
|
2020-04-29 02:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *UnknownFieldsProxy) UnmarshalUnknown(in *jlexer.Lexer, key string) {
|
|
|
|
if s.unknownFields == nil {
|
2020-05-03 07:05:16 +00:00
|
|
|
s.unknownFields = make(map[string][]byte, 1)
|
2020-04-29 02:23:32 +00:00
|
|
|
}
|
2020-05-03 07:05:16 +00:00
|
|
|
s.unknownFields[key] = in.Raw()
|
2020-04-29 02:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s UnknownFieldsProxy) MarshalUnknowns(out *jwriter.Writer, first bool) {
|
|
|
|
for key, val := range s.unknownFields {
|
|
|
|
if first {
|
|
|
|
first = false
|
|
|
|
} else {
|
|
|
|
out.RawByte(',')
|
|
|
|
}
|
|
|
|
out.String(string(key))
|
|
|
|
out.RawByte(':')
|
2020-05-03 07:05:16 +00:00
|
|
|
out.Raw(val, nil)
|
2020-04-29 02:23:32 +00:00
|
|
|
}
|
|
|
|
}
|