Skip to content

Encoder/Decoder Abstraction & Archive System

Encoder / Decoder Abstraction Architecture

In uprops, serialization, remote communication (gRPC / WebSockets / IPC), and view synchronization are abstracted through Encoder / Decoder pairs.

  • IEncoder: Serializes property values, containers, and metadata into a target format or stream.
  • IDecoder: Deserializes values, containers, and metadata from a source format or stream.
graph LR
    Prop["Property / Container"]
    Enc["IEncoder / IDecoder Interface"]
    FileArchive["File Archives (XML, Text, HRT, Log)"]
    NetStream["Network Streams (gRPC, WebSockets, IPC)"]
    ViewSync["View Synced Representations (Qt GUI, VTK Gizmos)"]

    Prop <--> Enc
    Enc <--> FileArchive
    Enc <--> NetStream
    Enc <--> ViewSync

IEncoder & IDecoder Interfaces

Defined under src/Core/uprops/backend/:

IEncoder.h

namespace uprops {

class PropertyBase;

class UPROPS_EXPORT IEncoder {
public:
    virtual ~IEncoder() = default;

    virtual void EncodeProperty(const PropertyBase& prop) = 0;
    virtual void EncodePayload(const PropertyChangePayload& payload) = 0;
};

} // namespace uprops

IDecoder.h

namespace uprops {

class PropertyBase;

class UPROPS_EXPORT IDecoder {
public:
    virtual ~IDecoder() = default;

    virtual bool DecodeProperty(PropertyBase& prop) = 0;
    virtual bool DecodePayload(PropertyChangePayload& payload) = 0;
};

} // namespace uprops

File & Stream Archives in uprops

Archives.h defines native archive formats built on top of Boost::serialization:

Archive Class Purpose Format / Style Header Option
uprops::Archive::xml_oarchive XML Output Archive Formatted XML tags with metadata attributes Optional XML header
uprops::Archive::xml_iarchive XML Input Archive Deserializes XML properties into C++ structures Optional XML header
uprops::Archive::text_oarchive Text Output Archive Space-separated plain text stream Standard header
uprops::Archive::text_iarchive Text Input Archive Reads plain text tokens into values Standard header
uprops::Archive::hrt_oarchive Human Readable Text Output Key-value pairs (Name: Value\n) Headerless
uprops::Archive::hrt_iarchive Human Readable Text Input Parses human-readable key-value text lines Headerless
uprops::Archive::log_archive Logging Output Archive Debug/Diagnostic XML string logging Headerless

Serialization & HRP Integration

uprops::Property<T> implements template serialization helpers using make_hrp:

template <typename T>
class Property : public PropertyBase {
public:
    template <class ArchiveT>
    void serialize_helper(ArchiveT & ar, const unsigned int version) {
        ar & boost::serialization::make_hrp(m_name.c_str(), *m_value, m_units.c_str());
    }

    virtual void serialize(Archive::xml_oarchive & ar, const unsigned int v) override { serialize_helper(ar, v); }
    virtual void serialize(Archive::xml_iarchive & ar, const unsigned int v) override { serialize_helper(ar, v); }
    virtual void serialize(Archive::text_oarchive & ar, const unsigned int v) override { serialize_helper(ar, v); }
    virtual void serialize(Archive::text_iarchive & ar, const unsigned int v) override { serialize_helper(ar, v); }
    virtual void serialize(Archive::hrt_oarchive & ar, const unsigned int v) override { serialize_helper(ar, v); }
    virtual void serialize(Archive::hrt_iarchive & ar, const unsigned int v) override { serialize_helper(ar, v); }
    virtual void serialize(Archive::log_archive & ar, const unsigned int v) override { serialize_helper(ar, v); }
};

This guarantees that whenever any archive serializes a property, the value is automatically wrapped with its name and units!