Ejemplo n.º 1
0
 public PartitionResponse(int partitionId, short errorCode)
 {
     PartitionId         = partitionId;
     ErrorCode           = (ResponseError)errorCode;
     AbortedTransactions = new AbortedTransaction[0];
     RecordBatches       = new RecordBatch[0];
 }
Ejemplo n.º 2
0
        private bool TryParseRecordBatch(ref SequenceReader <byte> reader, out RecordBatch message)
        {
            message = default;
            if (!reader.TryReadLong(out var baseOffset))
            {
                return(false);
            }
            if (!reader.TryReadInt(out var batchLength))
            {
                return(false);
            }
            if (reader.Remaining < batchLength)
            {
                return(false);
            }
            var startPos = reader.Consumed;

            if (!reader.TryReadInt(out var partitionLeaderEpoc))
            {
                return(false);
            }
            if (!reader.TryReadByte(out var magic))
            {
                return(false);
            }
            if (!reader.TryReadInt(out var crc))
            {
                return(false);
            }
            if (!reader.TryReadShort(out var attributes))
            {
                return(false);
            }
            if (!reader.TryReadInt(out var lastOffsetDelta))
            {
                return(false);
            }
            if (!reader.TryReadLong(out var firstTimeStamp))
            {
                return(false);
            }
            if (!reader.TryReadLong(out var maxTimeStamp))
            {
                return(false);
            }
            if (!reader.TryReadLong(out var producerId))
            {
                return(false);
            }
            if (!reader.TryReadShort(out var producerEpoc))
            {
                return(false);
            }
            if (!reader.TryReadInt(out var baseSequence))
            {
                return(false);
            }


            if (!reader.TryReadInt(out var x))
            {
                return(false);
            }

            var records = new List <RecordBatch.Record>();

            while (reader.Consumed - startPos < batchLength)
            {
                if (!TryParseRecord(ref reader, baseOffset, out var r))
                {
                    return(false);
                }
                records.Add(r);
            }

            message = new RecordBatch
            {
                BaseOffset          = baseOffset,
                BatchLength         = batchLength,
                PartitionLeaderEpoc = partitionLeaderEpoc,
                Magic           = magic,
                Crc             = crc,
                Attributes      = attributes,
                LastOffsetDelta = lastOffsetDelta,
                FirstTimeStamp  = firstTimeStamp,
                MaxTimeStamp    = maxTimeStamp,
                ProducerId      = producerId,
                ProducerEpoc    = producerEpoc,
                BaseSequence    = baseSequence,
                Records         = records.ToArray()
            };
            return(true);
        }