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

#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< NetcodeSerializeralloc ()
 

Detailed Description

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*.

Constructor & Destructor Documentation

◆ NetcodeSerializer()

cugl::net::NetcodeSerializer::NetcodeSerializer ( )
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.

Member Function Documentation

◆ alloc()

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

Returns a newly created Netcode Serializer.

This method is solely include for convenience purposes.

Returns
a newly created Netcode Serializer.

◆ reset()

void cugl::net::NetcodeSerializer::reset ( )

Clears the input buffer.

◆ serialize()

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.

Returns
a byte vector of all written values suitable for network transit.

◆ writeBool()

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.

Parameters
bThe value to write

◆ writeBoolVector()

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.

Parameters
vThe vector to write

◆ writeChars()

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.

Parameters
sThe value to write

◆ writeCharsVector()

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.

Parameters
vThe vector to write

◆ writeDouble()

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.

Parameters
dThe value to write

◆ writeDoubleVector()

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.

Parameters
vThe vector to write

◆ writeFloat()

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.

Parameters
fThe value to write

◆ writeFloatVector()

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.

Parameters
vThe vector to write

◆ writeJson()

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.

Parameters
jThe value to write

◆ writeJsonVector()

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.

Parameters
vThe vector to write

◆ writeSint32()

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.

Parameters
iThe value to write

◆ writeSint32Vector()

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.

Parameters
vThe vector to write

◆ writeSint64()

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.

Parameters
iThe value to write

◆ writeSint64Vector()

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.

Parameters
vThe vector to write

◆ writeString()

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.

Parameters
sThe value to write

◆ writeStringVector()

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.

Parameters
vThe vector to write

◆ writeUint32()

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.

Parameters
iThe value to write

◆ writeUint32Vector()

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.

Parameters
vThe vector to write

◆ writeUint64()

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.

Parameters
iThe value to write

◆ writeUint64Vector()

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.

Parameters
vThe vector to write

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