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

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

示例1: GetConfig

func (a *ADAM4000) GetConfig() error {
    resp, err := a.comResF("$%02X2\r", a.address)
    if err != nil {
        return err
    }

    addr := make([]byte, 1)
    typecode := make([]byte, 1)
    baud := make([]byte, 1)
    data := make([]byte, 1)

    hex.Decode(addr, resp[1:3])
    hex.Decode(typecode, resp[3:5])
    hex.Decode(baud, resp[5:7])
    hex.Decode(data, resp[7:9])

    a.Address = addr[0]
    a.InputRange = InputRangeCode(typecode[0])
    a.BaudRate = BaudRateCode(baud[0])
    fmt.Printf("%X\n", data)
    a.Integration_time = data[0]&byte(1<<7) > 0
    a.Checksum = data[0]&byte(1<<6) > 0
    a.DataFormat = DataFormatCode(data[0] & byte(2))
    if a.Address != a.address {
        fmt.Printf("Warning: Configured address (%d) differs from connected address (%d), in init mode?\n", a.Address, a.address)
    }
    return nil
}

开发者ID:thoj,项目名称:go-adam4000,代码行数:28,代码来源:adam4000.go

示例2: SetBytes

func (o *Commit) SetBytes(b []byte) (err error) {
    o.Content = b
    lines := bytes.Split(b, []byte{'\n'})
    for i := range lines {
        if len(lines[i]) > 0 {
            split := bytes.SplitN(lines[i], []byte{' '}, 2)
            switch string(split[0]) {
            case "tree":
                o.Tree = make([]byte, 20)
                _, err = hex.Decode(o.Tree, split[1])
            case "parent":
                h := make([]byte, 20)
                _, err = hex.Decode(h, split[1])
                if err == nil {
                    o.Parents = append(o.Parents, h)
                }
            case "author":
                o.Author = string(split[1])
            case "committer":
                o.Committer = string(split[1])
            }
            if err != nil {
                return
            }
        } else {
            o.Message = string(bytes.Join(append(lines[i+1:]), []byte{'\n'}))
            break
        }
    }
    return
}

开发者ID:linhua55,项目名称:gitchain,代码行数:31,代码来源:objects.go

示例3: UnmarshalText

func (c *Color) UnmarshalText(b []byte) (err error) {
    s := string(b)
    if s == "none" {
        c.RGBA.R = 0x00
        c.RGBA.G = 0x00
        c.RGBA.B = 0x00
        c.RGBA.A = 0x00
        return nil
    }
    var buf [4]byte
    switch len(b) {
    case 6:
        _, err = hex.Decode(buf[:3], b)
        buf[3] = 0xFF
    case 8:
        _, err = hex.Decode(buf[:], b)
    default:
        return fmt.Errorf("Color.UnmarshalText: expected a hexadecimal string in the form RRGGBB or RRGGBBAA, or \"none\" (not %q)", s)
    }
    if err != nil {
        return fmt.Errorf("Color.UnmarshalText: expected a hexadecimal string in the form RRGGBB or RRGGBBAA, or \"none\" (not %q)", s)
    }
    c.RGBA.R = buf[0]
    c.RGBA.G = buf[1]
    c.RGBA.B = buf[2]
    c.RGBA.A = buf[3]
    return nil
}

开发者ID:kierdavis,项目名称:k12,代码行数:28,代码来源:util.go

示例4: parseColor

func parseColor(colors []string) []dmx.Color {
    dmxcolors := make([]dmx.Color, 0, len(colors))
    for _, color := range colors {
        var data [1]byte
        _, err := hex.Decode(data[:], []byte(color[:2]))
        if err != nil {
            panic(err)
        }
        r := data[0]
        _, err = hex.Decode(data[:], []byte(color[2:4]))
        if err != nil {
            panic(err)
        }
        g := data[0]
        _, err = hex.Decode(data[:], []byte(color[4:6]))
        if err != nil {
            panic(err)
        }
        b := data[0]

        dmxcolors = append(dmxcolors, dmx.Color{r, g, b})
    }

    return dmxcolors
}

开发者ID:uvgroovy,项目名称:dmx,代码行数:25,代码来源:animate.go

示例5: byte_set

func (d *UUID) byte_set(uuid []byte) (err error) {
    t_uuid := [16]byte{}
    t_d := bytes.Split(uuid, []byte{'-'})

    if len(t_d) != 5 {
        return errors.New("not a uuid : [" + string(uuid) + "]")
    }

    if len(t_d[0]) != 8 {
        return errors.New("not a uuid : [" + string(uuid) + "]")
    }
    _, err = hex.Decode(t_uuid[0:4], t_d[0])
    if err != nil {
        return
    }

    if len(t_d[1]) != 4 || len(t_d[2]) != 4 || len(t_d[3]) != 4 {
        return errors.New("not a uuid : [" + string(uuid) + "]")
    }
    _, err = hex.Decode(t_uuid[4:6], t_d[1])
    if err != nil {
        return
    }
    _, err = hex.Decode(t_uuid[6:8], t_d[2])
    if err != nil {
        return
    }
    _, err = hex.Decode(t_uuid[8:10], t_d[3])
    if err != nil {
        return
    }

    if len(t_d[4]) != 12 {
        return errors.New("not a uuid : [" + string(uuid) + "]")
    }
    _, err = hex.Decode(t_uuid[10:16], t_d[4])
    if err != nil {
        return
    }

    switch t_uuid[6] & 0xf0 {
    case UUIDv1, UUIDv2, UUIDv3, UUIDv4, UUIDv5:
    default:
        return errors.New("unknown version : [" + string(uuid) + "]")
    }

    switch {
    case (t_uuid[8] & 0x80) == UUID_NCS:
    case (t_uuid[8] & 0xc0) == UUID_RFC:
    case (t_uuid[8] & 0xe0) == UUID_MS:
    case (t_uuid[8] & 0xe0) == UUID_UNUSED:
    default:
        err = errors.New("unknown variant : [" + string(uuid) + "]")
        return
    }
    *d = UUID(t_uuid)

    return nil
}

开发者ID:nathanaelle,项目名称:useful.types,代码行数:59,代码来源:uuid.go

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