Packets
In DarkNet, a packet is a versatile and efficient object which stores data. Packets can be sent, received and manipulated in a number of ways. Each packet has a used size, memory size and cursor position. Packets can be created, deleted or reused at any time.
Memory
DarkNet uses a unique high performance packet system which limits memory reallocation and data copying.
The memory of a packet is first allocated using mnSetMemorySize. This memory usually never needs to be reallocated, but can be using mnChangeMemorySize.
When data is added to a packet, its used size increases. This is the amount of memory that is used. When a packet is reset, the used size is simply set to 0, the data itself is left untouched.
Cursor
The cursor of a packet is used to specify the location at which data will be read or written to. The mnAdd and mnGet packet commands begin reading/writing at the cursor position, and move the cursor along by the amount of data read/written.
Example
Packet = mn Create Packet()
mn Set Memory Size Packet, 15
mn Add String Packet, "Hello", 0, 0
mn Add String Packet, " World", 0, 0 |
The used size is 11 which indicates 11 elements are in use, so everything before the element shaded in green is in use. Commands such as mnSendTCP will only send 11 elements of data and will ignore unused elements. Similarly, the cursor is also at element 11 which means further mnAdd commands will add data at this point; the cursor could be moved anywhere in the packet using mnSetCursor.
The memory size is 15 which means that the used size could expand a further 4 bytes in size. If the used size expands to 16 or above an error will occur (16 or above begins at element 15 which is shaded in red)
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
H |
E |
L |
L |
O |
|
W |
O |
R |
L |
D |
|
|
|
|
|
Manipulation
Several commands exist that provide an easy way to manipulate a packet's contents. We will look at two of these: mnErase and mnInsert.
mnInsert inserts a blank space anywhere in a packet. This space can then be filled using an mnAdd command. mnErase removes a specified portion of the packet. This is demonstrated below.
Screenshot

Code
C++
C#
VB.NET
DarkBASIC Pro
|