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

Golang gob.Decoder类代码示例

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

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



在下文中一共展示了Decoder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: netDstReceiver

// Get remote hashed intervals
func netDstReceiver(decoder *gob.Decoder, netInStream chan<- HashedInterval, netInStreamDone chan<- bool) {
	status := true
	for {
		if verboseClient {
			log.Debug("Client.netDstReceiver decoding...")
		}
		var r HashedInterval
		err := decoder.Decode(&r)
		if err != nil {
			log.Fatal("Cient protocol error:", err)
			status = false
			break
		}
		// interval := r.Interval
		if r.Kind == SparseIgnore {
			if verboseClient {
				log.Debug("Client.netDstReceiver got <eof>")
			}
			break
		}
		if verboseClient {
			switch r.Kind {
			case SparseData:
				log.Debug("Client.netDstReceiver got data", r.FileInterval, "hash[", len(r.Hash), "]")
			case SparseHole:
				log.Debug("Client.netDstReceiver got hole", r.FileInterval)
			}
		}
		netInStream <- r
	}
	close(netInStream)
	netInStreamDone <- status
}
开发者ID:th3architect,项目名称:longhorn,代码行数:34,代码来源:client.go


示例2: meta

func meta(cfg HiveConfig) hiveMeta {
	m := hiveMeta{}

	var dec *gob.Decoder
	metapath := path.Join(cfg.StatePath, "meta")
	f, err := os.Open(metapath)
	if err != nil {
		// TODO(soheil): We should also update our peer addresses when we have an
		// existing meta.
		m.Peers = peersInfo(cfg.PeerAddrs)
		m.Hive.Addr = cfg.Addr
		if len(cfg.PeerAddrs) == 0 {
			// The initial ID is 1. There is no raft node up yet to allocate an ID. So
			// we must do this when the hive starts.
			m.Hive.ID = 1
			goto save
		}

		m.Hive.ID = hiveIDFromPeers(cfg.Addr, cfg.PeerAddrs)
		goto save
	}

	dec = gob.NewDecoder(f)
	if err = dec.Decode(&m); err != nil {
		glog.Fatalf("Cannot decode meta: %v", err)
	}
	m.Hive.Addr = cfg.Addr
	f.Close()

save:
	saveMeta(m, cfg)
	return m
}
开发者ID:jyzhe,项目名称:beehive,代码行数:33,代码来源:meta.go


示例3: sendSyncRequest

func sendSyncRequest(encoder *gob.Encoder, decoder *gob.Decoder, path string, size int64, salt []byte) bool {
	err := encoder.Encode(requestHeader{requestMagic, syncRequestCode})
	if err != nil {
		log.Fatal("Client protocol encoder error:", err)
		return false
	}
	err = encoder.Encode(path)
	if err != nil {
		log.Fatal("Client protocol encoder error:", err)
		return false
	}
	err = encoder.Encode(size)
	if err != nil {
		log.Fatal("Client protocol encoder error:", err)
		return false
	}
	err = encoder.Encode(salt)
	if err != nil {
		log.Fatal("Client protocol encoder error:", err)
		return false
	}

	var ack bool
	err = decoder.Decode(&ack)
	if err != nil {
		log.Fatal("Client protocol decoder error:", err)
		return false
	}

	return ack
}
开发者ID:th3architect,项目名称:longhorn,代码行数:31,代码来源:client.go


示例4: LoadIndexConfig

func (p *IndexDb) LoadIndexConfig(path string) (*IndexDbConfig, error) {
	// initialize a buffer object
	var buf bytes.Buffer

	// initialize gob decoder
	var dec *gob.Decoder = gob.NewDecoder(&buf)

	// open the config file
	file, err := os.Open(path)
	if err != nil {
		return nil, err
		// log.Fatal(err)
	}

	// decode from the content of the file.
	_, err = buf.ReadFrom(file)
	if err != nil {
		return nil, err
		// log.Fatal(err)
	}

	var config IndexDbConfig
	err = dec.Decode(&config)
	if err != nil {
		return nil, err
		// log.Fatal("decode error:", decodeErr)
	}
	return &config, err
}
开发者ID:c9s,项目名称:golocate,代码行数:29,代码来源:indexdb.go


示例5: handleRequest

func (m *Manager) handleRequest(decoder *gob.Decoder,
	messageChan chan<- *proto.ServerMessage) error {
	var request proto.ClientRequest
	if err := decoder.Decode(&request); err != nil {
		if err == io.EOF {
			return err
		}
		return errors.New("error decoding ClientRequest: " + err.Error())
	}
	serverMessage := new(proto.ServerMessage)
	if request := request.YieldRequest; request != nil {
		m.updateMachineData(request.Machine)
		fileInfos := make([]proto.FileInfo, len(request.Pathnames))
		serverMessage.YieldResponse = &proto.YieldResponse{
			Hostname: request.Machine.Hostname,
			Files:    fileInfos}
		for index, pathname := range request.Pathnames {
			fileInfos[index] = m.computeFile(request.Machine, pathname)
		}
	}
	if request := request.GetObjectRequest; request != nil {
		_, reader, err := m.objectServer.GetObject(request.Hash)
		if err != nil {
			return err
		} else {
			data, _ := ioutil.ReadAll(reader)
			serverMessage.GetObjectResponse = &proto.GetObjectResponse{
				Hash: request.Hash,
				Data: data}
			reader.Close()
		}
	}
	messageChan <- serverMessage
	return nil
}
开发者ID:keep94,项目名称:Dominator,代码行数:35,代码来源:connect.go


