1 | <?php |
||
7 | class Buffertools |
||
8 | { |
||
9 | /** |
||
10 | * @param int $decimal |
||
11 | * @return string |
||
12 | * @throws \Exception |
||
13 | */ |
||
14 | 16 | public static function numToVarIntBin(int $decimal): string |
|
31 | |||
32 | /** |
||
33 | * Convert a decimal number into a VarInt Buffer |
||
34 | * |
||
35 | * @param integer $decimal |
||
36 | * @return BufferInterface |
||
37 | * @throws \Exception |
||
38 | */ |
||
39 | 16 | public static function numToVarInt(int $decimal): BufferInterface |
|
43 | |||
44 | /** |
||
45 | * Flip byte order of this binary string. Accepts a string or Buffer, |
||
46 | * and will return whatever type it was given. |
||
47 | * |
||
48 | * @param string|BufferInterface $bytes |
||
49 | * @return string|BufferInterface |
||
50 | */ |
||
51 | 20 | public static function flipBytes($bytes) |
|
65 | |||
66 | /** |
||
67 | * @param BufferInterface $buffer1 |
||
68 | * @param BufferInterface $buffer2 |
||
69 | * @param int|null $size |
||
70 | * @return BufferInterface |
||
71 | */ |
||
72 | 2 | public static function concat(BufferInterface $buffer1, BufferInterface $buffer2, int $size = null) |
|
76 | |||
77 | /** |
||
78 | * What if we don't have two buffers, or want to guard the types of the |
||
79 | * sorting algorithm? |
||
80 | * |
||
81 | * The default behaviour should be, take a list of Buffers/SerializableInterfaces, and |
||
82 | * sort their binary representation. |
||
83 | * |
||
84 | * If an anonymous function is provided, we completely defer the conversion of values to |
||
85 | * Buffer to the $convertToBuffer callable. |
||
86 | * |
||
87 | * This is to allow anonymous functions which are responsible for converting the item to a buffer, |
||
88 | * and which optionally type-hint the items in the array. |
||
89 | * |
||
90 | * @param array $items |
||
91 | * @param callable|null $convertToBuffer |
||
92 | * @return array |
||
93 | */ |
||
94 | 4 | public static function sort(array $items, callable $convertToBuffer = null): array |
|
116 | } |
||
117 |