summaryrefslogtreecommitdiff
path: root/src/dged/jsonrpc.h
blob: 2ac2787e1db051e56d7b4ebb91b7fa584f0ded23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef _JSONRPC_H
#define _JSONRPC_H

#include <stdint.h>

#include "json.h"
#include "s8.h"

enum jsonrpc_type {
  Jsonrpc_Request,
  Jsonrpc_Response,
  Jsonrpc_Notification,
};

struct jsonrpc_request {
  struct json_value id;
  struct s8 method;
  struct json_value params;
};

struct jsonrpc_error {
  int code;
  struct s8 message;
  struct json_value data;
};

struct jsonrpc_notification {
  struct s8 method;
  struct json_value params;
};

struct jsonrpc_response {
  struct json_value id;
  bool ok;
  union jsonrpc_value {
    struct json_value result;
    struct jsonrpc_error error;
  } value;
};

struct jsonrpc_message {
  enum jsonrpc_type type;
  union jsonrpc_msg {
    struct jsonrpc_request request;
    struct jsonrpc_response response;
    struct jsonrpc_notification notification;
  } message;

  struct json_value document;
};

struct jsonrpc_message jsonrpc_parse(const uint8_t *buf, uint64_t size);
struct s8 jsonrpc_format_request(struct json_value id, struct s8 method,
                                 struct s8 params);
struct s8 jsonrpc_format_response(struct json_value id, struct s8 result);
struct s8 jsonrpc_format_notification(struct s8 method, struct s8 params);

#endif