CUGL 2.1
Cornell University Game Library
|
#include <CUNetworkSerializer.h>
Public Member Functions | |
NetworkSerializer () | |
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 > b) |
void | writeFloatVector (std::vector< float > f) |
void | writeDoubleVector (std::vector< double > d) |
void | writeUint32Vector (std::vector< Uint32 > i) |
void | writeUint64Vector (std::vector< Uint64 > i) |
void | writeSint32Vector (std::vector< Sint32 > i) |
void | writeSint64Vector (std::vector< Sint64 > i) |
void | writeStringVector (std::vector< std::string > s) |
void | writeCharsVector (std::vector< char * > s) |
void | writeJsonVector (std::vector< std::shared_ptr< JsonValue >> j) |
const std::vector< uint8_t > & | serialize () |
void | reset () |
Static Public Member Functions | |
static std::shared_ptr< NetworkSerializer > | alloc () |
A class to serialize complex data into a byte array.
The class NetworkConnection 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 NetworkDeserializer.
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 Network Serializer on the stack.
Network 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 Network Serializer.
This method is solely include for convenience purposes.
void cugl::NetworkSerializer::reset | ( | ) |
Clears the input buffer.
const std::vector<uint8_t>& cugl::NetworkSerializer::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 NetworkDeserializer.
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 NetworkDeserializer.
void cugl::NetworkSerializer::writeBool | ( | bool | b | ) |
Writes a single boolean value.
Values will be deserialized on other machines in the same order they were written in. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
b | The value to write |
void cugl::NetworkSerializer::writeBoolVector | ( | std::vector< bool > | b | ) |
Writes a vector of boolean values.
Values will be deserialized on other machines in the same order they were written in. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
b | The vector to write |
void cugl::NetworkSerializer::writeChars | ( | char * | s | ) |
Writes a single string value.
Values will be deserialized on other machines in the same order they were written in. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
Note that this value will be deserialized by NetworkSerializer as a std::string
object.
s | The value to write |
void cugl::NetworkSerializer::writeCharsVector | ( | std::vector< char * > | s | ) |
Writes a vector of string values.
Values will be deserialized on other machines in the same order they were written in. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
Note that the vector contents will be deserialized by NetworkSerializer as std::string
objects.
s | The vector to write |
void cugl::NetworkSerializer::writeDouble | ( | double | d | ) |
Writes a single double value.
Values will be deserialized on other machines in the same order they were written in. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
d | The value to write |
void cugl::NetworkSerializer::writeDoubleVector | ( | std::vector< double > | d | ) |
Writes a vector of double values.
Values will be deserialized on other machines in the same order they were written in. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
d | The vector to write |
void cugl::NetworkSerializer::writeFloat | ( | float | f | ) |
Writes a single float value.
Values will be deserialized on other machines in the same order they were written in. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
f | The value to write |
void cugl::NetworkSerializer::writeFloatVector | ( | std::vector< float > | f | ) |
Writes a vector of float values.
Values will be deserialized on other machines in the same order they were written in. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
f | The vector to write |
void cugl::NetworkSerializer::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. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
j | The value to write |
void cugl::NetworkSerializer::writeJsonVector | ( | std::vector< std::shared_ptr< JsonValue >> | j | ) |
Write a vector of JsonValue objects.
Values will be deserialized on other machines in the same order they were written in. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
j | The vector to write |
void cugl::NetworkSerializer::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. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
i | The value to write |
void cugl::NetworkSerializer::writeSint32Vector | ( | std::vector< Sint32 > | i | ) |
Writes a vector of signed (32 bit) int values.
Values will be deserialized on other machines in the same order they were written in. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
i | The vector to write |
void cugl::NetworkSerializer::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. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
i | The value to write |
void cugl::NetworkSerializer::writeSint64Vector | ( | std::vector< Sint64 > | i | ) |
Writes a vector of signed (64 bit) int values.
Values will be deserialized on other machines in the same order they were written in. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
i | The vector to write |
void cugl::NetworkSerializer::writeString | ( | std::string | s | ) |
Writes a single string value.
Values will be deserialized on other machines in the same order they were written in. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
s | The value to write |
void cugl::NetworkSerializer::writeStringVector | ( | std::vector< std::string > | s | ) |
Writes a vector of string values.
Values will be deserialized on other machines in the same order they were written in. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
s | The vector to write |
void cugl::NetworkSerializer::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. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
i | The value to write |
void cugl::NetworkSerializer::writeUint32Vector | ( | std::vector< Uint32 > | i | ) |
Writes a vector of unsigned (32 bit) int values.
Values will be deserialized on other machines in the same order they were written in. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
i | The vector to write |
void cugl::NetworkSerializer::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. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
i | The value to write |
void cugl::NetworkSerializer::writeUint64Vector | ( | std::vector< Uint64 > | i | ) |
Writes a vector of unsigned (64 bit) int values.
Values will be deserialized on other machines in the same order they were written in. Pass the result of serialize to the NetworkConnection to send all values buffered up to this point.
i | The vector to write |