コード例 #1
0
ファイル: json_over_uttp.cpp プロジェクト: swuecho/igblast
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::SendNode(const CJsonNode& node)
{
    switch (node.GetNodeType()) {
    case CJsonNode::eObject:
        m_OutputStack.push_back(m_CurrentOutputNode);
        m_CurrentOutputNode.m_Node = node;
        m_CurrentOutputNode.m_ObjectIterator = node.GetObject().begin();
        m_SendHashValue = false;
        if (!m_UTTPWriter.SendControlSymbol('{'))
            return false;
        break;

    case CJsonNode::eArray:
        m_OutputStack.push_back(m_CurrentOutputNode);
        m_CurrentOutputNode.m_Node = node;
        m_CurrentOutputNode.m_ArrayIterator = node.GetArray().begin();
        if (!m_UTTPWriter.SendControlSymbol('['))
            return false;
        break;

    case CJsonNode::eString:
        {
            string str(node.GetString());
            if (!m_UTTPWriter.SendChunk(str.data(), str.length(), false))
                return false;
        }
        break;

    case CJsonNode::eNumber:
        if (!m_UTTPWriter.SendNumber(node.GetNumber()))
            return false;
        break;

    case CJsonNode::eBoolean:
        if (!m_UTTPWriter.SendControlSymbol(node.GetBoolean() ? 'Y' : 'N'))
            return false;
        break;

    case CJsonNode::eNull:
        if (!m_UTTPWriter.SendControlSymbol('U'))
            return false;
    }

    return true;
}
コード例 #3
0
ファイル: json_over_uttp.cpp プロジェクト: swuecho/igblast
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');
    }
}