TuyaOS
json_rpc.h
1
11#ifndef __JSON_RPC_H__
12#define __JSON_RPC_H__
13
14
15#include <stdint.h>
16#include "tuya_cloud_types.h"
17#include "cJSON.h"
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23
24#define JRPC_PASER_ERROR -32700
25#define JPRC_INVALID_REQUEST -32600
26#define JPRC_METHOD_NOT_FOUND -32601
27
28
29typedef enum {
30 JRPC_REQUEST = 0,
31 JRPC_RESPONSE,
32 JRPC_NOTIFICATION,
33 JRPC_ERROR,
34 JRPC_WRONG_OBJECT
35} jrpc_cmd_t;
36
37typedef enum {
38 JRPC_PARAMS = 0,
39 JRPC_RESULT
40} jrpc_type_t;
41
42typedef struct {
43 cJSON *json;
44 uint8_t *binary;
45 jrpc_cmd_t cmd;
47
49
59int jrpc_create_request(jrpc_msg_t *msg, char *method, int id);
68int jrpc_create_response(jrpc_msg_t *msg, int id);
79int jrpc_create_error(jrpc_msg_t *msg, int id, int code, char *message);
88int jrpc_create_notification(jrpc_msg_t *msg, char *method);
89
100int jrpc_write_int(jrpc_msg_t *msg, jrpc_type_t type, char *key, int value);
111int jrpc_write_string(jrpc_msg_t *msg, jrpc_type_t type, char *key, char *value);
112
123int jrpc_read_int(jrpc_msg_t *msg, jrpc_type_t type, char *key, int *value);
134int jrpc_read_string(jrpc_msg_t *msg, jrpc_type_t type, char *key, char **value);
143int jrpc_read_method(jrpc_msg_t *msg, char **method);
153int jrpc_read_error(jrpc_msg_t *msg, int *code, char **message);
165int jrpc_write_binary(jrpc_msg_t *msg, jrpc_type_t type, char *key, uint8_t *binary, uint16_t size);
177int jrpc_read_binary(jrpc_msg_t *msg, jrpc_type_t type, char *key, uint8_t **binary, uint16_t *size);
178
185void jrpc_delete(jrpc_msg_t *msg);
186
187#ifdef __cplusplus
188}
189#endif
190
191#endif
Definition: json_rpc.h:42
Definition: ty_cJSON.h:104