bytes.go 617 B

123456789101112131415161718192021222324252627282930313233343536
  1. package serial
  2. type Bytes interface {
  3. Bytes() []byte
  4. }
  5. type BytesLiteral []byte
  6. func (this BytesLiteral) Value() []byte {
  7. return []byte(this)
  8. }
  9. func (this BytesLiteral) Int64Value() int64 {
  10. value := this.Value()
  11. return int64(value[0])<<56 +
  12. int64(value[1])<<48 +
  13. int64(value[2])<<40 +
  14. int64(value[3])<<32 +
  15. int64(value[4])<<24 +
  16. int64(value[5])<<16 +
  17. int64(value[6])<<8 +
  18. int64(value[7])
  19. }
  20. func (this BytesLiteral) String() string {
  21. return string(this.Value())
  22. }
  23. func (this BytesLiteral) AllZero() bool {
  24. for _, b := range this {
  25. if b != 0 {
  26. return false
  27. }
  28. }
  29. return true
  30. }