public static function convertRemainingLengthStringToInt(string $remainingLengthField): int
    {
        $multiplier = 128;
        $value = 0;
        $iteration = 0;

        do {
            // Extract the next byte in the sequence
            $encodedByte = ord($remainingLengthField{$iteration});

            // Add the current multiplier^iteration * first half of byte
            $value += ($encodedByte & 127) * ($multiplier ** $iteration);
            if ($multiplier > 128 ** 3) {
                throw new LogicException('Malformed remaining length field');
            }

            // Prepare for the next iteration
            $iteration++;
        } while (($encodedByte & 128) !== 0);

        return $value;
    }