Esempio n. 1
0
void PJson::write(const Value& value, const MemBlock& name, Out& out)
{
    auto type = value.type();
    this->insert_spacing(type, out);

    this->scope_closed = false;

    if(this->scope_type != Type::Null &&
       this->scope_type != Type::Array &&
       type != Type::Scope_End) {

        insert_in_quotes(out, name);
        out.write(':');

        if(!this->compact) {
            out.write(' ');
        }
    }

    if(TpTools::is_scope(type)) {

        auto c = type == Type::Array ? '[' : '{';

        out.write(c);
        this->scope_stack.push(type);
        this->scope_closed = true;
        this->scope_type = type;

        return;
    }

    if(type == Type::Scope_End) {

        assert(!this->scope_stack.empty());

        auto c = this->scope_type == Type::Array ? ']' : '}';

        out.write(c);
        this->scope_stack.pop();

        this->scope_type = !this->scope_stack.empty()
            ? this->scope_stack.top()
            : Type::Null;

        return;
    }

    if(TpTools::is_scalar(type)) {
        out.write(value.data(), value.size());

    } else {
        bool escape = type != Type::Binary;
        insert_in_quotes(out, { value.data(), value.size() }, escape);
    }
}
Esempio n. 2
0
 void transfer(cyclic_buffer<capacity>& buf, Out& out) {
     if (!buf.isEmpty()) {
         char buffer[TRANSFER_CHUNK_SIZE];
         size_t s = buf.seek(buffer, sizeof(buffer));
         size_t numWritten = out.write(buffer, s);
         buf.skip(numWritten);
     }
 }
Esempio n. 3
0
void PJson::insert_spacing(Type type, Out& out)
{
    if(!this->scope_closed && type != Type::Scope_End) {
        out.write(',');
    }
    if(this->compact) {
        return;
    }
    auto depth = type == Type::Scope_End
        ? this->scope_stack.size() - 1
        : this->scope_stack.size();

    if(this->scope_stack.size() > 0) {
        out.write('\n');
    }

    out.write_times(depth, '\t');
}
Esempio n. 4
0
void MessageQueue::append(Out& stream) const
{
  stream.write(queue.buf, queue.usedSize);
}
Esempio n. 5
0
void MessageQueue::write(Out& stream) const
{
  stream << queue.usedSize << queue.numberOfMessages;
  stream.write(queue.buf, queue.usedSize);
}