...

Source file src/github.com/launchdarkly/go-server-sdk-evaluation/v2/ldmodel/model_serialization_easyjson.go

Documentation: github.com/launchdarkly/go-server-sdk-evaluation/v2/ldmodel

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

View as plain text