2020-09-01 23:01:23 +09: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-10-16 14:06:27 +09:00
|
|
|
unknownFields map[string][]byte
|
2020-09-01 23:01:23 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *UnknownFieldsProxy) UnmarshalUnknown(in *jlexer.Lexer, key string) {
|
|
|
|
if s.unknownFields == nil {
|
2020-10-16 14:06:27 +09:00
|
|
|
s.unknownFields = make(map[string][]byte, 1)
|
2020-09-01 23:01:23 +09:00
|
|
|
}
|
2020-10-16 14:06:27 +09:00
|
|
|
s.unknownFields[key] = in.Raw()
|
2020-09-01 23:01:23 +09: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-10-16 14:06:27 +09:00
|
|
|
out.Raw(val, nil)
|
2020-09-01 23:01:23 +09:00
|
|
|
}
|
|
|
|
}
|