Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you deal with network communications you must define a "protocol" to define what your "Message" is because network connections are <a href="https://stackoverflow.com/questions/3017633/difference-between-message-oriented-protocols-and-stream-oriented-protocols">Stream based not Message based</a>.</p> <p>So in the protocal is defined as the following</p> <pre> Description -> |dataIdentifier|name length|message length| name | message | Size in bytes -> | 4 | 4 | 4 |name length|message length| </pre> <p>A <code>int</code> will always be a <code>System.Int32</code> and a <code>System.Int32</code> will always take 4 bytes to store (divide 32 by 8 and you get 4).</p> <p>Here is another line showing the data types of each column, maybe that will help you</p> <pre> Description -> |dataIdentifier|name length|message length| name | message | Size in bytes -> | 4 | 4 | 4 |name length|message length| Data Type -> | int | int | int | string | string | </pre> <hr> <p>So, now why do we skip 4 bytes in the bit converter.</p> <p>Lets put the schema back up but this time I will but numbers down indicating the number of bytes</p> <p>Now the last two are "special" their length is not a fixed length like the first 3, what they do is take the value from a previous column and that is how many bytes are read in.</p> <pre> Description -> |dataIdentifier|name length|message length| name | message | Size in bytes -> | 4 | 4 | 4 | name length | message length | Bytes -> |0 1 2 3 | 4 5 6 7 | 8 9 10 11 | 12 through (12 + name length) | (12 + name length) + 1 through ((12 + name length) + 1 + message length) | </pre> <p>So you can see to read <code>dataIdentifier</code> we start at index 0 and read 4 bytes (which is how many <code>BitConverter.ToInt32</code> will read). Then when we want to read <code>nameLength</code> we need to start at index 4 then read another 4 bytes, that is why <code>BitConverter.ToInt32</code> is passed 4 (and <code>messageLength</code> will be passed 8)</p> <p>If there is anything not clear please say so in a comment and I will elaborate.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload