1 //go:build launchdarkly_easyjson 2 3 package ldreason 4 5 import ( 6 "github.com/launchdarkly/go-jsonstream/v3/jreader" 7 "github.com/launchdarkly/go-jsonstream/v3/jwriter" 8 9 "github.com/mailru/easyjson/jlexer" 10 ej_jwriter "github.com/mailru/easyjson/jwriter" 11 ) 12 13 // This conditionally-compiled file provides custom marshal/unmarshal functions for the EvaluationReason 14 // type in EasyJSON. 15 // 16 // EasyJSON's code generator does recognize the same MarshalJSON and UnmarshalJSON methods used by 17 // encoding/json, and will call them if present. But this mechanism is inefficient: when marshaling 18 // it requires the allocation of intermediate byte slices, and when unmarshaling it causes the 19 // JSON object to be parsed twice. It is preferable to have our marshal/unmarshal methods write to 20 // and read from the EasyJSON Writer/Lexer directly. Our go-jsonstream library provides methods for 21 // doing this, if the launchdarkly_easyjson build tag is set.package ldmodel 22 // 23 // For more information, see: https://github.com/launchdarkly/go-jsonstream/v3 24 25 func (r EvaluationReason) MarshalEasyJSON(writer *ej_jwriter.Writer) { 26 wrappedWriter := jwriter.NewWriterFromEasyJSONWriter(writer) 27 r.WriteToJSONWriter(&wrappedWriter) 28 } 29 30 func (r *EvaluationReason) UnmarshalEasyJSON(lexer *jlexer.Lexer) { 31 wrappedReader := jreader.NewReaderFromEasyJSONLexer(lexer) 32 r.ReadFromJSONReader(&wrappedReader) 33 lexer.AddError(wrappedReader.Error()) 34 } 35