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

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

示例1: pwdCrypt

func (rad *RadClientType) pwdCrypt(auth, passwd []byte) ([]byte, error) {

    //padding the password if the password not multiple of 16 octets
    text := make([]byte, 16*int(math.Ceil(float64(binary.Size(passwd))/16.0)))
    copy(text, passwd)
    for i := binary.Size(passwd); i < len(text); i++ {
        text[i] = 0
    }
    if len(text) > 128 {
        return nil, errors.New("Password exceeds maxiums of 128 bytes")
    }

    var result = make([]byte, 0)
    last := make([]byte, len(auth))

    copy(last, auth)
    for len(text) > 0 {
        hash := md5.Sum(bytes.Join([][]byte{rad.secret, last}, nil))

        for i := range hash {
            result = append(result, hash[i]^text[i])
        }
        last = result[len(result)-16:]
        text = text[16:]
    }
    return result, nil
}

开发者ID:johndoe26,项目名称:btunnel-go,代码行数:27,代码来源:radiusauth.go

示例2: parseSFNT

func parseSFNT(r io.ReaderAt, headerOffset int64, table map[int64]Table) (SFNT, error) {
    header := new(SfntHeader)
    headerSize := int64(binary.Size(header))
    sr := io.NewSectionReader(r, headerOffset, headerSize)
    if err := binary.Read(sr, binary.BigEndian, header); err != nil {
        return nil, err
    }
    numTables := header.NumTables
    offsetTable := make([]OffsetEntry, numTables)
    sr = io.NewSectionReader(r, headerOffset+headerSize, int64(binary.Size(offsetTable)))
    if err := binary.Read(sr, binary.BigEndian, offsetTable); err != nil {
        return nil, err
    }
    tableMap := make(SFNT)
    for _, entry := range offsetTable {
        tag := entry.Tag.String()
        offset := int64(entry.Offset)
        size := int64(entry.Length)
        if v, ok := table[offset]; ok {
            tableMap[tag] = v
        } else {
            v = &DefaultTable{entry.Tag, io.NewSectionReader(r, offset, size)}
            table[offset] = v
            tableMap[tag] = v
        }
    }
    for _, p := range DefaultParser {
        for i, v := range tableMap {
            tableMap[i] = p.Parse(tableMap, v)
        }
    }
    return tableMap, nil
}

开发者ID:mandel59,项目名称:gofont,代码行数:33,代码来源:parse.go

示例3: parseOptionsTemplateFlowSet

func parseOptionsTemplateFlowSet(data []byte, header *FlowSetHeader) (interface{}, error) {
    var set OptionsTemplateFlowSet
    var t OptionsTemplateRecord

    set.Id = header.Id
    set.Length = header.Length

    buf := bytes.NewBuffer(data)
    headerLen := binary.Size(t.TemplateId) + binary.Size(t.ScopeLength) + binary.Size(t.OptionLength)
    for buf.Len() >= 4 { // Padding aligns to 4 byte boundary
        if buf.Len() < headerLen {
            return nil, errorMissingData(headerLen - buf.Len())
        }
        binary.Read(buf, binary.BigEndian, &t.TemplateId)
        binary.Read(buf, binary.BigEndian, &t.ScopeLength)
        binary.Read(buf, binary.BigEndian, &t.OptionLength)

        if buf.Len() < int(t.ScopeLength)+int(t.OptionLength) {
            return nil, errorMissingData(int(t.ScopeLength) + int(t.OptionLength) - buf.Len())
        }

        scopeCount := int(t.ScopeLength) / binary.Size(Field{})
        optionCount := int(t.OptionLength) / binary.Size(Field{})

        t.Scopes = parseFieldList(buf, scopeCount)
        t.Options = parseFieldList(buf, optionCount)

        set.Records = append(set.Records, t)
    }

    return set, nil
}

开发者ID:ttaanngg,项目名称:nf9packet,代码行数:32,代码来源:decode.go

示例4: readData0

func (this *DataManager) readData0(inId InIdType) (BigFileIndex, error) {
    var d0 BigFileIndex
    var err error
    filenoSize := uint32(binary.Size(d0.FileNo))
    offsetSize := uint32(binary.Size(d0.Offset))
    lengthSize := uint32(binary.Size(d0.Length))

    // read fileno
    pos := uint32(inId) * uint32(binary.Size(BigFileIndex{}))
    fileno, err := this.data0.ReadNum(pos, filenoSize)
    if err != nil {
        return d0, err
    }

    // read fileoffset
    pos += filenoSize
    offset, err := this.data0.ReadNum(pos, offsetSize)
    if err != nil {
        return d0, err
    }

    // read filelength
    pos += offsetSize
    length, err := this.data0.ReadNum(pos, lengthSize)
    if err != nil {
        return d0, err
    }

    d0.FileNo = uint8(fileno)
    d0.Offset = uint32(offset)
    d0.Length = uint32(length)

    return d0, nil
}

开发者ID:caohao2008,项目名称:goose,代码行数:34,代码来源:datamanager.go

示例5: parseTemplateFlowSet

func parseTemplateFlowSet(data []byte, header *FlowSetHeader) (interface{}, error) {
    var set TemplateFlowSet
    var t TemplateRecord

    set.Id = header.Id
    set.Length = header.Length

    buf := bytes.NewBuffer(data)
    headerLen := binary.Size(t.TemplateId) + binary.Size(t.FieldCount)

    for buf.Len() >= 4 { // Padding aligns to 4 byte boundary
        if buf.Len() < headerLen {
            return nil, errorMissingData(headerLen - buf.Len())
        }
        binary.Read(buf, binary.BigEndian, &t.TemplateId)
        binary.Read(buf, binary.BigEndian, &t.FieldCount)

        fieldsLen := int(t.FieldCount) * binary.Size(Field{})
        if fieldsLen > buf.Len() {
            return nil, errorMissingData(fieldsLen - buf.Len())
        }
        t.Fields = parseFieldList(buf, int(t.FieldCount))

        set.Records = append(set.Records, t)
    }
    return set, nil

}

开发者ID:ttaanngg,项目名称:nf9packet,代码行数:28,代码来源:decode.go

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