mirror of
https://github.com/Zygo/bees.git
synced 2025-06-16 09:36:17 +02:00
fs: deprecate vector<char>
Use uint8_t when we mean uint8_t, i.e. vector<uint8_t> instead of vector<char>. Add a template parameter instead of vector so we can swap in a non-copying data type. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
@ -61,7 +61,7 @@ namespace crucible {
|
||||
decltype(elem_cnt) get_elem_cnt() const;
|
||||
decltype(elem_missed) get_elem_missed() const;
|
||||
|
||||
vector<char> m_data;
|
||||
vector<uint8_t> m_data;
|
||||
};
|
||||
|
||||
struct BtrfsIoctlLogicalInoArgs : public btrfs_ioctl_logical_ino_args {
|
||||
@ -164,8 +164,8 @@ namespace crucible {
|
||||
|
||||
struct BtrfsIoctlSearchHeader : public btrfs_ioctl_search_header {
|
||||
BtrfsIoctlSearchHeader();
|
||||
vector<char> m_data;
|
||||
size_t set_data(const vector<char> &v, size_t offset);
|
||||
vector<uint8_t> m_data;
|
||||
size_t set_data(const vector<uint8_t> &v, size_t offset);
|
||||
bool operator<(const BtrfsIoctlSearchHeader &that) const;
|
||||
};
|
||||
|
||||
@ -200,9 +200,9 @@ namespace crucible {
|
||||
uint64_t btrfs_get_root_id(int fd);
|
||||
uint64_t btrfs_get_root_transid(int fd);
|
||||
|
||||
template<class T>
|
||||
template<class T, class V>
|
||||
const T*
|
||||
get_struct_ptr(vector<char> &v, size_t offset = 0)
|
||||
get_struct_ptr(const V &v, size_t offset = 0)
|
||||
{
|
||||
// OK so sometimes btrfs overshoots a little
|
||||
if (offset + sizeof(T) > v.size()) {
|
||||
@ -212,11 +212,11 @@ namespace crucible {
|
||||
return reinterpret_cast<const T*>(v.data() + offset);
|
||||
}
|
||||
|
||||
template<class A, class R>
|
||||
template<class A, class R, class V>
|
||||
R
|
||||
call_btrfs_get(R (*func)(const A*), vector<char> &v, size_t offset = 0)
|
||||
call_btrfs_get(R (*func)(const A*), const V &v, size_t offset = 0)
|
||||
{
|
||||
return func(get_struct_ptr<A>(v, offset));
|
||||
return func(get_struct_ptr<A, V>(v, offset));
|
||||
}
|
||||
|
||||
template <class T> struct btrfs_get_le;
|
||||
@ -237,13 +237,13 @@ namespace crucible {
|
||||
uint8_t operator()(const void *p) { return get_unaligned_le8(p); }
|
||||
};
|
||||
|
||||
template<class S, class T>
|
||||
template<class S, class T, class V>
|
||||
T
|
||||
btrfs_get_member(T S::* member, vector<char> &v, size_t offset = 0)
|
||||
btrfs_get_member(T S::* member, V &v, size_t offset = 0)
|
||||
{
|
||||
const S *sp = reinterpret_cast<const S*>(NULL);
|
||||
const T *spm = &(sp->*member);
|
||||
auto member_offset = reinterpret_cast<const char *>(spm) - reinterpret_cast<const char *>(sp);
|
||||
const S *const sp = nullptr;
|
||||
const T *const spm = &(sp->*member);
|
||||
auto member_offset = reinterpret_cast<const uint8_t *>(spm) - reinterpret_cast<const uint8_t *>(sp);
|
||||
return btrfs_get_le<T>()(get_struct_ptr<S>(v, offset + member_offset));
|
||||
}
|
||||
|
||||
@ -256,7 +256,7 @@ namespace crucible {
|
||||
unsigned long available() const;
|
||||
};
|
||||
|
||||
ostream &hexdump(ostream &os, const vector<char> &v);
|
||||
template<class V> ostream &hexdump(ostream &os, const V &v);
|
||||
|
||||
struct BtrfsIoctlFsInfoArgs : public btrfs_ioctl_fs_info_args_v2 {
|
||||
BtrfsIoctlFsInfoArgs();
|
||||
|
@ -19,13 +19,13 @@ namespace crucible {
|
||||
memset(that, 0, sizeof(Base));
|
||||
}
|
||||
|
||||
// Copy a base class object (usually a C struct) into a vector<char>
|
||||
// Copy a base class object (usually a C struct) into a vector<uint8_t>
|
||||
template <class Base>
|
||||
vector<char>
|
||||
vector<uint8_t>
|
||||
vector_copy_struct(Base *that)
|
||||
{
|
||||
const char *begin_that = reinterpret_cast<const char *>(static_cast<const Base *>(that));
|
||||
return vector<char>(begin_that, begin_that + sizeof(Base));
|
||||
const uint8_t *begin_that = reinterpret_cast<const uint8_t *>(static_cast<const Base *>(that));
|
||||
return vector<uint8_t>(begin_that, begin_that + sizeof(Base));
|
||||
}
|
||||
|
||||
// int->hex conversion with sprintf
|
||||
@ -60,7 +60,7 @@ namespace crucible {
|
||||
ptrdiff_t
|
||||
pointer_distance(const P1 *a, const P2 *b)
|
||||
{
|
||||
return reinterpret_cast<const char *>(a) - reinterpret_cast<const char *>(b);
|
||||
return reinterpret_cast<const uint8_t *>(a) - reinterpret_cast<const uint8_t *>(b);
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user