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

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

示例1: Read

// Read a single sequence and return it or an error.
// TODO: Does not read multi-line fastq.
func (self *Reader) Read() (s seq.Sequence, err error) {
    var (
        buff, line, label []byte
        isPrefix          bool
        seqBuff           []alphabet.QLetter
        t                 seqio.SequenceAppender
    )

    inQual := false

    for {
        if buff, isPrefix, err = self.r.ReadLine(); err == nil {
            if isPrefix {
                line = append(line, buff...)
                continue
            } else {
                line = buff
            }

            line = bytes.TrimSpace(line)
            if len(line) == 0 {
                continue
            }
            switch {
            case !inQual && line[0] == '@':
                t = self.readHeader(line)
                label, line = line, nil
            case !inQual && line[0] == '+':
                if len(label) == 0 {
                    return nil, bio.NewError("fastq: no header line parsed before +line in fastq format", 0)
                }
                if len(line) > 1 && bytes.Compare(label[1:], line[1:]) != 0 {
                    return nil, bio.NewError("fastq: quality header does not match sequence header", 0)
                }
                inQual = true
            case !inQual:
                line = bytes.Join(bytes.Fields(line), nil)
                seqBuff = make([]alphabet.QLetter, len(line))
                for i := range line {
                    seqBuff[i].L = alphabet.Letter(line[i])
                }
            case inQual:
                line = bytes.Join(bytes.Fields(line), nil)
                if len(line) != len(seqBuff) {
                    return nil, bio.NewError("fastq: sequence/quality length mismatch", 0)
                }
                for i := range line {
                    seqBuff[i].Q = alphabet.DecodeToQphred(line[i], self.enc)
                }
                t.AppendQLetters(seqBuff...)

                return t, nil
            }
        } else {
            return
        }
    }

    panic("cannot reach")
}

开发者ID:frogs,项目名称:biogo,代码行数:62,代码来源:fastq.go

示例2: assertion

func (auth *Auth) assertion() ([]byte, error) {
    header, err := json.Marshal(
        map[string]interface{}{
            "typ": "JWT",
            "alg": "RS256",
        })
    if err != nil {
        return nil, err
    }
    parts := [3][]byte{}
    parts[0] = b64urlencode(header)
    now := time.Now()
    claims, err := json.Marshal(
        map[string]interface{}{
            "iss":   auth.Email,
            "scope": strings.Join(auth.Scope, " "),
            "aud":   aud,
            "exp":   now.Add(time.Hour).Unix(),
            "iat":   now.Unix(),
        })
    if err != nil {
        return nil, err
    }
    parts[1] = b64urlencode(claims)

    sha := sha256.New()
    sha.Write(bytes.Join(parts[:2], separator))
    signature, err := rsa.SignPKCS1v15(rand.Reader, auth.Key, crypto.SHA256, sha.Sum(nil))
    if err != nil {
        return nil, err
    }
    parts[2] = b64urlencode(signature)
    return bytes.Join(parts[:], separator), nil
}

开发者ID:doug,项目名称:gserviceauth,代码行数:34,代码来源:gserviceauth.go

示例3: toCamelCase

func toCamelCase(x string) string {
    if len(x) == 0 {
        return ""
    }

    output := make([]byte, 0)
    uppercase := true

    for len(x) > 0 {
        v, size := utf8.DecodeRuneInString(x)

        // If underscore, append and keep going.
        if v == '_' {
            uppercase = true
        } else if unicode.IsLetter(v) {
            if uppercase {
                uppercase = false
                buf := make([]byte, size)
                utf8.EncodeRune(buf, unicode.ToUpper(v))
                output = bytes.Join([][]byte{output, buf}, nil)
            } else if unicode.IsUpper(v) {
                buf := make([]byte, size)
                utf8.EncodeRune(buf, v)
                output = bytes.Join([][]byte{output, buf}, []byte("_"))
            }
        }

        x = x[size:]
    }

    return string(output)
}

开发者ID:huntaub,项目名称:go-db,代码行数:32,代码来源:db.go

示例4: packPUBLISH

/* Pack return data */
func packPUBLISH(dup bool, qos int, retain bool, topic string, messageID uint16, payload []byte) []byte {
    var remaining []byte
    if qos == 0 {
        remaining = bytes.Join([][]byte{
            str_to_bytes(topic),
            payload,
        }, nil)
    } else {
        remaining = bytes.Join([][]byte{
            str_to_bytes(topic),
            []byte{byte(messageID / 256), byte(messageID % 256)},
            payload,
        }, nil)
    }
    header := byte(PUBLISH*16 + qos*2)
    if dup {
        header |= 0x80
    }
    if retain {
        header |= 0x01
    }
    return bytes.Join([][]byte{
        []byte{header},
        encodeRemainLength(len(remaining)),
        remaining,
    }, nil)
}

开发者ID:nakagami,项目名称:toybroker,代码行数:28,代码来源:utils.go

示例5: TestReader_blockTooLarge

// This test validates errors returned when data blocks exceed size limits.
func TestReader_blockTooLarge(t *testing.T) {
    // the compressed chunk size is within the allowed encoding size
    // (maxEncodedBlockSize). but the uncompressed data is larger than allowed.
    badstream := bytes.Join([][]byte{
        streamID,
        compressedChunk(t, make([]byte, (1<<24)-5)),
    }, nil)
    r := NewReader(bytes.NewBuffer(badstream), true)
    p := make([]byte, 1)
    n, err := r.Read(p)
    if err == nil {
        t.Fatalf("read: expected error")
    }
    if n != 0 {
        t.Fatalf("read: read data from the stream")
    }

    // the compressed chunk size is within the allowed encoding size
    // (maxEncodedBlockSize). but the uncompressed data is larger than allowed.
    badstream = bytes.Join([][]byte{
        streamID,
        uncompressedChunk(t, make([]byte, (1<<24)-5)),
    }, nil)
    r = NewReader(bytes.NewBuffer(badstream), true)
    p = make([]byte, 1)
    n, err = r.Read(p)
    if err == nil {
        t.Fatalf("read: expected error")
    }
    if n != 0 {
        t.Fatalf("read: read data from the stream")
    }
}

开发者ID:hailocab,项目名称:go-snappystream,代码行数:34,代码来源:reader_test.go

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