Esempio n. 1
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)
}
Esempio n. 2
0
func (u ISBN10) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	u.MarshalEasyJSON(&w)
	return w.BuildBytes()
}
Esempio n. 3
0
func (h Hostname) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	h.MarshalEasyJSON(&w)
	return w.BuildBytes()
}
Esempio n. 4
0
func (e Email) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	e.MarshalEasyJSON(&w)
	return w.BuildBytes()
}
Esempio n. 5
0
func (b Base64) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	b.MarshalEasyJSON(&w)
	return w.BuildBytes()
}
Esempio n. 6
0
func (r Password) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	r.MarshalEasyJSON(&w)
	return w.BuildBytes()
}
Esempio n. 7
0
func (u CreditCard) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	u.MarshalEasyJSON(&w)
	return w.BuildBytes()
}
Esempio n. 8
0
func (t DateTime) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	t.MarshalEasyJSON(&w)
	return w.BuildBytes()
}
Esempio n. 9
0
// Marshal returns data as a single byte slice. Method is suboptimal as the data is likely to be copied
// from a chain of smaller chunks.
func Marshal(v Marshaler) ([]byte, error) {
	w := jwriter.Writer{}
	v.MarshalEasyJSON(&w)
	return w.BuildBytes()
}
Esempio n. 10
0
func (d Duration) MarshalJSON() ([]byte, error) {
	var w jwriter.Writer
	d.MarshalEasyJSON(&w)
	return w.BuildBytes()
}