GSF.TimeSeries.Transport.SerializableMeasurement.GenerateBinaryImage C# (CSharp) Method

GenerateBinaryImage() public method

Generates binary image of the SerializableMeasurement and copies it into the given buffer, for ISupportBinaryImage.BinaryLength bytes.

Field: Bytes:
--------- ---------
Key ID 4
SourceLen 4
Source SourceLen
Signal ID 16
TagLen 4
Tag TagLen
Value 8
Adder 8
Multiplier 8
Ticks 8
Flags 4

Constant Length = 64
Variable Length = SourceLen + TagLen

is null. /// or is less than 0 -or- /// and will exceed length. ///
public GenerateBinaryImage ( byte buffer, int startIndex ) : int
buffer byte Buffer used to hold generated binary image of the source object.
startIndex int 0-based starting index in the to start writing.
return int
        public int GenerateBinaryImage(byte[] buffer, int startIndex)
        {
            int length = BinaryLength;

            buffer.ValidateParameters(startIndex, length);

            byte[] bytes;
            int size, index = startIndex;
            string source = Key.Source.ToNonNullString();
            string tagName = TagName.ToNonNullString();

            // Encode key ID
            BigEndian.CopyBytes(Key.ID, buffer, index);
            index += 4;

            // Encode key source string length
            bytes = m_encoding.GetBytes(source);
            size = bytes.Length;
            BigEndian.CopyBytes(size, buffer, index);
            index += 4;

            // Encode key source string
            if (size > 0)
            {
                Buffer.BlockCopy(bytes, 0, buffer, index, size);
                index += size;
            }

            // Encode signal ID
            EndianOrder.BigEndian.CopyBytes(ID, buffer, index);
            index += 16;

            // Encode tag name string length
            bytes = m_encoding.GetBytes(tagName);
            size = bytes.Length;
            BigEndian.CopyBytes(size, buffer, index);
            index += 4;

            // Encode tag name string
            if (size > 0)
            {
                Buffer.BlockCopy(bytes, 0, buffer, index, size);
                index += size;
            }

            // Encode value
            BigEndian.CopyBytes(Value, buffer, index);
            index += 8;

            // Encode adder
            BigEndian.CopyBytes(Adder, buffer, index);
            index += 8;

            // Encode multiplier
            BigEndian.CopyBytes(Multiplier, buffer, index);
            index += 8;

            // Encode timestamp
            BigEndian.CopyBytes((long)Timestamp, buffer, index);
            index += 8;

            // Encode state flags
            BigEndian.CopyBytes((uint)StateFlags, buffer, index);

            return length;
        }