summaryrefslogtreecommitdiff
path: root/upb/pb/decoder.h
blob: c645688d4555ad006555f6d178baadc8be8b0555 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * upb - a minimalist implementation of protocol buffers.
 *
 * Copyright (c) 2009-2010 Google Inc.  See LICENSE for details.
 * Author: Josh Haberman <jhaberman@gmail.com>
 *
 * upb::Decoder implements a high performance, streaming decoder for protobuf
 * data that works by parsing input data one buffer at a time and calling into
 * a upb::Handlers.
 */

#ifndef UPB_DECODER_H_
#define UPB_DECODER_H_

#include "upb/sink.h"

// The maximum that any submessages can be nested.  Matches proto2's limit.
// At the moment this specifies the size of several statically-sized arrays
// and therefore setting it high will cause more memory to be used.  Will
// be replaced by a runtime-configurable limit and dynamically-resizing arrays.
// TODO: make this a runtime-settable property of Decoder.
#define UPB_DECODER_MAX_NESTING 64

#ifdef __cplusplus
namespace upb {
namespace pb {

// Frame type that encapsulates decoder state.
class Decoder;

// Resets the sink of the Decoder.  This must be called at  least once before
// the decoder can be used.  It may only be called with the decoder is in a
// state where it was just created or reset.  The given sink must be from the
// same pipeline as this decoder.
inline bool ResetDecoderSink(Decoder* d, Sink* sink);

// Gets the handlers suitable for parsing protobuf data according to the given
// destination handlers.  The protobuf schema to parse is taken from dest.
inline const upb::Handlers *GetDecoderHandlers(const upb::Handlers *dest,
                                               bool allowjit,
                                               const void *owner);

// Returns true if these handlers represent a upb::pb::Decoder.
bool IsDecoder(const upb::Handlers *h);

// Returns true if IsDecoder(h) and the given handlers have JIT code.
inline bool HasJitCode(const upb::Handlers* h);

// Returns the destination handlers if IsDecoder(h), otherwise returns NULL.
const upb::Handlers* GetDestHandlers(const upb::Handlers* h);

}  // namespace pb
}  // namespace upb

typedef upb::pb::Decoder upb_pbdecoder;

extern "C" {
#else
struct upb_pbdecoder;
typedef struct upb_pbdecoder upb_pbdecoder;
#endif

// C API.
const upb_frametype *upb_pbdecoder_getframetype();
bool upb_pbdecoder_resetsink(upb_pbdecoder *d, upb_sink *sink);
const upb_handlers *upb_pbdecoder_gethandlers(const upb_handlers *dest,
                                              bool allowjit,
                                              const void *owner);
bool upb_pbdecoder_isdecoder(const upb_handlers *h);
bool upb_pbdecoder_hasjitcode(const upb_handlers *h);
const upb_handlers *upb_pbdecoder_getdesthandlers(const upb_handlers *h);

// C++ implementation details. /////////////////////////////////////////////////

#ifdef __cplusplus
}  // extern "C"

namespace upb {

namespace pb {
inline bool ResetDecoderSink(Decoder* r, Sink* sink) {
  return upb_pbdecoder_resetsink(r, sink);
}
inline const upb::Handlers* GetDecoderHandlers(const upb::Handlers* dest,
                                               bool allowjit,
                                               const void* owner) {
  return upb_pbdecoder_gethandlers(dest, allowjit, owner);
}
inline bool IsDecoder(const upb::Handlers* h) {
  return upb_pbdecoder_isdecoder(h);
}
inline bool HasJitCode(const upb::Handlers* h) {
  return upb_pbdecoder_hasjitcode(h);
}
inline const upb::Handlers* GetDestHandlers(const upb::Handlers* h) {
  return upb_pbdecoder_getdesthandlers(h);
}
}  // namespace pb
}  // namespace upb
#endif

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