Skip to main content

Packet

A class in Root.Township, Alta.Networking.Internal.

An outgoing packet buffer that several messages are written into, each with a 2-byte length, before it is sent on a connection.

Constructors​

MemberWhat it is
Packet(int size)Creates a Packet from size.

Fields​

3 private and internal fields
MemberWhat it is
private readonly byte[] dataThe packet's byte buffer.
private static Logger loggerNLog logger for misuse and send errors.
private readonly ushort[] sizeOne-element buffer used to copy each message's 2-byte length into the packet.

Properties​

MemberWhat it is
bool IsEmpty { get; }True when nothing has been written.
bool IsPooled { get; set; }Set while the packet is in a pool. Using it then logs an error.
int Position { get; private set; }Write position in the buffer.
1 private and internal property
MemberWhat it is
private static int ByteOffset { get; }The transport's reserved bytes at the start of the buffer; writing starts after them.

Methods​

MemberWhat it is
bool HasSpace(int byteCount)True if that many more bytes fit.
void Reset()Clears the packet for reuse.
bool Send(Connection connection, ConnectionChannel channel)Sends the packet on the connection and channel. Resets it on success, or always on unreliable channels.
void Write(StreamWriter writer, int byteCount)Appends a message: its byte length, then its bytes.

Used in​

Members of other types that take, return or hold a Packet: