dsfml.network.packet



class Packet;
Packet wraps data to send / to receive through the network

The order of insertion and extraction must be the same.

You can derive from Packet and override onSend and onReceive to do custom operations before send or after reception.

Litterals integer are promoted to int. Litterals floating point are promoted to float.

Extraction or insertion can be specified with explicit template.

Examples:
   Packet p = new Packet();

   int i = 32, j = 42;
   char[] k = hello;

   p.set(i, k, j); //Set the data in the packet

   int a, b;
   char[] c;
   p.get(a, c, b); //Get data from the packet

   //...

   Packet p = new Packet();
   p.set!(byte)(5); // Litteral are inserted with byte type


See Also:
D litterals Specification for more informations.

this();
Default constructor

void append(byte[] data);
Append data to the end of the packet.

Params:
byte[] data Array of data to append

void clear();
Clear the packet data

byte* getData();
Get a pointer to the data contained in the packet the returned array may be invalid after you append data to the packet

Returns:
pointer to data

Remarks:
return an array of all data in the packet.

   Packet p = new Packet();

   char[] str1 = "Hi";
   char[] str2 = "Hello";

   p.set(str1, str2);

   char[] str3;
   p.get(str3);

   // returns an array containing str1 and str2. Length of the array is getDataSize()
   byte* ptr = p.getData();


uint getDataSize();
Get the size of the data contained in the packet

Returns:
Data size, in bytes

bool canRead();
Tell if the packet is valid for reading

Returns:
True if data can be extracted from the packet



Packet set(T,A...)(T t, A a);
Add new variables to the packet Accept (u)byte, (u)short, (u)int, float, double, char[] and wchar[] types

Packet get(T,A...)(ref T t, ref A a);
Retrieve data from the packet Accept (u)byte, (u)short, (u)int, float, double, char[] and wchar[] types

void onSend();
Called before packet is send

void onReceive();
Called after a packet has been received


Page generated by Ddoc.