...

Source file src/github.com/launchdarkly/go-sdk-common/v3/ldvalue/optionals_json_easyjson_conversion.go

Documentation: github.com/launchdarkly/go-sdk-common/v3/ldvalue

     1  //go:build launchdarkly_easyjson
     2  
     3  package ldvalue
     4  
     5  import (
     6  	"github.com/mailru/easyjson/jlexer"
     7  	ej_jwriter "github.com/mailru/easyjson/jwriter"
     8  )
     9  
    10  // MarshalEasyJSON implements the easyjson.Marshaler interface.
    11  //
    12  // This method is only defined if the launchdarkly_easyjson build tag is set. For more information,
    13  // see the package documentation for ldvalue.
    14  func (v OptionalBool) MarshalEasyJSON(writer *ej_jwriter.Writer) {
    15  	if value, ok := v.optValue.get(); ok {
    16  		writer.Bool(value)
    17  	} else {
    18  		writer.Raw(nullAsJSONBytes, nil)
    19  	}
    20  }
    21  
    22  // MarshalEasyJSON implements the easyjson.Marshaler interface.
    23  //
    24  // This method is only defined if the launchdarkly_easyjson build tag is set. For more information,
    25  // see the package documentation for ldvalue.
    26  func (v OptionalInt) MarshalEasyJSON(writer *ej_jwriter.Writer) {
    27  	if value, ok := v.optValue.get(); ok {
    28  		writer.Int(value)
    29  	} else {
    30  		writer.Raw(nullAsJSONBytes, nil)
    31  	}
    32  }
    33  
    34  // MarshalEasyJSON implements the easyjson.Marshaler interface.
    35  //
    36  // This method is only defined if the launchdarkly_easyjson build tag is set. For more information,
    37  // see the package documentation for ldvalue.
    38  func (v OptionalString) MarshalEasyJSON(writer *ej_jwriter.Writer) {
    39  	if value, ok := v.optValue.get(); ok {
    40  		writer.String(value)
    41  	} else {
    42  		writer.Raw(nullAsJSONBytes, nil)
    43  	}
    44  }
    45  
    46  // UnmarshalEasyJSON implements the easyjson.Unmarshaler interface.
    47  //
    48  // This method is only defined if the launchdarkly_easyjson build tag is set. For more information,
    49  // see the package documentation for ldvalue.
    50  func (v *OptionalBool) UnmarshalEasyJSON(lexer *jlexer.Lexer) {
    51  	if lexer.IsNull() {
    52  		lexer.Null()
    53  		*v = OptionalBool{}
    54  		return
    55  	}
    56  	*v = NewOptionalBool(lexer.Bool())
    57  }
    58  
    59  // UnmarshalEasyJSON implements the easyjson.Unmarshaler interface.
    60  //
    61  // This method is only defined if the launchdarkly_easyjson build tag is set. For more information,
    62  // see the package documentation for ldvalue.
    63  func (v *OptionalInt) UnmarshalEasyJSON(lexer *jlexer.Lexer) {
    64  	if lexer.IsNull() {
    65  		lexer.Null()
    66  		*v = OptionalInt{}
    67  		return
    68  	}
    69  	*v = NewOptionalInt(lexer.Int())
    70  }
    71  
    72  // UnmarshalEasyJSON implements the easyjson.Unmarshaler interface.
    73  //
    74  // This method is only defined if the launchdarkly_easyjson build tag is set. For more information,
    75  // see the package documentation for ldvalue.
    76  func (v *OptionalString) UnmarshalEasyJSON(lexer *jlexer.Lexer) {
    77  	if lexer.IsNull() {
    78  		lexer.Null()
    79  		*v = OptionalString{}
    80  		return
    81  	}
    82  	*v = NewOptionalString(lexer.String())
    83  }
    84  

View as plain text