當前位置: 首頁>>代碼示例>>Golang>>正文


Golang gob.Decoder類代碼示例

本文整理匯總了Golang中encoding/gob.Decoder的典型用法代碼示例。如果您正苦於以下問題:Golang Decoder類的具體用法?Golang Decoder怎麽用?Golang Decoder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Decoder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的encoding/gob.Decoder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。