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

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

示例1: gobDecodeList

func gobDecodeList(b *testing.B, l int) {
    var (
        enc *gob.Encoder
        buf bytes.Buffer
        err error
    )
    s := make([]int, l)
    for i, _ := range s {
        s[i] = rand.Int()
    }

    enc = gob.NewEncoder(&buf)
    err = enc.Encode(s)
    if err != nil {
        panic(err.Error())
    }

    var dest []int
    bs := buf.Bytes()
    b.ResetTimer()
    // decode
    for i := 0; i < b.N; i++ {
        nbuffer := bytes.NewBuffer(bs)
        dec := gob.NewDecoder(nbuffer)
        err := dec.Decode(&dest)
        if err != nil {
            panic(err.Error())
        }
    }
}

开发者ID:samuelyao314,项目名称:mygo,代码行数:30,代码来源:gob_test.go

示例2: SendPeer

func SendPeer(encod *gob.Encoder) {
    err := encod.Encode(*MyPublicPeer)

    if err != nil {
        log.Fatal("Error sending Public Peer: ", err)
    }
}

开发者ID:rcostu,项目名称:cosmofs,代码行数:7,代码来源:peer.go

示例3: sendMakeDirectory

func sendMakeDirectory(encoder *gob.Encoder, directory image.Directory) error {
    imageUpdate := imageserver.ImageUpdate{
        Directory: &directory,
        Operation: imageserver.OperationMakeDirectory,
    }
    return encoder.Encode(imageUpdate)
}

开发者ID:keep94,项目名称:Dominator,代码行数:7,代码来源:getImageUpdates.go

示例4: netSender

func netSender(netOutStream <-chan HashedInterval, encoder *gob.Encoder, netOutDoneStream chan<- bool) {
    for r := range netOutStream {
        if verboseServer {
            log.Debug("Server.netSender: sending", r.FileInterval)
        }
        err := encoder.Encode(r)
        if err != nil {
            log.Fatal("Protocol encoder error:", err)
            netOutDoneStream <- false
            return
        }
    }

    rEOF := HashedInterval{FileInterval{SparseIgnore, Interval{}}, make([]byte, 0)}
    if rEOF.Len() != 0 {
        log.Fatal("Server.netSender internal error")
    }
    // err := encoder.Encode(HashedInterval{FileInterval{}, make([]byte, 0)})
    err := encoder.Encode(rEOF)
    if err != nil {
        log.Fatal("Protocol encoder error:", err)
        netOutDoneStream <- false
        return
    }
    if verboseServer {
        log.Debug("Server.netSender: finished sending hashes")
    }
    netOutDoneStream <- true
}

开发者ID:th3architect,项目名称:longhorn,代码行数:29,代码来源:server.go

示例5: CreateGobsFile

func CreateGobsFile(targetFilePath string, recs *[]interface{}, getRecPtr GobRecPtrMaker, gzipped bool) {
    var file, err = os.Create(targetFilePath)
    var gobber *gob.Encoder
    var gzipper *gzip.Writer
    if file != nil {
        defer file.Close()
    }
    if err != nil {
        panic(err)
    }
    if gzipped {
        if gzipper, err = gzip.NewWriterLevel(file, gzip.BestCompression); gzipper != nil {
            defer gzipper.Close()
            gobber = gob.NewEncoder(gzipper)
        }
        if err != nil {
            panic(err)
        }
    } else {
        gobber = gob.NewEncoder(file)
    }
    for _, rec := range *recs {
        if err = gobber.Encode(coreutil.PtrVal(getRecPtr(rec))); err != nil {
            panic(err)
        }
    }
}

开发者ID:hyl87,项目名称:2011_Go_Geo_Gfx,代码行数:27,代码来源:gobutil.go

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