bytes.go 760 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. // String returns a string presentation of this ByteLiteral
  21. func (this BytesLiteral) String() string {
  22. return string(this.Value())
  23. }
  24. // All returns true if all bytes in the ByteLiteral are the same as given value.
  25. func (this BytesLiteral) All(v byte) bool {
  26. for _, b := range this {
  27. if b != v {
  28. return false
  29. }
  30. }
  31. return true
  32. }