diff options
author | Christopher Speller <crspeller@gmail.com> | 2018-01-29 14:17:40 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-29 14:17:40 -0800 |
commit | 961c04cae992eadb42d286d2f85f8a675bdc68c8 (patch) | |
tree | 3408f2d06f847e966c53485e2d54c692cdd037c1 /vendor/github.com/mailru/easyjson/opt/gotemplate_Int32.go | |
parent | 8d66523ba7d9a77129844be476732ebfd5272d64 (diff) | |
download | chat-961c04cae992eadb42d286d2f85f8a675bdc68c8.tar.gz chat-961c04cae992eadb42d286d2f85f8a675bdc68c8.tar.bz2 chat-961c04cae992eadb42d286d2f85f8a675bdc68c8.zip |
Upgrading server dependancies (#8154)
Diffstat (limited to 'vendor/github.com/mailru/easyjson/opt/gotemplate_Int32.go')
-rw-r--r-- | vendor/github.com/mailru/easyjson/opt/gotemplate_Int32.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/vendor/github.com/mailru/easyjson/opt/gotemplate_Int32.go b/vendor/github.com/mailru/easyjson/opt/gotemplate_Int32.go new file mode 100644 index 000000000..7c7637a38 --- /dev/null +++ b/vendor/github.com/mailru/easyjson/opt/gotemplate_Int32.go @@ -0,0 +1,79 @@ +// 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 Int32 struct { + V int32 + Defined bool +} + +// Creates an optional type with a given value. +func OInt32(v int32) Int32 { + return Int32{V: v, Defined: true} +} + +// Get returns the value or given default in the case the value is undefined. +func (v Int32) Get(deflt int32) int32 { + if !v.Defined { + return deflt + } + return v.V +} + +// MarshalEasyJSON does JSON marshaling using easyjson interface. +func (v Int32) MarshalEasyJSON(w *jwriter.Writer) { + if v.Defined { + w.Int32(v.V) + } else { + w.RawString("null") + } +} + +// UnmarshalEasyJSON does JSON unmarshaling using easyjson interface. +func (v *Int32) UnmarshalEasyJSON(l *jlexer.Lexer) { + if l.IsNull() { + l.Skip() + *v = Int32{} + } else { + v.V = l.Int32() + v.Defined = true + } +} + +// MarshalJSON implements a standard json marshaler interface. +func (v Int32) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + v.MarshalEasyJSON(&w) + return w.Buffer.BuildBytes(), w.Error +} + +// UnmarshalJSON implements a standard json unmarshaler interface. +func (v *Int32) 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 Int32) IsDefined() bool { + return v.Defined +} + +// String implements a stringer interface using fmt.Sprint for the value. +func (v Int32) String() string { + if !v.Defined { + return "<undefined>" + } + return fmt.Sprint(v.V) +} |