| 1802 | } |
| 1803 | |
| 1804 | bool toolboxObjectReadLatestAt( |
| 1805 | void* ctx, PJ_object_topic_handle_t topic, int64_t timestamp_ns, PJ_object_bytes_handle_t* out_handle, |
| 1806 | int64_t* out_timestamp, PJ_error_t* out_error) noexcept { |
| 1807 | auto* impl = static_cast<DatastoreToolboxObjectReadHostState*>(ctx); |
| 1808 | if (out_handle == nullptr) { |
| 1809 | propagateError(out_error, "out_handle must not be null"); |
| 1810 | return false; |
| 1811 | } |
| 1812 | *out_handle = nullptr; |
| 1813 | try { |
| 1814 | auto entry = impl->store.latestAt(ObjectTopicId{topic.id}, timestamp_ns); |
| 1815 | if (!entry.has_value() || entry->payload.anchor == nullptr) { |
| 1816 | impl->setError("no entry at-or-before timestamp"); |
| 1817 | propagateError(out_error, impl->last_error.c_str()); |
| 1818 | return false; |
| 1819 | } |
| 1820 | auto* payload_handle = new sdk::PayloadView(std::move(entry->payload)); |
| 1821 | *out_handle = reinterpret_cast<PJ_object_bytes_handle_t>(payload_handle); |
| 1822 | if (out_timestamp != nullptr) { |
| 1823 | *out_timestamp = entry->timestamp; |
| 1824 | } |
| 1825 | impl->last_error.clear(); |
| 1826 | return true; |
| 1827 | } catch (const std::exception& e) { |
| 1828 | impl->setError(e.what()); |
| 1829 | propagateError(out_error, impl->last_error.c_str()); |
| 1830 | return false; |
| 1831 | } catch (...) { |
| 1832 | impl->setError("readLatestAt: unknown exception"); |
| 1833 | propagateError(out_error, impl->last_error.c_str()); |
| 1834 | return false; |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | void toolboxObjectGetBytes(PJ_object_bytes_handle_t handle, const uint8_t** out_data, uint64_t* out_size) noexcept { |
| 1839 | if (out_data != nullptr) { |
nothing calls this directly
no test coverage detected