flatbuffer base

This commit is contained in:
2026-03-30 16:18:21 +03:00
parent 9a4b78f272
commit d83cb7fe7b
41 changed files with 1553 additions and 491 deletions

View File

@@ -1,10 +1,16 @@
#ifndef __PROTO_HANDLERS_CONTROL_H__
#define __PROTO_HANDLERS_CONTROL_H__
#include "proto/msg.h"
#include <stdint.h>
#include "client.h"
#include "context.h"
#include "proto/dial.h"
#include "control_reader.h"
void handleIncomingControlMessage(BaseMessage* msg, EmulContext* emulContext);
void handleIncomingCtrlMessage(
hmmmm_ctrl_CtrlClientMessage_table_t msg,
uint64_t nonce,
ClientContext* ctx,
EmulContext* emulContext);
#endif //ifndef __PROTO_HANDLERS_CONTROL_H__
#endif // __PROTO_HANDLERS_CONTROL_H__

View File

@@ -1,10 +1,16 @@
#ifndef __PROTO_HANDLERS_MEM_H__
#define __PROTO_HANDLERS_MEM_H__
#include "proto/msg.h"
#include <stdint.h>
#include "context.h"
#include "client.h"
#include "proto/dial.h"
#include "mem_reader.h"
void handleIncomingMemMessage(BaseMessage* msg, ClientContext* ctx, EmulContext* emulContext);
#endif //ifndef __PROTO_HANDLERS_MEM_H__
void handleIncomingMemMessage(
hmmmm_mem_MemClientMessage_table_t msg,
uint64_t nonce,
ClientContext* ctx,
EmulContext* emulContext);
#endif // __PROTO_HANDLERS_MEM_H__

View File

@@ -1,12 +1,19 @@
#ifndef __PROTO_HANDLERS_STREAM_H__
#define __PROTO_HANDLERS_STREAM_H__
#include "proto/msg.h"
#include <stdint.h>
#include "context.h"
#include "client.h"
#include "proto/dial.h"
#include "stream_reader.h"
void unregisterClientStream(EmulContext* emulContext, ClientContext* ctx, uint32_t regId);
void unregisterClientStreams(EmulContext* emulContext, ClientContext* ctx);
void handleIncomingStreamMessage(BaseMessage* msg, ClientContext* ctx, EmulContext* emulContext);
#endif //ifndef __PROTO_HANDLERS_STREAM_H__
void handleIncomingStreamMessage(
hmmmm_stream_StreamClientMessage_table_t msg,
uint64_t nonce,
ClientContext* ctx,
EmulContext* emulContext);
#endif // __PROTO_HANDLERS_STREAM_H__

View File

@@ -2,25 +2,59 @@
#define __PROTO_MSG_H__
#include "wsServer/include/ws.h"
#include <stdint.h>
#include <stdlib.h>
#include "flatcc/flatcc_builder.h"
// Raw FlatBuffers frame copied from the WS thread, queued to the main loop.
typedef struct {
uint8_t* data;
size_t size;
} FbMessage;
typedef struct {
ws_cli_conn_t clientIdx;
uint8_t* msg;
size_t msgLen;
uint8_t* msg;
size_t msgLen;
} OutgoingMessage;
typedef struct {
uint64_t nonce;
uint8_t packetType;
uint8_t payloadHeader;
const void* payload;
size_t payloadLen;
} BaseMessage;
// Build a ServerMessage{AuthResponse} frame. Returns a malloc'd buffer;
// ownership is transferred to the caller (dispatchOutgoingMessage will free it).
uint8_t* fb_build_auth_response(uint64_t nonce, uint64_t seat_id, size_t* len_out);
BaseMessage* parseMessage(const uint8_t* bytes, size_t size);
uint8_t* createControlNotifyMessage(uint64_t nonce, uint64_t clockCounter, uint8_t newEmulState, size_t* lenOut);
uint8_t* createDoneRegMessage(uint64_t nonce, uint8_t X, uint64_t devId, uint64_t segId, uint64_t startAddr, uint64_t segLength, uint32_t regId, size_t* lenOut);
uint8_t* createStreamSegmentPush(uint8_t mode, uint32_t regId, uint64_t clockCounter, uint8_t* payload, size_t payloadLen, size_t* lenOut);
// Build a ServerMessage{CtrlServerMessage{ExecNotifyMessage}} frame.
uint8_t* fb_build_exec_notify(uint64_t nonce, uint64_t tclk, uint8_t state, size_t* len_out);
#endif //ifndef __PROTO_MSG_H__
// Build a ServerMessage{StreamServerMessage{StreamDataPush}} frame.
// B must be a pre-initialized flatcc_builder_t; it is reset before use
// so the caller does not need to reset it manually between calls.
uint8_t* fb_build_stream_data_push(
flatcc_builder_t *B,
uint64_t nonce, uint32_t stream_id, uint64_t tclk,
const uint8_t* data, size_t data_len,
size_t* len_out);
// Build a ServerMessage{CtrlServerMessage{SetupBuf}} frame (echo back to client).
uint8_t* fb_build_setup_buf(uint64_t nonce, uint32_t lost_buf_size,
uint64_t client_lifetime_ticks, size_t* len_out);
// Build a ServerMessage{CtrlServerMessage{OrphanedResponse{entries=[]}}} frame.
uint8_t* fb_build_orphaned_response(uint64_t nonce, size_t* len_out);
// Build a ServerMessage{CtrlServerMessage{LostMessagesResponse{seat_id, messages=[]}}} frame.
uint8_t* fb_build_lost_messages_response(uint64_t nonce, uint64_t seat_id, size_t* len_out);
// Build a ServerMessage{MemServerMessage{MemReadResponse}} frame.
uint8_t* fb_build_mem_read_response(
uint64_t nonce, uint64_t tclk,
uint32_t device_id, uint32_t seg_id, uint32_t offset,
const uint8_t* data, size_t data_len,
size_t* len_out);
// Build a ServerMessage{StreamServerMessage{StreamRegConfirm}} frame.
uint8_t* fb_build_stream_reg_confirm(
uint64_t nonce, uint32_t stream_id,
uint32_t device_id, uint32_t seg_id, uint32_t offset, uint32_t length,
uint8_t mode, size_t* len_out);
#endif // __PROTO_MSG_H__