Ejemplo n.º 1
0
        public static InterfaceStatisticsBlock Parse(BaseBlock baseBlock, Action <Exception> ActionOnException)
        {
            //Contract.Requires<ArgumentNullException>(baseBlock != null, "BaseBlock cannot be null");
            //Contract.Requires<ArgumentNullException>(baseBlock.Body != null, "BaseBlock.Body cannot be null");
            //Contract.Requires<ArgumentException>(baseBlock.BlockType == BaseBlock.Types.InterfaceStatistics, "Invalid packet type");

            long positionInStream = baseBlock.PositionInStream;

            using (Stream stream = new MemoryStream(baseBlock.Body))
            {
                using (BinaryReader binaryReader = new BinaryReader(stream))
                {
                    int    interfaceID = binaryReader.ReadInt32().ReverseByteOrder(baseBlock.ReverseByteOrder);
                    byte[] timestamp   = binaryReader.ReadBytes(8);
                    if (timestamp.Length < 8)
                    {
                        throw new EndOfStreamException("Unable to read beyond the end of the stream");
                    }
                    TimestampHelper           timestampHelper = new TimestampHelper(timestamp, baseBlock.ReverseByteOrder);
                    InterfaceStatisticsOption options         = InterfaceStatisticsOption.Parse(binaryReader, baseBlock.ReverseByteOrder, ActionOnException);
                    InterfaceStatisticsBlock  statisticBlock  = new InterfaceStatisticsBlock(interfaceID, timestampHelper, options, positionInStream);
                    return(statisticBlock);
                }
            }
        }