GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Public Types | Static Public Member Functions | List of all members
gd::BinarySerializer Class Reference

Fast binary serialization/deserialization for SerializerElement trees. More...

#include <BinarySerializer.h>

Public Types

enum class  NodeType : uint8_t {
  Element = 0x01 , ValueUndefined = 0x02 , ValueBool = 0x03 , ValueInt = 0x04 ,
  ValueDouble = 0x05 , ValueString = 0x06
}
 

Static Public Member Functions

static void SerializeToBinaryBuffer (const SerializerElement &element, std::vector< uint8_t > &outBuffer)
 Serialize a SerializerElement tree to a binary buffer. More...
 
static bool DeserializeFromBinaryBuffer (const uint8_t *buffer, size_t bufferSize, SerializerElement &outElement)
 Deserialize a binary buffer back to a SerializerElement tree. More...
 
Helpers
static uintptr_t CreateBinarySnapshot (const SerializerElement &element)
 Create a binary snapshot and return the size. The binary data is written to Emscripten's heap at the returned pointer. More...
 
static size_t GetLastBinarySnapshotSize ()
 Get the size of the last created binary snapshot. Must be called immediately after CreateBinarySnapshot.
 
static void FreeBinarySnapshot (uintptr_t bufferPtr)
 Free a binary snapshot.
 
static SerializerElementDeserializeBinarySnapshot (uintptr_t bufferPtr, size_t size)
 Deserialize binary snapshot back to SerializerElement. More...
 

Detailed Description

Fast binary serialization/deserialization for SerializerElement trees.

This format is optimized for speed and compactness, not for human readability or long-term storage. For transferring data between "threads" (web workers).

Member Function Documentation

◆ CreateBinarySnapshot()

uintptr_t gd::BinarySerializer::CreateBinarySnapshot ( const SerializerElement element)
static

Create a binary snapshot and return the size. The binary data is written to Emscripten's heap at the returned pointer.

Returns
Pointer to binary data in Emscripten heap (use GetLastBinarySnapshotSize to get size)

◆ DeserializeBinarySnapshot()

SerializerElement * gd::BinarySerializer::DeserializeBinarySnapshot ( uintptr_t  bufferPtr,
size_t  size 
)
static

Deserialize binary snapshot back to SerializerElement.

Returns
New SerializerElement pointer (caller owns it)

◆ DeserializeFromBinaryBuffer()

bool gd::BinarySerializer::DeserializeFromBinaryBuffer ( const uint8_t *  buffer,
size_t  bufferSize,
SerializerElement outElement 
)
static

Deserialize a binary buffer back to a SerializerElement tree.

Parameters
bufferThe binary data
bufferSizeSize of the binary data
outElementThe output element (will be populated)
Returns
true if successful, false if corrupted data

◆ SerializeToBinaryBuffer()

void gd::BinarySerializer::SerializeToBinaryBuffer ( const SerializerElement element,
std::vector< uint8_t > &  outBuffer 
)
static

Serialize a SerializerElement tree to a binary buffer.

Parameters
elementThe root element to serialize
outBufferOutput buffer that will contain the binary data

The documentation for this class was generated from the following files: