protected override void Parse0(IoBuffer buf) { HermesPrimitiveCodec codec = new HermesPrimitiveCodec(buf); Topic = codec.ReadString(); Partition = codec.ReadInt(); GroupId = codec.ReadString(); }
protected override void ToBytes0(IoBuffer buf) { HermesPrimitiveCodec codec = new HermesPrimitiveCodec(buf); writeMsgSeqMap(codec, m_ackMsgSeqs); writeMsgSeqMap(codec, m_nackMsgSeqs); codec.WriteInt(Type); }
protected override void Parse0(IoBuffer buf) { HermesPrimitiveCodec codec = new HermesPrimitiveCodec(buf); m_ackMsgSeqs = readMsgSeqMap(codec); m_nackMsgSeqs = readMsgSeqMap(codec); Type = codec.ReadInt(); }
public PartialDecodedMessage DecodePartial(IoBuffer buf) { HermesPrimitiveCodec codec = new HermesPrimitiveCodec(buf); // skip whole length codec.ReadInt(); // skip header length int headerLen = codec.ReadInt(); // skip body length int bodyLen = codec.ReadInt(); verifyChecksum(buf, headerLen + bodyLen); PartialDecodedMessage msg = new PartialDecodedMessage(); msg.Key = codec.ReadString(); msg.BornTime = codec.ReadLong(); msg.RemainingRetries = codec.ReadInt(); msg.BodyCodecType = codec.ReadString(); int len = codec.ReadInt(); msg.DurableProperties = buf.GetSlice(len); len = codec.ReadInt(); msg.VolatileProperties = buf.GetSlice(len); msg.Body = buf.GetSlice(bodyLen); // skip crc codec.ReadLong(); return msg; }
protected override void ToBytes0(IoBuffer buf) { HermesPrimitiveCodec codec = new HermesPrimitiveCodec(buf); codec.WriteString(Topic); codec.WriteInt(Partition); codec.WriteString(GroupId); }
private void readBatchDatas(IoBuffer buf, HermesPrimitiveCodec codec, List<TppConsumerMessageBatch> batches) { foreach (TppConsumerMessageBatch batch in batches) { int len = codec.ReadInt(); batch.Data = buf.GetSlice(len); } }
protected override void Parse0(IoBuffer buf) { Buf = buf; var codec = new HermesPrimitiveCodec(buf); msgCounter.WriteFullFence(codec.ReadInt()); Topic = codec.ReadString(); Partition = codec.ReadInt(); }
protected override void ToBytes0(IoBuffer buf) { var codec = new HermesPrimitiveCodec(buf); codec.WriteInt(PullType); codec.WriteString(Topic); codec.WriteInt(Partition); codec.WriteString(GroupId); codec.WriteOffset(Offset); codec.WriteInt(Size); codec.WriteLong(ExpireTime); }
protected override void Parse0(IoBuffer buf) { var codec = new HermesPrimitiveCodec(buf); List<TppConsumerMessageBatch> batches = new List<TppConsumerMessageBatch>(); readBatchMetas(codec, batches); readBatchDatas(buf, codec, batches); Batches = batches; Offset = codec.ReadOffset(); }
private void writeMsgSeqMap(HermesPrimitiveCodec codec, ConcurrentDictionary<Triple<Tpp, String, Boolean>, List<AckContext>> msgSeqMap) { if (msgSeqMap == null) { codec.WriteInt(0); } else { codec.WriteInt(msgSeqMap.Count); foreach (Triple<Tpp, String, Boolean> tppgr in msgSeqMap.Keys) { Tpp tpp = tppgr.First; codec.WriteString(tpp.Topic); codec.WriteInt(tpp.Partition); codec.WriteInt(tpp.Priority ? 0 : 1); codec.WriteString(tppgr.Middle); codec.WriteBoolean(tppgr.Last); } foreach (Triple<Tpp, String, Boolean> tppgr in msgSeqMap.Keys) { List<AckContext> contexts = msgSeqMap[tppgr]; if (contexts == null || contexts.Count == 0) { codec.WriteInt(0); } else { codec.WriteInt(contexts.Count); foreach (AckContext context in contexts) { codec.WriteLong(context.MsgSeq); codec.WriteInt(context.RemainingRetries); codec.WriteLong(context.OnMessageStartTimeMillis); codec.WriteLong(context.OnMessageEndTimeMillis); } } } } }
private void readBatchMetas(HermesPrimitiveCodec codec, List<TppConsumerMessageBatch> batches) { int batchSize = codec.ReadInt(); for (int i = 0; i < batchSize; i++) { TppConsumerMessageBatch batch = new TppConsumerMessageBatch(); int msgSize = codec.ReadInt(); batch.Topic = codec.ReadString(); batch.Partition = codec.ReadInt(); batch.Priority = codec.ReadInt(); batch.Resend = codec.ReadBoolean(); for (int j = 0; j < msgSize; j++) { batch.AddMessageMeta(new MessageMeta(codec.ReadLong(), codec.ReadInt(), codec.ReadLong(), codec.ReadInt(), codec.ReadBoolean())); } batches.Add(batch); } }
protected override void Parse0(IoBuffer buf) { var codec = new HermesPrimitiveCodec(buf); totalSize = codec.ReadInt(); Successes = codec.ReadIntBooleanMap(); }
protected override void ToBytes0(IoBuffer buf) { var codec = new HermesPrimitiveCodec(buf); codec.WriteInt(totalSize); codec.WriteIntBooleanMap(Successes); }
private ConcurrentDictionary<Triple<Tpp, string, bool>, List<AckContext>> readMsgSeqMap(HermesPrimitiveCodec codec) { ConcurrentDictionary<Triple<Tpp, string, bool>, List<AckContext>> msgSeqMap = new ConcurrentDictionary<Triple<Tpp, string, bool>, List<AckContext>>(); int mapSize = codec.ReadInt(); if (mapSize != 0) { List<Triple<Tpp, string, bool>> tppgrs = new List<Triple<Tpp, string, bool>>(); for (int i = 0; i < mapSize; i++) { Tpp tpp = new Tpp(codec.ReadString(), codec.ReadInt(), codec.ReadInt() == 0 ? true : false); String groupId = codec.ReadString(); bool resend = codec.ReadBoolean(); tppgrs.Add(new Triple<Tpp, string, bool>(tpp, groupId, resend)); } for (int i = 0; i < mapSize; i++) { Triple<Tpp, string, bool> tppgr = tppgrs[i]; int len = codec.ReadInt(); if (len == 0) { msgSeqMap[tppgr] = new List<AckContext>(); } else { msgSeqMap[tppgr] = new List<AckContext>(len); } for (int j = 0; j < len; j++) { msgSeqMap[tppgr].Add(new AckContext(codec.ReadLong(), codec.ReadInt(), codec.ReadLong(), codec.ReadLong())); } } } return msgSeqMap; }
protected override void ToBytes0(IoBuffer buf) { var codec = new HermesPrimitiveCodec(buf); codec.WriteBoolean(Success); }
protected override void Parse0(IoBuffer buf) { var codec = new HermesPrimitiveCodec(buf); Success = codec.ReadBoolean(); }
protected override void ToBytes0(IoBuffer buf) { HermesPrimitiveCodec codec = new HermesPrimitiveCodec(buf); codec.WriteOffset(Offset); }
private void WriteDatas(IoBuffer buf, HermesPrimitiveCodec codec, IDictionary<int, IList<ProducerMessage>> messages) { codec.WriteInt(messages.Count); foreach (var kvp in messages) { codec.WriteInt(kvp.Key); WriteMessages(kvp.Value, codec, buf); } }
private void WriteProperties(Dictionary<string, string> properties, IoBuffer buf, HermesPrimitiveCodec codec) { var writeIndexBeforeLength = buf.Position; codec.WriteInt(-1); var writeIndexBeforeMap = buf.Position; codec.WriteStringStringMap(properties); var mapLength = buf.Position - writeIndexBeforeMap; var writeIndexEnd = buf.Position; buf.Position = writeIndexBeforeLength; codec.WriteInt(mapLength); buf.Position = writeIndexEnd; }
/// <summary> /// Read Datas /// </summary> /// <param name="buf"></param> /// <param name="codec"></param> /// <param name="topic"></param> /// <remarks> /// implements only in broker /// </remarks> private void ReadDatas(ByteBuffer buf, HermesPrimitiveCodec codec, string topic) { var size = codec.ReadInt(); for (int i = 0; i < size; i++) { var priority = codec.ReadInt(); //todo } }
private void WriteMessages(IList<ProducerMessage> list, HermesPrimitiveCodec codec, IoBuffer buf) { var msgCodec = ComponentLocator.Lookup<IMessageCodec>(); codec.WriteInt(list.Count); //seqNos foreach (var message in list) codec.WriteInt(message.SequenceNo); // placeholder for payload len var indexBeforeLen = buf.Position; codec.WriteInt(-1); var indexBeforePayload = buf.Position; //payload foreach (var message in list) msgCodec.Encode(message, buf); var indexAfterPayload = buf.Position; var payloadLen = indexAfterPayload - indexBeforePayload; // refill payload len buf.Position = indexBeforeLen; codec.WriteInt(payloadLen); buf.Position = indexAfterPayload; }
private void Encode(ProducerMessage message, IoBuffer buf, byte[] body, string codecType) { var codec = new HermesPrimitiveCodec(buf); var indexBeginning = buf.Position; codec.WriteInt(-1); // placeholder for whole length var indexAfterWholeLen = buf.Position; codec.WriteInt(-1); // placeholder for header length codec.WriteInt(-1); // placeholder for body length var indexBeforeHeader = buf.Position; // header begin codec.WriteString(message.Key); codec.WriteLong(message.BornTime); codec.WriteInt(0); //remaining retries codec.WriteString(codecType); var propertiesHolder = message.PropertiesHolder; WriteProperties(propertiesHolder.DurableProperties, buf, codec); WriteProperties(propertiesHolder.VolatileProperties, buf, codec); // header end var headerLen = buf.Position - indexBeforeHeader; //body begin var indexBeforeBody = buf.Position; buf.Put(body); var bodyLen = buf.Position - indexBeforeBody; //body end //crc codec.WriteLong(ChecksumUtil.Crc32(buf.GetSlice(indexBeforeHeader, headerLen + bodyLen))); var indexEnd = buf.Position; var wholeLen = indexEnd - indexAfterWholeLen; // refill whole length buf.Position = indexBeginning; codec.WriteInt(wholeLen); // refill header length codec.WriteInt(headerLen); // refill body length codec.WriteInt(bodyLen); buf.Position = indexEnd; }
private Dictionary<string, string> readProperties(IoBuffer buf) { HermesPrimitiveCodec codec = new HermesPrimitiveCodec(buf); return codec.ReadStringStringMap(); }
protected override void ToBytes0(IoBuffer buf) { var codec = new HermesPrimitiveCodec(buf); codec.WriteInt(msgCounter.ReadFullFence()); codec.WriteString(Topic); codec.WriteInt(Partition); WriteDatas(buf, codec, messages); }
protected override void Parse0(IoBuffer buf) { HermesPrimitiveCodec codec = new HermesPrimitiveCodec(buf); Offset = codec.ReadOffset(); }