示例6: exchangeHandshake

func (conn *LocalConnection) exchangeHandshake(localConnID uint64, usingPassword bool, enc *gob.Encoder, dec *gob.Decoder) (*FieldValidator, *[32]byte, error) {
	handshakeSend := map[string]string{
		"PeerNameFlavour": PeerNameFlavour,
		"Name":            conn.local.Name.String(),
		"NickName":        conn.local.NickName,
		"UID":             fmt.Sprint(conn.local.UID),
		"ConnID":          fmt.Sprint(localConnID)}
	handshakeRecv := map[string]string{}
	var public, private *[32]byte
	var err error
	if usingPassword {
		public, private, err = GenerateKeyPair()
		if err != nil {
			return nil, nil, err
		}
		handshakeSend["PublicKey"] = hex.EncodeToString(public[:])
	}
	enc.Encode(handshakeSend)
	if err = dec.Decode(&handshakeRecv); err != nil {
		return nil, nil, err
	}
	fv := NewFieldValidator(handshakeRecv)
	fv.CheckEqual("PeerNameFlavour", PeerNameFlavour)
	return fv, private, nil
}
开发者ID:rahulxkrishna,项目名称:weave,代码行数:25,代码来源:handshake.go


示例7: clientReadRoutine

func (s *Server) clientReadRoutine(dec *gob.Decoder) {
	defer s.StackCatcher()
	for {
		var data wireData
		err := dec.Decode(&data)
		if err != nil {
			if s.Logger != nil {
				s.Logger.Printf("CGF client read error: %v", err)
			}
			panic(err)
			return
		}
		switch {
		case data.GetErr() != nil:
			if s.Logger != nil {
				s.Logger.Printf("CGF error from server: %v", data.GetErr())
			}
			return

		case data.CompleteBundle != nil:
			s.Complete_bundles <- *data.CompleteBundle

		case data.Setup != nil:
			// Rawr?
		}
	}
}
开发者ID:runningwild,项目名称:cgf,代码行数:27,代码来源:server.go


示例8: receiveTCP

func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder) {
	usingPassword := conn.SessionKey != nil
	var receiver TCPReceiver
	if usingPassword {
		receiver = NewEncryptedTCPReceiver(conn.SessionKey, conn.outbound)
	} else {
		receiver = NewSimpleTCPReceiver()
	}
	var err error
	for {
		var msg []byte
		conn.extendReadDeadline()
		if err = decoder.Decode(&msg); err != nil {
			break
		}
		msg, err = receiver.Decode(msg)
		if err != nil {
			break
		}
		if len(msg) < 1 {
			conn.Log("ignoring blank msg")
			continue
		}
		if err = conn.handleProtocolMsg(ProtocolTag(msg[0]), msg[1:]); err != nil {
			break
		}
	}
	conn.Shutdown(err)
}
开发者ID:grkvlt,项目名称:weave,代码行数:29,代码来源:connection.go


示例9: decodeMeasureLatency

func (proto *latencyProtocol) decodeMeasureLatency(dec *gob.Decoder) (interface{}, error) {
	var val MeasureLatency
	err := dec.Decode(&val)
	if err != nil {
		return nil, fmt.Errorf("Error decoding MeasureLatency value: %v", err)
	}
	return &val, nil
}
开发者ID:antongulenko,项目名称:RTP,代码行数:8,代码来源:protocol.go


示例10: decodeConfigureHeartbeat

func (proto *heartbeatProtocol) decodeConfigureHeartbeat(decoder *gob.Decoder) (interface{}, error) {
	var val ConfigureHeartbeatPacket
	err := decoder.Decode(&val)
	if err != nil {
		return nil, fmt.Errorf("Error decoding ConfigureHeartbeat value: %v", err)
	}
	return &val, nil
}
开发者ID:antongulenko,项目名称:RTP,代码行数:8,代码来源:protocol.go


示例11: decodeLoad

func (proto *loadProtocol) decodeLoad(decoder *gob.Decoder) (interface{}, error) {
	var val LoadPacket
	err := decoder.Decode(&val)
	if err != nil {
		return nil, fmt.Errorf("Error decoding LoadPacket value: %v", err)
	}
	return &val, nil
}
开发者ID:antongulenko,项目名称:RTP,代码行数:8,代码来源:protocol.go


示例12: decodeStopProxy

