2017-06-30 16:18:54 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// This is to wrap the platform specific kinds of connect/read/write.
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2017-07-10 15:25:47 -07:00
|
|
|
enum class OPCODE : uint32_t {
|
|
|
|
HANDSHAKE = 0,
|
|
|
|
FRAME = 1,
|
|
|
|
CLOSE = 2,
|
|
|
|
};
|
|
|
|
|
2017-06-30 16:18:54 -07:00
|
|
|
struct RpcMessageFrame {
|
2017-07-10 15:25:47 -07:00
|
|
|
OPCODE opcode;
|
2017-06-30 16:18:54 -07:00
|
|
|
uint32_t length;
|
2017-07-10 15:25:47 -07:00
|
|
|
char message[64 * 1024 - 8];
|
2017-06-30 16:18:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RpcConnection {
|
|
|
|
void (*onConnect)() = nullptr;
|
|
|
|
void (*onDisconnect)() = nullptr;
|
2017-07-10 15:25:47 -07:00
|
|
|
char appId[64];
|
2017-06-30 16:18:54 -07:00
|
|
|
|
2017-07-10 15:25:47 -07:00
|
|
|
static RpcConnection* Create(const char* applicationId);
|
2017-06-30 16:18:54 -07:00
|
|
|
static void Destroy(RpcConnection*&);
|
|
|
|
void Open();
|
|
|
|
void Close();
|
|
|
|
void Write(const void* data, size_t length);
|
|
|
|
|
|
|
|
RpcMessageFrame* GetNextFrame();
|
|
|
|
void WriteFrame(RpcMessageFrame* frame);
|
|
|
|
};
|