예제 #1
0
        public void TestScEvent()
        {
            //new scEvent
            ScEvent scEvent = new ScEvent(new SubscriptionId(1), new ScAddress(1, 2), new ScAddress(1, 3));
            //get  bytes
            var bytes = scEvent.GetBytes();

            Assert.AreNotEqual(0, bytes.Length);
            byte[] bytesEvent = new byte[12] {
                1, 0, 0, 0, 1, 0, 2, 0, 1, 0, 3, 0
            };
            //new scEvent from bytes
            ScEvent scEventFromBytes = ScEvent.Parse(bytesEvent, 0);

            Assert.AreEqual(scEvent.SubscriptionId.Id, scEventFromBytes.SubscriptionId.Id);
            Assert.AreEqual(scEvent.ArcAddress.Segment, scEventFromBytes.ArcAddress.Segment);
            Assert.AreEqual(scEvent.ArcAddress.Offset, scEventFromBytes.ArcAddress.Offset);
            Assert.AreEqual(scEvent.ElementAddress.Segment, scEventFromBytes.ElementAddress.Segment);
            Assert.AreEqual(scEvent.ElementAddress.Offset, scEventFromBytes.ElementAddress.Offset);
        }
 /// <summary>
 /// Инициализирует новый экземпляр класса
 /// </summary>
 /// <param name="bytes">массив байт</param>
 public EmitEventsResponse(byte[] bytes)
     : base(bytes)
 {
     events = new List <ScEvent>();
     if (Header.ReturnCode == ReturnCode.Successfull)
     {
         uint eventsCount = BitConverter.ToUInt32(bytes, SctpProtocol.HeaderLength);
         if (eventsCount > 0)
         {
             int beginIndex = sizeof(uint) + SctpProtocol.HeaderLength;
             for (uint i = 0; i < eventsCount; i++)
             {
                 var @event = ScEvent.Parse(bytes, beginIndex);
                 if (@event != null)
                 {
                     events.Add(@event);
                 }
                 beginIndex += SctpProtocol.ScEventLength;
             }
         }
     }
 }