Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "net"
- "strconv"
- "strings"
- )
- //StringToUint8 convertion from string to uint8
- func StringToUint8(str string) uint8 {
- bufVal, _ := strconv.ParseUint(str, 10, 8)
- return uint8(bufVal)
- }
- //StringToUint16 convertion from string to uint16
- func StringToUint16(str string) uint16 {
- bufVal, _ := strconv.ParseUint(str, 10, 16)
- return uint16(bufVal)
- }
- //StringToUint32 convertion from string to uint16
- func StringToUint32(str string) uint32 {
- bufVal, _ := strconv.ParseUint(str, 10, 32)
- return uint32(bufVal)
- }
- // //StringToIP convertion from string to []byte for IP
- // func StringToIP(str string) net.IP {
- // strSplit := strings.Split(str, ".")
- // var ipParts [4]byte
- // for idx, i := range strSplit {
- // buf, _ := strconv.ParseInt(i, 10, 16)
- // ipParts[idx] = byte(buf)
- // }
- // return net.IPv4(ipParts[0], ipParts[1], ipParts[2], ipParts[3])
- // }
- //StringToHardAddr convertion from string to net.Hardware address
- func StringToHardAddr(str string) net.HardwareAddr {
- bytes := strings.Split(str, ":")
- var macParts [6]byte
- for idx, i := range bytes {
- buf, _ := strconv.ParseUint(i, 16, 32)
- macParts[idx] = byte(buf)
- }
- return net.HardwareAddr{macParts[0], macParts[1], macParts[2],
- macParts[3], macParts[4], macParts[5]}
- }
- //RadioToBool convertion from radio tag value to bool value
- func RadioToBool(str string) bool {
- if str == "on" {
- return true
- } else if str == "of" {
- return false
- }
- return false
- }
Add Comment
Please, Sign In to add comment