本文整理汇总了Golang中github.com/pquerna/ffjson/fflib/v1.EncodingBuffer.Encode方法的典型用法代码示例。如果您正苦于以下问题:Golang EncodingBuffer.Encode方法的具体用法?Golang EncodingBuffer.Encode怎么用?Golang EncodingBuffer.Encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pquerna/ffjson/fflib/v1.EncodingBuffer
的用法示例。
在下文中一共展示了EncodingBuffer.Encode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MarshalJSONBuf
func (mj *AgentRender) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
if mj == nil {
buf.WriteString("null")
return nil
}
var err error
var obj []byte
_ = obj
_ = err
buf.WriteString(`{"agent-type":`)
fflib.WriteJsonString(buf, string(mj.Type))
buf.WriteString(`,"position":`)
{
err = mj.Pos2D.MarshalJSONBuf(buf)
if err != nil {
return err
}
}
buf.WriteString(`,"heading":`)
fflib.AppendFloat(buf, float64(mj.Heading), 'g', -1, 64)
/* Struct fall back. type=colour.RGB256 kind=struct */
buf.WriteString(`,"colour":`)
err = buf.Encode(&mj.Colour)
if err != nil {
return err
}
buf.WriteByte('}')
return nil
}
示例2: MarshalJSONBuf
func (mj *TaskEvent) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
if mj == nil {
buf.WriteString("null")
return nil
}
var err error
var obj []byte
_ = obj
_ = err
buf.WriteString(`{"type":`)
fflib.WriteJsonString(buf, string(mj.Type))
buf.WriteString(`,"hostname":`)
fflib.WriteJsonString(buf, string(mj.Hostname))
buf.WriteString(`,"timestamp":`)
fflib.AppendFloat(buf, float64(mj.Timestamp), 'g', -1, 32)
buf.WriteString(`,"pid":`)
fflib.FormatBits2(buf, uint64(mj.PID), 10, mj.PID < 0)
buf.WriteString(`,"clock":`)
fflib.FormatBits2(buf, uint64(mj.Clock), 10, mj.Clock < 0)
buf.WriteString(`,"utcoffset":`)
fflib.FormatBits2(buf, uint64(mj.UTCOffset), 10, mj.UTCOffset < 0)
buf.WriteString(`,"uuid":`)
fflib.WriteJsonString(buf, string(mj.UUID))
buf.WriteString(`,"name":`)
fflib.WriteJsonString(buf, string(mj.Name))
buf.WriteString(`,"args":`)
fflib.WriteJsonString(buf, string(mj.Args))
buf.WriteString(`,"kwargs":`)
fflib.WriteJsonString(buf, string(mj.Kwargs))
buf.WriteString(`,"result":`)
fflib.WriteJsonString(buf, string(mj.Result))
buf.WriteString(`,"runtime":`)
fflib.AppendFloat(buf, float64(mj.Runtime), 'g', -1, 32)
buf.WriteString(`,"retries":`)
fflib.FormatBits2(buf, uint64(mj.Retries), 10, mj.Retries < 0)
buf.WriteString(`,"eta":`)
fflib.FormatBits2(buf, uint64(mj.ETA), 10, mj.ETA < 0)
buf.WriteString(`,"exception":`)
fflib.WriteJsonString(buf, string(mj.Exception))
buf.WriteString(`,"traceback":`)
fflib.WriteJsonString(buf, string(mj.Traceback))
if mj.Terminated {
buf.WriteString(`,"terminated":true`)
} else {
buf.WriteString(`,"terminated":false`)
}
buf.WriteString(`,"signum":`)
/* Interface types must use runtime reflection. type=interface {} kind=interface */
err = buf.Encode(mj.Signum)
if err != nil {
return err
}
if mj.Expired {
buf.WriteString(`,"expired":true`)
} else {
buf.WriteString(`,"expired":false`)
}
buf.WriteByte('}')
return nil
}
示例3: MarshalJSONBuf
func (mj *User) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
if mj == nil {
buf.WriteString("null")
return nil
}
var err error
var obj []byte
_ = obj
_ = err
buf.WriteString(`{"name":`)
fflib.WriteJsonString(buf, string(mj.Name))
buf.WriteString(`,"color":`)
fflib.WriteJsonString(buf, string(mj.Color))
if mj.LoggedIn {
buf.WriteString(`,"logged-in":true`)
} else {
buf.WriteString(`,"logged-in":false`)
}
/* Falling back. type=map[int]chat.voteOption kind=map */
buf.WriteString(`,"voteMask":`)
err = buf.Encode(mj.Votes)
if err != nil {
return err
}
buf.WriteByte('}')
return nil
}
示例4: MarshalJSONBuf
func (mj *OutMsg) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
if mj == nil {
buf.WriteString("null")
return nil
}
var err error
var obj []byte
_ = obj
_ = err
buf.WriteString(`{"type":`)
fflib.WriteJsonString(buf, string(mj.Type))
buf.WriteString(`,"data":`)
/* Interface types must use runtime reflection. type=interface {} kind=interface */
err = buf.Encode(mj.Data)
if err != nil {
return err
}
buf.WriteByte('}')
return nil
}
示例5: MarshalJSONBuf
func (mj *EventStream) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
if mj == nil {
buf.WriteString("null")
return nil
}
var err error
var obj []byte
_ = obj
_ = err
buf.WriteString(`{"Err":`)
/* Falling back. type=chan error kind=chan */
err = buf.Encode(mj.Err)
if err != nil {
return err
}
buf.WriteString(`,"Events":`)
/* Falling back. type=chan census.Event kind=chan */
err = buf.Encode(mj.Events)
if err != nil {
return err
}
buf.WriteString(`,"Closed":`)
/* Falling back. type=chan struct {} kind=chan */
err = buf.Encode(mj.Closed)
if err != nil {
return err
}
buf.WriteByte('}')
return nil
}