/* Copyright (c) 2023 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 __DataValueSchema_H__ #define __DataValueSchema_H__ #include "dynamictypes/DataValue.h" #include "serialization/DeserializationContext.h" #include "serialization/SerializationContext.h" #include #define DATA_VALUE_SCHEMA_FORMAT_TYPE "data_value_schema" #define DATA_VALUE_SCHEMA_FORMAT_VERSION 1 typedef struct DataValueSchemaField { DataValueType type; char * name; DataValue defaultValue; // Defined for all primitive types size_t metadataSize; void * metadata; struct DataValueSchema * subitemSchema; // Must be defined for hash table, array, and associative array; NULL for all other types } DataValueSchemaField; typedef struct DataValueSchema { unsigned int fieldCount; DataValueSchemaField * fields; } DataValueSchema; // Does not take ownership of fields of any of their names or subitems DataValueSchema * DataValueSchema_create(unsigned int fieldCount, DataValueSchemaField * fields); DataValueSchema * DataValueSchema_copy(DataValueSchema * schema); void DataValueSchema_dispose(DataValueSchema * schema); bool DataValueSchema_isEqual(DataValueSchema * schema1, DataValueSchema * schema2); void DataValueSchema_serializeMinimal(DataValueSchema * schema, compat_type(SerializationContext *) serializationContext); void DataValueSchema_serialize(DataValueSchema * schema, compat_type(SerializationContext *) serializationContext); DataValueSchema * DataValueSchema_deserializeMinimal(compat_type(DeserializationContext *) deserializationContext, uint16_t formatVersion); DataValueSchema * DataValueSchema_deserialize(compat_type(DeserializationContext *) deserializationContext); // Takes ownership of all contents of field. name and subitemSchema both must be either NULL or heap-allocated. // DataValueSchemaField_copyContents can be used if the provided field doesn't meet these requirements. void DataValueSchema_addField(DataValueSchema * schema, DataValueSchemaField field); void DataValueSchema_insertField(DataValueSchema * schema, DataValueSchemaField field, unsigned int index); void DataValueSchema_removeFieldAtIndex(DataValueSchema * schema, unsigned int index); DataValue DataValueSchema_createBlankValue(DataValueSchema * schema, DataValueType topLevelContainerType); DataValue DataValueSchema_createBlankFieldValue(DataValueSchemaField * field); DataValueSchemaField DataValueSchemaField_copyContents(DataValueSchemaField field); #endif