CUGL 2.5
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
cugl::physics2::net::LWSerializer Class Reference

#include <CULWSerializer.h>

Public Member Functions

 LWSerializer ()
 
void writeBool (bool b)
 
void writeByte (std::byte b)
 
void writeFloat (float f)
 
void writeSint32 (Sint32 i)
 
void writeUint16 (Uint16 i)
 
void writeUint32 (Uint32 i)
 
void writeUint64 (Uint64 i)
 
void writeByteVector (const std::vector< std::byte > &v)
 
void rewriteFirstUint32 (Uint32 i)
 
const std::vector< std::byte > & serialize ()
 
void reset ()
 

Static Public Member Functions

static std::shared_ptr< LWSerializeralloc ()
 

Detailed Description

A lightweight serializer for networked physics.

This class removes the type safety of cugl::net::NetcodeSerializer, and requires that the user know the type of the data. However, it is a more space efficient serializer, and is more appropriate for networked physics.

This class is to be paired with LWDeserializer for deserialization.

Constructor & Destructor Documentation

◆ LWSerializer()

cugl::physics2::net::LWSerializer::LWSerializer ( )
inline

Creates a new LWSerializer on the stack.

Serializers do not have any nontrivial state and so it is unnecessary to use an init method. However, we do include a static alloc method for creating shared pointers.

Member Function Documentation

◆ alloc()

static std::shared_ptr< LWSerializer > cugl::physics2::net::LWSerializer::alloc ( )
inlinestatic

Returns a newly allocated LWSerializer.

This method is solely include for convenience purposes.

Returns
a newly allocated LWSerializer.

◆ reset()

void cugl::physics2::net::LWSerializer::reset ( )
inline

Clears the input buffer.

Note that this will make previous serialize() returns invalid.

◆ rewriteFirstUint32()

void cugl::physics2::net::LWSerializer::rewriteFirstUint32 ( Uint32  i)
inline

Rewrites the first four bytes of the buffer with the given Uint32.

This method requires that the input buffer has at least four bytes. It can be used to add header information once a payload has been constructed.

Parameters
iThe new header

◆ serialize()

const std::vector< std::byte > & cugl::physics2::net::LWSerializer::serialize ( )
inline

Returns the serialized data.

Returns
A const reference to the serialized data. (Will be lost if reset)

◆ writeBool()

void cugl::physics2::net::LWSerializer::writeBool ( bool  b)
inline

Writes a single boolean value to the buffer.

Values will be deserialized on other machines in the same order they were written in.

Parameters
bThe value to write

◆ writeByte()

void cugl::physics2::net::LWSerializer::writeByte ( std::byte  b)
inline

Writes a single byte value to the buffer.

Values will be deserialized on other machines in the same order they were written in.

Parameters
bThe value to write

◆ writeByteVector()

void cugl::physics2::net::LWSerializer::writeByteVector ( const std::vector< std::byte > &  v)
inline

Writes a byte vector to the buffer.

Values will be deserialized on other machines in the same order they were written in.

Parameters
vThe byte vector to write

◆ writeFloat()

void cugl::physics2::net::LWSerializer::writeFloat ( float  f)
inline

Writes a single float value to the input buffer.

Values will be deserialized on other machines in the same order they were written in.

Parameters
fThe float to write

◆ writeSint32()

void cugl::physics2::net::LWSerializer::writeSint32 ( Sint32  i)
inline

Writes a signed 32-bit integer to the input buffer.

Values will be deserialized on other machines in the same order they were written in.

Parameters
iThe Sint32 to write

◆ writeUint16()

void cugl::physics2::net::LWSerializer::writeUint16 ( Uint16  i)
inline

Writes an unsigned 16-bit integer to the input buffer.

Values will be deserialized on other machines in the same order they were written in.

Parameters
iThe Uint16 to write

◆ writeUint32()

void cugl::physics2::net::LWSerializer::writeUint32 ( Uint32  i)
inline

Writes a unsigned 32-bit integer to the input buffer.

Values will be deserialized on other machines in the same order they were written in.

Parameters
ithe unsigned Uint32 to write

◆ writeUint64()

void cugl::physics2::net::LWSerializer::writeUint64 ( Uint64  i)
inline

Writes a unsigned 64-bit integer to the input buffer.

Values will be deserialized on other machines in the same order they were written in.

Parameters
ithe unsigned Uint64 to write

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