#include <CULWSerializer.h>
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.
◆ 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.
◆ 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
-
◆ 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
-
◆ 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
-
◆ 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
-
v | The 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
-
◆ 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
-
◆ 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
-
◆ 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
-
i | the 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
-
i | the unsigned Uint64 to write |
The documentation for this class was generated from the following file: