本文整理汇总了Golang中github.com/ugorji/go/codec.Encoder类的典型用法代码示例。如果您正苦于以下问题:Golang Encoder类的具体用法?Golang Encoder怎么用?Golang Encoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Encoder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: persistIndexes
func (s *nomadSnapshot) persistIndexes(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
// Get all the indexes
iter, err := s.snap.Indexes()
if err != nil {
return err
}
for {
// Get the next item
raw := iter.Next()
if raw == nil {
break
}
// Prepare the request struct
idx := raw.(*state.IndexEntry)
// Write out a node registration
sink.Write([]byte{byte(IndexSnapshot)})
if err := encoder.Encode(idx); err != nil {
return err
}
}
return nil
}
开发者ID:dgshep,项目名称:nomad,代码行数:26,代码来源:fsm.go
示例2: CodecEncodeSelf
// CodecEncodeSelf implements codec.Selfer
func (c *EdgeMetadatas) CodecEncodeSelf(encoder *codec.Encoder) {
if c.psMap != nil {
encoder.Encode(c.toIntermediate())
} else {
encoder.Encode(nil)
}
}
开发者ID:dilgerma,项目名称:scope,代码行数:8,代码来源:edge_metadatas.go
示例3: persistJobs
func (s *nomadSnapshot) persistJobs(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
// Get all the jobs
jobs, err := s.snap.Jobs()
if err != nil {
return err
}
for {
// Get the next item
raw := jobs.Next()
if raw == nil {
break
}
// Prepare the request struct
job := raw.(*structs.Job)
// Write out a job registration
sink.Write([]byte{byte(JobSnapshot)})
if err := encoder.Encode(job); err != nil {
return err
}
}
return nil
}
开发者ID:dgshep,项目名称:nomad,代码行数:26,代码来源:fsm.go
示例4: persistNodes
func (s *nomadSnapshot) persistNodes(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
// Get all the nodes
nodes, err := s.snap.Nodes()
if err != nil {
return err
}
for {
// Get the next item
raw := nodes.Next()
if raw == nil {
break
}
// Prepare the request struct
node := raw.(*structs.Node)
// Write out a node registration
sink.Write([]byte{byte(NodeSnapshot)})
if err := encoder.Encode(node); err != nil {
return err
}
}
return nil
}
开发者ID:dgshep,项目名称:nomad,代码行数:26,代码来源:fsm.go
示例5: persistAllocs
func (s *nomadSnapshot) persistAllocs(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
// Get all the allocations
allocs, err := s.snap.Allocs()
if err != nil {
return err
}
for {
// Get the next item
raw := allocs.Next()
if raw == nil {
break
}
// Prepare the request struct
alloc := raw.(*structs.Allocation)
// Write out the evaluation
sink.Write([]byte{byte(AllocSnapshot)})
if err := encoder.Encode(alloc); err != nil {
return err
}
}
return nil
}
开发者ID:dgshep,项目名称:nomad,代码行数:26,代码来源:fsm.go
示例6: persistEvals
func (s *nomadSnapshot) persistEvals(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
// Get all the evaluations
evals, err := s.snap.Evals()
if err != nil {
return err
}
for {
// Get the next item
raw := evals.Next()
if raw == nil {
break
}
// Prepare the request struct
eval := raw.(*structs.Evaluation)
// Write out the evaluation
sink.Write([]byte{byte(EvalSnapshot)})
if err := encoder.Encode(eval); err != nil {
return err
}
}
return nil
}
开发者ID:dgshep,项目名称:nomad,代码行数:26,代码来源:fsm.go
示例7: CodecEncodeSelf
// CodecEncodeSelf implements codec.Selfer
func (m *LatestMap) CodecEncodeSelf(encoder *codec.Encoder) {
if m.Map != nil {
encoder.Encode(m.toIntermediate())
} else {
encoder.Encode(nil)
}
}
开发者ID:CNDonny,项目名称:scope,代码行数:8,代码来源:latest_map.go
示例8: CodecEncodeSelf
// CodecEncodeSelf implements codec.Selfer
func (n *PluginSpecs) CodecEncodeSelf(encoder *codec.Encoder) {
if n.psMap != nil {
encoder.Encode(n.toIntermediate())
} else {
encoder.Encode(nil)
}
}
开发者ID:dilgerma,项目名称:scope,代码行数:8,代码来源:plugin_spec.go
示例9: persistPeriodicLaunches
func (s *nomadSnapshot) persistPeriodicLaunches(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
// Get all the jobs
launches, err := s.snap.PeriodicLaunches()
if err != nil {
return err
}
for {
// Get the next item
raw := launches.Next()
if raw == nil {
break
}
// Prepare the request struct
launch := raw.(*structs.PeriodicLaunch)
// Write out a job registration
sink.Write([]byte{byte(PeriodicLaunchSnapshot)})
if err := encoder.Encode(launch); err != nil {
return err
}
}
return nil
}
开发者ID:dgshep,项目名称:nomad,代码行数:26,代码来源:fsm.go
示例10: CodecEncodeSelf
// CodecEncodeSelf implements codec.Selfer
func (s *Sets) CodecEncodeSelf(encoder *codec.Encoder) {
if s.psMap != nil {
encoder.Encode(s.toIntermediate())
} else {
encoder.Encode(nil)
}
}
开发者ID:dilgerma,项目名称:scope,代码行数:8,代码来源:sets.go
示例11: persistKV
func (s *consulSnapshot) persistKV(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
streamCh := make(chan interface{}, 256)
errorCh := make(chan error)
go func() {
if err := s.state.KVSDump(streamCh); err != nil {
errorCh <- err
}
}()
for {
select {
case raw := <-streamCh:
if raw == nil {
return nil
}
sink.Write([]byte{byte(structs.KVSRequestType)})
if err := encoder.Encode(raw); err != nil {
return err
}
case err := <-errorCh:
return err
}
}
return nil
}
开发者ID:askagirl,项目名称:consul,代码行数:27,代码来源:fsm.go
示例12: encodeRecordSet
func encodeRecordSet(encoder *codec.Encoder, recordSet FluentRecordSet) error {
v := []interface{}{recordSet.Tag, recordSet.Records}
err := encoder.Encode(v)
if err != nil {
return err
}
return err
}
开发者ID:suzukaze,项目名称:fluentd-forwarder,代码行数:8,代码来源:output.go
示例13: CodecEncodeSelf
// CodecEncodeSelf marshals this ControlInstance. It takes the basic Metric
// rendering, then adds some row-specific fields.
func (c *ControlInstance) CodecEncodeSelf(encoder *codec.Encoder) {
encoder.Encode(wiredControlInstance{
ProbeID: c.ProbeID,
NodeID: c.NodeID,
ID: c.Control.ID,
Human: c.Control.Human,
Icon: c.Control.Icon,
Rank: c.Control.Rank,
})
}
开发者ID:dilgerma,项目名称:scope,代码行数:12,代码来源:node.go
示例14: encodeRecords
func encodeRecords(encoder *codec.Encoder, records []TinyFluentRecord) error {
for _, record := range records {
e := map[string]interface{}{"time": record.Timestamp}
for k, v := range record.Data {
e[k] = v
}
err := encoder.Encode(e)
if err != nil {
return err
}
}
return nil
}
开发者ID:idahoakl,项目名称:fluentd-forwarder,代码行数:13,代码来源:output_td.go
示例15: persistSessions
func (s *consulSnapshot) persistSessions(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
sessions, err := s.state.SessionList()
if err != nil {
return err
}
for _, s := range sessions {
sink.Write([]byte{byte(structs.SessionRequestType)})
if err := encoder.Encode(s); err != nil {
return err
}
}
return nil
}
开发者ID:askagirl,项目名称:consul,代码行数:15,代码来源:fsm.go
示例16: persistACLs
func (s *consulSnapshot) persistACLs(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
acls, err := s.state.ACLList()
if err != nil {
return err
}
for _, s := range acls {
sink.Write([]byte{byte(structs.ACLRequestType)})
if err := encoder.Encode(s); err != nil {
return err
}
}
return nil
}
开发者ID:askagirl,项目名称:consul,代码行数:15,代码来源:fsm.go
示例17: main
func main() {
log.Println("MsgPack test begin==>")
bookNode := Book{"web-founding", 36.5}
for i := 0; i < 200; i++ {
bookList = append(bookList, bookNode)
}
log.Println("json test=>begin")
jbook, err := json.Marshal(bookList)
if err != nil {
log.Println("json failed=>", err)
return
}
log.Println("length[", len(jbook), "]")
fh, _ := os.OpenFile("json.txt", os.O_CREATE|os.O_WRONLY, 0666)
nlen, _ := fh.Write(jbook)
log.Println("acive write byte length[", nlen, "]")
fh.Close()
log.Println("json test=>end")
log.Println("==================================")
log.Println("msgpack test=>begin")
log.Println("msgpack encoding...")
var h codec.Handle = new(codec.MsgpackHandle)
var buf []byte
var enc *codec.Encoder = codec.NewEncoderBytes(&buf, h)
err = enc.Encode(bookList)
if err != nil {
log.Println("msgpack encode err:", err)
return
}
// hlen := hex.Encode(dst, buf)
log.Println("buf:=>", len(hex.EncodeToString(buf)))
fmsg, _ := os.OpenFile("msg.txt", os.O_CREATE|os.O_WRONLY, 0666)
nlen, _ = fmsg.Write(buf)
log.Println("acive write byte length[", nlen, "]")
fmsg.Close()
log.Println("msgpack decoding...")
var dec *codec.Decoder = codec.NewDecoderBytes(buf, h)
v2 := new([]Book)
log.Println("src data len=>", len(buf))
err = dec.Decode(v2)
if err != nil {
log.Println("msgpack decode err:", err)
return
}
// log.Println("decode=>", *v2)
log.Println("msgpack test=>end")
log.Println("MsgPack test end==>")
}
开发者ID:sunvim,项目名称:codelab,代码行数:48,代码来源:msgpack.go
示例18: CodecEncodeSelf
// CodecEncodeSelf marshals this MetricRow. It takes the basic Metric
// rendering, then adds some row-specific fields.
func (m *MetricRow) CodecEncodeSelf(encoder *codec.Encoder) {
in := m.Metric.ToIntermediate()
encoder.Encode(wiredMetricRow{
ID: m.ID,
Label: m.Label,
Format: m.Format,
Group: m.Group,
Value: m.Value,
Priority: m.Priority,
Samples: in.Samples,
Min: in.Min,
Max: in.Max,
First: in.First,
Last: in.Last,
})
}
开发者ID:dilgerma,项目名称:scope,代码行数:18,代码来源:metric_row.go
示例19: New
/*
* New creates a new message from a message type and a generic payload
*/
func New(t Type, p interface{}) *Message {
var mh codec.MsgpackHandle
msg := new(Message)
msg.Type = t
// Encode payload to msgpack
bb := new(bytes.Buffer)
var enc *codec.Encoder = codec.NewEncoder(bb, &mh)
err := enc.Encode(p)
if err != nil {
log.WithError(err).Error("Error encoding payload")
return nil
}
// Copy the payload buffer
msg.Payload = bb.Bytes()
// Length is the buffer length
msg.Length = uint32(len(msg.Payload))
return msg
}
开发者ID:RookieGameDevs,项目名称:surviveler,代码行数:25,代码来源:messages.go
示例20: persistVaultAccessors
func (s *nomadSnapshot) persistVaultAccessors(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
accessors, err := s.snap.VaultAccessors()
if err != nil {
return err
}
for {
raw := accessors.Next()
if raw == nil {
break
}
accessor := raw.(*structs.VaultAccessor)
sink.Write([]byte{byte(VaultAccessorSnapshot)})
if err := encoder.Encode(accessor); err != nil {
return err
}
}
return nil
}
开发者ID:zanella,项目名称:nomad,代码行数:23,代码来源:fsm.go
注:本文中的github.com/ugorji/go/codec.Encoder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论