public bool TryAppend(string routingKey, BufferSlice content) { if (!Fits(routingKey, content)) { return(false); } WriteRecordsGroup(routingKey, content); groupsWritten++; WriteGroupsCount(); return(true); }
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(); }
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); }
private static bool IsCompleteBuffer(BufferSlice slice) { return(slice.Length == slice.Buffer.SnapshotLength); }
private void WriteRecordsGroup(string routingKey, BufferSlice content) { writer.Write(routingKey); writer.Write(content.Items); writer.WriteWithoutLengthPrefix(content.Buffer.InternalBuffer, content.Offset, content.Length); }