Debian Codegraph @

lib/3rdParty/composer/aws/aws-crt-php/src/AWS/CRT/Internal/Encoding.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 * SPDX-License-Identifier: Apache-2.0.
5 */
6 namespace AWS\CRT\Internal;
7
8 final class Encoding {
9 public static function readString(&$buffer) {
10 list($len, $str) = self::decodeString($buffer);
11 // Advance by sizeof(length) + strlen(str)
12 $buffer = substr($buffer, 4 + $len);
13 return $str;
14 }
15
16 public static function readStrings($buffer) {
17 $strings = [];
18 while (strlen($buffer)) {
19 $strings []= self::readString($buffer);
20 }
21 return $strings;
22 }
23
24 public static function decodeString($buffer) {
25 $len = unpack("N", $buffer)[1];
26 $buffer = substr($buffer, 4);
27 $str = unpack("a{$len}", $buffer)[1];
28 return [$len, $str];
29 }
30
31 public static function encodeString($str) {
32 if (is_array($str)) {
33 $str = $str[0];
34 }
35 return pack("Na*", strlen($str), $str);
36 }
37 }