• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang codec.Decoder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/ugorji/go/codec.Decoder的典型用法代码示例。如果您正苦于以下问题:Golang Decoder类的具体用法?Golang Decoder怎么用?Golang Decoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Decoder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:dilgerma,项目名称:scope,代码行数:8,代码来源:node_set.go


示例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)
}
开发者ID:dilgerma,项目名称:scope,代码行数:8,代码来源:plugin_spec.go


示例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)
}
开发者ID:dilgerma,项目名称:scope,代码行数:8,代码来源:counters.go


示例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()
}
开发者ID:dilgerma,项目名称:scope,代码行数:8,代码来源:metrics.go


示例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)
}
开发者ID:CNDonny,项目名称:scope,代码行数:8,代码来源:latest_map.go


示例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)
}
开发者ID:dilgerma,项目名称:scope,代码行数:8,代码来源:sets.go


示例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
}
开发者ID:rbg,项目名称:memberlist,代码行数:30,代码来源:net.go


示例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)
}
开发者ID:dilgerma,项目名称:scope,代码行数:8,代码来源:edge_metadatas.go


示例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
	}
}
开发者ID:nak3,项目名称:kubernetes,代码行数:15,代码来源:types.go


示例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,
	}
}
开发者ID:dilgerma,项目名称:scope,代码行数:11,代码来源:controls.go


示例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,
		},
	}
}
开发者ID:dilgerma,项目名称:scope,代码行数:15,代码来源:node.go


示例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
}
开发者ID:PagerDuty,项目名称:nomad,代码行数:16,代码来源:timetable.go


示例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==>")
}
开发者ID:sunvim,项目名称:codelab,代码行数:48,代码来源:msgpack.go


示例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
}
开发者ID:rbg,项目名称:memberlist,代码行数:43,代码来源:net.go


示例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,
	}
}
开发者ID:dilgerma,项目名称:scope,代码行数:22,代码来源:metric_row.go


示例16: CodecDecodeSelf

// CodecDecodeSelf  for ugorji.go codec package @todo write test ... not sure if ok
func (n *NullFloat64) CodecDecodeSelf(d *codec.Decoder) {
	if err := d.Decode(&n.Float64); err != nil {
		PkgLog.Debug("dbr.NullFloat64.CodecDecodeSelf", "err", err, "n", n)
	}
}
开发者ID:levcom,项目名称:csfw,代码行数:6,代码来源:types_cs.go


示例17: handleCommand

// handleCommand is used to decode and dispatch a single command
func (n *NetworkTransport) handleCommand(r *bufio.Reader, dec *codec.Decoder, enc *codec.Encoder) error {
	// Get the rpc type
	rpcType, err := r.ReadByte()
	if err != nil {
		return err
	}

	// Create the RPC object
	respCh := make(chan RPCResponse, 1)
	rpc := RPC{
		RespChan: respCh,
	}

	// Decode the command
	switch rpcType {
	case rpcAppendEntries:
		var req AppendEntriesRequest
		if err := dec.Decode(&req); err != nil {
			return err
		}
		rpc.Command = &req

	case rpcRequestVote:
		var req RequestVoteRequest
		if err := dec.Decode(&req); err != nil {
			return err
		}
		rpc.Command = &req

	case rpcInstallSnapshot:
		var req InstallSnapshotRequest
		if err := dec.Decode(&req); err != nil {
			return err
		}
		rpc.Command = &req
		rpc.Reader = io.LimitReader(r, req.Size)

	default:
		return fmt.Errorf("unknown rpc type %d", rpcType)
	}

	// Dispatch the RPC
	select {
	case n.consumeCh <- rpc:
	case <-n.shutdownCh:
		return ErrTransportShutdown
	}

	// Wait for response
	select {
	case resp := <-respCh:
		// Send the error first
		respErr := ""
		if resp.Error != nil {
			respErr = resp.Error.Error()
		}
		if err := enc.Encode(respErr); err != nil {
			return err
		}

		// Send the response
		if err := enc.Encode(resp.Response); err != nil {
			return err
		}
	case <-n.shutdownCh:
		return ErrTransportShutdown
	}
	return nil
}
开发者ID:rbg,项目名称:raft,代码行数:70,代码来源:net_transport.go


示例18: Decode

func (l *ListLink) Decode(p []byte, ctx *Context) error {
	var dec *codec.Decoder = codec.NewDecoderBytes(p, ctx.mh)
	err := dec.Decode(l)
	return err
}
开发者ID:Blackth0rn,项目名称:go-graph,代码行数:5,代码来源:message_handler.go


示例19: DecodeFrom

func (cm ChairMessage) DecodeFrom(dec *codec.Decoder) error {
	return dec.Decode(&cm)
}
开发者ID:samkumar99,项目名称:chairb,代码行数:3,代码来源:chairmsg.go


示例20: CodecDecodeSelf

// CodecDecodeSelf  for ugorji.go codec package @todo write test ... not sure if ok
func (n *NullFloat64) CodecDecodeSelf(d *codec.Decoder) {
	if err := d.Decode(&n.Float64); err != nil {
		log.Error("dbr.NullFloat64.CodecEncodeSelf", "err", err, "n", n)
	}
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:6,代码来源:types.go



注:本文中的github.com/ugorji/go/codec.Decoder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang codec.Encoder类代码示例发布时间:2022-05-28
下一篇:
Golang codec.NewEncoderBytes函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap