|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <memory> |
| 4 | +#include <rust/cxx.h> |
| 5 | +#include "codecfactory.h" |
| 6 | +#include "codecs.h" |
| 7 | + |
| 8 | +// Adding things to the same namespace as lib to keep things simpler |
| 9 | +namespace FastPForLib { |
| 10 | + |
| 11 | +// Instantiate Coder Factory |
| 12 | +inline std::unique_ptr<CODECFactory> new_codec_factory() { |
| 13 | + return std::make_unique<CODECFactory>(); |
| 14 | +} |
| 15 | + |
| 16 | +// Get a list of codec names |
| 17 | +inline std::unique_ptr<std::vector<std::string>> codec_factory_all_names( |
| 18 | + const CODECFactory& factory |
| 19 | +) { |
| 20 | + return std::make_unique<std::vector<std::string>>(factory.allNames()); |
| 21 | +} |
| 22 | + |
| 23 | +// Get codec by name from a factory |
| 24 | +inline std::shared_ptr<IntegerCODEC> codec_factory_get_from_name( |
| 25 | + const CODECFactory& factory, |
| 26 | + rust::Str name |
| 27 | +) { |
| 28 | + return factory.getFromName(std::string(name)); |
| 29 | +} |
| 30 | + |
| 31 | +// Encode helpers |
| 32 | +inline size_t codec_encode32( |
| 33 | + const std::shared_ptr<IntegerCODEC>& codec, |
| 34 | + const rust::Slice<const uint32_t> in, |
| 35 | + rust::Slice<uint32_t> out |
| 36 | +) { |
| 37 | + size_t outSize = out.size(); |
| 38 | + codec->encodeArray(in.data(), in.size(), out.data(), outSize); |
| 39 | + return outSize; |
| 40 | +} |
| 41 | + |
| 42 | +inline size_t codec_encode64( |
| 43 | + const std::shared_ptr<IntegerCODEC>& codec, |
| 44 | + const rust::Slice<const uint64_t> in, |
| 45 | + rust::Slice<uint32_t> out |
| 46 | +) { |
| 47 | + size_t outSize = out.size(); |
| 48 | + codec->encodeArray(in.data(), in.size(), out.data(), outSize); |
| 49 | + return outSize; |
| 50 | +} |
| 51 | + |
| 52 | +// Decode helper: returns consumed input elements |
| 53 | +inline size_t codec_decode32( |
| 54 | + const std::shared_ptr<IntegerCODEC>& codec, |
| 55 | + const rust::Slice<const uint32_t> in, |
| 56 | + rust::Slice<uint32_t> out |
| 57 | +) { |
| 58 | + size_t outSize = out.size(); |
| 59 | + codec->decodeArray(in.data(), in.size(), out.data(), outSize); |
| 60 | + return outSize; |
| 61 | +} |
| 62 | + |
| 63 | +inline size_t codec_decode64( |
| 64 | + const std::shared_ptr<IntegerCODEC>& codec, |
| 65 | + const rust::Slice<const uint32_t> in, |
| 66 | + rust::Slice<uint64_t> out |
| 67 | +) { |
| 68 | + size_t outSize = out.size(); |
| 69 | + codec->decodeArray(in.data(), in.size(), out.data(), outSize); |
| 70 | + return outSize; |
| 71 | +} |
| 72 | + |
| 73 | +} // namespace FastPForLib |
0 commit comments