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 ToBytes0(IoBuffer buf)
 {
     HermesPrimitiveCodec codec = new HermesPrimitiveCodec(buf);
     codec.WriteString(Topic);
     codec.WriteInt(Partition);
     codec.WriteString(GroupId);
 }
 protected override void ToBytes0(IoBuffer buf)
 {
     HermesPrimitiveCodec codec = new HermesPrimitiveCodec(buf);
     writeMsgSeqMap(codec, m_ackMsgSeqs);
     writeMsgSeqMap(codec, m_nackMsgSeqs);
     codec.WriteInt(Type);
 }
        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);
                        }
                    }
                }
            }

        }
 protected override void ToBytes0(IoBuffer buf)
 {
     var codec = new HermesPrimitiveCodec(buf);
     codec.WriteInt(totalSize);
     codec.WriteIntBooleanMap(Successes);
 }
 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);
     }
 }
 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);
 }
        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 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;
 }