/** * @param array|string $formats * @param string $blob * @return Message * @throws InvalidMessageException */ public function decode($formats, $blob) { $formats = (array) $formats; $prefixLen = 0; foreach ($formats as $format) { $prefixLen = max($prefixLen, strlen($format)); } list($prefix) = explode(Constants::PROTOCOL_DELIM, substr($blob, 0, $prefixLen + 1)); if (!in_array($prefix, $formats)) { if (in_array(GarbledMessage::NAME, $formats)) { return GarbledMessage::decode($blob); } else { throw new InvalidMessageException("Unexpected message type."); } } switch ($prefix) { case StdMessage::NAME: return StdMessage::decode($this->cxnStore, $blob); case InsecureMessage::NAME: return InsecureMessage::decode($blob); case RegistrationMessage::NAME: return RegistrationMessage::decode($this->appStore, $blob); case AppMetasMessage::NAME: return AppMetasMessage::decode($this->certValidator, $blob); default: throw new InvalidMessageException("Unrecognized message type."); } }
public function decode($formats, $message) { $prefixLen = 0; foreach ($formats as $format) { $prefixLen = max($prefixLen, strlen($format)); } list($prefix) = explode(Constants::PROTOCOL_DELIM, substr($message, 0, $prefixLen + 1)); if (!in_array($prefix, $formats)) { throw new InvalidMessageException("Unexpected message type."); } switch ($prefix) { case StdMessage::NAME: return StdMessage::decode($this->cxnStore, $message); case InsecureMessage::NAME: return InsecureMessage::decode($message); case RegistrationMessage::NAME: return RegistrationMessage::decode($this->appId, $this->appPrivKey, $message); default: throw new InvalidMessageException("Unrecognized message type"); } }