Write data into a PubSubBuffer
- Last UpdatedApr 08, 2026
- 1 minute read
This scenario guides you through the steps required to write the following values in a PubSubBuffer:
- Enumeration
- String
- Boolean
- Int32
- PubSubBuffer
To identify the code associated with each step, see the code comments in the Example code sections.
To write into a PubSubBuffer
- Open the Program.cs file from the created project.
- Initialize a PubSubBuffer.
The enumeration field value must be explicitly cast to a System.Byte type.
- Write the data into the created PubSubBuffer.
- Write the size and received PubSubBuffer into the created PubSubBuffer.
- Copy all the data to a byte array to return it.
Example code
public byte[] WriteIntoBuffer(PubSubBuffer psBuffer)
{
// Initialize a PubSubBuffer that will contain all the data.
var buffer = new PubSubBuffer();
// Write the data into the created PubSubBuffer.
// The enumeration field value must be explicitly cast to a System.Byte type.
buffer.Write((System.Byte)DALPSMessageType.Subscribe);
buffer.Write("TopicExample");
buffer.Write(true);
// Write the size and received PubSubBuffer into the created PubSubBuffer.
var dataPtr = psBuffer.GetAllocatedBuffer();
var psBufferLength = psBuffer.GetUsedBufferBytes();
buffer.Write(psBufferLength);
buffer.WriteBlob(dataPtr, psBufferLength);
// Copy all the data to a byte array to return it.
var ptr = buffer.GetAllocatedBuffer();
var size = buffer.GetUsedBufferBytes();
var returnData = new byte[size];
Array.Copy(ptr, returnData, size);
return returnData;
}