GSF.TimeSeries.Transport.SignalIndexCache.ParseBinaryImage C# (CSharp) Method

ParseBinaryImage() public method

Initializes the SignalIndexCache by parsing the specified buffer containing a binary image.
public ParseBinaryImage ( byte buffer, int startIndex, int length ) : int
buffer byte Buffer containing binary image to parse.
startIndex int 0-based starting index in the to start parsing.
length int Valid number of bytes within to read from .
return int
        public int ParseBinaryImage(byte[] buffer, int startIndex, int length)
        {
            int binaryLength;
            int offset = startIndex;

            int referenceCount;
            ushort signalIndex;
            Guid signalID;
            int sourceSize;
            string source;
            uint id;

            int unauthorizedIDCount;

            if ((object)m_encoding == null)
                throw new InvalidOperationException("Attempt to parse binary image of signal index cache without setting a character encoding.");

            buffer.ValidateParameters(startIndex, length);

            if (length < 4)
                return 0;

            // Byte size of cache
            binaryLength = BigEndian.ToInt32(buffer, offset);
            offset += 4;

            if (length < binaryLength)
                return 0;

            // We know we have enough data so we can empty the reference cache
            m_reference.Clear();

            // Subscriber ID
            m_subscriberID = EndianOrder.BigEndian.ToGuid(buffer, offset);
            offset += 16;

            // Number of references
            referenceCount = BigEndian.ToInt32(buffer, offset);
            offset += 4;

            for (int i = 0; i < referenceCount; i++)
            {
                // Signal index
                signalIndex = BigEndian.ToUInt16(buffer, offset);
                offset += 2;

                // Signal ID
                signalID = EndianOrder.BigEndian.ToGuid(buffer, offset);
                offset += 16;

                // Source
                sourceSize = BigEndian.ToInt32(buffer, offset);
                offset += 4;
                source = m_encoding.GetString(buffer, offset, sourceSize);
                offset += sourceSize;

                // ID
                id = BigEndian.ToUInt32(buffer, offset);
                offset += 4;

                m_reference[signalIndex] = MeasurementKey.LookUpOrCreate(signalID, source, id);
            }

            // Number of unauthorized IDs
            unauthorizedIDCount = BigEndian.ToInt32(buffer, offset);
            m_unauthorizedSignalIDs = new Guid[unauthorizedIDCount];
            offset += 4;

            for (int i = 0; i < unauthorizedIDCount; i++)
            {
                // Unauthorized ID
                m_unauthorizedSignalIDs[i] = EndianOrder.BigEndian.ToGuid(buffer, offset);
                offset += 16;
            }

            return binaryLength;
        }

Usage Example

Ejemplo n.º 1
0
        private SignalIndexCache DeserializeSignalIndexCache(byte[] buffer)
        {
            CompressionModes compressionModes = (CompressionModes)(m_operationalModes & OperationalModes.CompressionModeMask);
            bool useCommonSerializationFormat = (m_operationalModes & OperationalModes.UseCommonSerializationFormat) > 0;
            bool compressSignalIndexCache = (m_operationalModes & OperationalModes.CompressSignalIndexCache) > 0;

            SignalIndexCache deserializedCache;

            GZipStream inflater = null;

            if (compressSignalIndexCache && compressionModes.HasFlag(CompressionModes.GZip))
            {
                try
                {
                    using (MemoryStream compressedData = new MemoryStream(buffer))
                    {
                        inflater = new GZipStream(compressedData, CompressionMode.Decompress, true);
                        buffer = inflater.ReadStream();
                    }
                }
                finally
                {
                    if ((object)inflater != null)
                        inflater.Close();
                }
            }

            if (useCommonSerializationFormat)
            {
                deserializedCache = new SignalIndexCache();
                deserializedCache.Encoding = m_encoding;
                deserializedCache.ParseBinaryImage(buffer, 0, buffer.Length);
            }
            else
            {
                deserializedCache = Serialization.Deserialize<SignalIndexCache>(buffer, SerializationFormat.Binary);
            }

            return deserializedCache;
        }
All Usage Examples Of GSF.TimeSeries.Transport.SignalIndexCache::ParseBinaryImage