Skip to main content

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​

NameTypeDescription
netstringstringThe 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​

NameTypeDescription
inputstringThe 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​

NameTypeDescription
inputstringThe 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​

NameTypeDescription
netstringstringThe netstring to check.

Returns​

bool — Return true if the netstring is in valid format, and it is complete. Otherwise, it will return false.

ToNetstring(string)​

Encoding a regular string into a Netstring.

public static string ToNetstring(string str)

Parameters​

NameTypeDescription
strstringThe string to be encoded.

Returns​

string — The resulting netstring.

  • Remarks
  • Methods
    • FromNetstring(string)
    • GetNetstringLength(string)
    • HasNetstringPrefix(string)
    • IsValidNetstring(string)
    • ToNetstring(string)