func (proto *pcpProtocol) decodeStopProxy(decoder *gob.Decoder) (interface{}, error) {
	var val StopProxy
	err := decoder.Decode(&val)
	if err != nil {
		return nil, fmt.Errorf("Error decoding PCP StopProxy value: %v", err)
	}
	return &val, nil
}
开发者ID:antongulenko,项目名称:RTP,代码行数:8,代码来源:protocol.go


示例13: decodeError

func (frag *defaultProtocolFragment) decodeError(decoder *gob.Decoder) (interface{}, error) {
	var val string
	err := decoder.Decode(&val)
	if err != nil {
		return nil, fmt.Errorf("Error decoding Error value: %v", err)
	}
	return val, nil
}
开发者ID:antongulenko,项目名称:RTP,代码行数:8,代码来源:protocol.go


示例14: receiveIncoming

func receiveIncoming(dec *gob.Decoder, channel chan map[string]control.ElevatorNode) {
	var newMap = make(map[string]control.ElevatorNode)
	for {
		dec.Decode(&newMap)
		//fmt.Println(newMap)
		channel <- newMap
	}
}
开发者ID:CzarXerxes,项目名称:Sanntid,代码行数:8,代码来源:RouterModule.go


示例15: decodeResumeStream

func (proto *ampControlProtocol) decodeResumeStream(decoder *gob.Decoder) (interface{}, error) {
	var val ResumeStream
	err := decoder.Decode(&val)
	if err != nil {
		return nil, fmt.Errorf("Error decoding AMPcontrol ResumeStream value: %v", err)
	}
	return &val, nil
}
开发者ID:antongulenko,项目名称:RTP,代码行数:8,代码来源:protocol.go


示例16: decodePong

func (proto *pingProtocol) decodePong(decoder *gob.Decoder) (interface{}, error) {
	var val PongPacket
	err := decoder.Decode(&val)
	if err != nil {
		return nil, fmt.Errorf("Error decoding Pong value: %v", err)
	}
	return &val, nil
}
开发者ID:antongulenko,项目名称:RTP,代码行数:8,代码来源:protocol.go


示例17: decodePeer

func decodePeer(dec *gob.Decoder) (peerSummary PeerSummary, connSummaries []ConnectionSummary, err error) {
	if err = dec.Decode(&peerSummary); err != nil {
		return
	}
	if err = dec.Decode(&connSummaries); err != nil {
		return
	}
	return
}
开发者ID:jepsenwan,项目名称:weave,代码行数:9,代码来源:peers.go


示例18: decodeCacheFromGob

func (cbv *CachedBackendVersion) decodeCacheFromGob(dec *gob.Decoder) error {
	cbv.mu.Lock()
	defer cbv.mu.Unlock()

	if err := dec.Decode(&cbv.cache); err != nil {
		return fmt.Errorf("Failed to decode cache map: %v", err)
	}
	return nil
}
开发者ID:postfix,项目名称:otaru,代码行数:9,代码来源:cachedbackendversion.go


示例19: unpackSetCol

func (tb *TableBlock) unpackSetCol(dec *gob.Decoder, info SavedColumnInfo) {
	records := tb.RecordList

	saved_col := NewSavedSetColumn()
	into := &saved_col
	err := dec.Decode(into)
	if err != nil {
		log.Println("DECODE COL ERR:", err)
	}

	col_id := tb.table.get_key_id(into.Name)
	string_lookup := make(map[int32]string)

	col := tb.GetColumnInfo(col_id)
	// unpack the string table
	for k, v := range into.StringTable {
		col.StringTable[v] = int32(k)
		string_lookup[int32(k)] = v
	}
	col.val_string_id_lookup = string_lookup

	if into.BucketEncoded {
		for _, bucket := range into.Bins {
			// DONT FORGET TO DELTA UNENCODE THE RECORD VALUES
			prev := uint32(0)
			for _, r := range bucket.Records {
				if into.DeltaEncodedIDs {
					r = r + prev
				}

				cur_set, ok := records[r].SetMap[col_id]
				if !ok {
					cur_set = make(SetField, 0)
				}

				cur_set = append(cur_set, bucket.Value)
				records[r].SetMap[col_id] = cur_set

				records[r].Populated[col_id] = SET_VAL
				prev = r
			}

		}
	} else {
		for r, v := range into.Values {
			cur_set, ok := records[r].SetMap[col_id]
			if !ok {
				cur_set = make(SetField, 0)
				records[r].SetMap[col_id] = cur_set
			}

			records[r].SetMap[col_id] = SetField(v)
			records[r].Populated[col_id] = SET_VAL
		}
	}
}
开发者ID:logv,项目名称:sybil,代码行数:56,代码来源:column_store_io.go


示例20: interfaceDecode

// interfaceDecode decodes the next interface value from the stream and returns it.
func interfaceDecode(dec *gob.Decoder) Pythagoras {
	// The decode will fail unless the concrete type on the wire has been
	// registered. We registered it in the calling function.
	var p Pythagoras
	err := dec.Decode(&p)
	if err != nil {
		log.Fatal("decode:", err)
	}
	return p
}
开发者ID:2thetop,项目名称:go,代码行数:11,代码来源:example_interface_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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