Commit 871118f7 authored by Martin Heistermann's avatar Martin Heistermann
Browse files

Fix and clean up property default serialisation

parent d5e85283
Pipeline #18951 failed with stage
in 12 minutes and 1 second
......@@ -189,6 +189,8 @@ types:
type: array_span
- id: prop_idx
type: u4
- id: data
size-eos: true
propdir_chunk:
seq:
......
......@@ -19,12 +19,10 @@ namespace Codecs {
struct BoolPropCodec {
using T = bool;
static void encode_one(Encoder &enc, const T &val) {
uint8_t v = val ? 1 : 0;
enc.write(v);
enc.u8(val);
}
static void decode_one(Decoder &reader, T &val) {
uint8_t v = val ? 1 : 0;
reader.read(v);
uint8_t v = reader.u8();
if (v != 0 && v != 1) {
throw parse_error("invalid bool encoding");
}
......@@ -37,15 +35,13 @@ struct BoolPropCodec {
for (size_t bit = 0; bit < n_bits; ++bit) {
bitset.set(bit, vec[i+bit]);
}
uint8_t tmp = static_cast<uint8_t>(bitset.to_ulong());
enc.write(tmp);
enc.u8(static_cast<uint8_t>(bitset.to_ulong()));
}
}
static void decode_n(Decoder &decoder, std::vector<T> &vec, size_t idx_begin, size_t idx_end) {
decoder.need((idx_end-idx_begin+7)/8);
for (size_t i = idx_begin; i < idx_end; i += 8) {
uint8_t tmp = 0;
decoder.read(tmp);
uint8_t tmp = decoder.u8();
std::bitset<8> bitset(tmp);
size_t n_bits = std::min(size_t(8), idx_end-i);
for (size_t bit = 0; bit < n_bits; ++bit) {
......
......@@ -23,6 +23,10 @@ void WriteBuffer::reset()
pos_ = 0;
}
std::vector<uint8_t> WriteBuffer::vec() const {
return {data_.begin(), data_.begin() + pos_};
}
void WriteBuffer::write(const uint8_t *s, size_t n)
{
need(n);
......
......@@ -9,7 +9,7 @@ namespace OpenVolumeMesh::IO::detail {
class OVM_EXPORT WriteBuffer {
public:
void reset();
std::vector<uint8_t> const & vec() const {return data_;};
std::vector<uint8_t> vec() const;;
void write_to_stream(std::ostream &s);
size_t size() const {return pos_;}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment