Skip to content

Engine → Scripting → script_fields.h

field_blob_writer

Syntax

class CONJURE_API field_blob_writer

Constructors

AccessSignatureDescription
publicexplicit field_blob_writer( std::span<u8> output) noexcept;Writes into output; an empty span measures (required_size() reports what a real pass needs). Every write past the end sets overflowed() and keeps counting bytes.

Important

Copy constructor and assignment has been deleted.

Destructors

AccessSignatureDescription
public~field_blob_writer();

Variables

AccessNameTypeDefaultDescription
privatemBegunboolfalse
privatemCursorusize0
privatemFieldCountu320
privatemFieldOpenboolfalse
privatemOpenFieldPayloadStartusize0
privatemOpenFieldSizeOffsetusize0
privatemOutputstd::span<u8>{}
privatemOverflowedboolfalse

Functions

Public

begin

void begin();

Writes the header (the field count is patched by finish()).

begin_field

void begin_field(
    u64 hash,
    script_field_kind kind,
    script_field_kind elementKind);

Starts a field whose payload is written piecewise through the raw helpers; end_field() patches the payload size. Nested begin_field is not allowed.

end_field

void end_field();

field_count

[[nodiscard]] u32 field_count() const noexcept;

finish

[[nodiscard]] usize finish();

Patches the field count and returns the bytes the blob needs. When that is more than the output size (overflowed()), the output is NOT a valid blob: the header counts every field while the bytes stop at the overflow, possibly inside a field header, so field_blob_reader rejects it. Retry with an output of the returned size (the measure-then-write idiom json_to_blob uses).

overflowed

[[nodiscard]] bool overflowed() const noexcept;

pad_to_4

void pad_to_4();

required_size

[[nodiscard]] usize required_size() const noexcept;

write_asset

void write_asset(
    u64 hash,
    const core::uuid &value);

write_bool

void write_bool(
    u64 hash,
    bool value);

write_bytes

void write_bytes(
    std::span<const u8> bytes);

write_double

void write_double(
    u64 hash,
    f64 value);

write_entity

void write_entity(
    u64 hash,
    ecs::entity value);

write_field

void write_field(
    u64 hash,
    script_field_kind kind,
    script_field_kind elementKind,
    std::span<const u8> payload);

Writes one field header plus payload, padded to 4 bytes.

write_float

void write_float(
    u64 hash,
    f32 value);

write_floats

void write_floats(
    u64 hash,
    script_field_kind kind,
    std::span<const f32> values);

write_int32

void write_int32(
    u64 hash,
    i32 value,
    script_field_kind kind = script_field_kind::INT32);

write_int64

void write_int64(
    u64 hash,
    i64 value);

write_string

void write_string(
    u64 hash,
    std::string_view value);

write_u32

void write_u32(
    u32 value);

Private

patch_u16

void patch_u16(
    usize offset,
    u16 value);

patch_u32

void patch_u32(
    usize offset,
    u32 value);

put

void put(
    const void *data,
    usize size);