tsdb_hf.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // High frequency data API
  2. #ifndef TSDB_HF_CPP_HPP
  3. #define TSDB_HF_CPP_HPP
  4. #include <cstddef>
  5. #include <cstdint>
  6. #include <cstdio>
  7. #include <cstring>
  8. #include <memory>
  9. #include <string_view>
  10. #ifdef _WIN32
  11. #define TSDB_EXPORT __declspec(dllexport)
  12. #else
  13. #define TSDB_EXPORT
  14. #endif
  15. // NOTE: It is recommended to ALWAYS call `close` before dropping the object, otherwise you may
  16. // encounter unexpected behavior, including but not limited to silent data loss, crashes, etc.
  17. namespace tsdb_hf_cpp {
  18. struct tsdb_entry;
  19. struct tsdb_entry_stream {
  20. struct impl;
  21. ~tsdb_entry_stream();
  22. tsdb_entry_stream(tsdb_entry_stream&& other);
  23. /// @brief Closes the stream. Will also commit the stream if it has not been committed yet.
  24. /// It is recommended to always call this method before dropping the object.
  25. void close();
  26. void insert_point(double value);
  27. void insert_points(const double* values, size_t count);
  28. private:
  29. friend tsdb_entry;
  30. tsdb_entry_stream(std::unique_ptr<impl> impl);
  31. std::unique_ptr<impl> impl_;
  32. };
  33. /// @brief A time series database.
  34. struct tsdb_entry {
  35. struct impl;
  36. tsdb_entry();
  37. ~tsdb_entry();
  38. tsdb_entry(tsdb_entry&& other);
  39. /// @brief Closes the database. Will fail if there are open streams. It is recommended to always
  40. /// call this method before dropping the object.
  41. void close();
  42. void set_data_dir(std::string_view data_dir);
  43. /// @brief Sets how many points are stored in a single part.
  44. void set_part_size(size_t size);
  45. /// @brief Creates a new stream of points. The stream will be automatically committed when
  46. /// the object is dropped.
  47. /// @param name
  48. /// @param timestampOffset The starting timestamp offset (since epoch), in milliseconds.
  49. /// @param interval The interval between points, in nanoseconds.
  50. /// @return An object representing the stream.
  51. tsdb_entry_stream new_stream(std::string name, uint64_t timestampOffset, uint64_t interval);
  52. private:
  53. std::unique_ptr<impl> impl_;
  54. };
  55. } // namespace tsdb_hf_cpp
  56. #endif // TSDB_HFCPP_HPP