Concatenating and wrapping
You can concatenate or wrap bytes objects.
When concatenating, the underlying objects are copied into a new bytes object.
When wrapping, you are creating a view made of the underlying bytes objects. If their values change, the wrapped view changes as well.
Of course, wrapping is preferrable to avoid copying bytes in memory.
Copying and slicing
In the same spirit as above, you can copy or slice bytes objects. When you slice a bytes object, you create a view of the original bytes object, and the slice will change if the underlying bytes object changes. If you copy instead, you create a new copy of the bytes.
Shifting bytes
You can shift right and left the bits of a bytes object by a given distance.
This is equivalent to the <<<
or >>>
operators in Java.
xor, or, and
You can apply boolean operations to Bytes objects.
Those methods take as argument the value to compare this value with, and return a new Bytes object that is the result of the boolean operation.
If the argument and the value are different lengths, then the shorter will be zero-padded to the left.
not
The not
method returns a bit-wise NOT of the bytes.
commonPrefix
The commonPrefix
method returns the common bytes both the value and the argument start with.