예제 #1
0
        public IDataProtocol GetProtocol(DataProtocolVersion dataProtocolVersion)
        {
            IDataProtocol protocol = _container.GetAllInstances <IDataProtocol>().SingleOrDefault(p => p.Version == dataProtocolVersion);

            if (protocol == null)
            {
                // this exception means error in implementation => If we have DataProtocolVersion enum value, we should have protocol class registered
                throw new InvalidOperationException($"No protocol {dataProtocolVersion} registered in container");
            }

            return(protocol);
        }
        /// <summary>
        /// Read QueueEqntry from DataFile frame stream. This method is thread-safe.
        /// </summary>
        /// <exception cref="InvalidCrcException">This exception is thrown if crc calculated from stream does nto equal crc written in the file</exception>
        /// <exception cref="UnsupportedProtocolVersionException">This exception is thrown if stream data indicate to not implemented protocol</exception>
        /// <exception cref="InvalidBoundryByteException">This exception is thrown if values of start or end byte have wrong values. This might indicate that while reading, application poiints to wrong place in the stream</exception>
        /// <exception cref="DataFrameException">This exception is thrown if frame is not up to specification</exception>
        public QueueEntry ReadEntry(QueueContext context, Stream inputStream)
        {
#warning TEST
            if (!ReadStartByte(context, inputStream))
            {
                return(null);
            }

            DataProtocolVersion dataProtocolVersion = ReadDataProtocolVersion(context, inputStream);
            int    messageLength = ReadMessageLength(context, inputStream);
            byte[] messageBuffer = ReadMessageBuffer(context, inputStream, messageLength);
            uint   crc           = ReadCrc(context, inputStream);
            CheckCrc(context, messageBuffer, crc);
            ReadEndByte(context, inputStream);

            return(_dataProtocolFactory.GetProtocol(dataProtocolVersion).GetEntry(messageBuffer));
        }
예제 #3
0
 protected DataProtocol(DataProtocolVersion version)
 {
     Version = version;
 }