Skip to content

Commit

Permalink
Specify which transient flags to filter for JSON serialisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilliamson committed Jun 7, 2021
1 parent 7e4800e commit fcfa5fc
Show file tree
Hide file tree
Showing 4 changed files with 1,329 additions and 1,293 deletions.
12 changes: 6 additions & 6 deletions inc/clutl/Serialise.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,16 @@ namespace clutl
};

// JSON serialisation
CLCPP_API JSONError LoadJSON(ReadBuffer& in, void* object, const clcpp::Type* type);
CLCPP_API JSONError LoadJSON(JSONContext& ctx, void* object, const clcpp::Field* field);
CLCPP_API JSONError LoadJSON(ReadBuffer& in, void* object, const clcpp::Type* type, unsigned int transient_flags);
CLCPP_API JSONError LoadJSON(JSONContext& ctx, void* object, const clcpp::Field* field, unsigned int transient_flags);

// Save an object of a given type to the write buffer.
// If ptr_save is null, no pointers are serialised.
CLCPP_API void SaveJSON(WriteBuffer& out, const void* object, const clcpp::Type* type, IPtrMap* ptr_map,
unsigned int flags = 0);
CLCPP_API void SaveJSON(WriteBuffer& out, const void* object, const clcpp::Type* type, IPtrMap* ptr_map, unsigned int flags,
unsigned int transient_flags);

// Save an object described by the given field to the write buffer.
// If ptr_save is null, no pointers are serialised.
CLCPP_API void SaveJSON(WriteBuffer& out, const void* object, const clcpp::Field* field, IPtrMap* ptr_map,
unsigned int flags = 0);
CLCPP_API void SaveJSON(WriteBuffer& out, const void* object, const clcpp::Field* field, IPtrMap* ptr_map, unsigned int flags,
unsigned int transient_flags);
}
141 changes: 72 additions & 69 deletions inc/clutl/SerialiseFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,73 +35,76 @@
//
namespace clutl
{
//
// Contains a list of parameters ready to be passed to a function
// Each parameter is represented as a type/pointer pair, describing how the parameter is passed and
// where the parameter is located in memory.
//
class CLCPP_API ParameterData
{
public:
static const int MAX_NB_FIELDS = 16;

struct ParamDesc
{
const clcpp::Type* type;
clcpp::Qualifier::Operator op;
void* object;
};

ParameterData();

// Clears all parameter data
void Reset();

// Adds parameters, in left-to-right call order
void PushParameter(const clcpp::Type* type, clcpp::Qualifier::Operator op, void* object);

unsigned int GetNbParameters() const;
ParamDesc& GetParameter(unsigned int index);
const ParamDesc& GetParameter(unsigned int index) const;

private:
// Parameter array allocated locally
char m_ParameterData[MAX_NB_FIELDS * sizeof(ParamDesc)];
unsigned int m_NbParameters;
};


//
// When deserialising a chunk of data that has to be passed as to a function as parameters,
// this serves as the deserialisation source, allocating and constructing the required objects.
//
class CLCPP_API ParameterObjectCache
{
public:
~ParameterObjectCache();

// Call to initialise the object cache for a specific function
// Can safely be called multiple times with different objects
void Init(const clcpp::Function* function);

// Allocates and constructs a region of memory in the cache for objects of the type specified in the field
void* AllocParameter(const clcpp::Field* field);

ParameterData& GetParameters() { return m_Parameters; }
const ParameterData& GetParameters() const { return m_Parameters; }

private:
void DeleteObjects();

WriteBuffer m_Data;
ParameterData m_Parameters;
};



CLCPP_API bool BuildParameterObjectCache_JSON(ParameterObjectCache& poc, const clcpp::Function* function, ReadBuffer& parameter_source);


CLCPP_API bool CallFunction_x86_32_msvc_cdecl(const clcpp::Function* function, const ParameterData& parameters);
CLCPP_API bool CallFunction_x86_32_msvc_thiscall(const clcpp::Function* function, const ParameterData& parameters);
//
// Contains a list of parameters ready to be passed to a function
// Each parameter is represented as a type/pointer pair, describing how the parameter is passed and
// where the parameter is located in memory.
//
class CLCPP_API ParameterData
{
public:
static const int MAX_NB_FIELDS = 16;

struct ParamDesc
{
const clcpp::Type* type;
clcpp::Qualifier::Operator op;
void* object;
};

ParameterData();

// Clears all parameter data
void Reset();

// Adds parameters, in left-to-right call order
void PushParameter(const clcpp::Type* type, clcpp::Qualifier::Operator op, void* object);

unsigned int GetNbParameters() const;
ParamDesc& GetParameter(unsigned int index);
const ParamDesc& GetParameter(unsigned int index) const;

private:
// Parameter array allocated locally
char m_ParameterData[MAX_NB_FIELDS * sizeof(ParamDesc)];
unsigned int m_NbParameters;
};

//
// When deserialising a chunk of data that has to be passed as to a function as parameters,
// this serves as the deserialisation source, allocating and constructing the required objects.
//
class CLCPP_API ParameterObjectCache
{
public:
~ParameterObjectCache();

// Call to initialise the object cache for a specific function
// Can safely be called multiple times with different objects
void Init(const clcpp::Function* function);

// Allocates and constructs a region of memory in the cache for objects of the type specified in the field
void* AllocParameter(const clcpp::Field* field);

ParameterData& GetParameters()
{
return m_Parameters;
}
const ParameterData& GetParameters() const
{
return m_Parameters;
}

private:
void DeleteObjects();

WriteBuffer m_Data;
ParameterData m_Parameters;
};

CLCPP_API bool BuildParameterObjectCache_JSON(ParameterObjectCache& poc, const clcpp::Function* function,
ReadBuffer& parameter_source, unsigned int transient_flags);

CLCPP_API bool CallFunction_x86_32_msvc_cdecl(const clcpp::Function* function, const ParameterData& parameters);
CLCPP_API bool CallFunction_x86_32_msvc_thiscall(const clcpp::Function* function, const ParameterData& parameters);
}
Loading

0 comments on commit fcfa5fc

Please sign in to comment.