Click or drag to resize

BinaryTextEncodingLengthEncodedASCII4LE Property

Returns an encoder that will encode and decode 4-byte little-endian length encoded ASCII string. The string is formatted in the data buffer with the first two bytes containing the length of the string that follows. The characters in the string are ASCII.

Namespace:  Demo3D.IO
Assembly:  Demo3D.IO (in Demo3D.IO.dll) Version: 15.0.2.11458
Syntax
C#
public static BinaryTextEncoding LengthEncodedASCII4LE { get; }

Property Value

Type: BinaryTextEncoding
Examples

The following example shows simple examples for reading and writing strings.

C#
public void LengthEncodedStrings(IDataReader receivedPacket, IDataWriter packetToSend) {
    // Length encoded strings are prefixed with a binary number that states exactly how many
    // bytes belong to the string.  Most commonly, the number is itself 2-bytes (a 16-bit number),
    // and that number is itself encoded using the Big Endian format.
    var str = receivedPacket.ReadString(BinaryTextEncoding.LengthEncodedASCII2BE);

    // This example uses a 4-byte (32-bits) Little Endian number to describe the number of bytes
    // in the string.  The string is then interpretted as Unicode.
    str = receivedPacket.ReadString(BinaryTextEncoding.LengthEncoded(4, true, System.Text.Encoding.Unicode));

    // Writes the string "hello" into a packet ready to be sent to the peer.  The string is prepended with
    // two bytes 0x00, 0x05 (the length of the string).
    packetToSend.WriteString("hello", BinaryTextEncoding.LengthEncodedASCII2BE);
}
See Also