private function readFieldLength(string &$buffer): int
    {
        $block  = unpack('C4', $buffer);

        $length = $block[1];
        $skip   = 1;

        if ($length & 0x80) {
            $fullBlock = unpack('N', $buffer);
            $length    = $fullBlock[1] & 0x7FFFFFFF;
            $skip      = 4;
        }

        $buffer = substr($buffer, $skip);

        return $length;
    }