v2ray-core/common/serial/numbers.go

53 lines
864 B
Go
Raw Normal View History

2015-12-03 16:57:23 +01:00
package serial
import (
"strconv"
)
2016-05-24 21:55:46 +02:00
func Uint16ToBytes(value uint16) []byte {
return []byte{byte(value >> 8), byte(value)}
}
func Uint16ToString(value uint16) string {
return strconv.Itoa(int(value))
}
2016-05-24 22:15:46 +02:00
func Uint32ToBytes(value uint32) []byte {
return []byte{
byte(value >> 24),
byte(value >> 16),
byte(value >> 8),
byte(value),
}
}
2016-05-24 22:15:46 +02:00
func IntToBytes(value int) []byte {
2016-05-23 20:16:31 +02:00
return []byte{
byte(value >> 24),
byte(value >> 16),
byte(value >> 8),
byte(value),
}
}
2016-05-24 22:15:46 +02:00
func IntToString(value int) string {
return Int64ToString(int64(value))
2015-12-12 13:11:49 +01:00
}
2016-05-24 22:15:46 +02:00
func Int64ToBytes(value int64) []byte {
2015-12-12 13:11:49 +01:00
return []byte{
byte(value >> 56),
byte(value >> 48),
byte(value >> 40),
byte(value >> 32),
byte(value >> 24),
byte(value >> 16),
byte(value >> 8),
byte(value),
}
}
2016-05-24 22:15:46 +02:00
func Int64ToString(value int64) string {
return strconv.FormatInt(value, 10)
}