/** * Morph the given content into CBOR. * * @param mixed $content * @return string */ protected function morphToCbor($content) { if ($content instanceof CborableInterface) { return $content->toCbor(); } return Cbor::encode($content); }
/** * Get the CBOR payload for the request. * * @param string $key The key to get the value for, in "dot notation" (ex: user.username = cbor["user"]["username"]). * @param mixed $default Default value if the key isn't found. * @return mixed */ public function cbor($key = null, $default = null) { //Grab the content $content = $this->getContent(); //Deal with empty input. if (empty($content)) { return null; } //Don't decode twice! if (!isset($this->cbor)) { $this->cbor = new ParameterBag((array) Cbor::decode($content, true)); } //Return the whole array if no key was specified if (is_null($key)) { return $this->cbor; } //Get key value in dot notation return array_get($this->cbor->all(), $key, $default); }
/** * Get the cbor decoded data from the response * * @return mixed */ public function getData() { return Cbor::decode($this->data); }
function testAbruptStringEnd() { $this->setExpectedException(CBOR_EXCEPTION); Cbor::decode(pack('C*', 0b1111011, 97, 98)); }
/** * Encodes the first byte, with an additional type that is dependent on the float type. * * @return string The encoded byte. */ protected static function encodeFirstByte() { return Cbor::encodeFirstByte(MajorType::SIMPLE_AND_FLOAT, static::getAdditionalType()); }