Exemplo n.º 1
0
    inline std::string serialize_to_json(const message& m)
    {
        std::ostringstream result;

        result << "{ ";

        result
            << format::quote << "error" << ':' << "false" << ','
            << format::quote << "data" << ':';

        result << "{ ";

        result
            << format::quote << "timestamp" << ':' << format::quote << format::timestamp(m.timestamp()) << ','
            << format::quote << "id" << ':' << format::quote << m.id() << ','
            << format::quote << "type" << ':' << format::quote << m.type();

        switch (m.type())
        {
            case message::HEARTBEAT:
                {
                    result << ','
                        << format::quote << "heartbeat" << ':' << m.heartbeat();
                }
                break;

            case message::STATUS:
                {
                    result << ','
                        << format::quote << "status" << ':' << format::quote << "not implemented";
                }
                break;

            case message::USER:
                {
                    result << ','
                        << format::quote << "user" << ':' << format::quote << "not implemented";
                }
                break;

            default:
                break;
        }

        result << " }";

        result << " }";

        return result.str();
    }
Exemplo n.º 2
0
        void send_message(const message& msg) {
            assert(output);

            log_message("<==", msg.id(), msg.request_id(), msg.name(), msg.json_text(), msg.blob());

            if (!connected) {
                return;
            }

            auto& payload = msg.payload();
            boost::endian::little_uint32_buf_t msg_size(static_cast<uint32_t>(payload.size()));

            std::lock_guard<std::mutex> lock(output_lock);
            if (fwrite(&msg_size, sizeof msg_size, 1, output) == 1) {
                if (fwrite(payload.data(), payload.size(), 1, output) == 1) {
                    fflush(output);
                    return;
                }
            }

            disconnect();
        }
Exemplo n.º 3
0
 fc::ripemd160 id_on_server() {
     return content.id();
 }