|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <filesystem> // path |
| 4 | +#include <memory> // unique_ptr |
| 5 | + |
| 6 | +#include "databento/dbn.hpp" // DecodeMetadata |
| 7 | +#include "databento/dbn_decoder.hpp" // DbnDecoder |
| 8 | +#include "databento/enums.hpp" // VersionUpgradePolicy |
| 9 | +#include "databento/ireadable.hpp" |
| 10 | +#include "databento/log.hpp" |
| 11 | +#include "databento/record.hpp" |
| 12 | +#include "databento/timeseries.hpp" // MetadataCallback, RecordCallback |
| 13 | + |
| 14 | +namespace databento { |
| 15 | +// A reader for DBN data from files or streams. This class provides both a callback API |
| 16 | +// similar to `LiveThreaded` for live data as well as a blocking API similar to that of |
| 17 | +// `LiveBlocking`. Only one API should be used on a given instance. |
| 18 | +class DbnStore { |
| 19 | + public: |
| 20 | + explicit DbnStore(const std::filesystem::path& file_path); |
| 21 | + DbnStore(ILogReceiver* log_receiver, const std::filesystem::path& file_path, |
| 22 | + VersionUpgradePolicy upgrade_policy); |
| 23 | + DbnStore(ILogReceiver* log_receiver, std::unique_ptr<IReadable> input, |
| 24 | + VersionUpgradePolicy upgrade_policy); |
| 25 | + |
| 26 | + // Callback API: calling Replay consumes the input. |
| 27 | + void Replay(const MetadataCallback& metadata_callback, |
| 28 | + const RecordCallback& record_callback); |
| 29 | + void Replay(const RecordCallback& record_callback); |
| 30 | + |
| 31 | + // Blocking API |
| 32 | + const databento::Metadata& GetMetadata(); |
| 33 | + // Returns the next record or `nullptr` if there are no remaining records. |
| 34 | + const Record* NextRecord(); |
| 35 | + |
| 36 | + private: |
| 37 | + void MaybeDecodeMetadata(); |
| 38 | + |
| 39 | + DbnDecoder decoder_; |
| 40 | + databento::Metadata metadata_{}; |
| 41 | + bool has_decoded_metadata_{false}; |
| 42 | +}; |
| 43 | +} // namespace databento |
0 commit comments