2015-12-03 10:57:23 -05:00
|
|
|
package serial
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2016-05-24 15:55:46 -04:00
|
|
|
func Uint16ToBytes(value uint16) []byte {
|
|
|
|
return []byte{byte(value >> 8), byte(value)}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Uint16ToString(value uint16) string {
|
|
|
|
return strconv.Itoa(int(value))
|
|
|
|
}
|
|
|
|
|
|
|
|
func IntToString(value int) string {
|
|
|
|
return Int64ToString(int64(value))
|
|
|
|
}
|
|
|
|
|
|
|
|
func Int64ToString(value int64) string {
|
|
|
|
return strconv.FormatInt(value, 10)
|
|
|
|
}
|
|
|
|
|
2015-12-03 10:57:23 -05:00
|
|
|
type Uint16 interface {
|
|
|
|
Value() uint16
|
|
|
|
}
|
|
|
|
|
|
|
|
type Uint16Literal uint16
|
|
|
|
|
|
|
|
func (this Uint16Literal) String() string {
|
|
|
|
return strconv.Itoa(int(this))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this Uint16Literal) Value() uint16 {
|
|
|
|
return uint16(this)
|
|
|
|
}
|
|
|
|
|
2016-01-18 19:21:07 -05:00
|
|
|
func (this Uint16Literal) Bytes() []byte {
|
|
|
|
return []byte{byte(this >> 8), byte(this)}
|
|
|
|
}
|
|
|
|
|
2015-12-03 10:57:23 -05:00
|
|
|
type Int interface {
|
|
|
|
Value() int
|
|
|
|
}
|
|
|
|
|
|
|
|
type IntLiteral int
|
|
|
|
|
|
|
|
func (this IntLiteral) String() string {
|
|
|
|
return strconv.Itoa(int(this))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this IntLiteral) Value() int {
|
|
|
|
return int(this)
|
|
|
|
}
|
2015-12-12 07:11:49 -05:00
|
|
|
|
2016-01-29 10:43:45 -05:00
|
|
|
func (this IntLiteral) Bytes() []byte {
|
|
|
|
value := this.Value()
|
|
|
|
return []byte{
|
|
|
|
byte(value >> 24),
|
|
|
|
byte(value >> 16),
|
|
|
|
byte(value >> 8),
|
|
|
|
byte(value),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-23 14:16:31 -04:00
|
|
|
type Uint32Literal uint32
|
|
|
|
|
|
|
|
func (this Uint32Literal) String() string {
|
|
|
|
return strconv.FormatUint(uint64(this.Value()), 10)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this Uint32Literal) Value() uint32 {
|
|
|
|
return uint32(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this Uint32Literal) Bytes() []byte {
|
|
|
|
value := this.Value()
|
|
|
|
return []byte{
|
|
|
|
byte(value >> 24),
|
|
|
|
byte(value >> 16),
|
|
|
|
byte(value >> 8),
|
|
|
|
byte(value),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-12 07:11:49 -05:00
|
|
|
type Int64Literal int64
|
|
|
|
|
|
|
|
func (this Int64Literal) String() string {
|
|
|
|
return strconv.FormatInt(this.Value(), 10)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this Int64Literal) Value() int64 {
|
|
|
|
return int64(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this Int64Literal) Bytes() []byte {
|
|
|
|
value := this.Value()
|
|
|
|
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),
|
|
|
|
}
|
|
|
|
}
|