61#define JSON_RPC_CODE_PARSE_ERROR (-32700)
64#define JSON_RPC_CODE_INVALID_REQUEST (-32600)
67#define JSON_RPC_CODE_METHOD_NOT_FOUND (-32601)
70#define JSON_RPC_CODE_INVALID_PARAMS (-32602)
73#define JSON_RPC_CODE_INTERNAL_ERROR (-32603)
206typedef void *(*mjrpc_malloc_func)(
size_t size);
227typedef char *(*mjrpc_strdup_func)(
const char *str);
509 const char *method_name,
void *arg2func);
577 void (*callback)(
const char *method_name,
void *
arg,
652 const cJSON *request_cjson,
int *ret_code);
char * mjrpc_request_str(const char *method, cJSON *params, cJSON *id)
Build a JSON-RPC request as a string.
cJSON * mjrpc_request_cjson(const char *method, cJSON *params, cJSON *id)
Build a JSON-RPC request as a cJSON object.
int mjrpc_destroy_handle(mjrpc_handle_t *handle)
Destroy a JSON-RPC handle and free all associated memory.
mjrpc_handle_t * mjrpc_create_handle(size_t initial_capacity)
Create a new JSON-RPC handle.
int mjrpc_set_memory_hooks(mjrpc_malloc_func malloc_func, mjrpc_free_func free_func, mjrpc_strdup_func strdup_func)
Set custom memory management functions.
void(* mjrpc_free_func)(void *ptr)
Function pointer type for custom memory deallocation.
void *(* mjrpc_malloc_func)(size_t size)
Function pointer type for custom memory allocation.
char *(* mjrpc_strdup_func)(const char *str)
Function pointer type for custom string duplication.
int mjrpc_del_method(mjrpc_handle_t *handle, const char *method_name)
Unregister an RPC method.
int mjrpc_enum_methods(const mjrpc_handle_t *handle, void(*callback)(const char *method_name, void *arg, void *user_data), void *user_data)
Enumerate all registered methods.
int mjrpc_add_method(mjrpc_handle_t *handle, mjrpc_func function_pointer, const char *method_name, void *arg2func)
Register a new RPC method.
size_t mjrpc_get_method_count(const mjrpc_handle_t *handle)
Get the number of registered methods.
cJSON * mjrpc_process_cjson(const mjrpc_handle_t *handle, const cJSON *request_cjson, int *ret_code)
Process a JSON-RPC request cJSON object.
char * mjrpc_process_str(const mjrpc_handle_t *handle, const char *request_str, int *ret_code)
Process a JSON-RPC request string.
cJSON * mjrpc_response_error(int code, const char *message, cJSON *id)
Build an error JSON-RPC response.
cJSON * mjrpc_response_ok(cJSON *result, cJSON *id)
Build a successful JSON-RPC response with result.
mjrpc_error_return
Reserved for implementation-defined server-errors (-32000 to -32099)
@ MJRPC_RET_ERROR_NOT_FOUND
Requested method not found.
@ MJRPC_RET_OK_NOTIFICATION
Operation completed successfully (notification request)
@ MJRPC_RET_ERROR_MEM_ALLOC_FAILED
Memory allocation failed.
@ MJRPC_RET_ERROR_HANDLE_NOT_INITIALIZED
Handle not initialized.
@ MJRPC_RET_ERROR_NOT_OBJ_ARY
Request is not a JSON object or array.
@ MJRPC_RET_ERROR_EMPTY_REQUEST
Empty request received.
@ MJRPC_RET_ERROR_PARSE_FAILED
JSON parsing failed.
@ MJRPC_RET_OK
Operation completed successfully.
@ MJRPC_RET_ERROR_INVALID_PARAM
Invalid parameter provided.
cJSON *(* mjrpc_func)(mjrpc_func_ctx_t *context, cJSON *params, cJSON *id)
Function pointer type for RPC method implementations.
struct mjrpc_handle mjrpc_handle_t
Typedef for struct mjrpc_handle for convenience.
Context structure passed to RPC method callback functions.
int32_t error_code
Error code to be set by the method implementation (0 = no error)
char * error_message
Error message to be set by the method implementation (will be freed automatically)
int params_type
Parameter type: 0=object, 1=array, 2=no params.
void * data
User data pointer passed during method registration.
Main handle structure for managing RPC methods.
size_t capacity
Total capacity of the hash table.
struct mjrpc_method * methods
Array of registered methods (hash table)
size_t size
Current number of registered methods.
Internal structure representing a registered RPC method.
void * arg
User argument passed to the function.
mjrpc_func func
Function pointer to method implementation.
int state
Internal state for hash table management.