platform/api/symfony/Component/Uid/BinaryUtil.yaml
2024-09-02 10:44:11 -07:00

71 lines
4.2 KiB
YAML

name: BinaryUtil
class_comment: '# * @internal
# *
# * @author Nicolas Grekas <p@tchwork.com>'
dependencies: []
properties: []
methods:
- name: hexToNumericString
visibility: public
parameters:
- name: time
comment: "# * @internal\n# *\n# * @author Nicolas Grekas <p@tchwork.com>\n# */\n\
# class BinaryUtil\n# {\n# public const BASE10 = [\n# '' => '0123456789',\n# 0,\
\ 1, 2, 3, 4, 5, 6, 7, 8, 9,\n# ];\n# \n# public const BASE58 = [\n# '' => '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz',\n\
# 1 => 0, 1, 2, 3, 4, 5, 6, 7, 8, 'A' => 9,\n# 'B' => 10, 'C' => 11, 'D' => 12,\
\ 'E' => 13, 'F' => 14, 'G' => 15,\n# 'H' => 16, 'J' => 17, 'K' => 18, 'L' =>\
\ 19, 'M' => 20, 'N' => 21,\n# 'P' => 22, 'Q' => 23, 'R' => 24, 'S' => 25, 'T'\
\ => 26, 'U' => 27,\n# 'V' => 28, 'W' => 29, 'X' => 30, 'Y' => 31, 'Z' => 32,\
\ 'a' => 33,\n# 'b' => 34, 'c' => 35, 'd' => 36, 'e' => 37, 'f' => 38, 'g' =>\
\ 39,\n# 'h' => 40, 'i' => 41, 'j' => 42, 'k' => 43, 'm' => 44, 'n' => 45,\n#\
\ 'o' => 46, 'p' => 47, 'q' => 48, 'r' => 49, 's' => 50, 't' => 51,\n# 'u' =>\
\ 52, 'v' => 53, 'w' => 54, 'x' => 55, 'y' => 56, 'z' => 57,\n# ];\n# \n# // https://tools.ietf.org/html/rfc4122#section-4.1.4\n\
# // 0x01b21dd213814000 is the number of 100-ns intervals between the\n# // UUID\
\ epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.\n# private\
\ const TIME_OFFSET_INT = 0x01B21DD213814000;\n# private const TIME_OFFSET_BIN\
\ = \"\\x01\\xb2\\x1d\\xd2\\x13\\x81\\x40\\x00\";\n# private const TIME_OFFSET_COM1\
\ = \"\\xfe\\x4d\\xe2\\x2d\\xec\\x7e\\xbf\\xff\";\n# private const TIME_OFFSET_COM2\
\ = \"\\xfe\\x4d\\xe2\\x2d\\xec\\x7e\\xc0\\x00\";\n# \n# public static function\
\ toBase(string $bytes, array $map): string\n# {\n# $base = \\strlen($alphabet\
\ = $map['']);\n# $bytes = array_values(unpack(\\PHP_INT_SIZE >= 8 ? 'n*' : 'C*',\
\ $bytes));\n# $digits = '';\n# \n# while ($count = \\count($bytes)) {\n# $quotient\
\ = [];\n# $remainder = 0;\n# \n# for ($i = 0; $i !== $count; ++$i) {\n# $carry\
\ = $bytes[$i] + ($remainder << (\\PHP_INT_SIZE >= 8 ? 16 : 8));\n# $digit = intdiv($carry,\
\ $base);\n# $remainder = $carry % $base;\n# \n# if ($digit || $quotient) {\n\
# $quotient[] = $digit;\n# }\n# }\n# \n# $digits = $alphabet[$remainder].$digits;\n\
# $bytes = $quotient;\n# }\n# \n# return $digits;\n# }\n# \n# public static function\
\ fromBase(string $digits, array $map): string\n# {\n# $base = \\strlen($map['']);\n\
# $count = \\strlen($digits);\n# $bytes = [];\n# \n# while ($count) {\n# $quotient\
\ = [];\n# $remainder = 0;\n# \n# for ($i = 0; $i !== $count; ++$i) {\n# $carry\
\ = ($bytes ? $digits[$i] : $map[$digits[$i]]) + $remainder * $base;\n# \n# if\
\ (\\PHP_INT_SIZE >= 8) {\n# $digit = $carry >> 16;\n# $remainder = $carry & 0xFFFF;\n\
# } else {\n# $digit = $carry >> 8;\n# $remainder = $carry & 0xFF;\n# }\n# \n\
# if ($digit || $quotient) {\n# $quotient[] = $digit;\n# }\n# }\n# \n# $bytes[]\
\ = $remainder;\n# $count = \\count($digits = $quotient);\n# }\n# \n# return pack(\\\
PHP_INT_SIZE >= 8 ? 'n*' : 'C*', ...array_reverse($bytes));\n# }\n# \n# public\
\ static function add(string $a, string $b): string\n# {\n# $carry = 0;\n# for\
\ ($i = 7; 0 <= $i; --$i) {\n# $carry += \\ord($a[$i]) + \\ord($b[$i]);\n# $a[$i]\
\ = \\chr($carry & 0xFF);\n# $carry >>= 8;\n# }\n# \n# return $a;\n# }\n# \n#\
\ /**\n# * @param string $time Count of 100-nanosecond intervals since the UUID\
\ epoch 1582-10-15 00:00:00 in hexadecimal\n# *\n# * @return string Count of 100-nanosecond\
\ intervals since the UUID epoch 1582-10-15 00:00:00 as a numeric string"
- name: hexToDateTime
visibility: public
parameters:
- name: time
comment: '# * Sub-microseconds are lost since they are not handled by \DateTimeImmutable.
# *
# * @param string $time Count of 100-nanosecond intervals since the UUID epoch
1582-10-15 00:00:00 in hexadecimal'
- name: dateTimeToHex
visibility: public
parameters:
- name: time
comment: '# * @return string Count of 100-nanosecond intervals since the UUID epoch
1582-10-15 00:00:00 in hexadecimal'
traits: []
interfaces: []