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