ceph-csi/vendor/github.com/mailru/easyjson/opt/gotemplate_Float64.go
Serguei Bezverkhi 7b24313bd6 vendor files
2018-01-10 13:42:26 -05:00

80 lines
1.7 KiB
Go

// generated by gotemplate
package opt
import (
"fmt"
"github.com/mailru/easyjson/jlexer"
"github.com/mailru/easyjson/jwriter"
)
// template type Optional(A)
// A 'gotemplate'-based type for providing optional semantics without using pointers.
type Float64 struct {
V float64
Defined bool
}
// Creates an optional type with a given value.
func OFloat64(v float64) Float64 {
return Float64{V: v, Defined: true}
}
// Get returns the value or given default in the case the value is undefined.
func (v Float64) Get(deflt float64) float64 {
if !v.Defined {
return deflt
}
return v.V
}
// MarshalEasyJSON does JSON marshaling using easyjson interface.
func (v Float64) MarshalEasyJSON(w *jwriter.Writer) {
if v.Defined {
w.Float64(v.V)
} else {
w.RawString("null")
}
}
// UnmarshalEasyJSON does JSON unmarshaling using easyjson interface.
func (v *Float64) UnmarshalEasyJSON(l *jlexer.Lexer) {
if l.IsNull() {
l.Skip()
*v = Float64{}
} else {
v.V = l.Float64()
v.Defined = true
}
}
// MarshalJSON implements a standard json marshaler interface.
func (v Float64) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
v.MarshalEasyJSON(&w)
return w.Buffer.BuildBytes(), w.Error
}
// UnmarshalJSON implements a standard json unmarshaler interface.
func (v *Float64) UnmarshalJSON(data []byte) error {
l := jlexer.Lexer{Data: data}
v.UnmarshalEasyJSON(&l)
return l.Error()
}
// IsDefined returns whether the value is defined, a function is required so that it can
// be used in an interface.
func (v Float64) IsDefined() bool {
return v.Defined
}
// String implements a stringer interface using fmt.Sprint for the value.
func (v Float64) String() string {
if !v.Defined {
return "<undefined>"
}
return fmt.Sprint(v.V)
}