本文整理匯總了Golang中github.com/pquerna/ffjson/fflib/v1.Buffer.Bytes方法的典型用法代碼示例。如果您正苦於以下問題:Golang Buffer.Bytes方法的具體用法?Golang Buffer.Bytes怎麽用?Golang Buffer.Bytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pquerna/ffjson/fflib/v1.Buffer
的用法示例。
在下文中一共展示了Buffer.Bytes方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MarshalJSON
func (mj *Event) MarshalJSON() ([]byte, error) {
var buf fflib.Buffer
err := mj.MarshalJSONBuf(&buf)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
示例2: MarshalJSON
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
}
示例3: MarshalJSON
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
}
示例4: MarshalJSON
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
}
示例5: Marshal
// 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)
}