numbers.go 963 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package serial
  2. import (
  3. "strconv"
  4. )
  5. type Uint16 interface {
  6. Value() uint16
  7. }
  8. type Uint16Literal uint16
  9. func (this Uint16Literal) String() string {
  10. return strconv.Itoa(int(this))
  11. }
  12. func (this Uint16Literal) Value() uint16 {
  13. return uint16(this)
  14. }
  15. func (this Uint16Literal) Bytes() []byte {
  16. return []byte{byte(this >> 8), byte(this)}
  17. }
  18. type Int interface {
  19. Value() int
  20. }
  21. type IntLiteral int
  22. func (this IntLiteral) String() string {
  23. return strconv.Itoa(int(this))
  24. }
  25. func (this IntLiteral) Value() int {
  26. return int(this)
  27. }
  28. type Int64Literal int64
  29. func (this Int64Literal) String() string {
  30. return strconv.FormatInt(this.Value(), 10)
  31. }
  32. func (this Int64Literal) Value() int64 {
  33. return int64(this)
  34. }
  35. func (this Int64Literal) Bytes() []byte {
  36. value := this.Value()
  37. return []byte{
  38. byte(value >> 56),
  39. byte(value >> 48),
  40. byte(value >> 40),
  41. byte(value >> 32),
  42. byte(value >> 24),
  43. byte(value >> 16),
  44. byte(value >> 8),
  45. byte(value),
  46. }
  47. }