コード例 #1
0
        public bool TryAppend(string routingKey, BufferSlice content)
        {
            if (!Fits(routingKey, content))
            {
                return(false);
            }

            WriteRecordsGroup(routingKey, content);

            groupsWritten++;

            WriteGroupsCount();

            return(true);
        }
コード例 #2
0
        private IEnumerable <IDataBatch> HandleSlice(string routingKey, BufferSlice slice, DataBatchBuildingContext context)
        {
            if (context.CurrentMessageBuilder.TryAppend(routingKey, slice))
            {
                context.CurrentSlices.Add(slice);
                yield break;
            }

            if (context.IsEmpty)
            {
                throw new Exception($"Bug! Somehow there's a buffer slice of size {slice.Length} that does not fit into max batch size {messageBuffer.Length} with overhead considered.");
            }

            yield return(context.CreateBatch());

            context.Reset();
        }
コード例 #3
0
        public bool TryCompleteSnapshot(BufferSlice slice)
        {
            if (IsCompleteBuffer(slice))
            {
                return(true);
            }

            var buffer = slice.Buffer;

            if (!slicesByBuffer.TryGetValue(buffer, out var slices))
            {
                slicesByBuffer[buffer] = slices = new List <BufferSlice>();
            }

            slices.Add(slice);

            if (IsCompleteBuffer(buffer, slices))
            {
                slicesByBuffer.Remove(buffer);
                return(true);
            }

            return(false);
        }
コード例 #4
0
 private static bool IsCompleteBuffer(BufferSlice slice)
 {
     return(slice.Length == slice.Buffer.SnapshotLength);
 }
コード例 #5
0
 private void WriteRecordsGroup(string routingKey, BufferSlice content)
 {
     writer.Write(routingKey);
     writer.Write(content.Items);
     writer.WriteWithoutLengthPrefix(content.Buffer.InternalBuffer, content.Offset, content.Length);
 }