src, lib: fixup lint and format issues for DataQueue/Blob

Co-authored-by: flakey5 <73616808+flakey5@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/45258
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
James M Snellandflakey5 committed 2023-02-19 16:26:59 -08:00
1 parent 950cec4c26
commit 71fb06fd64
18 files changed
+1261 -1137

No files matched your search

+37 -38
View File
@@ -3,15 +3,16 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include <base_object.h>
#include <memory_tracker.h>
#include <node.h>
#include <node_bob.h>
#include <node_file.h>
#include <memory_tracker.h>
#include <stream_base.h>
#include <v8.h>
#include <uv.h>
#include <v8.h>
#include <memory>
#include <optional>
#include <vector>
namespace node {
@@ -101,17 +102,18 @@ namespace node {
// To read from a DataQueue, we use the node::bob::Source API
// (see src/node_bob.h).
//
// std::unique_ptr<DataQueue::Reader> reader = data_queue->getReader();
// std::shared_ptr<DataQueue::Reader> reader = data_queue->get_reader();
//
// reader->Pull(
// [](int status, const DataQueue::Vec* vecs, size_t count, Done done) {
// [](int status, const DataQueue::Vec* vecs,
// uint64_t count, Done done) {
// // status is one of node::bob::Status
// // vecs is zero or more data buffers containing the read data
// // count is the number of vecs
// // done is a callback to be invoked when done processing the data
// }, options, nullptr, 0, 16);
//
// Keep calling Pull() until status is equal to node::bob::Status::STATUS_END.
// Keep calling Pull() until status is equal to node::bob::Status::STATUS_EOS.
//
// For idempotent DataQueues, any number of readers can be created and
// pull concurrently from the same DataQueue. The DataQueue can be read
@@ -126,15 +128,14 @@ class DataQueue : public MemoryRetainer {
public:
struct Vec {
uint8_t* base;
size_t len;
uint64_t len;
};
// A DataQueue::Reader consumes the DataQueue. If the data queue is
// idempotent, multiple Readers can be attached to the DataQueue at
// any given time, all guaranteed to yield the same result when the
// data is read. Otherwise, only a single Reader can be attached.
class Reader : public MemoryRetainer,
public bob::Source<Vec> {
class Reader : public MemoryRetainer, public bob::Source<Vec> {
public:
using Next = bob::Next<Vec>;
using Done = bob::Done;
@@ -150,26 +151,25 @@ class DataQueue : public MemoryRetainer {
// offset is omitted, the slice extends to the end of the
// data.
//
// Creating a slice is only possible if isIdempotent() returns
// Creating a slice is only possible if is_idempotent() returns
// true. This is because consuming either the original entry or
// the new entry would change the state of the other in non-
// deterministic ways. When isIdempotent() returns false, slice()
// deterministic ways. When is_idempotent() returns false, slice()
// must return a nulled unique_ptr.
//
// Creating a slice is also only possible if the size of the
// entry is known. If size() returns v8::Nothing<size_t>, slice()
// entry is known. If size() returns std::nullopt, slice()
// must return a nulled unique_ptr.
virtual std::unique_ptr<Entry> slice(
size_t start,
v8::Maybe<size_t> end = v8::Nothing<size_t>()) = 0;
uint64_t start, std::optional<uint64_t> end = std::nullopt) = 0;
// Returns the number of bytes represented by this Entry if it is
// known. Certain types of entries, such as those backed by streams
// might not know the size in advance and therefore cannot provide
// a value. In such cases, size() must return v8::Nothing<size_t>.
// a value. In such cases, size() must return v8::Nothing<uint64_t>.
//
// If the entry is idempotent, a size should always be available.
virtual v8::Maybe<size_t> size() const = 0;
virtual std::optional<uint64_t> size() const = 0;
// When true, multiple reads on the object must produce the exact
// same data or the reads will fail. Some sources of entry data,
@@ -177,7 +177,7 @@ class DataQueue : public MemoryRetainer {
// and therefore must not claim to be. If an entry claims to be
// idempotent and cannot preserve that quality, subsequent reads
// must fail with an error when a variance is detected.
virtual bool isIdempotent() const = 0;
virtual bool is_idempotent() const = 0;
};
// Creates an idempotent DataQueue with a pre-established collection
@@ -190,7 +190,7 @@ class DataQueue : public MemoryRetainer {
// mutated and updated such that multiple reads are not guaranteed
// to produce the same result. The entries added can be of any type.
static std::shared_ptr<DataQueue> Create(
v8::Maybe<size_t> capped = v8::Nothing<size_t>());
std::optional<uint64_t> capped = std::nullopt);
// Creates an idempotent Entry from a v8::ArrayBufferView. To help
// ensure idempotency, the underlying ArrayBuffer is detached from
@@ -207,26 +207,26 @@ class DataQueue : public MemoryRetainer {
// is not detachable, nullptr will be returned.
static std::unique_ptr<Entry> CreateInMemoryEntryFromBackingStore(
std::shared_ptr<v8::BackingStore> store,
size_t offset,
size_t length);
uint64_t offset,
uint64_t length);
static std::unique_ptr<Entry> CreateDataQueueEntry(
std::shared_ptr<DataQueue> data_queue);
static std::unique_ptr<Entry> CreateFdEntry(
BaseObjectPtr<fs::FileHandle> handle);
static std::unique_ptr<Entry> CreateFdEntry(Environment* env,
v8::Local<v8::Value> path);
// Creates a Reader for the given queue. If the queue is idempotent,
// any number of readers can be created, all of which are guaranteed
// to provide the same data. Otherwise, only a single reader is
// permitted.
virtual std::unique_ptr<Reader> getReader() = 0;
virtual std::shared_ptr<Reader> get_reader() = 0;
// Append a single new entry to the queue. Appending is only allowed
// when isIdempotent() is false. v8::Nothing<bool>() will be returned
// if isIdempotent() is true. v8::Just(false) will be returned if the
// when is_idempotent() is false. std::nullopt will be returned
// if is_idempotent() is true. std::optional(false) will be returned if the
// data queue is not idempotent but the entry otherwise cannot be added.
virtual v8::Maybe<bool> append(std::unique_ptr<Entry> entry) = 0;
virtual std::optional<bool> append(std::unique_ptr<Entry> entry) = 0;
// Caps the size of this DataQueue preventing additional entries to
// be added if those cause the size to extend beyond the specified
@@ -239,12 +239,12 @@ class DataQueue : public MemoryRetainer {
// If the size of the data queue is not known, the limit will be
// ignored and no additional entries will be allowed at all.
//
// If isIdempotent is true capping is unnecessary because the data
// If is_idempotent is true capping is unnecessary because the data
// queue cannot be appended to. In that case, cap() is a non-op.
//
// If the data queue has already been capped, cap can be called
// again with a smaller size.
virtual void cap(size_t limit = 0) = 0;
virtual void cap(uint64_t limit = 0) = 0;
// Returns a new DataQueue that is a view over this queues data
// from the start offset to the ending offset. If the end offset
@@ -252,39 +252,38 @@ class DataQueue : public MemoryRetainer {
//
// The slice will coverage a range from start up to, but excluding, end.
//
// Creating a slice is only possible if isIdempotent() returns
// Creating a slice is only possible if is_idempotent() returns
// true. This is because consuming either the original DataQueue or
// the new queue would change the state of the other in non-
// deterministic ways. When isIdempotent() returns false, slice()
// deterministic ways. When is_idempotent() returns false, slice()
// must return a nulled unique_ptr.
//
// Creating a slice is also only possible if the size of the
// DataQueue is known. If size() returns v8::Nothing<size_t>, slice()
// DataQueue is known. If size() returns std::nullopt, slice()
// must return a null unique_ptr.
virtual std::shared_ptr<DataQueue> slice(
size_t start,
v8::Maybe<size_t> end = v8::Nothing<size_t>()) = 0;
uint64_t start, std::optional<uint64_t> end = std::nullopt) = 0;
// The size of DataQueue is the total size of all of its member entries.
// If any of the entries is not able to specify a size, the DataQueue
// will also be incapable of doing so, in which case size() must return
// v8::Nothing<size_t>.
virtual v8::Maybe<size_t> size() const = 0;
// std::nullopt.
virtual std::optional<uint64_t> size() const = 0;
// A DataQueue is idempotent only if all of its member entries are
// idempotent.
virtual bool isIdempotent() const = 0;
virtual bool is_idempotent() const = 0;
// True only if cap is called or the data queue is a limited to a
// fixed size.
virtual bool isCapped() const = 0;
virtual bool is_capped() const = 0;
// If the data queue has been capped, and the size of the data queue
// is known, maybeCapRemaining will return the number of additional
// bytes the data queue can receive before reaching the cap limit.
// If the size of the queue cannot be known, or the cap has not
// been set, maybeCapRemaining() will return v8::Nothing<size_t>.
virtual v8::Maybe<size_t> maybeCapRemaining() const = 0;
// been set, maybeCapRemaining() will return std::nullopt.
virtual std::optional<uint64_t> maybeCapRemaining() const = 0;
static void Initialize(Environment* env, v8::Local<v8::Object> target);
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);