Arch Sub-System: Coder

01 The encoder and decoder functions of Semys Lib are wrapped by corresponding classes, which furthermore implement a common interface.

Coder

02 The common (abstract) Coder class defines the serialization methods for the basic types that are supported by the underlying coder Sub-System from Semys Lib, plus some helper methods.
03 The derived Encoder and Decoder objects implement the abstract methods and call the respective coder functions.
04 A complex object (generally, any structural type) typically implements a method called Code() that takes a reference to a Coder object.
Most member data can be serialized with the coder object, regardless whether it is encoding or decoding. Typically only container objects need special attention.
05 Simple example:
class Person
{
  void Code(Coder &coder)
  {
    coder.Code(mName);
    coder.Code(mAge);
  }

  std::string mName;
  uint32 mAge;
}

CoderContext

06 The CoderContext class helps implementing version compatibility as described in About: Method Compatibility.
It codes a version number and a size value at construction and jumps to the end of the context at destruction.
07 Simple example:
class Person
{
  void Code(Coder &coder)
  {
    CoderContext ctx(coder, 2, "Person");

    if (ctx.GetVersion() >= 1)
    {
      coder.Code(mName);
      coder.Code(mAge);
    }
    if (ctx.GetVersion() >= 2)
    {
      mAddress.Code(coder);
    }
  }

  std::string mName;
  uint32 mAge;
  Address mAddress;
}

08 See Lib Coder Sub-System for detailed information on serialization.

Goto: Main Page; This page is part of the Semys software documentation. See About: Documentation for details.