public static void GetMessage(this IoBuffer buffer, ref Message obj) { obj.Header = buffer.GetHeader(); while (buffer.HasRemaining) { SubMessage submsg = buffer.GetSubMessage(); obj.SubMessages.Add(submsg); } }
public static void PutMessage(this IoBuffer buffer, Message msg) { buffer.PutHeader(msg.Header); int position = 0; int subMessageCount = 0; foreach (SubMessage submsg in msg.SubMessages) { int subMsgStartPosition = buffer.Position; position =buffer.PutSubMessage(submsg); subMessageCount++; } // Length of last submessage is 0, @see 8.3.3.2.3 submessageLength if (subMessageCount > 0) buffer.PutInt16(position - 2, (short)0); }
public static Message GetMessage(this IoBuffer buffer) { Message obj = new Message(); buffer.GetMessage(ref obj); return obj; }
/// <summary> /// Handles incoming Message. Each sub message is transferred to /// corresponding reader. /// </summary> /// <param name="msg"></param> private void HandleMessage(Message msg) { #if TODO int msgId = msg.GetHashCode(); Time timestamp = null; GuidPrefix destGuidPrefix = GuidPrefix.GUIDPREFIX_UNKNOWN; GuidPrefix sourceGuidPrefix = msg.Header.GuidPrefix; if (participant.Guid.Prefix.Equals(sourceGuidPrefix)) { log.Debug("Discarding message originating from this participant"); return; } ISet<Reader> dataReceivers = new HashSet<Reader>(); IList<SubMessage> subMessages = msg.SubMessages; foreach (SubMessage subMsg in subMessages) { switch (subMsg.Kind) { case SubMessageKind.ACKNACK: if (ignoredParticipants.Contains(sourceGuidPrefix)) { continue; } handleAckNack(sourceGuidPrefix, (AckNack)subMsg); break; case SubMessageKind.DATA: if (ignoredParticipants.Contains(sourceGuidPrefix)) { continue; } try { Data data = (Data)subMsg; Reader r = participant.getReader(data.getReaderId(), data.getWriterId()); if (r != null) { if (dataReceivers.Add(r)) { r.StartMessageProcessing(msgId); } r.CreateSample(msgId, sourceGuidPrefix, data, timestamp); } else { log.WarnFormat("No Reader({0}) to handle Data from {1}", data.getReaderId(), data.getWriterId()); } } catch (Exception ioe) { log.WarnFormat("Failed to handle data: {0}", ioe); } break; case SubMessageKind.HEARTBEAT: if (ignoredParticipants.Contains(sourceGuidPrefix)) { continue; } HandleHeartbeat(sourceGuidPrefix, (Heartbeat)subMsg); break; case SubMessageKind.INFO_DST: destGuidPrefix = ((InfoDestination)subMsg).getGuidPrefix(); break; case SubMessageKind.INFO_SRC: sourceGuidPrefix = ((InfoSource)subMsg).getGuidPrefix(); break; case SubMessageKind.INFO_TS: timestamp = ((InfoTimestamp)subMsg).getTimeStamp(); break; case SubMessageKind.INFO_REPLY: // TODO: HB, AC & DATA needs to use replyLocators, // if present InfoReply ir = (InfoReply)subMsg; List<Locator> replyLocators = ir.getUnicastLocatorList(); if (ir.multicastFlag()) { replyLocators.Add(ir.getMulticastLocatorList()); } log.Warn("InfoReply not handled"); break; case SubMessageKind.INFO_REPLY_IP4: // TODO: HB, AC & DATA needs to use these // Locators, if present InfoReplyIp4 ir4 = (InfoReplyIp4)subMsg; LocatorUDPv4 unicastLocator = ir4.getUnicastLocator(); if (ir4.multicastFlag()) { LocatorUDPv4 multicastLocator = ir4.getMulticastLocator(); } log.Warn("InfoReplyIp4 not handled"); break; case SubMessageKind.GAP: HandleGap(sourceGuidPrefix, (Gap)subMsg); break; default: log.WarnFormat("SubMessage not handled: {0}", subMsg); } } log.DebugFormat("Releasing samples for {0} readers", dataReceivers.Count); foreach (Reader reader in dataReceivers) { reader.stopMessageProcessing(msgId); } #endif throw new NotImplementedException(); }