示例#1
0
static void s_Repr_Value(CNcbiOstrstream& oss, const CJsonNode& node)
{
    switch (node.GetNodeType()) {
    case CJsonNode::eObject:
        oss << '{';
        s_Repr_Object(oss, node);
        oss << '}';
        break;
    case CJsonNode::eArray:
        oss << '[';
        s_Repr_Array(oss, node);
        oss << ']';
        break;
    case CJsonNode::eString:
        oss << '"' << NStr::PrintableString(node.AsString()) << '"';
        break;
    case CJsonNode::eInteger:
        oss << node.AsInteger();
        break;
    case CJsonNode::eDouble:
        oss << node.AsDouble();
        break;
    case CJsonNode::eBoolean:
        oss << (node.AsBoolean() ? "true" : "false");
        break;
    default: /* case CJsonNode::eNull: */
        oss << "null";
    }
}
示例#2
0
bool CJsonOverUTTPWriter::x_SendNode(const CJsonNode& node)
{
    switch (node.GetNodeType()) {
    case CJsonNode::eObject:
        x_PushNode(node);
        m_CurrentOutputNode.m_Iterator = node.Iterate();
        m_SendHashValue = false;
        return m_UTTPWriter.SendControlSymbol('{');

    case CJsonNode::eArray:
        x_PushNode(node);
        m_CurrentOutputNode.m_Iterator = node.Iterate();
        return m_UTTPWriter.SendControlSymbol('[');

    case CJsonNode::eString:
        {
            const string& str(static_cast<const SJsonStringNodeImpl*>(
                (const SJsonNodeImpl*) node)->m_String);
            return m_UTTPWriter.SendChunk(str.data(), str.length(), false);
        }

    case CJsonNode::eInteger:
        return m_UTTPWriter.SendNumber(node.AsInteger());

    case CJsonNode::eDouble:
        m_Double = node.AsDouble();
        if (!m_UTTPWriter.SendControlSymbol(DOUBLE_PREFIX)) {
            x_PushNode(node);
            return false;
        }
        return m_UTTPWriter.SendRawData(&m_Double, sizeof(m_Double));

    case CJsonNode::eBoolean:
        return m_UTTPWriter.SendControlSymbol(node.AsBoolean() ? 'Y' : 'N');

    default: /* case CJsonNode::eNull: */
        return m_UTTPWriter.SendControlSymbol('U');
    }
}