2015-12-03 15:57:23 +00:00
|
|
|
package serial
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2016-06-26 20:34:48 +00:00
|
|
|
func Uint16ToBytes(value uint16, b []byte) []byte {
|
|
|
|
return append(b, byte(value>>8), byte(value))
|
2016-05-24 19:55:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Uint16ToString(value uint16) string {
|
|
|
|
return strconv.Itoa(int(value))
|
|
|
|
}
|
|
|
|
|
2016-06-26 20:34:48 +00:00
|
|
|
func Uint32ToBytes(value uint32, b []byte) []byte {
|
|
|
|
return append(b, byte(value>>24), byte(value>>16), byte(value>>8), byte(value))
|
2016-01-29 15:43:45 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 20:22:01 +00:00
|
|
|
func Uint32ToString(value uint32) string {
|
|
|
|
return strconv.FormatUint(uint64(value), 10)
|
|
|
|
}
|
|
|
|
|
2016-06-26 20:34:48 +00:00
|
|
|
func IntToBytes(value int, b []byte) []byte {
|
|
|
|
return append(b, byte(value>>24), byte(value>>16), byte(value>>8), byte(value))
|
2016-05-23 18:16:31 +00:00
|
|
|
}
|
|
|
|
|
2016-05-24 20:15:46 +00:00
|
|
|
func IntToString(value int) string {
|
|
|
|
return Int64ToString(int64(value))
|
2015-12-12 12:11:49 +00:00
|
|
|
}
|
|
|
|
|
2016-06-26 20:34:48 +00:00
|
|
|
func Int64ToBytes(value int64, b []byte) []byte {
|
|
|
|
return append(b,
|
|
|
|
byte(value>>56),
|
|
|
|
byte(value>>48),
|
|
|
|
byte(value>>40),
|
|
|
|
byte(value>>32),
|
|
|
|
byte(value>>24),
|
|
|
|
byte(value>>16),
|
|
|
|
byte(value>>8),
|
|
|
|
byte(value))
|
2015-12-12 12:11:49 +00:00
|
|
|
}
|
2016-05-24 20:15:46 +00:00
|
|
|
|
|
|
|
func Int64ToString(value int64) string {
|
|
|
|
return strconv.FormatInt(value, 10)
|
|
|
|
}
|