Serialize any input for the NEM network.

@param   array|string|integer|\NEM\Core\Serializer   $data
@return  array       Returns a byte-array with values in UInt8 representation.
@throws  RuntimeException    On unrecognized `data` argument.
517983
public function serialize(/*mixed*/ $data) 
    {
        if (null === $data) {
            return $this->serializeInt(null);
        }
        elseif (is_array($data)) {
            return $this->serializeUInt8($data);
        }
        elseif (is_integer($data)) {
            return $this->serializeLong($data);
        }
        elseif (is_string($data)) {
            return $this->serializeString($data);
        }
        elseif ($data instanceof Serializable) {
            return $data->serialize();
        }

        throw new RuntimeException("Invalid parameter provided to \\NEM\\Core\\Serialize::serialize().");
    }
488695
public function write($data)
    {

        $path = (string)$this->url();

        $isAppending = static::isAppendingMode($this->mode) || $this->didWrite;

        if (!is_resource($data) && !$data instanceof Stream && Type::isStringable($data)) {
            $this->didWrite = $isAppending ? $this->flysystem->update($path, $this->concat($data)) : $this->flysystem->write($path, $data);
            return $this->didWrite;
        }

        // Write while READING FROM A RESOURCE
        $readResource = $data instanceof Stream ? $data->resource() : $data;

        if (!is_resource($readResource)) {
            throw new RuntimeException('Cannot extract resource of ' . Type::of($data));
        }

        if ($isAppending) {
            $this->didWrite = $this->flysystem->updateStream($path, $readResource);
            return $this->didWrite;
        }

        $this->didWrite = $this->flysystem->writeStream($path, $readResource);

        return $this->didWrite;

    }
91126
protected function _toArray($data)
    {
        $array = array();

        foreach ($data as $key => $value) {
            if (is($value, 'AnDomainBehaviorSerializable')) {
                $array[$key] = $value->toSerializableArray();
            } elseif (is_array($value)) {
                $array[$key] = $this->_toArray($value);
            } else {
                $array[$key] = $value;
            }
        }

        return $array;
    }
985337
protected function serializeItem($data) {
        if ($data instanceof IArrayable) {
            return $data->toArray();
        } else if ($data instanceof IJsonable) {
            return $data->toJson();
        } else if ($data instanceof IStringable) {
            return $data->toString();
        }

        return $data;
    }
715370
public static function encode($data)
    {
        $flag = (int)is_scalar($data['body']);
        if (!$flag) {
            $data['body'] = serialize($data['body']);
        }
        $data['flag'] |= $flag;
        $ext_len      = strlen($data['ext_data']);
        $package_len  = self::HEAD_LEN + $ext_len + strlen($data['body']);
        return pack("NCNnNnNCnN", $package_len,
                $data['cmd'], $data['local_ip'],
                $data['local_port'], $data['client_ip'],
                $data['client_port'], $data['connection_id'],
                $data['flag'], $data['gateway_port'],
                $ext_len) . $data['ext_data'] . $data['body'];
    }
486035
public static function unserialize( $data )
    {
        $data = json_decode( $data, true );
        return new static( $data[0], $data[1], $data[2], $data[3] );
    }
1346696
public function jsonEncode($data): string
    {
        $plain = json_encode($data);

        if (json_last_error() != JSON_ERROR_NONE) {
            throw new \RuntimeException(self::$messages[json_last_error()]);
        }

        return $plain;
    }
744103
public static function jsonUnserialize($data) {

		$report = null;

		if (!is_array($data)) {
			$data = (Array) json_decode($data, true);
		}

		if (count(array_intersect(['type', 'message', 'data'], array_keys($data))) == 3) {
			$report = new self($data['type'], $data['message'], $data['data']);
			if (isset($data['children']) && is_array($data['children'])) {
				foreach ($data['children'] as $child) {
					$report->add(static::jsonUnserialize($child));
				}
			}
		}

		return $report;
	}
