StreamPeer
Base byte-stream API and typed binary input/output.
StreamPeer is abstract. Use StreamPeerBuffer for memory data and a supported transport for networking. Streams do not automatically create message boundaries: agree on format, lengths, byte order and partial-operation handling.
GetData/GetPartialData return Error and bytes; PutPartialData returns Error and sent count. Numeric getters/setters and string shortcuts do not provide that separate status. A returned number is not proof of a successful read; collect and verify a complete field first.
BigEndian changes subsequent numeric operations, not bytes of an existing array. UTF-8 lengths count bytes rather than C# string.Length. Impose protocol limits on externally supplied lengths.
See StreamPeerBuffer for a complete checked-message example.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Properties1
BigEndianProperty
public bool BigEndian { get; set; }Byte order for subsequent numeric operations and length prefixes. Defaults to false for little-endian; true selects big-endian. Changing it does not reorder existing bytes or raw PutData arrays.
Methods37
Get16short
public short Get16();Reads 2 bytes as signed 16-bit. Widths greater than one byte follow BigEndian. Returns no Error: ensure a complete field beforehand; a short/failed read does not yield a trustworthy number.
shortRead value of C# type short. Not an Error/value pair; the value does not establish read success.
Get32int
public int Get32();Reads 4 bytes as signed 32-bit. Widths greater than one byte follow BigEndian. Returns no Error: ensure a complete field beforehand; a short/failed read does not yield a trustworthy number.
intRead value of C# type int. Not an Error/value pair; the value does not establish read success.
Get64long
public long Get64();Reads 8 bytes as signed 64-bit. Widths greater than one byte follow BigEndian. Returns no Error: ensure a complete field beforehand; a short/failed read does not yield a trustworthy number.
longRead value of C# type long. Not an Error/value pair; the value does not establish read success.
Get8sbyte
public sbyte Get8();Reads 1 byte as signed 8-bit. Widths greater than one byte follow BigEndian. Returns no Error: ensure a complete field beforehand; a short/failed read does not yield a trustworthy number.
sbyteRead value of C# type sbyte. Not an Error/value pair; the value does not establish read success.
GetAvailableBytesint
public int GetAvailableBytes();Returns readable-byte availability for the implementation. Not the next message size or a guarantee of a complete field/packet. For StreamPeerBuffer this is GetSize()-GetPosition().
intAvailable byte count. StreamPeerBuffer can return a negative value after Resize leaves its cursor beyond the end; repair position first.
GetDataReckfell.Collections.Array
public Reckfell.Collections.Array GetData(int bytes);Attempts to read the requested byte count and returns [Error, byte[]]. Check Error before using data. Socket streams can wait for missing bytes; a short StreamPeerBuffer read reports failure after already consuming the available portion.
| Name | Type | Default |
|---|---|---|
bytes | int | — |
bytesNonnegative byte count to read. Check your protocol’s upper limit before calling.
Reckfell.Collections.ArrayTwo-Variant Array: [Error code, packed bytes]. Extract byte[] in C# after checking the code. On failure, do not assume complete or safely initialized contents.
GetDoubledouble
public double GetDouble();Reads 8 bytes as binary64. Widths greater than one byte follow BigEndian. Returns no Error: ensure a complete field beforehand; a short/failed read does not yield a trustworthy number.
doubleRead value of C# type double. Not an Error/value pair; the value does not establish read success.
GetFloatfloat
public float GetFloat();Reads 4 bytes as binary32. Widths greater than one byte follow BigEndian. Returns no Error: ensure a complete field beforehand; a short/failed read does not yield a trustworthy number.
floatRead value of C# type float. Not an Error/value pair; the value does not establish read success.
GetHalffloat
public float GetHalf();Reads 2 bytes as binary16. Widths greater than one byte follow BigEndian. Returns no Error: ensure a complete field beforehand; a short/failed read does not yield a trustworthy number. binary16 has less precision/range than C# float.
floatRead value of C# type float. Not an Error/value pair; the value does not establish read success.
GetPartialDataReckfell.Collections.Array
public Reckfell.Collections.Array GetPartialData(int bytes);Reads up to the requested byte count without requiring all bytes in this call. Returns [Error, byte[]]; on success the array length is the actual received count. Accumulate incomplete messages in your own buffer.
| Name | Type | Default |
|---|---|---|
bytes | int | — |
bytesNonnegative byte count to read. Check your protocol’s upper limit before calling.
Reckfell.Collections.ArrayArray [Error code, packed bytes]. On Error.Ok the array length is the actual read count; on failure the array is empty.
GetStringstring
public string GetString(int bytes = -1);Reads the plain string format paired with PutString. bytes<0 reads a 32-bit length prefix first; otherwise reads the exact byte count without a prefix. Use the UTF-8 pair for Unicode. Bound externally supplied lengths before allocation.
| Name | Type | Default |
|---|---|---|
bytes | int | -1 |
bytesString byte count. A negative value reads a 32-bit length prefix; a nonnegative value reads exactly that many bytes without a prefix.
stringResulting string. Empty text alone does not distinguish empty content from read failure.
GetU16ushort
public ushort GetU16();Reads 2 bytes as unsigned 16-bit. Widths greater than one byte follow BigEndian. Returns no Error: ensure a complete field beforehand; a short/failed read does not yield a trustworthy number.
ushortRead value of C# type ushort. Not an Error/value pair; the value does not establish read success.
GetU32uint
public uint GetU32();Reads 4 bytes as unsigned 32-bit. Widths greater than one byte follow BigEndian. Returns no Error: ensure a complete field beforehand; a short/failed read does not yield a trustworthy number.
uintRead value of C# type uint. Not an Error/value pair; the value does not establish read success.
GetU64ulong
public ulong GetU64();Reads 8 bytes as unsigned 64-bit. Widths greater than one byte follow BigEndian. Returns no Error: ensure a complete field beforehand; a short/failed read does not yield a trustworthy number.
ulongRead value of C# type ulong. Not an Error/value pair; the value does not establish read success.
GetU8byte
public byte GetU8();Reads 1 byte as unsigned 8-bit. Widths greater than one byte follow BigEndian. Returns no Error: ensure a complete field beforehand; a short/failed read does not yield a trustworthy number.
byteRead value of C# type byte. Not an Error/value pair; the value does not establish read success.
GetUtf8Stringstring
public string GetUtf8String(int bytes = -1);Reads UTF-8 text. bytes<0 consumes its own 32-bit prefix; a supplied count reads those bytes only. Do not pass a C# character count. No separate Error is returned; explicitly control lengths/decoding for strict external formats.
| Name | Type | Default |
|---|---|---|
bytes | int | -1 |
bytesString byte count. A negative value reads a 32-bit length prefix; a nonnegative value reads exactly that many bytes without a prefix.
stringResulting string. Empty text alone does not distinguish empty content from read failure.
GetVarVariant
public Variant GetVar(bool allowObjects = false);Reads a length-prefixed binary Variant produced by PutVar. Not JSON. Check input trust, size and expected type; the method does not impose an application packet-size limit or return a separate Error.
| Name | Type | Default |
|---|---|---|
allowObjects | bool | false |
allowObjectsDefaults to false. true permits object reconstruction during decoding; do not enable for untrusted content. Not schema validation or a sandbox.
VariantDecoded Variant; Nil can be valid data or a failure result with diagnostics.
IsBigEndianEnabledbool
public bool IsBigEndianEnabled();Returns the same flag as BigEndian; does not detect the byte order of loaded data.
boolCurrent BigEndian setting; false means little-endian.
Put16void
public void Put16(short value);Writes 2 bytes as signed 16-bit. Widths greater than one byte follow BigEndian. Returns no Error; use explicit raw-write result checks for fallible transports.
| Name | Type | Default |
|---|---|---|
value | short | — |
valueValue for signed 16-bit, 2 bytes. Agree on the same format with the reader; a numeric type alone does not define message schema.
Put32void
public void Put32(int value);Writes 4 bytes as signed 32-bit. Widths greater than one byte follow BigEndian. Returns no Error; use explicit raw-write result checks for fallible transports.
| Name | Type | Default |
|---|---|---|
value | int | — |
valueValue for signed 32-bit, 4 bytes. Agree on the same format with the reader; a numeric type alone does not define message schema.
Put64void
public void Put64(long value);Writes 8 bytes as signed 64-bit. Widths greater than one byte follow BigEndian. Returns no Error; use explicit raw-write result checks for fallible transports.
| Name | Type | Default |
|---|---|---|
value | long | — |
valueValue for signed 64-bit, 8 bytes. Agree on the same format with the reader; a numeric type alone does not define message schema.
Put8void
public void Put8(sbyte value);Writes 1 byte as signed 8-bit. Widths greater than one byte follow BigEndian. Returns no Error; use explicit raw-write result checks for fallible transports.
| Name | Type | Default |
|---|---|---|
value | sbyte | — |
valueValue for signed 8-bit, 1 byte. Agree on the same format with the reader; a numeric type alone does not define message schema.
PutData2 overloads
public Error PutData(byte[] data);Writes raw bytes without an automatic header, length or reordering. Returns Error; full socket writes can wait. One call does not define a TCP message boundary.
| Name | Type | Default |
|---|---|---|
data | byte[] | — |
dataRaw bytes to write, not text or an automatically serialized structure. Array/span length specifies the byte count.
ErrorError.Ok for successful complete transfer under the implementation contract; otherwise a failure code. Does not confirm receiver processing.
public Error PutData(ReadOnlySpan<byte> data);Writes raw bytes without an automatic header, length or reordering. Returns Error; full socket writes can wait. One call does not define a TCP message boundary.
| Name | Type | Default |
|---|---|---|
data | ReadOnlySpan<byte> | — |
dataRaw bytes to write, not text or an automatically serialized structure. Array/span length specifies the byte count.
ErrorError.Ok for successful complete transfer under the implementation contract; otherwise a failure code. Does not confirm receiver processing.
PutDoublevoid
public void PutDouble(double value);Writes 8 bytes as binary64. Widths greater than one byte follow BigEndian. Returns no Error; use explicit raw-write result checks for fallible transports.
| Name | Type | Default |
|---|---|---|
value | double | — |
valueValue for binary64, 8 bytes. Agree on the same format with the reader; a numeric type alone does not define message schema.
PutFloatvoid
public void PutFloat(float value);Writes 4 bytes as binary32. Widths greater than one byte follow BigEndian. Returns no Error; use explicit raw-write result checks for fallible transports.
| Name | Type | Default |
|---|---|---|
value | float | — |
valueValue for binary32, 4 bytes. Agree on the same format with the reader; a numeric type alone does not define message schema.
PutHalfvoid
public void PutHalf(float value);Writes 2 bytes as binary16. Widths greater than one byte follow BigEndian. Returns no Error; use explicit raw-write result checks for fallible transports. binary16 has less precision/range than C# float.
| Name | Type | Default |
|---|---|---|
value | float | — |
valueValue for binary16, 2 bytes. Agree on the same format with the reader; a numeric type alone does not define message schema.
PutPartialData2 overloads
public Reckfell.Collections.Array PutPartialData(byte[] data);Attempts a partial raw write and returns [Error, count]. Check both values and resume from the remaining portion when needed. A successful StreamPeerBuffer write normally accepts the entire array.
| Name | Type | Default |
|---|---|---|
data | byte[] | — |
dataRaw bytes to write, not text or an automatically serialized structure. Array/span length specifies the byte count.
Reckfell.Collections.ArrayArray [Error code, actual sent-byte count]. Success does not guarantee the entire request was sent.
public Reckfell.Collections.Array PutPartialData(ReadOnlySpan<byte> data);Attempts a partial raw write and returns [Error, count]. Check both values and resume from the remaining portion when needed. A successful StreamPeerBuffer write normally accepts the entire array.
| Name | Type | Default |
|---|---|---|
data | ReadOnlySpan<byte> | — |
dataRaw bytes to write, not text or an automatically serialized structure. Array/span length specifies the byte count.
Reckfell.Collections.ArrayArray [Error code, actual sent-byte count]. Success does not guarantee the entire request was sent.
PutStringvoid
public void PutString(string value);Writes ASCII representation with a 32-bit byte-length prefix. Use PutUtf8String for Unicode. Prefix byte order follows BigEndian; a terminator is not part of the payload string.
| Name | Type | Default |
|---|---|---|
value | string | — |
valueText to write as ASCII. Use PutUtf8String for Cyrillic, emoji and other Unicode text.
PutU16void
public void PutU16(ushort value);Writes 2 bytes as unsigned 16-bit. Widths greater than one byte follow BigEndian. Returns no Error; use explicit raw-write result checks for fallible transports.
| Name | Type | Default |
|---|---|---|
value | ushort | — |
valueValue for unsigned 16-bit, 2 bytes. Agree on the same format with the reader; a numeric type alone does not define message schema.
PutU32void
public void PutU32(uint value);Writes 4 bytes as unsigned 32-bit. Widths greater than one byte follow BigEndian. Returns no Error; use explicit raw-write result checks for fallible transports.
| Name | Type | Default |
|---|---|---|
value | uint | — |
valueValue for unsigned 32-bit, 4 bytes. Agree on the same format with the reader; a numeric type alone does not define message schema.
PutU64void
public void PutU64(ulong value);Writes 8 bytes as unsigned 64-bit. Widths greater than one byte follow BigEndian. Returns no Error; use explicit raw-write result checks for fallible transports.
| Name | Type | Default |
|---|---|---|
value | ulong | — |
valueValue for unsigned 64-bit, 8 bytes. Agree on the same format with the reader; a numeric type alone does not define message schema.
PutU8void
public void PutU8(byte value);Writes 1 byte as unsigned 8-bit. Widths greater than one byte follow BigEndian. Returns no Error; use explicit raw-write result checks for fallible transports.
| Name | Type | Default |
|---|---|---|
value | byte | — |
valueValue for unsigned 8-bit, 1 byte. Agree on the same format with the reader; a numeric type alone does not define message schema.
PutUtf8Stringvoid
public void PutUtf8String(string value);Writes UTF-8 bytes with a 32-bit byte-length prefix. Emoji/Cyrillic byte count differs from C# string.Length. Read with GetUtf8String(), or consume the prefix separately and call GetUtf8String(byte_count).
| Name | Type | Default |
|---|---|---|
value | string | — |
valueText to encode as UTF-8. The method writes its own 32-bit byte-length prefix before the payload.
PutVarvoid
public void PutVar(Variant value, bool fullObjects = false);Writes a 32-bit length and binary Variant representation. A separate engine format, not JSON or complete game-state serialization. BigEndian affects the outer prefix, not re-encoding the internal Variant format.
| Name | Type | Default |
|---|---|---|
value | Variant | — |
fullObjects | bool | false |
valueVariant to encode in binary. The reader must use GetVar with the same outer-prefix byte order.
fullObjectsDefault false does not store full Object contents. true enables object encoding, not transfer of owners, live trees or server resources between processes.
SetBigEndianvoid
public void SetBigEndian(bool enable);Sets BigEndian for subsequent operations. Reader and writer must agree on byte order and field types.
| Name | Type | Default |
|---|---|---|
enable | bool | — |
enabletrue selects big-endian, false little-endian for subsequent numeric operations; not input autodetection.