/** * serialize the 'properties' attribute (a dictionary) into the * raw bytes making up a set of property flags and a property * list, suitable for putting into a content frame header. */ public function serializeProperties() { $shift = 15; $flagBits = 0; $flags = array(); $rawBytes = new Writer(); foreach ($this->propertyTypes as $key => $proptype) { if (isset($this->properties[$key])) { $value = $this->properties[$key]; } else { $value = null; } if ($value != null) { if ($shift == 0) { $flags[] = $flagBits; $flagBits = 0; $shift = 15; } $flagBits |= 1 << $shift; if ($proptype != 'bit') { $proptype = ucfirst($proptype); $rawBytes->{'write' . $proptype}($value); } } $shift -= 1; } $flags[] = $flagBits; $result = new Writer(); foreach ($flags as $flagBits) { $result->writeShort($flagBits); } $result->write($rawBytes->getvalue()); return $result->getvalue(); }
/** * @param string $channel * @param string $methodSig * @param Writer|string $args * * @return Connection */ public function sendChannelMethodFrame($channel, $methodSig, $args = '') { if ($args instanceof Writer) { $args = $args->getvalue(); } $outboundPacket = new Writer(); $outboundPacket->writeOctet(1); $outboundPacket->writeShort($channel); $outboundPacket->writeLong(strlen($args) + 4); // 4 = length of class_id and method_id // in payload $outboundPacket->writeShort($methodSig[0]); // class_id $outboundPacket->writeShort($methodSig[1]); // method_id $outboundPacket->write($args); $outboundPacket->writeOctet(0xce); $outboundPacket = $outboundPacket->getvalue(); $this->write($outboundPacket); if ($this->debug) { Helper::debugMsg('< ' . Helper::methodSig($methodSig) . ': ' . AbstractChannel::$globalMethodNames[Helper::methodSig($methodSig)]); } return $this; }