2015-12-12 12:11:49 +00:00
|
|
|
package serial
|
|
|
|
|
|
|
|
type Bytes interface {
|
|
|
|
Bytes() []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
type BytesLiteral []byte
|
|
|
|
|
|
|
|
func (this BytesLiteral) Value() []byte {
|
|
|
|
return []byte(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this BytesLiteral) Int64Value() int64 {
|
|
|
|
value := this.Value()
|
|
|
|
return int64(value[0])<<56 +
|
|
|
|
int64(value[1])<<48 +
|
|
|
|
int64(value[2])<<40 +
|
|
|
|
int64(value[3])<<32 +
|
|
|
|
int64(value[4])<<24 +
|
|
|
|
int64(value[5])<<16 +
|
|
|
|
int64(value[6])<<8 +
|
|
|
|
int64(value[7])
|
|
|
|
}
|
2016-01-18 11:58:04 +00:00
|
|
|
|
2016-01-21 11:52:09 +00:00
|
|
|
// String returns a string presentation of this ByteLiteral
|
2016-01-18 11:58:04 +00:00
|
|
|
func (this BytesLiteral) String() string {
|
|
|
|
return string(this.Value())
|
|
|
|
}
|
2016-01-20 16:45:50 +00:00
|
|
|
|
2016-01-21 11:52:09 +00:00
|
|
|
// All returns true if all bytes in the ByteLiteral are the same as given value.
|
|
|
|
func (this BytesLiteral) All(v byte) bool {
|
2016-01-20 16:45:50 +00:00
|
|
|
for _, b := range this {
|
2016-01-21 11:52:09 +00:00
|
|
|
if b != v {
|
2016-01-20 16:45:50 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|