Skip to content

Commit a05031a

Browse files
committed
MB-69242: Create Sink interface
Add a base-class/interface Sink Change-Id: I63ee1ed23e66f1d4175ec0175736bcff97d9c806 Reviewed-on: https://review.couchbase.org/c/platform/+/237050 Reviewed-by: Trond Norbye <trond.norbye@couchbase.com> Tested-by: Build Bot <build@couchbase.com>
1 parent 5b90468 commit a05031a

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

include/platform/file_sink.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#pragma once
1212

13+
#include <platform/sink.h>
14+
1315
#include <cstdio>
1416
#include <filesystem>
1517
#include <limits>
@@ -20,7 +22,7 @@ namespace cb::io {
2022
* A sink which writes to a file and throws std::system_error on failures to
2123
* write the data to the file.
2224
*/
23-
class FileSink {
25+
class FileSink : public Sink {
2426
public:
2527
enum class Mode {
2628
/// Append to the file if it exists, otherwise create a new file
@@ -51,7 +53,7 @@ class FileSink {
5153
* Write a blob of data to the end of the file
5254
* @param data The data to write to the file
5355
*/
54-
void sink(std::string_view data);
56+
void sink(std::string_view data) override;
5557

5658
/**
5759
* (Explicit) Flush any uncommited data to the file system
@@ -61,7 +63,7 @@ class FileSink {
6163
* @throws std::system_error if there is an error writing the data to the
6264
* file
6365
*/
64-
std::size_t fsync();
66+
std::size_t fsync() override;
6567

6668
/**
6769
* Close the file (flushing any pending data). Trying to write to the file
@@ -71,10 +73,10 @@ class FileSink {
7173
* @throws std::system_error if there is an error writing the data to the
7274
* file
7375
*/
74-
std::size_t close();
76+
std::size_t close() override;
7577

7678
/// Get the number of bytes written to the file so far
77-
std::size_t getBytesWritten() const {
79+
std::size_t getBytesWritten() const override {
7880
return bytes_written;
7981
}
8082

include/platform/sink.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2025-Present Couchbase, Inc.
3+
*
4+
* Use of this software is governed by the Business Source License included
5+
* in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
6+
* in that file, in accordance with the Business Source License, use of this
7+
* software will be governed by the Apache License, Version 2.0, included in
8+
* the file licenses/APL2.txt.
9+
*/
10+
11+
#pragma once
12+
13+
#include <cstddef>
14+
#include <string_view>
15+
namespace cb::io {
16+
17+
// Abstract Sink for moving data from network to a destination
18+
class Sink {
19+
public:
20+
virtual ~Sink() = default;
21+
virtual void sink(std::string_view data) = 0;
22+
virtual std::size_t fsync() = 0;
23+
virtual std::size_t close() = 0;
24+
virtual std::size_t getBytesWritten() const = 0;
25+
};
26+
27+
} // namespace cb::io

0 commit comments

Comments
 (0)