summaryrefslogtreecommitdiff
path: root/upb/pb/textprinter.h
blob: 97e01f70c945664950920959630831980c55e5ca (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * upb - a minimalist implementation of protocol buffers.
 *
 * Copyright (c) 2009 Google Inc.  See LICENSE for details.
 * Author: Josh Haberman <jhaberman@gmail.com>
 */

#ifndef UPB_TEXT_H_
#define UPB_TEXT_H_

#include "upb/sink.h"

#ifdef __cplusplus
namespace upb {
namespace pb {
class TextPrinter;
}  // namespace pb
}  // namespace upb
#endif

UPB_DECLARE_TYPE(upb::pb::TextPrinter, upb_textprinter);

UPB_DEFINE_CLASS0(upb::pb::TextPrinter,
 public:
  // The given handlers must have come from NewHandlers().  It must outlive the
  // TextPrinter.
  explicit TextPrinter(const upb::Handlers* handlers);

  void SetSingleLineMode(bool single_line);

  bool ResetOutput(BytesSink* output);
  Sink* input();

  // If handler caching becomes a requirement we can add a code cache as in
  // decoder.h
  static reffed_ptr<const Handlers> NewHandlers(const MessageDef* md);

 private:
,
UPB_DEFINE_STRUCT0(upb_textprinter,
  upb_sink input_;
  upb_bytessink *output_;
  int indent_depth_;
  bool single_line_;
  void *subc;
));

UPB_BEGIN_EXTERN_C  // {

// C API.
void upb_textprinter_init(upb_textprinter *p, const upb_handlers *h);
void upb_textprinter_uninit(upb_textprinter *p);
bool upb_textprinter_resetoutput(upb_textprinter *p, upb_bytessink *output);
void upb_textprinter_setsingleline(upb_textprinter *p, bool single_line);
upb_sink *upb_textprinter_input(upb_textprinter *p);

const upb_handlers *upb_textprinter_newhandlers(const upb_msgdef *m,
                                                const void *owner);

UPB_END_EXTERN_C  // }

#ifdef __cplusplus

namespace upb {
namespace pb {
inline TextPrinter::TextPrinter(const upb::Handlers* handlers) {
  upb_textprinter_init(this, handlers);
}
inline void TextPrinter::SetSingleLineMode(bool single_line) {
  upb_textprinter_setsingleline(this, single_line);
}
inline bool TextPrinter::ResetOutput(BytesSink* output) {
  return upb_textprinter_resetoutput(this, output);
}
inline Sink* TextPrinter::input() {
  return upb_textprinter_input(this);
}
inline reffed_ptr<const Handlers> TextPrinter::NewHandlers(
    const MessageDef *md) {
  const Handlers* h = upb_textprinter_newhandlers(md, &h);
  return reffed_ptr<const Handlers>(h, &h);
}
}  // namespace pb
}  // namespace upb

#endif

#endif  /* UPB_TEXT_H_ */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback