Skip to content

Instantly share code, notes, and snippets.

@mitallast
Created April 8, 2016 10:46
Show Gist options
  • Select an option

  • Save mitallast/d4f986719decc5e5cabb9cdb1a33ea44 to your computer and use it in GitHub Desktop.

Select an option

Save mitallast/d4f986719decc5e5cabb9cdb1a33ea44 to your computer and use it in GitHub Desktop.
$ go test -bench=.
testing: warning: no tests to run
PASS
BenchmarkJsonReflection-8 100000 14689 ns/op
BenchmarkFFJson-8 200000 6345 ns/op
ok github.com/mitallast/goprotoserver/protocol 2.974s
package protocol
// ffjson: skip
type TypeWithReflection struct {
IntField1 int `json:"int_field_1"`
IntField2 int `json:"int_field_2"`
IntField3 int `json:"int_field_3"`
IntField4 int `json:"int_field_4"`
IntField5 int `json:"int_field_5"`
StringField1 string `json:"str_field_1"`
StringField2 string `json:"str_field_2"`
StringField3 string `json:"str_field_3"`
StringField4 string `json:"str_field_4"`
StringField5 string `json:"str_field_5"`
BoolField1 bool `json:"bool_field_1"`
BoolField2 bool `json:"bool_field_2"`
BoolField3 bool `json:"bool_field_3"`
BoolField4 bool `json:"bool_field_4"`
BoolField5 bool `json:"bool_field_5"`
}
type TypeWithoutReflection struct {
IntField1 int
IntField2 int
IntField3 int
IntField4 int
IntField5 int
StringField1 string
StringField2 string
StringField3 string
StringField4 string
StringField5 string
BoolField1 bool
BoolField2 bool
BoolField3 bool
BoolField4 bool
BoolField5 bool
}
// DO NOT EDIT!
// Code generated by ffjson <https://github.com/pquerna/ffjson>
// source: json_struct.go
// DO NOT EDIT!
package protocol
import (
"bytes"
"errors"
"fmt"
fflib "github.com/pquerna/ffjson/fflib/v1"
)
func (mj *TypeWithoutReflection) MarshalJSON() ([]byte, error) {
var buf fflib.Buffer
if mj == nil {
buf.WriteString("null")
return buf.Bytes(), nil
}
err := mj.MarshalJSONBuf(&buf)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func (mj *TypeWithoutReflection) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
if mj == nil {
buf.WriteString("null")
return nil
}
var err error
var obj []byte
_ = obj
_ = err
buf.WriteString(`{"IntField1":`)
fflib.FormatBits2(buf, uint64(mj.IntField1), 10, mj.IntField1 < 0)
buf.WriteString(`,"IntField2":`)
fflib.FormatBits2(buf, uint64(mj.IntField2), 10, mj.IntField2 < 0)
buf.WriteString(`,"IntField3":`)
fflib.FormatBits2(buf, uint64(mj.IntField3), 10, mj.IntField3 < 0)
buf.WriteString(`,"IntField4":`)
fflib.FormatBits2(buf, uint64(mj.IntField4), 10, mj.IntField4 < 0)
buf.WriteString(`,"IntField5":`)
fflib.FormatBits2(buf, uint64(mj.IntField5), 10, mj.IntField5 < 0)
buf.WriteString(`,"StringField1":`)
fflib.WriteJsonString(buf, string(mj.StringField1))
buf.WriteString(`,"StringField2":`)
fflib.WriteJsonString(buf, string(mj.StringField2))
buf.WriteString(`,"StringField3":`)
fflib.WriteJsonString(buf, string(mj.StringField3))
buf.WriteString(`,"StringField4":`)
fflib.WriteJsonString(buf, string(mj.StringField4))
buf.WriteString(`,"StringField5":`)
fflib.WriteJsonString(buf, string(mj.StringField5))
if mj.BoolField1 {
buf.WriteString(`,"BoolField1":true`)
} else {
buf.WriteString(`,"BoolField1":false`)
}
if mj.BoolField2 {
buf.WriteString(`,"BoolField2":true`)
} else {
buf.WriteString(`,"BoolField2":false`)
}
if mj.BoolField3 {
buf.WriteString(`,"BoolField3":true`)
} else {
buf.WriteString(`,"BoolField3":false`)
}
if mj.BoolField4 {
buf.WriteString(`,"BoolField4":true`)
} else {
buf.WriteString(`,"BoolField4":false`)
}
if mj.BoolField5 {
buf.WriteString(`,"BoolField5":true`)
} else {
buf.WriteString(`,"BoolField5":false`)
}
buf.WriteByte('}')
return nil
}
const (
ffj_t_TypeWithoutReflectionbase = iota
ffj_t_TypeWithoutReflectionno_such_key
ffj_t_TypeWithoutReflection_IntField1
ffj_t_TypeWithoutReflection_IntField2
ffj_t_TypeWithoutReflection_IntField3
ffj_t_TypeWithoutReflection_IntField4
ffj_t_TypeWithoutReflection_IntField5
ffj_t_TypeWithoutReflection_StringField1
ffj_t_TypeWithoutReflection_StringField2
ffj_t_TypeWithoutReflection_StringField3
ffj_t_TypeWithoutReflection_StringField4
ffj_t_TypeWithoutReflection_StringField5
ffj_t_TypeWithoutReflection_BoolField1
ffj_t_TypeWithoutReflection_BoolField2
ffj_t_TypeWithoutReflection_BoolField3
ffj_t_TypeWithoutReflection_BoolField4
ffj_t_TypeWithoutReflection_BoolField5
)
var ffj_key_TypeWithoutReflection_IntField1 = []byte("IntField1")
var ffj_key_TypeWithoutReflection_IntField2 = []byte("IntField2")
var ffj_key_TypeWithoutReflection_IntField3 = []byte("IntField3")
var ffj_key_TypeWithoutReflection_IntField4 = []byte("IntField4")
var ffj_key_TypeWithoutReflection_IntField5 = []byte("IntField5")
var ffj_key_TypeWithoutReflection_StringField1 = []byte("StringField1")
var ffj_key_TypeWithoutReflection_StringField2 = []byte("StringField2")
var ffj_key_TypeWithoutReflection_StringField3 = []byte("StringField3")
var ffj_key_TypeWithoutReflection_StringField4 = []byte("StringField4")
var ffj_key_TypeWithoutReflection_StringField5 = []byte("StringField5")
var ffj_key_TypeWithoutReflection_BoolField1 = []byte("BoolField1")
var ffj_key_TypeWithoutReflection_BoolField2 = []byte("BoolField2")
var ffj_key_TypeWithoutReflection_BoolField3 = []byte("BoolField3")
var ffj_key_TypeWithoutReflection_BoolField4 = []byte("BoolField4")
var ffj_key_TypeWithoutReflection_BoolField5 = []byte("BoolField5")
func (uj *TypeWithoutReflection) UnmarshalJSON(input []byte) error {
fs := fflib.NewFFLexer(input)
return uj.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
}
func (uj *TypeWithoutReflection) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
var err error = nil
currentKey := ffj_t_TypeWithoutReflectionbase
_ = currentKey
tok := fflib.FFTok_init
wantedTok := fflib.FFTok_init
mainparse:
for {
tok = fs.Scan()
// println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
if tok == fflib.FFTok_error {
goto tokerror
}
switch state {
case fflib.FFParse_map_start:
if tok != fflib.FFTok_left_bracket {
wantedTok = fflib.FFTok_left_bracket
goto wrongtokenerror
}
state = fflib.FFParse_want_key
continue
case fflib.FFParse_after_value:
if tok == fflib.FFTok_comma {
state = fflib.FFParse_want_key
} else if tok == fflib.FFTok_right_bracket {
goto done
} else {
wantedTok = fflib.FFTok_comma
goto wrongtokenerror
}
case fflib.FFParse_want_key:
// json {} ended. goto exit. woo.
if tok == fflib.FFTok_right_bracket {
goto done
}
if tok != fflib.FFTok_string {
wantedTok = fflib.FFTok_string
goto wrongtokenerror
}
kn := fs.Output.Bytes()
if len(kn) <= 0 {
// "" case. hrm.
currentKey = ffj_t_TypeWithoutReflectionno_such_key
state = fflib.FFParse_want_colon
goto mainparse
} else {
switch kn[0] {
case 'B':
if bytes.Equal(ffj_key_TypeWithoutReflection_BoolField1, kn) {
currentKey = ffj_t_TypeWithoutReflection_BoolField1
state = fflib.FFParse_want_colon
goto mainparse
} else if bytes.Equal(ffj_key_TypeWithoutReflection_BoolField2, kn) {
currentKey = ffj_t_TypeWithoutReflection_BoolField2
state = fflib.FFParse_want_colon
goto mainparse
} else if bytes.Equal(ffj_key_TypeWithoutReflection_BoolField3, kn) {
currentKey = ffj_t_TypeWithoutReflection_BoolField3
state = fflib.FFParse_want_colon
goto mainparse
} else if bytes.Equal(ffj_key_TypeWithoutReflection_BoolField4, kn) {
currentKey = ffj_t_TypeWithoutReflection_BoolField4
state = fflib.FFParse_want_colon
goto mainparse
} else if bytes.Equal(ffj_key_TypeWithoutReflection_BoolField5, kn) {
currentKey = ffj_t_TypeWithoutReflection_BoolField5
state = fflib.FFParse_want_colon
goto mainparse
}
case 'I':
if bytes.Equal(ffj_key_TypeWithoutReflection_IntField1, kn) {
currentKey = ffj_t_TypeWithoutReflection_IntField1
state = fflib.FFParse_want_colon
goto mainparse
} else if bytes.Equal(ffj_key_TypeWithoutReflection_IntField2, kn) {
currentKey = ffj_t_TypeWithoutReflection_IntField2
state = fflib.FFParse_want_colon
goto mainparse
} else if bytes.Equal(ffj_key_TypeWithoutReflection_IntField3, kn) {
currentKey = ffj_t_TypeWithoutReflection_IntField3
state = fflib.FFParse_want_colon
goto mainparse
} else if bytes.Equal(ffj_key_TypeWithoutReflection_IntField4, kn) {
currentKey = ffj_t_TypeWithoutReflection_IntField4
state = fflib.FFParse_want_colon
goto mainparse
} else if bytes.Equal(ffj_key_TypeWithoutReflection_IntField5, kn) {
currentKey = ffj_t_TypeWithoutReflection_IntField5
state = fflib.FFParse_want_colon
goto mainparse
}
case 'S':
if bytes.Equal(ffj_key_TypeWithoutReflection_StringField1, kn) {
currentKey = ffj_t_TypeWithoutReflection_StringField1
state = fflib.FFParse_want_colon
goto mainparse
} else if bytes.Equal(ffj_key_TypeWithoutReflection_StringField2, kn) {
currentKey = ffj_t_TypeWithoutReflection_StringField2
state = fflib.FFParse_want_colon
goto mainparse
} else if bytes.Equal(ffj_key_TypeWithoutReflection_StringField3, kn) {
currentKey = ffj_t_TypeWithoutReflection_StringField3
state = fflib.FFParse_want_colon
goto mainparse
} else if bytes.Equal(ffj_key_TypeWithoutReflection_StringField4, kn) {
currentKey = ffj_t_TypeWithoutReflection_StringField4
state = fflib.FFParse_want_colon
goto mainparse
} else if bytes.Equal(ffj_key_TypeWithoutReflection_StringField5, kn) {
currentKey = ffj_t_TypeWithoutReflection_StringField5
state = fflib.FFParse_want_colon
goto mainparse
}
}
if fflib.AsciiEqualFold(ffj_key_TypeWithoutReflection_BoolField5, kn) {
currentKey = ffj_t_TypeWithoutReflection_BoolField5
state = fflib.FFParse_want_colon
goto mainparse
}
if fflib.AsciiEqualFold(ffj_key_TypeWithoutReflection_BoolField4, kn) {
currentKey = ffj_t_TypeWithoutReflection_BoolField4
state = fflib.FFParse_want_colon
goto mainparse
}
if fflib.AsciiEqualFold(ffj_key_TypeWithoutReflection_BoolField3, kn) {
currentKey = ffj_t_TypeWithoutReflection_BoolField3
state = fflib.FFParse_want_colon
goto mainparse
}
if fflib.AsciiEqualFold(ffj_key_TypeWithoutReflection_BoolField2, kn) {
currentKey = ffj_t_TypeWithoutReflection_BoolField2
state = fflib.FFParse_want_colon
goto mainparse
}
if fflib.AsciiEqualFold(ffj_key_TypeWithoutReflection_BoolField1, kn) {
currentKey = ffj_t_TypeWithoutReflection_BoolField1
state = fflib.FFParse_want_colon
goto mainparse
}
if fflib.EqualFoldRight(ffj_key_TypeWithoutReflection_StringField5, kn) {
currentKey = ffj_t_TypeWithoutReflection_StringField5
state = fflib.FFParse_want_colon
goto mainparse
}
if fflib.EqualFoldRight(ffj_key_TypeWithoutReflection_StringField4, kn) {
currentKey = ffj_t_TypeWithoutReflection_StringField4
state = fflib.FFParse_want_colon
goto mainparse
}
if fflib.EqualFoldRight(ffj_key_TypeWithoutReflection_StringField3, kn) {
currentKey = ffj_t_TypeWithoutReflection_StringField3
state = fflib.FFParse_want_colon
goto mainparse
}
if fflib.EqualFoldRight(ffj_key_TypeWithoutReflection_StringField2, kn) {
currentKey = ffj_t_TypeWithoutReflection_StringField2
state = fflib.FFParse_want_colon
goto mainparse
}
if fflib.EqualFoldRight(ffj_key_TypeWithoutReflection_StringField1, kn) {
currentKey = ffj_t_TypeWithoutReflection_StringField1
state = fflib.FFParse_want_colon
goto mainparse
}
if fflib.AsciiEqualFold(ffj_key_TypeWithoutReflection_IntField5, kn) {
currentKey = ffj_t_TypeWithoutReflection_IntField5
state = fflib.FFParse_want_colon
goto mainparse
}
if fflib.AsciiEqualFold(ffj_key_TypeWithoutReflection_IntField4, kn) {
currentKey = ffj_t_TypeWithoutReflection_IntField4
state = fflib.FFParse_want_colon
goto mainparse
}
if fflib.AsciiEqualFold(ffj_key_TypeWithoutReflection_IntField3, kn) {
currentKey = ffj_t_TypeWithoutReflection_IntField3
state = fflib.FFParse_want_colon
goto mainparse
}
if fflib.AsciiEqualFold(ffj_key_TypeWithoutReflection_IntField2, kn) {
currentKey = ffj_t_TypeWithoutReflection_IntField2
state = fflib.FFParse_want_colon
goto mainparse
}
if fflib.AsciiEqualFold(ffj_key_TypeWithoutReflection_IntField1, kn) {
currentKey = ffj_t_TypeWithoutReflection_IntField1
state = fflib.FFParse_want_colon
goto mainparse
}
currentKey = ffj_t_TypeWithoutReflectionno_such_key
state = fflib.FFParse_want_colon
goto mainparse
}
case fflib.FFParse_want_colon:
if tok != fflib.FFTok_colon {
wantedTok = fflib.FFTok_colon
goto wrongtokenerror
}
state = fflib.FFParse_want_value
continue
case fflib.FFParse_want_value:
if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
switch currentKey {
case ffj_t_TypeWithoutReflection_IntField1:
goto handle_IntField1
case ffj_t_TypeWithoutReflection_IntField2:
goto handle_IntField2
case ffj_t_TypeWithoutReflection_IntField3:
goto handle_IntField3
case ffj_t_TypeWithoutReflection_IntField4:
goto handle_IntField4
case ffj_t_TypeWithoutReflection_IntField5:
goto handle_IntField5
case ffj_t_TypeWithoutReflection_StringField1:
goto handle_StringField1
case ffj_t_TypeWithoutReflection_StringField2:
goto handle_StringField2
case ffj_t_TypeWithoutReflection_StringField3:
goto handle_StringField3
case ffj_t_TypeWithoutReflection_StringField4:
goto handle_StringField4
case ffj_t_TypeWithoutReflection_StringField5:
goto handle_StringField5
case ffj_t_TypeWithoutReflection_BoolField1:
goto handle_BoolField1
case ffj_t_TypeWithoutReflection_BoolField2:
goto handle_BoolField2
case ffj_t_TypeWithoutReflection_BoolField3:
goto handle_BoolField3
case ffj_t_TypeWithoutReflection_BoolField4:
goto handle_BoolField4
case ffj_t_TypeWithoutReflection_BoolField5:
goto handle_BoolField5
case ffj_t_TypeWithoutReflectionno_such_key:
err = fs.SkipField(tok)
if err != nil {
return fs.WrapErr(err)
}
state = fflib.FFParse_after_value
goto mainparse
}
} else {
goto wantedvalue
}
}
}
handle_IntField1:
/* handler: uj.IntField1 type=int kind=int quoted=false*/
{
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
}
}
{
if tok == fflib.FFTok_null {
} else {
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
if err != nil {
return fs.WrapErr(err)
}
uj.IntField1 = int(tval)
}
}
state = fflib.FFParse_after_value
goto mainparse
handle_IntField2:
/* handler: uj.IntField2 type=int kind=int quoted=false*/
{
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
}
}
{
if tok == fflib.FFTok_null {
} else {
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
if err != nil {
return fs.WrapErr(err)
}
uj.IntField2 = int(tval)
}
}
state = fflib.FFParse_after_value
goto mainparse
handle_IntField3:
/* handler: uj.IntField3 type=int kind=int quoted=false*/
{
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
}
}
{
if tok == fflib.FFTok_null {
} else {
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
if err != nil {
return fs.WrapErr(err)
}
uj.IntField3 = int(tval)
}
}
state = fflib.FFParse_after_value
goto mainparse
handle_IntField4:
/* handler: uj.IntField4 type=int kind=int quoted=false*/
{
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
}
}
{
if tok == fflib.FFTok_null {
} else {
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
if err != nil {
return fs.WrapErr(err)
}
uj.IntField4 = int(tval)
}
}
state = fflib.FFParse_after_value
goto mainparse
handle_IntField5:
/* handler: uj.IntField5 type=int kind=int quoted=false*/
{
if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
}
}
{
if tok == fflib.FFTok_null {
} else {
tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
if err != nil {
return fs.WrapErr(err)
}
uj.IntField5 = int(tval)
}
}
state = fflib.FFParse_after_value
goto mainparse
handle_StringField1:
/* handler: uj.StringField1 type=string kind=string quoted=false*/
{
{
if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
}
}
if tok == fflib.FFTok_null {
} else {
outBuf := fs.Output.Bytes()
uj.StringField1 = string(string(outBuf))
}
}
state = fflib.FFParse_after_value
goto mainparse
handle_StringField2:
/* handler: uj.StringField2 type=string kind=string quoted=false*/
{
{
if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
}
}
if tok == fflib.FFTok_null {
} else {
outBuf := fs.Output.Bytes()
uj.StringField2 = string(string(outBuf))
}
}
state = fflib.FFParse_after_value
goto mainparse
handle_StringField3:
/* handler: uj.StringField3 type=string kind=string quoted=false*/
{
{
if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
}
}
if tok == fflib.FFTok_null {
} else {
outBuf := fs.Output.Bytes()
uj.StringField3 = string(string(outBuf))
}
}
state = fflib.FFParse_after_value
goto mainparse
handle_StringField4:
/* handler: uj.StringField4 type=string kind=string quoted=false*/
{
{
if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
}
}
if tok == fflib.FFTok_null {
} else {
outBuf := fs.Output.Bytes()
uj.StringField4 = string(string(outBuf))
}
}
state = fflib.FFParse_after_value
goto mainparse
handle_StringField5:
/* handler: uj.StringField5 type=string kind=string quoted=false*/
{
{
if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
}
}
if tok == fflib.FFTok_null {
} else {
outBuf := fs.Output.Bytes()
uj.StringField5 = string(string(outBuf))
}
}
state = fflib.FFParse_after_value
goto mainparse
handle_BoolField1:
/* handler: uj.BoolField1 type=bool kind=bool quoted=false*/
{
if tok != fflib.FFTok_bool && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for bool", tok))
}
}
{
if tok == fflib.FFTok_null {
} else {
tmpb := fs.Output.Bytes()
if bytes.Compare([]byte{'t', 'r', 'u', 'e'}, tmpb) == 0 {
uj.BoolField1 = true
} else if bytes.Compare([]byte{'f', 'a', 'l', 's', 'e'}, tmpb) == 0 {
uj.BoolField1 = false
} else {
err = errors.New("unexpected bytes for true/false value")
return fs.WrapErr(err)
}
}
}
state = fflib.FFParse_after_value
goto mainparse
handle_BoolField2:
/* handler: uj.BoolField2 type=bool kind=bool quoted=false*/
{
if tok != fflib.FFTok_bool && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for bool", tok))
}
}
{
if tok == fflib.FFTok_null {
} else {
tmpb := fs.Output.Bytes()
if bytes.Compare([]byte{'t', 'r', 'u', 'e'}, tmpb) == 0 {
uj.BoolField2 = true
} else if bytes.Compare([]byte{'f', 'a', 'l', 's', 'e'}, tmpb) == 0 {
uj.BoolField2 = false
} else {
err = errors.New("unexpected bytes for true/false value")
return fs.WrapErr(err)
}
}
}
state = fflib.FFParse_after_value
goto mainparse
handle_BoolField3:
/* handler: uj.BoolField3 type=bool kind=bool quoted=false*/
{
if tok != fflib.FFTok_bool && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for bool", tok))
}
}
{
if tok == fflib.FFTok_null {
} else {
tmpb := fs.Output.Bytes()
if bytes.Compare([]byte{'t', 'r', 'u', 'e'}, tmpb) == 0 {
uj.BoolField3 = true
} else if bytes.Compare([]byte{'f', 'a', 'l', 's', 'e'}, tmpb) == 0 {
uj.BoolField3 = false
} else {
err = errors.New("unexpected bytes for true/false value")
return fs.WrapErr(err)
}
}
}
state = fflib.FFParse_after_value
goto mainparse
handle_BoolField4:
/* handler: uj.BoolField4 type=bool kind=bool quoted=false*/
{
if tok != fflib.FFTok_bool && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for bool", tok))
}
}
{
if tok == fflib.FFTok_null {
} else {
tmpb := fs.Output.Bytes()
if bytes.Compare([]byte{'t', 'r', 'u', 'e'}, tmpb) == 0 {
uj.BoolField4 = true
} else if bytes.Compare([]byte{'f', 'a', 'l', 's', 'e'}, tmpb) == 0 {
uj.BoolField4 = false
} else {
err = errors.New("unexpected bytes for true/false value")
return fs.WrapErr(err)
}
}
}
state = fflib.FFParse_after_value
goto mainparse
handle_BoolField5:
/* handler: uj.BoolField5 type=bool kind=bool quoted=false*/
{
if tok != fflib.FFTok_bool && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for bool", tok))
}
}
{
if tok == fflib.FFTok_null {
} else {
tmpb := fs.Output.Bytes()
if bytes.Compare([]byte{'t', 'r', 'u', 'e'}, tmpb) == 0 {
uj.BoolField5 = true
} else if bytes.Compare([]byte{'f', 'a', 'l', 's', 'e'}, tmpb) == 0 {
uj.BoolField5 = false
} else {
err = errors.New("unexpected bytes for true/false value")
return fs.WrapErr(err)
}
}
}
state = fflib.FFParse_after_value
goto mainparse
wantedvalue:
return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
wrongtokenerror:
return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
tokerror:
if fs.BigError != nil {
return fs.WrapErr(fs.BigError)
}
err = fs.Error.ToError()
if err != nil {
return fs.WrapErr(err)
}
panic("ffjson-generated: unreachable, please report bug.")
done:
return nil
}
package protocol
import (
"testing"
"encoding/json"
"github.com/pquerna/ffjson/ffjson"
)
func BenchmarkJsonReflection(b *testing.B) {
value := &TypeWithReflection{
IntField1: 3245235235,
IntField2: 213541454356234,
IntField3: 3453456356,
IntField4: 345634562,
IntField5: 1352345234,
StringField1: "rlkgwenpfhqwpoeifqwmepf",
StringField2: "erwgwergwergwergwergeqrg",
StringField3: "regw3pefqowfh`qpewfuhqif",
StringField4: "ergfywqe8ruh34qbcfq34b98cyr023489rn",
StringField5: "wefny30wcywercgyeprwybcpwreycgewrybg",
BoolField1: true,
BoolField2: true,
BoolField3: true,
BoolField4: false,
BoolField5: false,
}
for i := 0; i < b.N; i++ {
bytes, err := json.Marshal(value)
if err != nil {
panic(err);
}
err = json.Unmarshal(bytes, value)
if err != nil {
panic(err);
}
}
}
func BenchmarkFFJson(b *testing.B) {
value := &TypeWithoutReflection{
IntField1: 3245235235,
IntField2: 213541454356234,
IntField3: 3453456356,
IntField4: 345634562,
IntField5: 1352345234,
StringField1: "rlkgwenpfhqwpoeifqwmepf",
StringField2: "erwgwergwergwergwergeqrg",
StringField3: "regw3pefqowfh`qpewfuhqif",
StringField4: "ergfywqe8ruh34qbcfq34b98cyr023489rn",
StringField5: "wefny30wcywercgyeprwybcpwreycgewrybg",
BoolField1: true,
BoolField2: true,
BoolField3: true,
BoolField4: false,
BoolField5: false,
}
for i := 0; i < b.N; i++ {
bytes, err := ffjson.Marshal(value)
if err != nil {
panic(err);
}
err = ffjson.Unmarshal(bytes, value)
if err != nil {
panic(err);
}
ffjson.Pool(bytes)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment