Parses the ByteBuffer and returns an AMQP frame
@return AmqpFrame
192882
public AmqpFrame getFrame()
    {    
        int pos = this.position();       
        AmqpMethod method = new AmqpMethod();
        int classIndex;
        AmqpFrame frame = new AmqpFrame(); 
                 
        // If there is at least one Frame in the buffer, attempt to decode it.
        if (this.remaining() > 7)
        {            
            frame.setHeader(this.getFrameHeader());           
            frame.setChannelId((short) frame.getHeader().channel);           
            frame.setType((short) frame.getHeader().frameType);           
            // the buffer must have an additional byte for the Frame end marker 
            
            if (this.remaining() >= frame.getHeader().size + 1)
            {                
                switch (frame.getType())
                {                
                    case AmqpConstants.FRAME_BODY:                        
                        WrappedByteBuffer body = new AmqpBuffer();
                        // copy body into new Buffer
                        int end = this.position() + (int)frame.getHeader().size;
                        while (position() < end)
                        {
                            body.put(get());
                        }
                        frame.setBody(body);
                        frame.setMethodName("body");                        
                        break;

                    case AmqpConstants.FRAME_HEADER:                        
                        classIndex = this.getUnsignedShort();
                        @SuppressWarnings("unused")
                        short weight = (short)this.getUnsignedShort();
                        @SuppressWarnings("unused")
                        long bodySize = this.getUnsignedLong();                            
                        
                        frame.setContentProperties(this.getContentProperties());
                        frame.setMethodName("header");                        
                        break;

                    case AmqpConstants.FRAME_METHOD:
                         classIndex = this.getUnsignedShort();
                        int methodIndex = this.getUnsignedShort();
                        String indexes = String.valueOf(classIndex) + String.valueOf(methodIndex);                      
                        method = MethodLookup.LookupMethod(indexes);
                        
                        // pull parameter list off of method
                        List<Parameter> params = method.allParameters;

                        frame.setMethodName(method.name);
                        frame.setArgs(this.getMethodArguments(params));                        
                        break;

                    case AmqpConstants.FRAME_HEARTBEAT:
                    case AmqpConstants.FRAME_RABBITMQ_HEARTBEAT:
                    	throw new IllegalStateException("Received heartbeat frame even though the client has expressed no interest in heartbeat via tune-ok method.");

                    default:
                    	throw new IllegalStateException("Unrecognized AMQP 0-9-1 Frame type = " + frame.getType());
                }
                
                short frameEnd = (short) this.getUnsigned();                
                if (frameEnd != AmqpConstants.FRAME_END)
                {                    
                    throw new IllegalStateException("Invalid end of AMQP method frame");
                }
            }
            else
            {                
                this.position(pos);
                return null;
            }
            return frame;
        }
        return null;
    }
1124127
public function validateamqpAction()
    {
        $request = $this->getRequest();

        $configMap = Mage::getModel('radial_amqp/config');
        $hostname = $this->_validatorHelper->getParamOrFallbackValue(
            $request,
            self::HOSTNAME_PARAM,
            self::HOSTNAME_USE_DEFAULT_PARAM,
            $configMap->getPathForKey('hostname')
        );
        $username = $this->_validatorHelper->getParamOrFallbackValue(
            $request,
            self::USERNAME_PARAM,
            self::USERNAME_USE_DEFAULT_PARAM,
            $configMap->getPathForKey('username')
        );
        $password = $this->_validatorHelper->getEncryptedParamOrFallbackValue(
            $request,
            self::PASSWORD_PARAM,
            self::PASSWORD_USE_DEFAULT_PARAM,
            $configMap->getPathForKey('password')
        );

        $validator = $this->_getAmqpApiValidator($this->_getSourceStore());
        $this->getResponse()->setHeader('Content-Type', 'text/json')
            ->setBody(json_encode($validator->testConnection($hostname, $username, $password)));
        return $this;
    }
140812
static ByteBuffer toFrame(ByteBuffer input, int dataSize) throws GeneralSecurityException {
    Preconditions.checkNotNull(input);
    if (dataSize > input.remaining()) {
      dataSize = input.remaining();
    }
    Producer producer = new Producer();
    ByteBuffer inputAlias = input.duplicate();
    inputAlias.limit(input.position() + dataSize);
    producer.readBytes(inputAlias);
    producer.flush();
    input.position(inputAlias.position());
    ByteBuffer output = producer.getRawFrame();
    return output;
  }
239134
protected ByteBuffer inputStreamToByteBuffer() throws IOException {
        return byteBuffer == null ? byteBuffer = ByteBuffer.wrap(inputStreamToByteArray()) : byteBuffer;
    }
956057
private function readHeader(): self
    {
        if (null !== $this->statusLine) {
            return $this;
        }

        do {
            $this->parseStatusLine($this->socket->readLine());
            $headers = '';
            $line    = '';
            while (!$this->socket->eof() && Http::END_OF_LINE !== $line) {
                $line     = $this->socket->readLine() . Http::END_OF_LINE;
                $headers .= $line;
            }

            $this->headers->append($headers);
        } while ($this->requireContinue());
        return $this;
    }
778376
def _parseAtFrame(self, src):
        
        src = src[len('@frame '):].lstrip()
        box, src = self._getIdent(src)
        src, properties = self._parseDeclarationGroup(src.lstrip())
        result = [self.cssBuilder.atFrame(box, properties)]
        return src.lstrip(), result
970192
protected function getStreamContext()
    {
        $ctx = stream_context_create();

        stream_context_set_option($ctx, "ssl", "local_cert", $this->pem);
        if (strlen($this->passphrase)) {
            stream_context_set_option($ctx, "ssl", "passphrase", $this->passphrase);
        }

        return $ctx;
    }
1098323
protected function processJpeg()
    {
        ob_start();
        imagejpeg($this->image->getCore(), null, $this->quality);
        $this->image->mime = image_type_to_mime_type(IMAGETYPE_JPEG);
        $buffer = ob_get_contents();
        ob_end_clean();

        return $buffer;
    }
10799
public function serializePartialToString() {
    $enc = new Encoder();
    $this->outputPartial($enc);
    $res = $enc->toString();

    # Continue to be a little paranoid about the correctness of the protocol
    # buffer implementation.
    if (mt_rand(0, 99) === 0 && $this->byteSizePartial() !== strlen($res)) {
      throw new ProtocolBufferEncodeError(
        "Internal bug: Encoded size doesn't match predicted");
    }
    return $res;
  }
1018220
public function readObject() {

            $object = array();
            $this->refList[] =& $object;
            while (true) {
                $key = $this->readString();
                $vartype = $this->stream->readByte();
                if ($vartype==SabreAMF_AMF0_Const::DT_OBJECTTERM) break;
                $object[$key] = $this->readAmfData($vartype);
            }
            if (defined('SABREAMF_OBJECT_AS_ARRAY')) {
                $object = (object)$object;
            }
            return $object;    

        }
1359690
public function getBuffer() {
        // cut last line (is always prompt)
        $buf = explode("\n", $this->buffer);
        unset($buf[count($buf) - 1]);
        $buf = implode("\n", $buf);
        return trim($buf);
    }
992636
protected function getReceivingFrame(): Frame
    {
        $current = $this->getCurrentFrame();

        if ($current->isComplete()) {
            if ($current->isFinal()) {
                throw new PayloadException('Payload cannot receive data: it is already complete');
            } else {
                $this->frames[] = $current = $this->getFrame();
            }
        }

        return $current;
    }
1322166
public static function parseFrame(string &$buffer): Record
    {
        $bufferLength = strlen($buffer);
        if ($bufferLength < FCGI::HEADER_LEN) {
            throw new \RuntimeException("Not enough data in the buffer to parse");
        }
        $recordHeader = unpack(FCGI::HEADER_FORMAT, $buffer);
        $recordType   = $recordHeader['type'];
        if (!isset(self::$classMapping[$recordType])) {
            throw new \DomainException("Invalid FCGI record type {$recordType} received");
        }

        /** @var Record $className */
        $className = self::$classMapping[$recordType];
        $record    = $className::unpack($buffer);


        $offset = FCGI::HEADER_LEN + $record->getContentLength() + $record->getPaddingLength();
        $buffer = substr($buffer, $offset);

        return $record;
    }
438649
private function parseLink()
    {
        $value = $this->RAW();

        if (!$value) {
            return false;
        }

        $output = false;

        if (preg_match(
            '/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/i',
            $value,
            $matches
        )) {
            foreach ($matches as $match) {
                if (preg_match('/^[0-9]{6,12}$/', $match)) {
                    $output = [
                        'VideoID'      => $match,
                        'VideoService' => 'Vimeo',
                    ];
                }
            }
        } elseif (preg_match('/https?:\/\/youtu\.be\/([a-z0-9\_\-]+)/i', $value, $matches)) {
            $output = [
                'VideoID'      => $matches[1],
                'VideoService' => 'YouTube',
            ];
        } elseif (preg_match('/youtu\.?be/i', $value)) {
            $query_string = [];
            parse_str(parse_url($value, PHP_URL_QUERY), $query_string);
            if (!empty($query_string['v'])) {
                $output = [
                    'VideoID'      => $query_string['v'],
                    'VideoService' => 'YouTube',
                ];
            }
        }

        return ($output) ? $output : false;
    }
1003447
private function parseField()
    {
        $type = $this->buffer[0];
        $this->buffer = substr($this->buffer, 1);

        // @todo bench switch vs if vs method map
        switch ($type) {
            case 's':
                return $this->parseSignedInt16();
            case 'l':
                return $this->parseSignedInt64();
            case 'x':
                return $this->parseByteArray();
            case 't':
                return $this->parseUnsignedInt8() !== 0;
            case 'b':
                return $this->parseSignedInt8();
            case 'I':
                return $this->parseSignedInt32();
            case 'f':
                return $this->parseFloat();
            case 'd':
                return $this->parseDouble();
            case 'D':
                return $this->parseDecimal();
            case 'S':
                return $this->parseLongString();
            case 'A':
                return $this->parseArray();
            case 'T':
                return $this->parseUnsignedInt64();
            case 'F':
                return $this->parseTable();
            case 'V':
                return null;
        }

        throw new AMQPProtocolException(
            sprintf(
                'table value type (0x%02x) is invalid or unrecognised.',
                ord($type)
            )
        );
    }
590297
public function readByte()
    {
        if (($this->_needle + 1) > $this->_streamLength) {
            require_once 'Zend/Amf/Exception.php';
            throw new Zend_Amf_Exception('Buffer underrun at needle position: ' . $this->_needle . ' while requesting length: ' . $length);
        }

        return ord($this->_stream{$this->_needle++});
    }
227292
protected function loadBuffer()
	{
		$this->remainder = 0;
		
		if($this->ended)
		{
			return;
		}
		
		while(!$this->stream->eof() && strlen($this->buffer) < self::BUFFER_SIZE)
		{
			$this->buffer .= $this->stream->read(self::BUFFER_SIZE);
		}
		
		$m = NULL;
		
		if(preg_match("'^\r?\n?([a-fA-F0-9]+).*\r\n'", $this->buffer, $m))
		{
			$this->remainder = hexdec($m[1]);
			$this->buffer = (string)substr($this->buffer, strlen($m[0]));
			
			if($this->remainder === 0)
			{
				$this->buffer = '';
				$this->ended = true;
			}
			else
			{
				while(!$this->stream->eof() && strlen($this->buffer) < $this->remainder)
				{
					$this->buffer .= $this->stream->read($this->remainder);
				}
				
				if(strlen($this->buffer) < $this->remainder)
				{
					$this->buffer = '';
					$this->ended = true;
				}
			}
		}
		else
		{
			$this->buffer = '';
			$this->ended = true;
		}
	}