本文整理汇总了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

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng