Commit 40e01383 authored by Martin Heistermann's avatar Martin Heistermann
Browse files

Fix and clean up property default serialisation

parent d41f8c2a
...@@ -189,6 +189,8 @@ types: ...@@ -189,6 +189,8 @@ types:
type: array_span type: array_span
- id: prop_idx - id: prop_idx
type: u4 type: u4
- id: data
size-eos: true
propdir_chunk: propdir_chunk:
seq: seq:
......
...@@ -19,12 +19,10 @@ namespace Codecs { ...@@ -19,12 +19,10 @@ namespace Codecs {
struct BoolPropCodec { struct BoolPropCodec {
using T = bool; using T = bool;
static void encode_one(Encoder &enc, const T &val) { static void encode_one(Encoder &enc, const T &val) {
uint8_t v = val ? 1 : 0; enc.u8(val);
enc.write(v);
} }
static void decode_one(Decoder &reader, T &val) { static void decode_one(Decoder &reader, T &val) {
uint8_t v = val ? 1 : 0; uint8_t v = reader.u8();
reader.read(v);
if (v != 0 && v != 1) { if (v != 0 && v != 1) {
throw parse_error("invalid bool encoding"); throw parse_error("invalid bool encoding");
} }
...@@ -37,15 +35,13 @@ struct BoolPropCodec { ...@@ -37,15 +35,13 @@ struct BoolPropCodec {
for (size_t bit = 0; bit < n_bits; ++bit) { for (size_t bit = 0; bit < n_bits; ++bit) {
bitset.set(bit, vec[i+bit]); bitset.set(bit, vec[i+bit]);
} }
uint8_t tmp = static_cast<uint8_t>(bitset.to_ulong()); enc.u8(static_cast<uint8_t>(bitset.to_ulong()));
enc.write(tmp);
} }
} }
static void decode_n(Decoder &decoder, std::vector<T> &vec, size_t idx_begin, size_t idx_end) { 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); decoder.need((idx_end-idx_begin+7)/8);
for (size_t i = idx_begin; i < idx_end; i += 8) { for (size_t i = idx_begin; i < idx_end; i += 8) {
uint8_t tmp = 0; uint8_t tmp = decoder.u8();
decoder.read(tmp);
std::bitset<8> bitset(tmp); std::bitset<8> bitset(tmp);
size_t n_bits = std::min(size_t(8), idx_end-i); size_t n_bits = std::min(size_t(8), idx_end-i);
for (size_t bit = 0; bit < n_bits; ++bit) { for (size_t bit = 0; bit < n_bits; ++bit) {
......
...@@ -23,6 +23,10 @@ void WriteBuffer::reset() ...@@ -23,6 +23,10 @@ void WriteBuffer::reset()
pos_ = 0; 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) void WriteBuffer::write(const uint8_t *s, size_t n)
{ {
need(n); need(n);
......
...@@ -9,7 +9,7 @@ namespace OpenVolumeMesh::IO::detail { ...@@ -9,7 +9,7 @@ namespace OpenVolumeMesh::IO::detail {
class OVM_EXPORT WriteBuffer { class OVM_EXPORT WriteBuffer {
public: public:
void reset(); void reset();
std::vector<uint8_t> const & vec() const {return data_;}; std::vector<uint8_t> vec() const;;
void write_to_stream(std::ostream &s); void write_to_stream(std::ostream &s);
size_t size() const {return pos_;} size_t size() const {return pos_;}
......
Supports Markdown
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