Class NetstringUtility
A helper/utility class containing mehtods that encodes/decodes messages in the netstring format (:,)
used for length-prefixed framing over the TCP stream between the simulation and
the remote-control client.
public class NetstringUtility
Inheritance
Remarks
Raw TCP delivers a byte stream with no inherent message boundaries. Netstrings solve the framing problem without a delimiter that could appear inside the payload: the receiver reads the length prefix first and knows exactly how many bytes to consume, preventing partial-read bugs when the OS delivers data in multiple chunks.
Methods
FromNetstring(string)
Decoding a Netstring back to a regular string
public static string FromNetstring(string netstring)
Parameters
| Name | Type | Description |
|---|---|---|
netstring | string | The netstring to be decoded. |
Returns
string — The resulting string.
GetNetstringLength(string)
Retrives the length of the Netstring from its header
public static int GetNetstringLength(string input)
Parameters
| Name | Type | Description |
|---|---|---|
input | string | The input Netstring. |
Returns
int — The extracted length of the Netstring.
HasNetstringPrefix(string)
Checks if the provided string has a valid Netstring prefix.
public static bool HasNetstringPrefix(string input)
Parameters
| Name | Type | Description |
|---|---|---|
input | string | The string to be checked. |
Returns
bool — Return true if the provided is a valid Netstring.
IsValidNetstring(string)
Check if the provided netstring is a valid/complete netstring.
public static bool IsValidNetstring(string netstring)
Parameters
| Name | Type | Description |
|---|---|---|
netstring | string | The netstring to check. |
Returns
bool — Return true if the netstring is in valid format, and it is complete. Otherwise, it will return false.