Class BufferChunk
Overview:
----------------------------------------------------------------
BufferChunk is a helper class created to make network
calls in DotNet easier by allowing byte[] to be passed
around along with an index (or offset) and length (or chunksize).
Members:
----------------------------------------------------------------
- index - offset inside the buffer where valid data starts
- length - amount of valid data
- buffer - byte[] containing the data
Except for constructors (which set index and length member
variables), when index and length are passed as parameters,
they are used as offsets into the valid data, not offsets
into the buffer.
Object State:
----------------------------------------------------------------
BufferChunk does not accept or return null or zero-length objects.
However, it is valid
for a BufferChunk to be in a state where it has no data to
manipulate i.e. length == 0 this.index + this.length cannot be >
buffer.Length index + length cannot be > this.length when
manipulating inside the valid data
index must be >= 0
length must be >= 0
Integral types:
--------------------------------------------------------------
BufferChunk allows the reading and writing of integral types
(Int16, Int32, Int64 and the unsigned counterparts)
into the byte[].
Implements the
System.IDisposable
Implements the
System.ICloneable
Inheritance
System.Object
BufferChunk
Implements
System.IDisposable
System.ICloneable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: TM
Assembly: TM.dll
Syntax
[ComVisible(false)]
public class BufferChunk : IDisposable, ICloneable
Constructors
|
Improve this Doc
View Source
BufferChunk(Byte[])
Constructor, create a BufferChunk using an existing byte[] without performing a memcopy
Declaration
public BufferChunk(byte[] buffer)
Parameters
Type |
Name |
Description |
System.Byte[] |
buffer |
byte[] to be used as the data store for the BufferChunk,
cannot be null or zero length
|
Examples
byte[] buffer = new byte[2000];
BufferChunk bufferChunk = new BufferChunk(buffer);
|
Improve this Doc
View Source
BufferChunk(Byte[], Int32, Int32)
Constructor, create a BufferChunk from its constituent parts
Declaration
public BufferChunk(byte[] buffer, int index, int length)
Parameters
Type |
Name |
Description |
System.Byte[] |
buffer |
byte[] to be used as the data store for the BufferChunk |
System.Int32 |
index |
offset at which the valid data starts |
System.Int32 |
length |
amount of 'valid data' |
Examples
byte[] buffer = new byte[2000];
BufferChunk bufferChunk = new BufferChunk(buffer, 10, 200);
|
Improve this Doc
View Source
BufferChunk(Int32)
Constructor, create a new BufferChunk and allocate a new byte[] to hold the data.
Declaration
public BufferChunk(int size = 1024)
Parameters
Type |
Name |
Description |
System.Int32 |
size |
int size of the new byte[] to create, must be >= 1 |
Examples
BufferChunk bufferChunk = new BufferChunk(2000);
Properties
|
Improve this Doc
View Source
Buffer
Buffer gives you direct access to the byte[] which is storing the raw data of the
BufferChunk. Buffer is simply a byte[] that is passed ByRef so you have easy and
efficient access to the basic data.
Note: This property may be removed going forward
Declaration
public byte[] Buffer { get; set; }
Property Value
Type |
Description |
System.Byte[] |
The buffer. |
Examples
public int SendTo(BufferChunk bufferChunk, EndPoint endPoint)
{
return SendTo(bufferChunk.Buffer, bufferChunk.Index, bufferChunk.Length,
SocketFlags.None, endPoint);
}
|
Improve this Doc
View Source
Index
Index points to the start of the valid data area
Note: This property may be removed going forward
Declaration
public int Index { get; set; }
Property Value
Type |
Description |
System.Int32 |
The index. |
Examples
public int SendTo(BufferChunk bufferChunk, EndPoint endPoint)
{
return SendTo(bufferChunk.Buffer, bufferChunk.Index, bufferChunk.Length,
SocketFlags.None, endPoint);
}
|
Improve this Doc
View Source
Item[Int32]
Indexer used to allow us to treat a BufferChunk like a byte[].
Useful when making in place modifications or reads from a BufferChunk.
Declaration
public byte this[int index] { get; set; }
Parameters
Type |
Name |
Description |
System.Int32 |
index |
The index. |
Property Value
Type |
Description |
System.Byte |
System.Byte. |
|
Improve this Doc
View Source
Length
Length is amount of valid data in the buffer
Length should not be directly manipulated to select smaller sections of the BufferChunk
because this would abandon valid data. Instead, you should use the method
Peek(Int32, Int32) to create a shallow copy new BufferChunk pointing to
just the section you want.
Note: This property may be removed going forward
Declaration
public int Length { get; set; }
Property Value
Type |
Description |
System.Int32 |
The length. |
Examples
public int SendTo(BufferChunk bufferChunk, EndPoint endPoint)
{
return SendTo(bufferChunk.Buffer, bufferChunk.Index, bufferChunk.Length,
SocketFlags.None, endPoint);
}
Methods
|
Improve this Doc
View Source
Clear()
Used to zero out the data area of the BufferChunk.
Declaration
|
Improve this Doc
View Source
Clone()
Creates a shallow copy (new Index and Length, duplicate reference to the same Buffer) of a BufferChunk.
Declaration
Returns
Type |
Description |
System.Object |
BufferChunk instance with ref Buffer, ByVal Index, and ByVal Length |
|
Improve this Doc
View Source
Compare(Byte[], Byte[])
Compares the specified obj1.
Declaration
public static bool Compare(byte[] obj1, byte[] obj2)
Parameters
Type |
Name |
Description |
System.Byte[] |
obj1 |
The obj1. |
System.Byte[] |
obj2 |
The obj2. |
Returns
Type |
Description |
System.Boolean |
true if XXXX, false otherwise |
|
Improve this Doc
View Source
Copy(Byte[])
Copies the specified source.
Declaration
public static byte[] Copy(byte[] source)
Parameters
Type |
Name |
Description |
System.Byte[] |
source |
The source. |
Returns
Type |
Description |
System.Byte[] |
System.Byte[][]. |
|
Improve this Doc
View Source
CopyFrom(IntPtr, Int32)
Copies from.
Declaration
public void CopyFrom(IntPtr src, int length)
Parameters
Type |
Name |
Description |
System.IntPtr |
src |
The SRC. |
System.Int32 |
length |
The length. |
|
Improve this Doc
View Source
CopyTo(IntPtr, Int32)
Copies to.
Declaration
public void CopyTo(IntPtr dest, int length)
Parameters
Type |
Name |
Description |
System.IntPtr |
dest |
The dest. |
System.Int32 |
length |
The length. |
|
Improve this Doc
View Source
CopyTo(BufferChunk, Int32)
Copy the valid data section of 'this' to the destination BufferChunk
overwriting dest's previous contents
This method does not allow dest's valid data section to grow or shrink
(i.e. treat valid data as a fixed buffer)
Declaration
public void CopyTo(BufferChunk destination, int index)
Parameters
Type |
Name |
Description |
BufferChunk |
destination |
BufferChunk |
System.Int32 |
index |
offset in the destination BufferChunk's valid data |
|
Improve this Doc
View Source
Dispose()
Disposes the internal state of the object
Declaration
|
Improve this Doc
View Source
GetByte(Int32)
Retrieves 1 byte from inside the BufferChunk
This method is included for consistency. It simply forwards to the indexer.
Declaration
public byte GetByte(int index)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
Returns
Type |
Description |
System.Byte |
System.Byte. |
|
Improve this Doc
View Source
GetDouble(Int32)
Retrieves 8 bytes inside the BufferChunk
Declaration
public double GetDouble(int index)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
Returns
Type |
Description |
System.Double |
System.Double. |
|
Improve this Doc
View Source
GetFloat(Int32)
Retrieves 4 bytes inside the BufferChunk
Declaration
public float GetFloat(int index)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
Returns
Type |
Description |
System.Single |
System.Single. |
|
Improve this Doc
View Source
GetInt16(Int32)
Retrieves 2 bytes inside the BufferChunk
Declaration
public short GetInt16(int index)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
Returns
Type |
Description |
System.Int16 |
System.Int16. |
|
Improve this Doc
View Source
GetInt32(Int32)
Retrieves 4 bytes inside the BufferChunk
Declaration
public int GetInt32(int index)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
Returns
Type |
Description |
System.Int32 |
System.Int32. |
|
Improve this Doc
View Source
GetInt64(Int32)
Retrieves 8 bytes inside the BufferChunk
Declaration
public long GetInt64(int index)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
Returns
Type |
Description |
System.Int64 |
System.Int64. |
|
Improve this Doc
View Source
GetPaddedUInt16(Int32)
Gets the padded U int16.
Declaration
public ushort GetPaddedUInt16(int index)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
The index. |
Returns
Type |
Description |
System.UInt16 |
System.UInt16. |
|
Improve this Doc
View Source
GetPaddedUInt32(Int32)
Gets the padded UInt32.
Declaration
public uint GetPaddedUInt32(int index)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
The index. |
Returns
Type |
Description |
System.UInt32 |
System.UInt32. |
|
Improve this Doc
View Source
GetPaddedUInt64(Int32)
Gets the padded UInt64.
Declaration
public ulong GetPaddedUInt64(int index)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
The index. |
Returns
Type |
Description |
System.UInt64 |
System.UInt64. |
|
Improve this Doc
View Source
GetUInt16(Int32)
Retrieves 2 bytes inside the BufferChunk
Declaration
public ushort GetUInt16(int index)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
Returns
Type |
Description |
System.UInt16 |
System.UInt16. |
|
Improve this Doc
View Source
GetUInt32(Int32)
Retrieves 4 bytes inside the BufferChunk
Declaration
public uint GetUInt32(int index)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
Returns
Type |
Description |
System.UInt32 |
System.UInt32. |
|
Improve this Doc
View Source
GetUInt64(Int32)
Retrieves 8 bytes inside the BufferChunk
Declaration
public ulong GetUInt64(int index)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
Returns
Type |
Description |
System.UInt64 |
System.UInt64. |
|
Improve this Doc
View Source
GetUTF8String(Int32, Int32)
Retrieves length bytes from inside the BufferChunk and converts from UTF8 string
Declaration
public string GetUTF8String(int index, int length)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
System.Int32 |
length |
The length. |
Returns
Type |
Description |
System.String |
System.String. |
|
Improve this Doc
View Source
NextBufferChunk(Int32)
Returns a BufferChunk consisting of the next 'length' bytes of the BufferChunk instance.
Automatically increments Index and decrements Length.
This function is useful for iterative functions that parse through a large BufferChunk returning smaller
BufferChunks
Declaration
public BufferChunk NextBufferChunk(int length)
Parameters
Type |
Name |
Description |
System.Int32 |
length |
int |
Returns
Examples
...
frameBuffer = new BufferChunk(500000);
...
int packetsInFrame = (ushort)((frameBuffer.Length + RtpHeaderExtensionSize) / (MaximumPacketPayload));
if (((frameBuffer.Length + RtpHeaderExtensionSize) % (MaximumPacketPayload)) > 0)
packetsInFrame++;
for (int i = 0; i < packetsInFrame; i++)
{
int sizeToCopy = (frameBuffer.Length < MaximumPacketPayload) ? frameBuffer.Length : MaximumPacketPayload;
socket.Send((byte[])frameBuffer.NextBufferChunk(sizeToCopy));
}
|
Improve this Doc
View Source
NextBufferChunkMax(Int32)
Declaration
public BufferChunk NextBufferChunkMax(int length)
Parameters
Type |
Name |
Description |
System.Int32 |
length |
|
Returns
|
Improve this Doc
View Source
NextByte()
Nexts the byte.
Declaration
Returns
Type |
Description |
System.Byte |
System.Byte. |
|
Improve this Doc
View Source
NextDouble()
Nexts the Double.
Declaration
public double NextDouble()
Returns
Type |
Description |
System.Double |
System.Double. |
|
Improve this Doc
View Source
NextFloat()
Nexts the float.
Declaration
Returns
Type |
Description |
System.Single |
System.Single. |
|
Improve this Doc
View Source
NextInt16()
Nexts the Int16.
Declaration
Returns
Type |
Description |
System.Int16 |
System.Int16. |
|
Improve this Doc
View Source
NextInt32()
Nexts the Int32.
Declaration
Returns
Type |
Description |
System.Int32 |
System.Int32. |
|
Improve this Doc
View Source
NextInt64()
Nexts the Int64.
Declaration
Returns
Type |
Description |
System.Int64 |
System.Int64. |
|
Improve this Doc
View Source
NextUInt16()
Nexts the UInt16.
Declaration
public ushort NextUInt16()
Returns
Type |
Description |
System.UInt16 |
System.UInt16. |
|
Improve this Doc
View Source
NextUInt32()
Nexts the UInt32.
Declaration
Returns
Type |
Description |
System.UInt32 |
System.UInt32. |
|
Improve this Doc
View Source
NextUInt64()
Nexts the UInt64.
Declaration
public ulong NextUInt64()
Returns
Type |
Description |
System.UInt64 |
System.UInt64. |
|
Improve this Doc
View Source
NextUtf8String(Int32)
Nexts the UTF8 string.
Declaration
public string NextUtf8String(int length)
Parameters
Type |
Name |
Description |
System.Int32 |
length |
The length. |
Returns
Type |
Description |
System.String |
System.String. |
|
Improve this Doc
View Source
Peek(Int32, Int32)
Create a return BufferChunk containing a subset of the data from the valid data.
Declaration
public BufferChunk Peek(int index, int length)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
int index into the valid data area |
System.Int32 |
length |
int length of the data to copy |
Returns
Type |
Description |
BufferChunk |
BufferChunk length Length that was extracted from the source BufferChunk |
|
Improve this Doc
View Source
Reset()
Reset the BufferChunk's Index and Length pointers to zero so it is ready for reuse as an empty BufferChunk.
Note that the actual byte[] buffer is not reset, so the memory is not deallocated/reallocated, allowing for
more efficient reuse of memory without abusing the GC
Declaration
|
Improve this Doc
View Source
Reset(Int32, Int32)
Reset the BufferChunk's Index and Length pointers to supplied values
Declaration
public void Reset(int index, int length)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
The index. |
System.Int32 |
length |
The length. |
|
Improve this Doc
View Source
SetByte(Int32, Byte)
Modifies 1 byte inside the BufferChunk
This method is included for consistency. It simply forwards to the indexer.
Declaration
public void SetByte(int index, byte data)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
System.Byte |
data |
Value to write at index |
|
Improve this Doc
View Source
SetInt16(Int32, Int16)
Modifies 2 bytes inside the BufferChunk
Declaration
public void SetInt16(int index, short data)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
System.Int16 |
data |
Value to write at index |
|
Improve this Doc
View Source
SetInt32(Int32, Int32)
Modifies 4 bytes inside the BufferChunk
Declaration
public void SetInt32(int index, int data)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
System.Int32 |
data |
Value to write at index |
|
Improve this Doc
View Source
SetInt64(Int32, Int64)
Modifies 8 bytes inside the BufferChunk
Declaration
public void SetInt64(int index, long data)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
System.Int64 |
data |
Value to write at index |
|
Improve this Doc
View Source
SetNetworking(Boolean)
Sets the networking.
Declaration
public static void SetNetworking(bool v = true)
Parameters
Type |
Name |
Description |
System.Boolean |
v |
if set to true [v]. |
|
Improve this Doc
View Source
SetPaddedUInt16(Int32, UInt16)
Declaration
public void SetPaddedUInt16(int index, ushort data)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
|
System.UInt16 |
data |
|
|
Improve this Doc
View Source
SetPaddedUInt32(Int32, UInt32)
Sets the padded UInt32.
Declaration
public void SetPaddedUInt32(int index, uint data)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
The index. |
System.UInt32 |
data |
The data. |
|
Improve this Doc
View Source
SetPaddedUInt64(Int32, UInt64)
Sets the padded UInt64.
Declaration
public void SetPaddedUInt64(int index, ulong data)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
The index. |
System.UInt64 |
data |
The data. |
|
Improve this Doc
View Source
SetUInt16(Int32, UInt16)
Modifies 2 bytes inside the BufferChunk
Declaration
public void SetUInt16(int index, ushort data)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
System.UInt16 |
data |
Value to write at index |
|
Improve this Doc
View Source
SetUInt32(Int32, UInt32)
Modifies 4 bytes inside the BufferChunk
Declaration
public void SetUInt32(int index, uint data)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
System.UInt32 |
data |
Value to write at index |
|
Improve this Doc
View Source
SetUInt64(Int32, UInt64)
Modifies 8 bytes inside the BufferChunk
Declaration
public void SetUInt64(int index, ulong data)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
System.UInt64 |
data |
Value to write at index |
|
Improve this Doc
View Source
SetUTF8String(Int32, String)
Modifies UTF8.GetBytes(data) bytes inside the BufferChunk
Declaration
public void SetUTF8String(int index, string data)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
Offset into the valid data |
System.String |
data |
Value to write at index |
|
Improve this Doc
View Source
Skip(Int32)
Skips the specified length.
Declaration
public void Skip(int len)
Parameters
Type |
Name |
Description |
System.Int32 |
len |
The length. |
Operators
|
Improve this Doc
View Source
Addition(BufferChunk, Byte)
Implements the +.
Declaration
public static BufferChunk operator +(BufferChunk destination, byte b)
Parameters
Type |
Name |
Description |
BufferChunk |
destination |
The destination. |
System.Byte |
b |
The b. |
Returns
Type |
Description |
BufferChunk |
The result of the operator. |
|
Improve this Doc
View Source
Addition(BufferChunk, Byte[])
Implements the +.
Declaration
public static BufferChunk operator +(BufferChunk destination, byte[] source)
Parameters
Type |
Name |
Description |
BufferChunk |
destination |
The destination. |
System.Byte[] |
source |
The source. |
Returns
Type |
Description |
BufferChunk |
The result of the operator. |
|
Improve this Doc
View Source
Addition(BufferChunk, Double)
Implements the +.
Declaration
public static BufferChunk operator +(BufferChunk destination, double data)
Parameters
Type |
Name |
Description |
BufferChunk |
destination |
The destination. |
System.Double |
data |
The data. |
Returns
Type |
Description |
BufferChunk |
The result of the operator. |
|
Improve this Doc
View Source
Addition(BufferChunk, Int16)
Implements the +.
Declaration
public static BufferChunk operator +(BufferChunk destination, short data)
Parameters
Type |
Name |
Description |
BufferChunk |
destination |
The destination. |
System.Int16 |
data |
The data. |
Returns
Type |
Description |
BufferChunk |
The result of the operator. |
|
Improve this Doc
View Source
Addition(BufferChunk, Int32)
Implements the +.
Declaration
public static BufferChunk operator +(BufferChunk destination, int data)
Parameters
Type |
Name |
Description |
BufferChunk |
destination |
The destination. |
System.Int32 |
data |
The data. |
Returns
Type |
Description |
BufferChunk |
The result of the operator. |
|
Improve this Doc
View Source
Addition(BufferChunk, Int64)
Implements the +.
Declaration
public static BufferChunk operator +(BufferChunk destination, long data)
Parameters
Type |
Name |
Description |
BufferChunk |
destination |
The destination. |
System.Int64 |
data |
The data. |
Returns
Type |
Description |
BufferChunk |
The result of the operator. |
|
Improve this Doc
View Source
Addition(BufferChunk, Single)
Implements the +.
Declaration
public static BufferChunk operator +(BufferChunk destination, float data)
Parameters
Type |
Name |
Description |
BufferChunk |
destination |
The destination. |
System.Single |
data |
The data. |
Returns
Type |
Description |
BufferChunk |
The result of the operator. |
|
Improve this Doc
View Source
Addition(BufferChunk, String)
Implements the +.
Declaration
public static BufferChunk operator +(BufferChunk destination, string s)
Parameters
Type |
Name |
Description |
BufferChunk |
destination |
The destination. |
System.String |
s |
The s. |
Returns
Type |
Description |
BufferChunk |
The result of the operator. |
|
Improve this Doc
View Source
Addition(BufferChunk, UInt16)
Implements the +.
Declaration
public static BufferChunk operator +(BufferChunk destination, ushort data)
Parameters
Type |
Name |
Description |
BufferChunk |
destination |
The destination. |
System.UInt16 |
data |
The data. |
Returns
Type |
Description |
BufferChunk |
The result of the operator. |
|
Improve this Doc
View Source
Addition(BufferChunk, UInt32)
Implements the +.
Declaration
public static BufferChunk operator +(BufferChunk destination, uint data)
Parameters
Type |
Name |
Description |
BufferChunk |
destination |
The destination. |
System.UInt32 |
data |
The data. |
Returns
Type |
Description |
BufferChunk |
The result of the operator. |
|
Improve this Doc
View Source
Addition(BufferChunk, UInt64)
Implements the +.
Declaration
public static BufferChunk operator +(BufferChunk destination, ulong data)
Parameters
Type |
Name |
Description |
BufferChunk |
destination |
The destination. |
System.UInt64 |
data |
The data. |
Returns
Type |
Description |
BufferChunk |
The result of the operator. |
|
Improve this Doc
View Source
Addition(BufferChunk, BufferChunk)
Override + and += operator to allow appending of buffers,
provided there is room in the left-most BufferChunk
Declaration
public static BufferChunk operator +(BufferChunk destination, BufferChunk source)
Parameters
Type |
Name |
Description |
BufferChunk |
destination |
BufferChunk destination that will be appended to |
BufferChunk |
source |
BufferChunk source |
Returns
Type |
Description |
BufferChunk |
Reference to BufferChunk destination |
|
Improve this Doc
View Source
Explicit(Byte[] to BufferChunk)
Explicitly cast a byte[] into a BufferChunk. Useful when you want to start acting upon a byte[] in an incremental
fashion by taking advantage of The functionality a BufferChunk provides over a byte[]. For instance, this is useful
for aking a large (say 500k) dataset and dividing it up into smaller (say 1.5k) chunks.
This is functionally equivalent to new BufferChunk(buffer)
Declaration
public static explicit operator BufferChunk(byte[] buffer)
Parameters
Type |
Name |
Description |
System.Byte[] |
buffer |
byte[] buffer containing valid data |
Returns
|
Improve this Doc
View Source
Explicit(String to BufferChunk)
Explicitly cast a string to a BufferChunk. Helpful for applications that want to send strings or XML over the
network without worrying about the String to UTF8 logic.
Declaration
public static explicit operator BufferChunk(string source)
Parameters
Type |
Name |
Description |
System.String |
source |
The source. |
Returns
Type |
Description |
BufferChunk |
The result of the conversion. |
|
Improve this Doc
View Source
Explicit(BufferChunk to Byte[])
Explicitly cast the valid data into a new byte[]. This function creates a copy of the
BufferChunk data and omits the bytes before the Index and after the Length from the
byte[] copy. This is a simple way to interoperate BufferChunks with functions that
only know how to deal with byte[].
Declaration
public static explicit operator byte[](BufferChunk source)
Parameters
Returns
Type |
Description |
System.Byte[] |
byte[] containing the valid data from the BufferChunk |
Examples
using P;
using System.Net.Sockets;
Socket socket = new Socket(...); // This standard socket only knows byte[]
BufferChunk bufferChunk = new bufferChunk(500); // Create a new BufferChunk containing a 500 byte buffer
socket.Send((byte[])bufferChunk, SocketFlags.None); //Note the explicit cast from BufferChunk to byte[]
|
Improve this Doc
View Source
Explicit(BufferChunk to String)
Explicitly cast the valid data to a string. Helpful for applications that want to send
strings or XML over the network without worrying about the String to UTF8 logic.
Declaration
public static explicit operator string (BufferChunk source)
Parameters
Type |
Name |
Description |
BufferChunk |
source |
BufferChunk containing the data |
Returns
Type |
Description |
System.String |
string form of data |
Examples
BufferChunk bc = new BufferChunk(new byte[] {74, 97, 115, 111, 110});
if((string)bc == "Jason")...
Implements
System.IDisposable
System.ICloneable
Extension Methods
See Also
System.IDisposable
System.ICloneable