ark::serialization::OutputStream

Defined in header “ark/serialization/output_stream.hh”.


An output stream allows you to serialize data in C++ to a stream that can later be read from, safely. It is the lowest level primitive in the serialization stack.

Methods

  • OutputStream()
    Constructor. Initializes a new output stream.

  • OutputStream(core::ByteBuffer & buffer)
    Constructor. Initializes using the given byte buffer. Allows you to reuse an existing byte buffer (to reduce re-allocations, for example).

  • void write_bitstream_header()
    Writes a stream header out. This is typically used to identify a new structure/bitstream.

  • void write(const Type & type)
    A primary dispatcher this allows you to dispatch between writing primitives out, and writing more complex classes recursively.

  • void write_primitive(bool value)
    These routines write their respective primitives into the internal bitstream.

  • void write_primitive(int8_t value)

  • void write_primitive(int16_t value)

  • void write_primitive(int32_t value)

  • void write_primitive(int64_t value)

  • void write_primitive(uint8_t value)

  • void write_primitive(uint16_t value)

  • void write_primitive(uint32_t value)

  • void write_primitive(uint64_t value)

  • void write_primitive(float value)

  • void write_primitive(double value)

  • void write_primitive(const char * value)

  • void write_primitive(const std::string & value)

  • void write_primitive(const std::chrono::nanoseconds & value)

  • void write_primitive(const std::chrono::steady_clock::time_point & value)

  • void write_primitive(const std::chrono::system_clock::time_point & value)

  • void write_primitive(const std::vector< Type > & value)
    Writes out a vector of objects.

  • void write_primitive(const std::vector< Type > & value, uint32_t size)
    Writes out a vector of objects.

  • void write_primitive(const std::array< Type, ArraySize > & value)
    Writes out a array of objects.

  • void write_primitive(const std::map< Key, Value > & value)
    Writes out a dictionary of objects.

  • void write_primitive(const std::optional< Type > & type)
    Writes out the given optional field to the bitstream. If the optional is set, the underlying type will be serialized into the bitstream.

  • void write(const IndexedVariant< VariantSubtypes… > & value)
    Write out a variant containing one of any number of types.

  • void write_bytes(const void *data __attribute__, size_t size)
    Writes an arbitrary number of bytes into the given byte stream. Used internally from the other primitive writers.

  • uint8_t * advance(size_t size)
    Allocates the given size in the buffer bitstream and returns a pointer to the start of newly allocated space. This allows a user to write directly to the bitstream, mainly useful for integration with third party systems.

    NOTE: Any call to reserve, write or advance will invalidate the pointer.

  • void begin_optional_group(uint8_t identifier)
    Begin writing out a new optional group. You must call the finish_optional_group() API to complete this.

  • void finish_optional_group()
    Finishes writing the active optional group.

  • void reserve(size_t capacity)
    Reserves some number of bytes in the underlying byte buffer; this can be useful if you know the size of the object you are going to serialize ahead of time, to reduce memory buffer resizes.

  • uint32_t begin_writing_object_with_length()
    Begins writing an object out by reserving room for the object’s length. Returns the offset of the empty length reservation.

  • void finish_writing_object_with_length(uint32_t start_offset)
    Completes writing out the object, updating the length in the bitstream at the given offset.

  • const core::ByteBuffer & data()
    Returns the raw bitstream.