void ConnectionHandler::SendProtobufMessage(UInt32 opcode, google::protobuf::Message &msg) {
		// send length
		UInt32Bytes length{ByteOrder::toLittleEndian(static_cast<UInt32>(msg.ByteSize()))};
		socket_.sendBytes(length.bytes, 4);
		// send opcode
		UInt32Bytes opcodeBytes{Poco::ByteOrder::toLittleEndian(opcode)};
		socket_.sendBytes(opcodeBytes.bytes, 4);
		// send data
		socket_.sendBytes(msg.SerializeAsString().data(), msg.ByteSize());
	}
Exemplo n.º 2
0
    void Client::sendPacket(google::protobuf::Message &msg, const std::string &packetID, bool reliable)
    {
        std::string buffer(packetID + msg.SerializeAsString());

        int enetFlags = 0;

        if(reliable)
            enetFlags = ENET_PACKET_FLAG_RELIABLE;

        ENetPacket *packet = enet_packet_create(&buffer[0u], buffer.length(), enetFlags);
        enet_peer_send(m_serverPeer, 1, packet);
    }
Exemplo n.º 3
0
void ProtoClientConnection::sendMessage(const google::protobuf::Message &message)
{
	std::string serializedReply = message.SerializeAsString();
	uint32_t size = serializedReply.size();
	uint8_t sizeData[] = {uint8_t(size >> 24), uint8_t(size >> 16), uint8_t(size >> 8), uint8_t(size)};
Exemplo n.º 4
0
void Messenger::send_message(MessageType msg_type, const ::google::protobuf::Message& message) {
    auto type = static_cast<std::int32_t>(msg_type);
    spdlog::get("console")->info("send message {0}\n{1}", type, message.Utf8DebugString());
    auto* raw_message = new RawMessage(type, message.SerializeAsString());
    socket_rpc_send_and_recv(raw_message);
}