1 | <?php |
||
5 | class Buffertools |
||
6 | { |
||
7 | public static function numToVarIntBin($decimal) |
||
24 | |||
25 | /** |
||
26 | * Convert a decimal number into a VarInt Buffer |
||
27 | * |
||
28 | * @param integer $decimal |
||
29 | * @return Buffer |
||
30 | * @throws \Exception |
||
31 | */ |
||
32 | public static function numToVarInt($decimal) |
||
36 | |||
37 | /** |
||
38 | * Flip byte order of this binary string. Accepts a string or Buffer, |
||
39 | * and will return whatever type it was given. |
||
40 | * |
||
41 | * @param string|BufferInterface $bytes |
||
42 | * @return string|BufferInterface |
||
43 | */ |
||
44 | public static function flipBytes($bytes) |
||
58 | |||
59 | /** |
||
60 | * @param BufferInterface $buffer1 |
||
61 | * @param BufferInterface $buffer2 |
||
62 | * @param int $size |
||
63 | * @return BufferInterface |
||
64 | */ |
||
65 | public static function concat(BufferInterface $buffer1, BufferInterface $buffer2, $size = null) |
||
69 | |||
70 | /** |
||
71 | * What if we don't have two buffers, or want to guard the types of the |
||
72 | * sorting algorithm? |
||
73 | * |
||
74 | * The default behaviour should be, take a list of Buffers/SerializableInterfaces, and |
||
75 | * sort their binary representation. |
||
76 | * |
||
77 | * If an anonymous function is provided, we completely defer the conversion of values to |
||
78 | * Buffer to the $convertToBuffer callable. |
||
79 | * |
||
80 | * This is to allow anonymous functions which are responsible for converting the item to a buffer, |
||
81 | * and which optionally type-hint the items in the array. |
||
82 | * |
||
83 | * @param array $items |
||
84 | * @param callable $convertToBuffer |
||
85 | * @return array |
||
86 | */ |
||
87 | public static function sort(array $items, callable $convertToBuffer = null) |
||
109 | } |
||
110 |