Buffer
发布者:admin 发表于:416天前 阅读数:617 评论:0

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

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

示例1: csv2String

func csv2String() string {
    buf := new(bytes.Buffer)
    for _, pub := range csv2.pubkeys {
        buf.WriteString(fmt.Sprintf("%s,\n", pub))
    }
    return string(buf.Bytes())
}

开发者ID:dbabits,项目名称:mint-client,代码行数:7,代码来源:gen_test.go

示例2: bigIntToNetIPv6

// bigIntToNetIPv6 is a helper function that correctly returns a net.IP with the
// correctly padded values.
func bigIntToNetIPv6(bi *big.Int) *net.IP {
    x := make(net.IP, IPv6len)
    ipv6Bytes := bi.Bytes()

    // It's possibe for ipv6Bytes to be less than IPv6len bytes in size.  If
    // they are different sizes we to pad the size of response.
    if len(ipv6Bytes) < IPv6len {
        buf := new(bytes.Buffer)
        buf.Grow(IPv6len)

        for i := len(ipv6Bytes); i < IPv6len; i++ {
            if err := binary.Write(buf, binary.BigEndian, byte(0)); err != nil {
                panic(fmt.Sprintf("Unable to pad byte %d of input %v: %v", i, bi, err))
            }
        }

        for _, b := range ipv6Bytes {
            if err := binary.Write(buf, binary.BigEndian, b); err != nil {
                panic(fmt.Sprintf("Unable to preserve endianness of input %v: %v", bi, err))
            }
        }

        ipv6Bytes = buf.Bytes()
    }
    i := copy(x, ipv6Bytes)
    if i != IPv6len {
        panic("IPv6 wrong size")
    }
    return &x
}

开发者ID:luizbafilho,项目名称:fusis,代码行数:32,代码来源:ipv6addr.go

示例3: processTask

// Processes new tasks
func (m *etcdMinion) processTask(t *task.Task) error {
    var buf bytes.Buffer

    // Update state of task to indicate that we are now processing it
    t.State = task.TaskStateProcessing
    m.SaveTaskResult(t)

    cmd := exec.Command(t.Command, t.Args...)
    cmd.Stdout = &buf
    cmd.Stderr = &buf

    log.Printf("Processing task %s\n", t.TaskID)

    cmdError := cmd.Run()
    t.TimeProcessed = time.Now().Unix()
    t.Result = buf.String()

    if cmdError != nil {
        log.Printf("Failed to process task %s\n", t.TaskID)
        t.Error = cmdError.Error()
        t.State = task.TaskStateFailed
    } else {
        log.Printf("Finished processing task %s\n", t.TaskID)
        t.State = task.TaskStateSuccess
    }

    m.SaveTaskResult(t)

    return cmdError
}

开发者ID:leobcn,项目名称:gru,代码行数:31,代码来源:etcd.go

示例4: TestDumper

func TestDumper(t *testing.T) {
    var in [40]byte
    for i := range in {
        in[i] = byte(i + 30)
    }

    for stride := 1; stride < len(in); stride++ {
        var out bytes.Buffer
        dumper := Dumper(&out)
        done := 0
        for done < len(in) {
            todo := done + stride
            if todo > len(in) {
                todo = len(in)
            }
            dumper.Write(in[done:todo])
            done = todo
        }

        dumper.Close()
        if !bytes.Equal(out.Bytes(), expectedHexDump) {
            t.Errorf("stride: %d failed. got:\n%s\nwant:\n%s", stride, out.Bytes(), expectedHexDump)
        }
    }
}

开发者ID:anuvazhayil,项目名称:HelloWorld_32bitOS,代码行数:25,代码来源:hex_test.go

示例5: Format

// Format implements the NodeFormatter interface.
func (node IndexElem) Format(buf *bytes.Buffer, f FmtFlags) {
    FormatNode(buf, f, node.Column)
    if node.Direction != DefaultDirection {
        buf.WriteByte(' ')
        buf.WriteString(node.Direction.String())
    }
}

开发者ID:GitGoldie,项目名称:cockroach,代码行数:8,代码来源:create.go