Esempio n. 1
0
void
Object::Serialise(TextWriter &writer, int indent) const
{
  writer.Write('{');
  if (indent >= 0)
    writer.NewLine();

  for (auto it = children.begin(), end = children.end(); it != end;) {
    if (indent >= 0) {
      SerialiseIndent(writer, indent + 1);
      writer.Format("\"%s\": ", it->first.c_str());
      it->second->Serialise(writer, indent + 1);
      if (++it != end)
        writer.Write(',');
      writer.NewLine();
    } else {
      writer.Format("\"%s\":", it->first.c_str());
      it->second->Serialise(writer, indent);
      if (++it != end)
        writer.Write(',');
    }
  }

  if (indent >= 0)
    SerialiseIndent(writer, indent);

  writer.Write('}');
}
Esempio n. 2
0
void
Array::Serialise(TextWriter &writer, int indent) const
{
  writer.Write('[');
  if (indent >= 0)
    writer.NewLine();

  for (auto it = children.begin(), end = children.end(); it != end;) {
    if (indent >= 0) {
      SerialiseIndent(writer, indent + 1);
      (*it)->Serialise(writer, indent + 1);

      if (++it != end)
        writer.Write(',');

      writer.NewLine();
    } else {
      (*it)->Serialise(writer, indent);

      if (++it != end)
        writer.Write(',');
    }
  }

  if (indent >= 0)
    SerialiseIndent(writer, indent);

  writer.Write(']');
}
Esempio n. 3
0
void
GRecord::WriteTo(TextWriter &writer) const
{
  char digest[DIGEST_LENGTH + 1];
  GetDigest(digest);

  static constexpr size_t chars_per_line = 16;
  static_assert(DIGEST_LENGTH % chars_per_line == 0, "wrong digest length");

  for (const char *i = digest, *end = digest + DIGEST_LENGTH;
       i != end; i += chars_per_line) {
    writer.Write('G');
    writer.Write(i, chars_per_line);
    writer.NewLine();
  }
}