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

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

示例1: packRequest

func (c *conn) packRequest(r *http.Request) (*http.Request, error) {
    buf := &bytes.Buffer{}
    zbuf, err := zlib.NewWriterLevel(buf, zlib.BestCompression)
    if err != nil {
        return nil, fmt.Errorf("conn.packRequest(zlib.NewWriterLevel)>%s", err)
    }
    url := c.url + r.URL.String()
    urlhex := make([]byte, hex.EncodedLen(len(url)))
    hex.Encode(urlhex, []byte(url))
    fmt.Fprintf(zbuf, "url=%s", urlhex)
    fmt.Fprintf(zbuf, "&method=%s", hex.EncodeToString([]byte(r.Method)))
    if c.ps.password != "" {
        fmt.Fprintf(zbuf, "&password=%s", c.ps.password)
    }
    fmt.Fprint(zbuf, "&headers=")
    for k, v := range r.Header {
        fmt.Fprint(zbuf, hex.EncodeToString([]byte(fmt.Sprintf("%s:%s\r\n", k, v[0]))))
    }
    body, err := ioutil.ReadAll(r.Body)
    if err != nil {
        return nil, fmt.Errorf("conn.packRequest(ioutil.ReadAll(r.Body))>%s", err)
    }
    payload := hex.EncodeToString(body)
    fmt.Fprintf(zbuf, "&payload=%s", payload)
    zbuf.Close()
    req, err := http.NewRequest("POST", c.ps.path, buf)
    if err != nil {
        return nil, fmt.Errorf("conn.packRequest(http.NewRequest)>%s", err)
    }
    req.Host = c.ps.appid[rand.Intn(len(c.ps.appid))] + ".appspot.com"
    req.URL.Scheme = "http"
    return req, nil
}

开发者ID:shitfSign,项目名称:goagent-go,代码行数:33,代码来源:proxy.go

示例2: GetSHA256

// Get the corresponding ID, which is the (hex encoded) SHA256 of the (base64 encoded) public key.
func (pk PublicKey) GetSHA256() []byte {
    h := sha256.New()
    h.Write([]byte(pk.String()))
    sha256hex := make([]byte, hex.EncodedLen(sha256.Size))
    hex.Encode(sha256hex, h.Sum(nil))
    return sha256hex
}

开发者ID:laprice,项目名称:cryptoballot,代码行数:8,代码来源:PublicKey.go

示例3: newSID

func newSID() string {
    b := make([]byte, 8)
    rand.Read(b)
    d := make([]byte, hex.EncodedLen(len(b)))
    hex.Encode(d, b)
    return string(d)
}

开发者ID:samegoal,项目名称:wcchat,代码行数:7,代码来源:wcchat.go

示例4: GetSHA256

// Get the (hex-encoded) SHA256 of the String value of the ballot.
func (ballot *Ballot) GetSHA256() []byte {
    h := sha256.New()
    h.Write([]byte(ballot.String()))
    sha256hex := make([]byte, hex.EncodedLen(sha256.Size))
    hex.Encode(sha256hex, h.Sum(nil))
    return sha256hex
}

开发者ID:laprice,项目名称:cryptoballot,代码行数:8,代码来源:Ballot.go

示例5: Value

// Value implements the driver.Valuer interface. It uses the "hex" format which
// is only supported on PostgreSQL 9.0 or newer.
func (a ByteaArray) Value() (driver.Value, error) {
    if a == nil {
        return nil, nil
    }

    if n := len(a); n > 0 {
        // There will be at least two curly brackets, 2*N bytes of quotes,
        // 3*N bytes of hex formatting, and N-1 bytes of delimiters.
        size := 1 + 6*n
        for _, x := range a {
            size += hex.EncodedLen(len(x))
        }

        b := make([]byte, size)

        for i, s := 0, b; i < n; i++ {
            o := copy(s, `,"\\x`)
            o += hex.Encode(s[o:], a[i])
            s[o] = '"'
            s = s[o+1:]
        }

        b[0] = '{'
        b[size-1] = '}'

        return string(b), nil
    }

    return "{}", nil
}

开发者ID:CatchRelease,项目名称:s3zipper,代码行数:32,代码来源:array.go

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