blob: 7e20d7521bff1ece1b2cc539d98abdd15fc83975 (
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
59
60
61
62
63
64
65
66
67
68
69
|
/*
** upb::pb::TextPrinter (upb_textprinter)
**
** Handlers for writing to protobuf text format.
*/
#ifndef UPB_TEXT_H_
#define UPB_TEXT_H_
#include "upb/sink.h"
#ifdef __cplusplus
namespace upb {
namespace pb {
class TextPrinterPtr;
} /* namespace pb */
} /* namespace upb */
#endif
/* upb_textprinter ************************************************************/
struct upb_textprinter;
typedef struct upb_textprinter upb_textprinter;
#ifdef __cplusplus
extern "C" {
#endif
/* C API. */
upb_textprinter *upb_textprinter_create(upb_arena *arena, const upb_handlers *h,
upb_bytessink output);
void upb_textprinter_setsingleline(upb_textprinter *p, bool single_line);
upb_sink upb_textprinter_input(upb_textprinter *p);
upb_handlercache *upb_textprinter_newcache(void);
#ifdef __cplusplus
} /* extern "C" */
class upb::pb::TextPrinterPtr {
public:
TextPrinterPtr(upb_textprinter* ptr) : ptr_(ptr) {}
/* The given handlers must have come from NewHandlers(). It must outlive the
* TextPrinter. */
static TextPrinterPtr Create(Arena *arena, upb::HandlersPtr *handlers,
BytesSink output) {
return TextPrinterPtr(
upb_textprinter_create(arena->ptr(), handlers->ptr(), output.sink()));
}
void SetSingleLineMode(bool single_line) {
upb_textprinter_setsingleline(ptr_, single_line);
}
Sink input() { return upb_textprinter_input(ptr_); }
/* If handler caching becomes a requirement we can add a code cache as in
* decoder.h */
static HandlerCache NewCache() {
return HandlerCache(upb_textprinter_newcache());
}
private:
upb_textprinter* ptr_;
};
#endif
#endif /* UPB_TEXT_H_ */
|