Exemple #1
0
// 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")
	}
}
Exemple #2
0
// MarshalEasyJSON does JSON marshaling using easyjson interface.
func (v *RawMessage) MarshalEasyJSON(w *jwriter.Writer) {
	if len(*v) == 0 {
		w.RawString("null")
	} else {
		w.Raw(*v, nil)
	}
}
Exemple #3
0
// MarshalEasyJSON does JSON marshaling using easyjson interface.
func (v Uint) MarshalEasyJSON(w *jwriter.Writer) {
	if v.Defined {
		w.Uint(v.V)
	} else {
		w.RawString("null")
	}
}
Exemple #4
0
// MarshalEasyJSON does JSON marshaling using easyjson interface.
func (v Optional) MarshalEasyJSON(w *jwriter.Writer) {
	if v.Defined {
		w.Optional(v.V)
	} else {
		w.RawString("null")
	}
}
Exemple #5
0
// MarshalEasyJSON does JSON marshaling using easyjson interface.
func (v Int16) MarshalEasyJSON(w *jwriter.Writer) {
	if v.Defined {
		w.Int16(v.V)
	} else {
		w.RawString("null")
	}
}
Exemple #6
0
// MarshalEasyJSON does JSON marshaling using easyjson interface.
func (v Bool) MarshalEasyJSON(w *jwriter.Writer) {
	if v.Defined {
		w.Bool(v.V)
	} else {
		w.RawString("null")
	}
}
Exemple #7
0
// WriteJSON writes json data, prefers finding an appropriate interface to short-circuit the marshaller
// so it takes the fastest option available.
func WriteJSON(data interface{}) ([]byte, error) {
	if d, ok := data.(ejMarshaler); ok {
		jw := new(jwriter.Writer)
		d.MarshalEasyJSON(jw)
		return jw.BuildBytes()
	}
	if d, ok := data.(json.Marshaler); ok {
		return d.MarshalJSON()
	}
	return json.Marshal(data)
}
Exemple #8
0
func easyjson_encode_github_com_buger_jsonparser_benchmark_CBGithub(out *jwriter.Writer, in *CBGithub) {
	out.RawByte('{')
	first := true
	_ = first
	if !first {
		out.RawByte(',')
	}
	first = false
	out.RawString("\"followers\":")
	out.Int(in.Followers)
	out.RawByte('}')
}
Exemple #9
0
func easyjson_encode_github_com_buger_jsonparser_benchmark_DSUser(out *jwriter.Writer, in *DSUser) {
	out.RawByte('{')
	first := true
	_ = first
	if !first {
		out.RawByte(',')
	}
	first = false
	out.RawString("\"username\":")
	out.String(in.Username)
	out.RawByte('}')
}
Exemple #10
0
func easyjson_encode_github_com_buger_jsonparser_benchmark_CBName(out *jwriter.Writer, in *CBName) {
	out.RawByte('{')
	first := true
	_ = first
	if !first {
		out.RawByte(',')
	}
	first = false
	out.RawString("\"full_name\":")
	out.String(in.FullName)
	out.RawByte('}')
}
Exemple #11
0
func easyjson_encode_github_com_buger_jsonparser_benchmark_CBAvatar(out *jwriter.Writer, in *CBAvatar) {
	out.RawByte('{')
	first := true
	_ = first
	if !first {
		out.RawByte(',')
	}
	first = false
	out.RawString("\"url\":")
	out.String(in.Url)
	out.RawByte('}')
}
Exemple #12
0
// MarshalToHTTPResponseWriter sets Content-Length and Content-Type headers for the
// http.ResponseWriter, and send the data to the writer. started will be equal to
// false if an error occurred before any http.ResponseWriter methods were actually
// invoked (in this case a 500 reply is possible).
func MarshalToHTTPResponseWriter(v Marshaler, w http.ResponseWriter) (started bool, written int, err error) {
	jw := jwriter.Writer{}
	v.MarshalEasyJSON(&jw)
	if jw.Error != nil {
		return false, 0, jw.Error
	}
	w.Header().Set("Content-Type", "application/json")
	w.Header().Set("Content-Length", strconv.Itoa(jw.Size()))

	started = true
	written, err = jw.DumpTo(w)
	return
}
Exemple #13
0
func BenchmarkEJ_Marshal_M_ToWriter(b *testing.B) {
	var l int64
	out := &DummyWriter{}
	for i := 0; i < b.N; i++ {
		w := jwriter.Writer{}
		largeStructData.MarshalEasyJSON(&w)
		if w.Error != nil {
			b.Error(w.Error)
		}

		l = int64(w.Size())
		w.DumpTo(out)
	}
	b.SetBytes(l)

}
Exemple #14
0
func BenchmarkEJ_Marshal_L_ToWriter_Parallel(b *testing.B) {
	out := &DummyWriter{}
	b.RunParallel(func(pb *testing.PB) {
		var l int64
		for pb.Next() {
			w := jwriter.Writer{}

			xlStructData.MarshalEasyJSON(&w)
			if w.Error != nil {
				b.Error(w.Error)
			}
			l = int64(w.Size())
			w.DumpTo(out)
		}
		if l > 0 {
			b.SetBytes(l)
		}
	})
}
Exemple #15
0
func easyjson_encode_finance_provider_yahoo_Response(out *jwriter.Writer, in *Response) {
	out.RawByte('{')
	first := true
	_ = first
	if !first {
		out.RawByte(',')
	}
	first = false
	out.RawString("\"query\":")
	(in.Query).MarshalEasyJSON(out)
	out.RawByte('}')
}
Exemple #16
0
func (e Email) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(e))
}
Exemple #17
0
func (e Email) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	e.MarshalEasyJSON(&w)
	return w.BuildBytes()
}
Exemple #18
0
func (b Base64) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(base64.StdEncoding.EncodeToString([]byte(b)))
}
Exemple #19
0
func (b Base64) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	b.MarshalEasyJSON(&w)
	return w.BuildBytes()
}
Exemple #20
0
func (r Password) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(r))
}
Exemple #21
0
func (r Password) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	r.MarshalEasyJSON(&w)
	return w.BuildBytes()
}
Exemple #22
0
func (u UUID5) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}
Exemple #23
0
func (h Hostname) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	h.MarshalEasyJSON(&w)
	return w.BuildBytes()
}
Exemple #24
0
func (u ISBN10) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}
Exemple #25
0
func (h Hostname) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(h))
}
Exemple #26
0
func (h HexColor) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(h))
}
Exemple #27
0
func (u ISBN10) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	u.MarshalEasyJSON(&w)
	return w.BuildBytes()
}
Exemple #28
0
func (r RGBColor) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(r))
}
func easyjson_encode_go_serialization_benchmarks_A(out *jwriter.Writer, in *A) {
	out.RawByte('{')
	first := true
	_ = first
	if !first {
		out.RawByte(',')
	}
	first = false
	out.RawString("\"Name\":")
	out.String(in.Name)
	if !first {
		out.RawByte(',')
	}
	first = false
	out.RawString("\"BirthDay\":")
	out.Raw((in.BirthDay).MarshalJSON())
	if !first {
		out.RawByte(',')
	}
	first = false
	out.RawString("\"Phone\":")
	out.String(in.Phone)
	if !first {
		out.RawByte(',')
	}
	first = false
	out.RawString("\"Siblings\":")
	out.Int(in.Siblings)
	if !first {
		out.RawByte(',')
	}
	first = false
	out.RawString("\"Spouse\":")
	out.Bool(in.Spouse)
	if !first {
		out.RawByte(',')
	}
	first = false
	out.RawString("\"Money\":")
	out.Float64(in.Money)
	out.RawByte('}')
}
Exemple #30
0
func (u CreditCard) MarshalEasyJSON(w *jwriter.Writer) {
	w.String(string(u))
}