本文整理汇总了Golang中github.com/ugorji/go/codec.Decoder.Decode方法的典型用法代码示例。如果您正苦于以下问题:Golang Decoder.Decode方法的具体用法?Golang Decoder.Decode怎么用?Golang Decoder.Decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ugorji/go/codec.Decoder
的用法示例。
在下文中一共展示了Decoder.Decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CodecDecodeSelf
// CodecDecodeSelf implements codec.Selfer
func (n *NodeSet) CodecDecodeSelf(decoder *codec.Decoder) {
in := []Node{}
if err := decoder.Decode(&in); err != nil {
return
}
*n = NodeSet{}.fromIntermediate(in)
}
示例2: CodecDecodeSelf
// CodecDecodeSelf implements codec.Selfer
func (n *PluginSpecs) CodecDecodeSelf(decoder *codec.Decoder) {
in := []PluginSpec{}
if err := decoder.Decode(&in); err != nil {
return
}
*n = PluginSpecs{}.fromIntermediate(in)
}
示例3: CodecDecodeSelf
// CodecDecodeSelf implements codec.Selfer
func (c *Counters) CodecDecodeSelf(decoder *codec.Decoder) {
in := map[string]int{}
if err := decoder.Decode(&in); err != nil {
return
}
*c = Counters{}.fromIntermediate(in)
}
示例4: CodecDecodeSelf
// CodecDecodeSelf implements codec.Selfer
func (m *Metric) CodecDecodeSelf(decoder *codec.Decoder) {
in := WireMetrics{}
if err := decoder.Decode(&in); err != nil {
return
}
*m = in.FromIntermediate()
}
示例5: CodecDecodeSelf
// CodecDecodeSelf implements codec.Selfer
func (m *LatestMap) CodecDecodeSelf(decoder *codec.Decoder) {
in := map[string]LatestEntry{}
if err := decoder.Decode(&in); err != nil {
return
}
*m = LatestMap{}.fromIntermediate(in)
}
示例6: CodecDecodeSelf
// CodecDecodeSelf implements codec.Selfer
func (s *Sets) CodecDecodeSelf(decoder *codec.Decoder) {
in := map[string]StringSet{}
if err := decoder.Decode(&in); err != nil {
return
}
*s = Sets{}.fromIntermediate(in)
}
示例7: readUserMsg
// readUserMsg is used to decode a UserMsg from a TCP stream
func (m *Memberlist) readUserMsg(bufConn io.Reader, dec *codec.Decoder) error {
// Read the user message header
var header userMsgHeader
if err := dec.Decode(&header); err != nil {
return err
}
// Read the user message into a buffer
var userBuf []byte
if header.UserMsgLen > 0 {
userBuf = make([]byte, header.UserMsgLen)
bytes, err := io.ReadAtLeast(bufConn, userBuf, header.UserMsgLen)
if err == nil && bytes != header.UserMsgLen {
err = fmt.Errorf(
"Failed to read full user message (%d / %d)",
bytes, header.UserMsgLen)
}
if err != nil {
return err
}
d := m.config.Delegate
if d != nil {
d.NotifyMsg(userBuf)
}
}
return nil
}
示例8: CodecDecodeSelf
// CodecDecodeSelf implements codec.Selfer
func (c *EdgeMetadatas) CodecDecodeSelf(decoder *codec.Decoder) {
in := map[string]EdgeMetadata{}
if err := decoder.Decode(&in); err != nil {
return
}
*c = EdgeMetadatas{}.fromIntermediate(in)
}
示例9: CodecDecodeSelf
// CodecDecodeSelf is part of the codec.Selfer interface. It is overwritten here to make sure
// that an empty verbs list is not decoded as nil. On the other hand, an undefined verbs list
// will lead to nil because this decoding for Verbs is not invoked.
//
// TODO(sttts): this is due to a ugorji regression: https://github.com/ugorji/go/issues/119. Remove the
// workaround when the regression is fixed.
func (vs *Verbs) CodecDecodeSelf(decoder *codec.Decoder) {
m := []string{}
decoder.Decode(&m)
if len(m) == 0 {
*vs = []string{}
} else {
*vs = m
}
}
示例10: CodecDecodeSelf
// CodecDecodeSelf implements codec.Selfer
func (nc *NodeControls) CodecDecodeSelf(decoder *codec.Decoder) {
in := WireNodeControls{}
if err := decoder.Decode(&in); err != nil {
return
}
*nc = NodeControls{
Timestamp: parseTime(in.Timestamp),
Controls: in.Controls,
}
}
示例11: CodecDecodeSelf
// CodecDecodeSelf implements codec.Selfer
func (c *ControlInstance) CodecDecodeSelf(decoder *codec.Decoder) {
var in wiredControlInstance
decoder.Decode(&in)
*c = ControlInstance{
ProbeID: in.ProbeID,
NodeID: in.NodeID,
Control: report.Control{
ID: in.ID,
Human: in.Human,
Icon: in.Icon,
Rank: in.Rank,
},
}
}
示例12: Deserialize
// Deserialize is used to deserialize the time table
// and restore the state
func (t *TimeTable) Deserialize(dec *codec.Decoder) error {
// Decode the table
var table []TimeTableEntry
if err := dec.Decode(&table); err != nil {
return err
}
// Witness from oldest to newest
n := len(table)
for i := n - 1; i >= 0; i-- {
t.Witness(table[i].Index, table[i].Time)
}
return nil
}
示例13: 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==>")
}
示例14: readRemoteState
// readRemoteState is used to read the remote state from a connection
func (m *Memberlist) readRemoteState(bufConn io.Reader, dec *codec.Decoder) (bool, []pushNodeState, []byte, error) {
// Read the push/pull header
var header pushPullHeader
if err := dec.Decode(&header); err != nil {
return false, nil, nil, err
}
// Allocate space for the transfer
remoteNodes := make([]pushNodeState, header.Nodes)
// Try to decode all the states
for i := 0; i < header.Nodes; i++ {
if err := dec.Decode(&remoteNodes[i]); err != nil {
return false, nil, nil, err
}
}
// Read the remote user state into a buffer
var userBuf []byte
if header.UserStateLen > 0 {
userBuf = make([]byte, header.UserStateLen)
bytes, err := io.ReadAtLeast(bufConn, userBuf, header.UserStateLen)
if err == nil && bytes != header.UserStateLen {
err = fmt.Errorf(
"Failed to read full user state (%d / %d)",
bytes, header.UserStateLen)
}
if err != nil {
return false, nil, nil, err
}
}
// For proto versions < 2, there is no port provided. Mask old
// behavior by using the configured port
for idx := range remoteNodes {
if m.ProtocolVersion() < 2 || remoteNodes[idx].Port == 0 {
remoteNodes[idx].Port = uint16(m.config.BindPort)
}
}
return header.Join, remoteNodes, userBuf, nil
}
示例15: CodecDecodeSelf
// CodecDecodeSelf implements codec.Selfer
func (m *MetricRow) CodecDecodeSelf(decoder *codec.Decoder) {
var in wiredMetricRow
decoder.Decode(&in)
w := WireMetrics{
Samples: in.Samples,
Min: in.Min,
Max: in.Max,
First: in.First,
Last: in.Last,
}
metric := w.FromIntermediate()
*m = MetricRow{
ID: in.ID,
Label: in.Label,
Format: in.Format,
Group: in.Group,
Value: in.Value,
Priority: in.Priority,
Metric: &metric,
}
}