numbers.go 873 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. type Int interface {
  16. Value() int
  17. }
  18. type IntLiteral int
  19. func (this IntLiteral) String() string {
  20. return strconv.Itoa(int(this))
  21. }
  22. func (this IntLiteral) Value() int {
  23. return int(this)
  24. }
  25. type Int64Literal int64
  26. func (this Int64Literal) String() string {
  27. return strconv.FormatInt(this.Value(), 10)
  28. }
  29. func (this Int64Literal) Value() int64 {
  30. return int64(this)
  31. }
  32. func (this Int64Literal) Bytes() []byte {
  33. value := this.Value()
  34. return []byte{
  35. byte(value >> 56),
  36. byte(value >> 48),
  37. byte(value >> 40),
  38. byte(value >> 32),
  39. byte(value >> 24),
  40. byte(value >> 16),
  41. byte(value >> 8),
  42. byte(value),
  43. }
  44. }