Example #1
0
func (mj *Event) MarshalJSON() ([]byte, error) {
	var buf fflib.Buffer
	err := mj.MarshalJSONBuf(&buf)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
func (mj *ResponseCountry) MarshalJSON() ([]byte, error) {
	var buf fflib.Buffer
	buf.Grow(128)
	err := mj.MarshalJSONBuf(&buf)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
func (mj *Traits) MarshalJSON() ([]byte, error) {
	var buf fflib.Buffer
	buf.Grow(16)
	err := mj.MarshalJSONBuf(&buf)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
func (mj *Subdivision) MarshalJSON() ([]byte, error) {
	var buf fflib.Buffer
	buf.Grow(256)
	err := mj.MarshalJSONBuf(&buf)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
func (mj *RepresentedCountry) MarshalJSON() ([]byte, error) {
	var buf fflib.Buffer
	buf.Grow(256)
	err := mj.MarshalJSONBuf(&buf)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
func (mj *ConnectionType) MarshalJSON() ([]byte, error) {
	var buf fflib.Buffer
	buf.Grow(64)
	err := mj.MarshalJSONBuf(&buf)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
Example #7
0
// Marshal will act the same way as json.Marshal, except
// it will choose the ffjson marshal function before falling
// back to using json.Marshal.
// Using this function will bypass the internal copying and parsing
// the json library normally does, which greatly speeds up encoding time.
// It is ok to call this function even if no ffjson code has been
// generated for the data type you pass in the interface.
func Marshal(v interface{}) ([]byte, error) {
	f, ok := v.(marshalerFaster)
	if ok {
		buf := fflib.Buffer{}
		err := f.MarshalJSONBuf(&buf)
		b := buf.Bytes()
		if err != nil {
			if len(b) > 0 {
				Pool(b)
			}
			return nil, err
		}
		return b, nil
	}

	j, ok := v.(json.Marshaler)
	if ok {
		return j.MarshalJSON()
	}
	return json.Marshal(v)
}
Example #8
0
func (mj *Pos2D) 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
}