forked from facebook/watchman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatchman_pdu.h
98 lines (85 loc) · 2.6 KB
/
watchman_pdu.h
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* Copyright 2012-present Facebook, Inc.
* Licensed under the Apache License, Version 2.0 */
#pragma once
enum w_pdu_type {
need_data,
is_json_compact,
is_json_pretty,
is_bser,
is_bser_v2
};
struct watchman_json_buffer {
char *buf;
uint32_t allocd;
uint32_t rpos, wpos;
enum w_pdu_type pdu_type;
uint32_t capabilities;
~watchman_json_buffer();
watchman_json_buffer();
watchman_json_buffer(const watchman_json_buffer&) = delete;
watchman_json_buffer& operator=(const watchman_json_buffer&) = delete;
void clear();
bool jsonEncodeToStream(const json_ref& json, w_stm_t stm, int flags);
bool bserEncodeToStream(
uint32_t bser_version,
uint32_t bser_capabilities,
const json_ref& json,
w_stm_t stm);
bool pduEncodeToStream(
enum w_pdu_type pdu_type,
uint32_t capabilities,
const json_ref& json,
w_stm_t stm);
json_ref decodeNext(w_stm_t stm, json_error_t* jerr);
bool passThru(
enum w_pdu_type output_pdu,
uint32_t output_capabilities,
watchman_json_buffer* output_pdu_buf,
w_stm_t stm);
private:
bool readAndDetectPdu(w_stm_t stm, json_error_t* jerr);
inline uint32_t shuntDown();
bool fillBuffer(w_stm_t stm);
inline enum w_pdu_type detectPdu();
json_ref readJsonPrettyPdu(w_stm_t stm, json_error_t* jerr);
json_ref readJsonPdu(w_stm_t stm, json_error_t* jerr);
json_ref readBserPdu(w_stm_t stm, uint32_t bser_version, json_error_t* jerr);
json_ref decodePdu(w_stm_t stm, json_error_t* jerr);
bool decodePduInfo(
w_stm_t stm,
uint32_t bser_version,
json_int_t* len,
json_int_t* bser_capabilities,
json_error_t* jerr);
bool streamPdu(w_stm_t stm, json_error_t* jerr);
bool streamUntilNewLine(w_stm_t stm);
bool streamN(w_stm_t stm, json_int_t len, json_error_t* jerr);
};
typedef struct bser_ctx {
uint32_t bser_version;
uint32_t bser_capabilities;
json_dump_callback_t dump;
} bser_ctx_t;
typedef struct watchman_json_buffer w_jbuffer_t;
#define BSER_MAGIC "\x00\x01"
#define BSER_V2_MAGIC "\x00\x02"
// BSERv2 capabilities. Must be powers of 2.
#define BSER_CAP_DISABLE_UNICODE 0x1
#define BSER_CAP_DISABLE_UNICODE_FOR_ERRORS 0x2
int w_bser_write_pdu(
const uint32_t bser_version,
const uint32_t capabilities,
json_dump_callback_t dump,
const json_ref& json,
void* data);
int w_bser_dump(const bser_ctx_t* ctx, const json_ref& json, void* data);
bool bunser_int(
const char* buf,
json_int_t avail,
json_int_t* needed,
json_int_t* val);
json_ref bunser(
const char* buf,
const char* end,
json_int_t* needed,
json_error_t* jerr);