本文整理匯總了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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?
}
}
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
}
示例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
}