2019-03-27 23:40:35 +01:00
|
|
|
#include "serialise.hh"
|
2019-03-27 14:12:20 +01:00
|
|
|
|
|
|
|
namespace rust {
|
|
|
|
|
|
|
|
// Depending on the internal representation of Rust slices is slightly
|
|
|
|
// evil...
|
|
|
|
template<typename T> struct Slice
|
|
|
|
{
|
2019-03-27 20:45:56 +01:00
|
|
|
T * ptr;
|
2019-03-27 14:12:20 +01:00
|
|
|
size_t size;
|
|
|
|
|
2019-03-27 20:45:56 +01:00
|
|
|
Slice(T * ptr, size_t size) : ptr(ptr), size(size)
|
2019-03-27 14:12:20 +01:00
|
|
|
{
|
|
|
|
assert(ptr);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StringSlice : Slice<char>
|
|
|
|
{
|
2019-03-27 20:45:56 +01:00
|
|
|
StringSlice(const std::string & s): Slice((char *) s.data(), s.size()) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Source
|
|
|
|
{
|
|
|
|
size_t (*fun)(void * source_this, rust::Slice<uint8_t> data);
|
|
|
|
nix::Source * _this;
|
|
|
|
|
|
|
|
Source(nix::Source & _this)
|
|
|
|
: fun(sourceWrapper), _this(&_this)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// FIXME: how to propagate exceptions?
|
|
|
|
static size_t sourceWrapper(void * _this, rust::Slice<uint8_t> data)
|
|
|
|
{
|
|
|
|
auto n = ((nix::Source *) _this)->read(data.ptr, data.size);
|
|
|
|
return n;
|
|
|
|
}
|
2019-03-27 14:12:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
2019-09-10 21:55:32 +02:00
|
|
|
void unpack_tarfile(rust::Source source, rust::StringSlice dest_dir);
|
2019-03-27 14:12:20 +01:00
|
|
|
}
|