Make Copier and Encoder support writing partial messages
Along with changes to DummyEncoder, this gets us nicely setup to create
nice round buffer sizes for both DummyEncoder and LzmaEncoder. Those
can be written using O_DIRECT in a follow on commit for much more
efficient IO.
To do this, we need to introduce both start and stop bytes to Copier,
and then teach Encoder how to return what it was able to encode, and
then to restart part way through a message.
--flush_size now sets the buffer size.
Change-Id: I7a26d2ce677a28bd0e73333514302dc0612195c2
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/events/logging/buffer_encoder.h b/aos/events/logging/buffer_encoder.h
index f4a6251..ed5bef6 100644
--- a/aos/events/logging/buffer_encoder.h
+++ b/aos/events/logging/buffer_encoder.h
@@ -30,7 +30,7 @@
size_t size_;
};
- // Coppies a span. The span must have a longer lifetime than the coppier is
+ // Copies a span. The span must have a longer lifetime than the coppier is
// being used.
class SpanCopier : public Copier {
public:
@@ -55,12 +55,13 @@
// the output needs to be flushed.
virtual bool HasSpace(size_t request) const = 0;
- // Encodes and enqueues the given data encoder.
- virtual void Encode(Copier *copy) = 0;
+ // Returns the space available.
+ virtual size_t space() const = 0;
- // If this returns true, the encoder may be bypassed by writing directly to
- // the file.
- virtual bool may_bypass() const { return false; }
+ // Encodes and enqueues the given data encoder. Starts at the start byte
+ // (which must be a multiple of 8 bytes), and goes as far as it can. Returns
+ // the amount encoded.
+ virtual size_t Encode(Copier *copy, size_t start_byte) = 0;
// Finalizes the encoding process. After this, queue_size() represents the
// full extent of data which will be written to this file.
@@ -90,7 +91,7 @@
// and queues it up as is.
class DummyEncoder final : public DataEncoder {
public:
- DummyEncoder(size_t max_buffer_size);
+ DummyEncoder(size_t max_message_size, size_t buffer_size = 128 * 1024);
DummyEncoder(const DummyEncoder &) = delete;
DummyEncoder(DummyEncoder &&other) = delete;
DummyEncoder &operator=(const DummyEncoder &) = delete;
@@ -98,8 +99,8 @@
~DummyEncoder() override = default;
bool HasSpace(size_t request) const final;
- void Encode(Copier *copy) final;
- bool may_bypass() const final { return true; }
+ size_t space() const final;
+ size_t Encode(Copier *copy, size_t start_byte) final;
void Finish() final {}
void Clear(int n) final;
absl::Span<const absl::Span<const uint8_t>> queue() final;