/* Copyright (c) 2015 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __DataSerializer_H__ #define __DataSerializer_H__ #ifdef __cplusplus extern "C" { #endif #include "dynamictypes/DataValue.h" #include "dynamictypes/DataValueSchema.h" #include "serialization/DeserializationContext.h" #include "serialization/SerializationContext.h" #define DATA_SERIALIZER_SCHEMA_ITEM_MISMATCH 300 #define DATA_SERIALIZER_UNSUPPORTED_DATA_TYPE 301 #define DATA_SERIALIZER_UNKNOWN_DATA_TYPE 302 #define DATA_SERIALIZER_MISSING_ITEM 303 // Reads from or writes to a lossless representation of a DataValue hierarchy. Restrictions: // - value must be a container type (DATA_TYPE_ARRAY, DATA_TYPE_HASH_TABLE, or DATA_TYPE_ASSOCIATIVE_ARRAY) // - Values of type DATA_TYPE_POINTER anywhere in the hierarchy will be ignored and will not be serialized void DataValue_serializeGeneric(DataValue * value, compat_type(SerializationContext *) serializationContext); // If deserialization fails, returns valueCreateBoolean(false) DataValue DataValue_deserializeGeneric(compat_type(DeserializationContext *) deserializationContext); bool DataValue_serializeWithSchema(DataValue * value, DataValueSchema * schema, const char * topLevelKey, compat_type(SerializationContext *) serializationContext); // Note: If tolerateErrors is set to true and an error has already occurred in the deserialization context // passed to DataValue_deserializeWithSchema(), the context's error status may be erased on return. If it's // necessary to handle deserialization errors in a situation where data is being tolerantly deserialized, // handle them before calling this function. DataValue DataValue_deserializeWithSchema(DataValueSchema * schema, const char * topLevelKey, DataValueType topLevelContainerType, compat_type(DeserializationContext *) deserializationContext, bool tolerateErrors); #ifdef __cplusplus } #endif #endif