public int GenerateBinaryImage(byte[] buffer, int startIndex)
{
Guid[] unauthorizedSignalIDs = m_unauthorizedSignalIDs ?? new Guid[0];
int binaryLength = BinaryLength;
int offset = startIndex;
byte[] bigEndianBuffer;
byte[] unicodeBuffer;
if ((object)m_encoding == null)
throw new InvalidOperationException("Attempt to generate binary image of signal index cache without setting a character encoding.");
buffer.ValidateParameters(startIndex, binaryLength);
// Byte size of cache
bigEndianBuffer = BigEndian.GetBytes(binaryLength);
Buffer.BlockCopy(bigEndianBuffer, 0, buffer, offset, bigEndianBuffer.Length);
offset += bigEndianBuffer.Length;
// Subscriber ID
bigEndianBuffer = EndianOrder.BigEndian.GetBytes(m_subscriberID);
Buffer.BlockCopy(bigEndianBuffer, 0, buffer, offset, bigEndianBuffer.Length);
offset += bigEndianBuffer.Length;
// Number of references
bigEndianBuffer = BigEndian.GetBytes(m_reference.Count);
Buffer.BlockCopy(bigEndianBuffer, 0, buffer, offset, bigEndianBuffer.Length);
offset += bigEndianBuffer.Length;
foreach (KeyValuePair<ushort, MeasurementKey> kvp in m_reference)
{
// Signal index
bigEndianBuffer = BigEndian.GetBytes(kvp.Key);
Buffer.BlockCopy(bigEndianBuffer, 0, buffer, offset, bigEndianBuffer.Length);
offset += bigEndianBuffer.Length;
// Signal ID
bigEndianBuffer = EndianOrder.BigEndian.GetBytes(kvp.Value.SignalID);
Buffer.BlockCopy(bigEndianBuffer, 0, buffer, offset, bigEndianBuffer.Length);
offset += bigEndianBuffer.Length;
// Source
unicodeBuffer = m_encoding.GetBytes(kvp.Value.Source);
bigEndianBuffer = BigEndian.GetBytes(unicodeBuffer.Length);
Buffer.BlockCopy(bigEndianBuffer, 0, buffer, offset, bigEndianBuffer.Length);
offset += bigEndianBuffer.Length;
Buffer.BlockCopy(unicodeBuffer, 0, buffer, offset, unicodeBuffer.Length);
offset += unicodeBuffer.Length;
// ID
bigEndianBuffer = BigEndian.GetBytes(kvp.Value.ID);
Buffer.BlockCopy(bigEndianBuffer, 0, buffer, offset, bigEndianBuffer.Length);
offset += bigEndianBuffer.Length;
}
// Number of unauthorized IDs
bigEndianBuffer = BigEndian.GetBytes(unauthorizedSignalIDs.Length);
Buffer.BlockCopy(bigEndianBuffer, 0, buffer, offset, bigEndianBuffer.Length);
offset += bigEndianBuffer.Length;
foreach (Guid signalID in unauthorizedSignalIDs)
{
// Unauthorized ID
bigEndianBuffer = EndianOrder.BigEndian.GetBytes(signalID);
Buffer.BlockCopy(bigEndianBuffer, 0, buffer, offset, bigEndianBuffer.Length);
offset += bigEndianBuffer.Length;
}
return binaryLength;
}