C# Class NetMQ.Msg

A Msg struct is the lowest-level interpretation of a ZeroMQ message, and simply contains byte-array data and MsgType and MsgFlags properties. It supports message buffer pooling.
Many users will not use this class directly. However in high-performance situations it may be useful. When used correctly it's possible to have zero-copy and zero-allocation behaviour.
Exibir arquivo Open project: NetMQ/NetMQ3-x Class Usage Examples

Public Methods

Method Description
AddReferences ( int amount ) : void

If this Msg is of MsgType.Pool, then - add the given amount number to the reference-counter and set the shared-data Flags bit. If this is not a Pool Msg, this does nothing.

CloneData ( ) : byte[]

Returns a new array containing the first Size bytes of Data.

Close ( ) : void

Clear the Data and set the MsgType to Invalid. If this is not a shared-data Msg (MsgFlags.Shared is not set), or it is shared but the reference-counter has dropped to zero, then return the data back to the BufferPool.

Copy ( Msg &src ) : void

Close this Msg, and effectively make this Msg a copy of the given source Msg by simply setting it to point to the given source Msg. If this is a Pool Msg, then this also increases the reference-counter and sets the Shared bit.

InitDelimiter ( ) : void

Set this Msg to be of type MsgType.Delimiter with no bits set within MsgFlags.

InitEmpty ( ) : void

Clear this Msg to empty - ie, set MsgFlags to None, MsgType to Empty, and clear the Data.

InitGC ( [ data, int size ) : void

Initialise this Msg to be of MsgType.GC with the given data-buffer value.

InitGC ( [ data, int offset, int size ) : void

Initialise this Msg to be of MsgType.GC with the given data-buffer value.

InitPool ( int size ) : void

Initialise this Msg to be of MsgType.Pool, with a data-buffer of the given number of bytes.

Move ( Msg &src ) : void

Close this Msg and make it reference the given source Msg, and then clear the Msg to empty.

Put ( [ src, int i, int len ) : void

Copy the given byte-array data to this Msg's Data buffer.

Put ( [ src, int srcOffset, int i, int len ) : void

Copy the given byte-array data to this Msg's Data buffer.

Put ( byte b ) : void

Copy the given single byte to this Msg's Data buffer.

Put ( byte b, int i ) : void

Copy the given single byte to this Msg's Data buffer at the given array-index.

RemoveReferences ( int amount ) : void

If this Msg is of MsgType.Pool and is marked as Shared, then - subtract the given amount number from the reference-counter and, if that reaches zero - return the data to the shared-data pool. If this is not both a Pool Msg and also marked as Shared, this simply Closes this Msg.

ResetFlags ( MsgFlags flags ) : void

Clear the indicated Flags bits.

SetFlags ( MsgFlags flags ) : void

Set the indicated Flags bits.

ToString ( ) : string

Override the Object ToString method to show the object-type, and values of the MsgType, Size, and Flags properties.

TrimPrefix ( int count ) : void

Increase Offset and decrease Size by the given count.

this ( int index ) : byte

Get and set the byte value in the Data buffer at a specific index.

Private Methods

Method Description
Check ( ) : bool

Method Details

AddReferences() public method

If this Msg is of MsgType.Pool, then - add the given amount number to the reference-counter and set the shared-data Flags bit. If this is not a Pool Msg, this does nothing.
public AddReferences ( int amount ) : void
amount int the number to add to the internal reference-counter
return void

CloneData() public method

Returns a new array containing the first Size bytes of Data.
public CloneData ( ) : byte[]
return byte[]

Close() public method

Clear the Data and set the MsgType to Invalid. If this is not a shared-data Msg (MsgFlags.Shared is not set), or it is shared but the reference-counter has dropped to zero, then return the data back to the BufferPool.
The object is not initialised.
public Close ( ) : void
return void

Copy() public method

Close this Msg, and effectively make this Msg a copy of the given source Msg by simply setting it to point to the given source Msg. If this is a Pool Msg, then this also increases the reference-counter and sets the Shared bit.
The object is not initialised.
public Copy ( Msg &src ) : void
src Msg the source Msg to copy from
return void

InitDelimiter() public method

Set this Msg to be of type MsgType.Delimiter with no bits set within MsgFlags.
public InitDelimiter ( ) : void
return void

InitEmpty() public method

Clear this Msg to empty - ie, set MsgFlags to None, MsgType to Empty, and clear the Data.
public InitEmpty ( ) : void
return void

InitGC() public method

Initialise this Msg to be of MsgType.GC with the given data-buffer value.
public InitGC ( [ data, int size ) : void
data [ the byte-array of data to assign to the Msg's Data property
size int the number of bytes that are in the data byte-array
return void

InitGC() public method

Initialise this Msg to be of MsgType.GC with the given data-buffer value.
public InitGC ( [ data, int offset, int size ) : void
data [ the byte-array of data to assign to the Msg's Data property
offset int first byte in the data array
size int the number of bytes that are in the data byte-array
return void

InitPool() public method

Initialise this Msg to be of MsgType.Pool, with a data-buffer of the given number of bytes.
public InitPool ( int size ) : void
size int the number of bytes to allocate in the data-buffer
return void

Move() public method

Close this Msg and make it reference the given source Msg, and then clear the Msg to empty.
The object is not initialised.
public Move ( Msg &src ) : void
src Msg the source-Msg to become
return void

Put() public method

Copy the given byte-array data to this Msg's Data buffer.
public Put ( [ src, int i, int len ) : void
src [ the source byte-array to copy from
i int index within the internal Data array to copy that byte to
len int the number of bytes to copy
return void

Put() public method

Copy the given byte-array data to this Msg's Data buffer.
public Put ( [ src, int srcOffset, int i, int len ) : void
src [ the source byte-array to copy from
srcOffset int first byte in the source byte-array
i int index within the internal Data array to copy that byte to
len int the number of bytes to copy
return void

Put() public method

Copy the given single byte to this Msg's Data buffer.
public Put ( byte b ) : void
b byte the source byte to copy from
return void

Put() public method

Copy the given single byte to this Msg's Data buffer at the given array-index.
public Put ( byte b, int i ) : void
b byte the source byte to copy from
i int index within the internal Data array to copy that byte to
return void

RemoveReferences() public method

If this Msg is of MsgType.Pool and is marked as Shared, then - subtract the given amount number from the reference-counter and, if that reaches zero - return the data to the shared-data pool. If this is not both a Pool Msg and also marked as Shared, this simply Closes this Msg.
public RemoveReferences ( int amount ) : void
amount int the number to subtract from the internal reference-counter
return void

ResetFlags() public method

Clear the indicated Flags bits.
public ResetFlags ( MsgFlags flags ) : void
flags MsgFlags which Flags bits to clear (More, Identity, or Shared)
return void

SetFlags() public method

Set the indicated Flags bits.
public SetFlags ( MsgFlags flags ) : void
flags MsgFlags which Flags bits to set (More, Identity, or Shared)
return void

ToString() public method

Override the Object ToString method to show the object-type, and values of the MsgType, Size, and Flags properties.
public ToString ( ) : string
return string

TrimPrefix() public method

Increase Offset and decrease Size by the given count.
public TrimPrefix ( int count ) : void
count int Number of bytes to remove from a message
return void

this() public method

Get and set the byte value in the Data buffer at a specific index.
public this ( int index ) : byte
index int The index to access
return byte