Exemplo n.º 1
0
        public static void GetDataFrag(this IoBuffer buffer, ref DataFrag obj)
        {
            int start_count = buffer.Position; // start of bytes Read so far from the
            // beginning

            obj.ExtraFlags = (short)buffer.GetInt16();
            int octetsToInlineQos = buffer.GetInt16() & 0xffff;

            int currentCount = buffer.Position; // count bytes to inline qos

            obj.ReaderId = buffer.GetEntityId();
            obj.WriterId = buffer.GetEntityId();
            obj.WriterSequenceNumber = buffer.GetSequenceNumber();

            obj.FragmentStartingNumber = buffer.GetInt32(); // ulong
            obj.FragmentsInSubmessage = buffer.GetInt16(); // ushort
            obj.FragmentSize = buffer.GetInt16(); // ushort
            obj.SampleSize = buffer.GetInt32(); // ulong

            int bytesRead = buffer.Position - currentCount;
            int unknownOctets = octetsToInlineQos - bytesRead;

            for (int i = 0; i < unknownOctets; i++)
            {
                buffer.Get(); // Skip unknown octets, @see 9.4.5.3.3 octetsToInlineQos
            }

            if (obj.HasInlineQosFlag)
            {
                obj.ParameterList = buffer.GetParameterList();
            }

            int end_count = buffer.Position; // end of bytes Read so far from the beginning
            if (obj.Header.SubMessageLength != 0)
            {
                obj.SerializedPayload = new byte[obj.Header.SubMessageLength - (end_count - start_count)];
            }
            else
            { // SubMessage is the last one. Rest of the bytes are Read.
                // @see 8.3.3.2.3
                obj.SerializedPayload = new byte[buffer.Remaining];
            }

            buffer.Get(obj.SerializedPayload, 0, obj.SerializedPayload.Length);
        }
Exemplo n.º 2
0
        public static void PutDataFrag(this IoBuffer buffer, DataFrag obj)
        {
            buffer.PutInt16(obj.ExtraFlags);

            short octets_to_inline_qos = 4 + 4 + 8 + 4 + 2 + 2 + 4;
            buffer.PutInt16(octets_to_inline_qos);

            buffer.PutEntityId(obj.ReaderId);
            buffer.PutEntityId(obj.WriterId);
            buffer.PutSequenceNumber(obj.WriterSequenceNumber);

            buffer.PutInt32(obj.FragmentStartingNumber);
            buffer.PutInt16((short)obj.FragmentsInSubmessage);
            buffer.PutInt16((short)obj.FragmentSize);
            buffer.PutInt32(obj.SampleSize);

            if (obj.HasInlineQosFlag)
            {
                buffer.PutParameterList(obj.ParameterList);
            }

            buffer.Put(obj.SerializedPayload); // TODO: check this
        }
Exemplo n.º 3
0
 public static DataFrag GetDataFrag(this IoBuffer buffer)
 {
     DataFrag obj = new DataFrag();
     buffer.GetDataFrag(ref obj);
     return obj;
 }
Exemplo n.º 4
0
        public static void GetSubMessage(this IoBuffer buffer, ref SubMessage obj)
        {
            buffer.Align(4);
            int smhPosition = buffer.Position;

            SubMessageHeader header = buffer.GetSubMessageHeader();
            int smStart = buffer.Position;

            switch (header.SubMessageKind)
            { // @see 9.4.5.1.1
                case SubMessageKind.PAD:
                    Pad smPad = new Pad();
                    smPad.Header = header;
                    buffer.GetPad(ref smPad);
                    obj = smPad;
                    break;
                case SubMessageKind.ACKNACK:
                    AckNack smAckNack = new AckNack();
                    smAckNack.Header = header;
                    buffer.GetAckNack(ref smAckNack);
                    obj = smAckNack;
                    break;
                case SubMessageKind.HEARTBEAT:
                    Heartbeat smHeartbeat = new Heartbeat();
                    smHeartbeat.Header = header;
                    buffer.GetHeartbeat(ref smHeartbeat);
                    obj = smHeartbeat;
                    break;
                case SubMessageKind.GAP:
                    Gap smgap = new Gap();
                    smgap.Header = header;
                    buffer.GetGap(ref smgap);
                    obj = smgap;
                    break;
                case SubMessageKind.INFO_TS:
                    InfoTimestamp sminfots = new InfoTimestamp();
                    sminfots.Header = header;
                    buffer.GetInfoTimestamp(ref sminfots);
                    obj = sminfots;
                    break;
                case SubMessageKind.INFO_SRC:
                    InfoSource smInfoSource = new InfoSource();
                    smInfoSource.Header = header;
                    buffer.GetInfoSource(ref smInfoSource);
                    obj = smInfoSource;
                    break;
                case SubMessageKind.INFO_REPLY_IP4:
                    InfoReplyIp4 smInfoReplyIp4 = new InfoReplyIp4();
                    smInfoReplyIp4.Header = header;
                    buffer.GetInfoReplyIp4(ref smInfoReplyIp4);
                    obj = smInfoReplyIp4;
                    break;
                case SubMessageKind.INFO_DST:
                    InfoDestination smInfoDestination = new InfoDestination();
                    smInfoDestination.Header = header;
                    buffer.GetInfoDestination(ref smInfoDestination);
                    obj = smInfoDestination;
                    break;
                case SubMessageKind.INFO_REPLY:
                    InfoReply smInfoReply = new InfoReply();
                    smInfoReply.Header = header;
                    buffer.GetInfoReply(ref smInfoReply);
                    obj = smInfoReply;
                    break;
                case SubMessageKind.NACK_FRAG:
                    NackFrag smNackFrag = new NackFrag();
                    smNackFrag.Header = header;
                    buffer.GetNackFrag(ref smNackFrag);
                    obj = smNackFrag;
                    break;
                case SubMessageKind.HEARTBEAT_FRAG:
                    HeartbeatFrag smHeartbeatFrag = new HeartbeatFrag();
                    smHeartbeatFrag.Header = header;
                    buffer.GetHeartbeatFrag(ref smHeartbeatFrag);
                    obj = smHeartbeatFrag;
                    break;
                case SubMessageKind.DATA:
                    Data smdata = new Data();
                    smdata.Header = header;
                    buffer.GetDataSubMessage(ref smdata);
                    obj = smdata;
                    break;
                case SubMessageKind.DATA_FRAG:
                    DataFrag smdDataFrag = new DataFrag();
                    smdDataFrag.Header = header;
                    buffer.GetDataFrag(ref smdDataFrag);
                    obj = smdDataFrag;
                    break;

                default:
                    throw new NotSupportedException();
            }

            int smEnd = buffer.Position;
            int smLength = smEnd - smStart;
            if (smLength != header.SubMessageLength && header.SubMessageLength != 0)
            {
                log.WarnFormat("SubMessage length differs for {0} != {1} for {2}", smLength, header.SubMessageLength, obj);
                if (smLength < header.SubMessageLength)
                {
                    byte[] unknownBytes = new byte[header.SubMessageLength - smLength];
                    log.DebugFormat("Trying to skip {0} bytes", unknownBytes.Length);

                    buffer.Get(unknownBytes, 0, unknownBytes.Length);
                }
            }

            log.DebugFormat("SubMsg in:  {0}", obj);
        }