![]() |
CUGL 2.5
Cornell University Game Library
|
#include <CUNetcodeSerializer.h>
Public Member Functions | |
NetcodeSerializer () | |
void | writeBool (bool b) |
void | writeFloat (float f) |
void | writeDouble (double d) |
void | writeUint32 (Uint32 i) |
void | writeUint64 (Uint64 i) |
void | writeSint32 (Sint32 i) |
void | writeSint64 (Sint64 i) |
void | writeString (std::string s) |
void | writeChars (char *s) |
void | writeJson (const std::shared_ptr< JsonValue > &j) |
void | writeBoolVector (std::vector< bool > v) |
void | writeFloatVector (std::vector< float > v) |
void | writeDoubleVector (std::vector< double > v) |
void | writeUint32Vector (std::vector< Uint32 > v) |
void | writeUint64Vector (std::vector< Uint64 > v) |
void | writeSint32Vector (std::vector< Sint32 > v) |
void | writeSint64Vector (std::vector< Sint64 > v) |
void | writeStringVector (std::vector< std::string > v) |
void | writeCharsVector (std::vector< char * > v) |
void | writeJsonVector (std::vector< std::shared_ptr< JsonValue > > v) |
const std::vector< std::byte > & | serialize () |
void | reset () |
Static Public Member Functions | |
static std::shared_ptr< NetcodeSerializer > | alloc () |
A class to serialize complex data into a byte array.
The class NetcodeConnection
is only capable of transmitting byte arrays. You should use this class to construct a byte array for a single message so that you can transmit it.
This class is capable of serializing the following data types:
You should deserialize all of these with the NetcodeDeserializer
.
Note that if a char* (not a C++ string) is written, it will be deserialized as a std::string. The same applies to vectors of char*.
|
inline |
Creates a new Netcode Serializer on the stack.
Netcode 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.
|
inlinestatic |
Returns a newly created Netcode Serializer.
This method is solely include for convenience purposes.
void cugl::net::NetcodeSerializer::reset | ( | ) |
Clears the input buffer.
const std::vector< std::byte > & cugl::net::NetcodeSerializer::serialize | ( | ) |
Returns a byte vector of all written values suitable for network transit.
This method should be called after the appropriate write methods have been called. This provides a vector for network transit. It will need to be deserialized on the other end by NetcodeDeserializer
.
You MUST call reset() after this method to clear the input buffer. Otherwise, the next call to this method will still contain all the contents written in this call.
The contents of the returned vector should be treated as opaque. You should only read the output via the use of NetcodeDeserializer
.
void cugl::net::NetcodeSerializer::writeBool | ( | bool | b | ) |
Writes a single boolean value.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
b | The value to write |
void cugl::net::NetcodeSerializer::writeBoolVector | ( | std::vector< bool > | v | ) |
Writes a vector of boolean values.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
v | The vector to write |
void cugl::net::NetcodeSerializer::writeChars | ( | char * | s | ) |
Writes a single string value.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
Note that this value will be deserialized by NetcodeSerializer
as a std::string
object.
s | The value to write |
void cugl::net::NetcodeSerializer::writeCharsVector | ( | std::vector< char * > | v | ) |
Writes a vector of string values.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
Note that the vector contents will be deserialized by NetcodeSerializer
as std::string
objects.
v | The vector to write |
void cugl::net::NetcodeSerializer::writeDouble | ( | double | d | ) |
Writes a single double value.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
d | The value to write |
void cugl::net::NetcodeSerializer::writeDoubleVector | ( | std::vector< double > | v | ) |
Writes a vector of double values.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
v | The vector to write |
void cugl::net::NetcodeSerializer::writeFloat | ( | float | f | ) |
Writes a single float value.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
f | The value to write |
void cugl::net::NetcodeSerializer::writeFloatVector | ( | std::vector< float > | v | ) |
Writes a vector of float values.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
v | The vector to write |
void cugl::net::NetcodeSerializer::writeJson | ( | const std::shared_ptr< JsonValue > & | j | ) |
Writes a single JsonValue
.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
j | The value to write |
void cugl::net::NetcodeSerializer::writeJsonVector | ( | std::vector< std::shared_ptr< JsonValue > > | v | ) |
Write a vector of JsonValue
objects.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
v | The vector to write |
void cugl::net::NetcodeSerializer::writeSint32 | ( | Sint32 | i | ) |
Writes a single signed (32 bit) int value.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
i | The value to write |
void cugl::net::NetcodeSerializer::writeSint32Vector | ( | std::vector< Sint32 > | v | ) |
Writes a vector of signed (32 bit) int values.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
v | The vector to write |
void cugl::net::NetcodeSerializer::writeSint64 | ( | Sint64 | i | ) |
Writes a single signed (64 bit) int value.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
i | The value to write |
void cugl::net::NetcodeSerializer::writeSint64Vector | ( | std::vector< Sint64 > | v | ) |
Writes a vector of signed (64 bit) int values.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
v | The vector to write |
void cugl::net::NetcodeSerializer::writeString | ( | std::string | s | ) |
Writes a single string value.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
s | The value to write |
void cugl::net::NetcodeSerializer::writeStringVector | ( | std::vector< std::string > | v | ) |
Writes a vector of string values.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
v | The vector to write |
void cugl::net::NetcodeSerializer::writeUint32 | ( | Uint32 | i | ) |
Writes a single unsigned (32 bit) int value.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
i | The value to write |
void cugl::net::NetcodeSerializer::writeUint32Vector | ( | std::vector< Uint32 > | v | ) |
Writes a vector of unsigned (32 bit) int values.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
v | The vector to write |
void cugl::net::NetcodeSerializer::writeUint64 | ( | Uint64 | i | ) |
Writes a single unsigned (64 bit) int value.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
i | The value to write |
void cugl::net::NetcodeSerializer::writeUint64Vector | ( | std::vector< Uint64 > | v | ) |
Writes a vector of unsigned (64 bit) int values.
Values will be deserialized on other machines in the same order they were written in. You should pass the result of serialize
to the NetcodeConnection
to send all values buffered up to this point.
v | The vector to write |