/* Copyright (c) 2014 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 __SerializationShared_H__ #define __SerializationShared_H__ #ifdef __cplusplus extern "C" { #endif #include #include typedef struct Serialization_enumKeyValue { const char * key; int32_t value; } Serialization_enumKeyValue; typedef struct Serialization_bitName { const char * name; unsigned int index; } Serialization_bitName; // No error #define SERIALIZATION_ERROR_OK 0 // General incorrect API usage #define SERIALIZATION_ERROR_INVALID_OPERATION 1 // The requested key is not present in the current dictionary or structure #define SERIALIZATION_ERROR_KEY_NOT_FOUND 2 // A call to begin wasn't paired with the correct one of end #define SERIALIZATION_ERROR_CONTAINER_TYPE_MISMATCH 3 // More calls to end than to begin #define SERIALIZATION_ERROR_CONTAINER_UNDERFLOW 4 // After a matched number of calls to , begin is called again #define SERIALIZATION_ERROR_MULTIPLE_TOP_LEVEL_CONTAINERS 5 // In a call to Bitfield<8|16|32|64>, one or more of set bits isn't named in function arguments #define SERIALIZATION_ERROR_UNNAMED_BIT 6 // In a call to Bitfield<8|16|32|64>, multiple bits are given the same name or index #define SERIALIZATION_ERROR_DUPLICATE_BIT 7 // In a call to Enumeration, the enumeration value is not named #define SERIALIZATION_ERROR_ENUM_NOT_NAMED 8 // In a call to Enumeration, multiple enumeration values are given the same name #define SERIALIZATION_ERROR_DUPLICATE_ENUM_NAME 9 // In a call to Enumeration, multiple enumeration names are given the same value #define SERIALIZATION_ERROR_DUPLICATE_ENUM_VALUE 10 // key parameter is NULL when reading from/writing to a structure or dictionary #define SERIALIZATION_ERROR_NULL_KEY 11 // The value being deserialized is not of the requested data type #define SERIALIZATION_ERROR_INCORRECT_TYPE 12 // The number value being deserialized is too large or small to fit in the requested data type #define SERIALIZATION_ERROR_NUMBER_OUT_OF_RANGE 13 // More fields requested for deserialization than exist in the container being deserialized #define SERIALIZATION_ERROR_END_OF_CONTAINER 14 // A read or write call was issued before the first begin call, or after the last end call #define SERIALIZATION_ERROR_NO_CONTAINER_STARTED 15 // An attempt was made to save data without having serialized anything #define SERIALIZATION_ERROR_NO_TOP_LEVEL_CONTAINER 16 // A bit was specified at an index beyond the maximum range of its type #define SERIALIZATION_ERROR_BIT_OUT_OF_RANGE 17 // Reported format of data being read does not match expected format #define SERIALIZATION_ERROR_FORMAT_TYPE_MISMATCH 18 // Reported version of data being read is older than oldest supported #define SERIALIZATION_ERROR_FORMAT_VERSION_TOO_OLD 19 // Reported version of data being read is newer than newest supported #define SERIALIZATION_ERROR_FORMAT_VERSION_TOO_NEW 20 // Array has too many (or too few) items for the data being read #define SERIALIZATION_ERROR_ARRAY_COUNT_OUT_OF_RANGE 21 // Other errors defined by concrete serialization modules /* Returns a human-readable string constant describing one of the errors defined above. Note that you should normally call the errorString() instance method on the context that generated the error instead of this function, since they can describe error codes defined by extensions. This function can only define the ones contained within this header. */ const char * Serialization_errorString(int status); // For internal use by SerializationContext/DeserializationContext subclasses. Returns a serialization status code indicating whether readBitfield* arguments are malformed. int Serialization_checkBitfield8Errors(uint8_t value, unsigned int bitNameCount, Serialization_bitName * bitNames); int Serialization_checkBitfield16Errors(uint16_t value, unsigned int bitNameCount, Serialization_bitName * bitNames); int Serialization_checkBitfield32Errors(uint32_t value, unsigned int bitNameCount, Serialization_bitName * bitNames); int Serialization_checkBitfield64Errors(uint64_t value, unsigned int bitNameCount, Serialization_bitName * bitNames); // For internal use by SerializationContext/DeserializationContext subclasses. Returns a serialization status code indicating whether readEnumeration arguments are malformed. int Serialization_checkEnumerationErrors(int value, unsigned int valueCount, Serialization_enumKeyValue * values); #ifdef __cplusplus } #endif #endif