1258855
protected static function deserializeCommonAttributes(array $data)
    {
        $result = new static(isset($data['id']) ? $data['id'] : null);
        if ($result->getResourceType() != $data['meta']['resourceType']) {
            throw new \RuntimeException(sprintf('Error deserializing resource type "%s" into class "%s"', $data['meta']['resourceType'], get_class($result)));
        }
        $result->meta = Meta::deserializeObject($data['meta']);
        if (isset($arr['externalId'])) {
            $result->externalId = $data['externalId'];
        }
        if (isset($data['schemas'])) {
            foreach ($data['schemas'] as $schemaId) {
                if ($schemaId != $result->getSchemaId()) {
                    $result->extensions[$schemaId] = isset($data[$schemaId]) ? $data[$schemaId] : null;
                }
            }
        }

        return $result;
    }
526782
public function unserialize($data)
    {
        $this->throwIfTrue(!is_string($data), '$data must be a string');

        set_error_handler($this->getErrorHandler());
        try {
            $unserialized = unserialize($data);
            $this->throwIfTrue($unserialized === false, '$data could not be unserialized');
            return $unserialized;
        } finally {
            restore_error_handler();
        }
    }
382870
public function serialize()
    {
        if ($this->getIsModified() || $this->getIsNew()) {
            throw new RuntimeException($this->translate(
                'Cannot serialize modified or new object.'
            ));
        }

        if ($this->collection && $this->type) {
            $this->fullyLoad(true);
        }
        $data = [
            $this->initialValues,
            $this->getCollectionName(),
            $this->getTypeName()
        ];

        return serialize($data);
    }
624891
public function encode($data)
    {
        $result = '';
        foreach($data as $k => $v)
        {
            $result .= $k . '|' . serialize($v);
        }
        return $result;
    }
917928
public static function encode($data)
    {
        switch (gettype($data)) {
            case 'array':
                return self::encodeArray($data);
            case 'object':
                return self::encodeObject($data);
            case 'string':
                return self::encodeString($data);
            case 'integer':
                return self::encodeInteger($data);
            case 'boolean':
                return self::encodeBoolean($data);
            case 'double':
                return self::encodeDouble($data);
            case 'NULL':
                return self::encodeNull($data);
            case 'resource':
                // TODO
                break;
            default:
                throw new UnencodeableException('Contains unencodeable type', 3);
        }
    }
168304
public function decode(string $data): array
    {
        $rawData = [];
        parse_str($data, $rawData);

        if ('' !== $data && [] === $rawData) {
            throw DeserializerRuntimeException::createNotParsable($this->getContentType());
        }

        return $this->fixValues($rawData);
    }
858203
private function convertSerializedToObjects($data)
    {
        $data = @unserialize($data);

        // If it is an object then
        // we can just return it...
        if (is_object($data))
        {
            return $data;
        }

        // It could be a associative array so use
        // JSON to encode it and then decode it properly...
        if (is_array($data) and $json = $this->convertToJson($data))
        {
            return $this->convertJsonToObjects($json);
        }

        return null;
    }
884369
public static function deserializeObject(array $data)
    {
        $subAttributes = [];
        if (isset($data['subAttributes'])) {
            foreach ($data['subAttributes'] as $subAttribute) {
                $subAttributes[] = static::deserializeObject($subAttribute);
            }
        }
        $result = new static(
            $data['name'],
            $data['type'],
            $data['multiValued'],
            $data['required'],
            isset($data['description']) ? $data['description'] : null,
            $subAttributes,
            isset($data['canonicalValues']) ? $data['canonicalValues'] : [],
            isset($data['caseExact']) ? $data['caseExact'] : false,
            $data['mutability'],
            $data['returned'],
            isset($data['uniqueness']) ? $data['uniqueness'] : null,
            isset($data['referenceTypes']) ? $data['referenceTypes'] : []
        );

        return $result;
    }
766824
protected function jsonEncode($data)
    {
        $return = json_encode($data);

        if ($return === false) {
            throw new ConverterException(
                sprintf(
                    "Could not convert %s data to JSON. Driver returned '%s'.",
                    gettype($data),
                    json_last_error()
                )
            );
        }

        return $return;
    }