Newer
Older
WickedDocs / Serializing / ideas.txt


Item - A Serializable thing
     - has children which need to be Items

String is an Item
Array is an Item

class SerializerVisitor
{
public:
  void Enter(const char* name)
  {
  }
  void Exit(const char* name)
  {
  }
  void Visit(int32 var)
  {
  }
  template <class T>
  void Visit(const char* name, T var)
  {
    Enter(name);
    Visit(var);
    Exit(name);
  }
  template <class T>
  void Visit(const char* name, T var)
  {
    Enter(name);
    var.Visit(this);
    Exit(name);
  }
};


struct Person
{
  int32          id;
  string         name;
  Array<string>  email;
  Array<string>  phoneNumbers;

  // This can do both the serializing and de-serializing
  // This might be good to have generated, but possibly being more explicit could be better too
  template <class V>
  void Visit(V& v)
  {
    v.Visit("id",id);
    v.Visit("name",name);
    v.Visit("email",email);
    v.Visit("numbers",phoneNumbers);
  }
}


If use JSON, then order of members doesn't matter
Also schema can change, have members added, reordered etc, and can still work
JSON doesn't handle member names changing
Pretty similar for XML
JSON and XML have heavy overhead in size and parsing / writing

EXI seperates the schema and data - avoids much of the overheads

Protocol Buffers? Looks like code generation

Pickling - Python specific