-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeature_read.hpp
More file actions
67 lines (56 loc) · 1.9 KB
/
Copy pathfeature_read.hpp
File metadata and controls
67 lines (56 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2025-Present Datadog, Inc.
#pragma once
#include <cstdint>
#include "datadog/impl/core/block.hpp"
#include "datadog/impl/core/storage/filesystem_wrapper.hpp"
#include "datadog/impl/core/tlv.hpp"
#include "datadog/impl/core/util/assert.hpp"
#include "datadog/impl/core/util/diagnostics.hpp"
namespace datadog::impl {
/**
* Lightweight wrapper for a block of TLV-formatted data read from a file. The data
* pointed to by `data` will be an exact copy of an `event` or `event_metadata` value
* previously enqueued for storage.
*/
struct TLVBlock {
TLVBlockType type;
Block data;
};
/**
* Interface passed to Feature::UploadThread_PrepareReport, allowing it iteratively read
* blocks of TLV-formatted data from the relevant batch file.
*/
class BatchReader {
private:
DiagnosticLogger& _logger;
File _file;
std::vector<char>& _block_data_buffer;
public:
/**
* Initializes a new BatchReader to read TLV data from a file that's open for read,
* using the provided buffer to store each block as it's read.
*/
explicit BatchReader(
DiagnosticLogger& in_logger, File&& in_file, std::vector<char>& in_buffer
);
/**
* Result of an attempt to read a single TLV block from the file.
*/
struct Result {
enum class Status : uint8_t {
Success, // A complete TLV block was successfully read from the file
EndOfFile, // We're done with the file; no more blocks are present
Error // Failed to read or parse a block; details were logged
} status{Status::Success};
TLVBlock block; // Valid only on Success
};
/**
* Attempts to read the next block of TLV data from the open file.
*/
Result ReadNext();
};
} // namespace datadog::impl