コード例 #1
0
        public override byte[] ConvertToByte(bool reverseByteOrder, Action <Exception> ActionOnException)
        {
            List <byte> ret = new List <byte>();

            if (Comment != null)
            {
                byte[] comentValue = UTF8Encoding.UTF8.GetBytes(Comment);
                if (comentValue.Length <= UInt16.MaxValue)
                {
                    ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceStatisticsOptionCode.CommentCode, comentValue, reverseByteOrder, ActionOnException));
                }
            }

            if (StartTime != null)
            {
                ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceStatisticsOptionCode.StartTimeCode, StartTime.ConvertToByte(reverseByteOrder), reverseByteOrder, ActionOnException));
            }

            if (EndTime != null)
            {
                ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceStatisticsOptionCode.EndTimeCode, EndTime.ConvertToByte(reverseByteOrder), reverseByteOrder, ActionOnException));
            }

            if (InterfaceReceived.HasValue)
            {
                byte[] receivedCountValue = BitConverter.GetBytes(InterfaceReceived.Value.ReverseByteOrder(reverseByteOrder));
                ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceStatisticsOptionCode.InterfaceReceivedCode, receivedCountValue, reverseByteOrder, ActionOnException));
            }

            if (InterfaceDrop.HasValue)
            {
                byte[] dropCountValue = BitConverter.GetBytes(InterfaceDrop.Value.ReverseByteOrder(reverseByteOrder));
                ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceStatisticsOptionCode.InterfaceDropCode, dropCountValue, reverseByteOrder, ActionOnException));
            }

            if (FilterAccept.HasValue)
            {
                byte[] filterValue = BitConverter.GetBytes(FilterAccept.Value.ReverseByteOrder(reverseByteOrder));
                ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceStatisticsOptionCode.FilterAcceptCode, filterValue, reverseByteOrder, ActionOnException));
            }

            if (SystemDrop.HasValue)
            {
                byte[] systemDropValue = BitConverter.GetBytes(SystemDrop.Value.ReverseByteOrder(reverseByteOrder));
                ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceStatisticsOptionCode.SystemDropCode, systemDropValue, reverseByteOrder, ActionOnException));
            }

            if (DeliveredToUser.HasValue)
            {
                byte[] deliverValue = BitConverter.GetBytes(DeliveredToUser.Value.ReverseByteOrder(reverseByteOrder));
                ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceStatisticsOptionCode.DeliveredToUserCode, deliverValue, reverseByteOrder, ActionOnException));
            }

            ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceStatisticsOptionCode.EndOfOptionsCode, new byte[0], reverseByteOrder, ActionOnException));
            return(ret.ToArray());
        }