carb/dictionary/ISerializer.h

File members: carb/dictionary/ISerializer.h

// Copyright (c) 2019-2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#pragma once

#include "../Framework.h"
#include "../Interface.h"
#include "../datasource/IDataSource.h"
#include "../dictionary/IDictionary.h"

#include <cstdint>

namespace carb
{
namespace dictionary
{

using SerializerOptions = uint32_t;

constexpr SerializerOptions fSerializerOptionIncludeDictionaryName = 1;

constexpr SerializerOptions fSerializerOptionMakePretty = (1 << 1);

constexpr SerializerOptions fSerializerOptionEmptyDictionaryIsArray = (1 << 2);

constexpr SerializerOptions fSerializerOptionSerializeInfinityAsNull = (1 << 3);

CARB_DEPRECATED("Use fSerializerOptionIncludeDictionaryName instead.")
constexpr SerializerOptions fSerializerOptionIncludeCollectionName = fSerializerOptionIncludeDictionaryName;
CARB_DEPRECATED("Use fSerializerOptionIncludeDictionaryName instead.")
constexpr SerializerOptions kSerializerOptionIncludeDictionaryName = fSerializerOptionIncludeDictionaryName;
CARB_DEPRECATED("Use fSerializerOptionMakePretty instead.")
constexpr SerializerOptions kSerializerOptionMakePretty = fSerializerOptionMakePretty;
CARB_DEPRECATED("Use fSerializerOptionEmptyDictionaryIsArray instead.")
constexpr SerializerOptions kSerializerOptionEmptyDictionaryIsArray = fSerializerOptionEmptyDictionaryIsArray;
CARB_DEPRECATED("Use fSerializerOptionSerializeInfinityAsNull instead.")
constexpr SerializerOptions kSerializerOptionSerializeInfinityAsNull = fSerializerOptionSerializeInfinityAsNull;
CARB_DEPRECATED("Use fSerializerOptionIncludeDictionaryName instead.")
constexpr SerializerOptions kSerializerOptionIncludeCollectionName = fSerializerOptionIncludeDictionaryName;
/* @} **/

using DeserializerOptions = uint32_t;

constexpr DeserializerOptions kDeserializerOptionNone = 0;

constexpr DeserializerOptions fDeserializerOptionInSitu = (1 << 0);

struct ISerializer
{
    CARB_PLUGIN_INTERFACE("carb::dictionary::ISerializer", 1, 1)

    CARB_DEPRECATED("use the new createDictionaryFromStringBuffer")
    dictionary::Item*(CARB_ABI* deprecatedCreateDictionaryFromStringBuffer)(const char* serializedString);

    const char*(CARB_ABI* createStringBufferFromDictionary)(const dictionary::Item* dictionary,
                                                            SerializerOptions serializerOptions);

    void(CARB_ABI* destroyStringBuffer)(const char* serializedString);

    dictionary::Item*(CARB_ABI* internalCreateDictionaryFromStringBuffer)(const char* string,
                                                                          size_t len,
                                                                          DeserializerOptions options);

    dictionary::Item* createDictionaryFromStringBuffer(const char* string,
                                                       size_t len = size_t(-1),
                                                       DeserializerOptions options = kDeserializerOptionNone)
    {
        return internalCreateDictionaryFromStringBuffer(string, len, options);
    }
};

} // namespace dictionary
} // namespace carb