summaryrefslogtreecommitdiff
path: root/upb/pb/decoder.h
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2019-01-09 22:40:50 -0800
committerJoshua Haberman <jhaberman@gmail.com>2019-01-09 22:40:50 -0800
commit0553eff64a87eceff0de3b6260b4f2d45b61703a (patch)
tree5b051740c041786655d1794a5034ccf20928e8ee /upb/pb/decoder.h
parent31e0997c1abaa531505d28e36473f1c972ca0849 (diff)
upb_refcounted is gone! Some tests still to fix.
Diffstat (limited to 'upb/pb/decoder.h')
-rw-r--r--upb/pb/decoder.h128
1 files changed, 30 insertions, 98 deletions
diff --git a/upb/pb/decoder.h b/upb/pb/decoder.h
index 7c1877a..1a00801 100644
--- a/upb/pb/decoder.h
+++ b/upb/pb/decoder.h
@@ -30,10 +30,7 @@ class DecoderMethodOptions;
UPB_DECLARE_TYPE(upb::pb::CodeCache, upb_pbcodecache)
UPB_DECLARE_TYPE(upb::pb::Decoder, upb_pbdecoder)
-UPB_DECLARE_TYPE(upb::pb::DecoderMethodOptions, upb_pbdecodermethodopts)
-
-UPB_DECLARE_DERIVED_TYPE(upb::pb::DecoderMethod, upb::RefCounted,
- upb_pbdecodermethod, upb_refcounted)
+UPB_DECLARE_TYPE(upb::pb::DecoderMethod, upb_pbdecodermethod)
/* The maximum number of bytes we are required to buffer internally between
* calls to the decoder. The value is 14: a 5 byte unknown tag plus ten-byte
@@ -44,35 +41,10 @@ UPB_DECLARE_DERIVED_TYPE(upb::pb::DecoderMethod, upb::RefCounted,
#ifdef __cplusplus
-/* The parameters one uses to construct a DecoderMethod.
- * TODO(haberman): move allowjit here? Seems more convenient for users.
- * TODO(haberman): move this to be heap allocated for ABI stability. */
-class upb::pb::DecoderMethodOptions {
- public:
- /* Parameter represents the destination handlers that this method will push
- * to. */
- explicit DecoderMethodOptions(const Handlers* dest_handlers);
-
- /* Should the decoder push submessages to lazy handlers for fields that have
- * them? The caller should set this iff the lazy handlers expect data that is
- * in protobuf binary format and the caller wishes to lazy parse it. */
- void set_lazy(bool lazy);
-#else
-struct upb_pbdecodermethodopts {
-#endif
- const upb_handlers *handlers;
- bool lazy;
-};
-
-#ifdef __cplusplus
-
/* Represents the code to parse a protobuf according to a destination
* Handlers. */
class upb::pb::DecoderMethod {
public:
- /* Include base methods from upb::ReferenceCounted. */
- UPB_REFCOUNTED_CPPMETHODS
-
/* The destination handlers that are statically bound to this method.
* This method is only capable of outputting to a sink that uses these
* handlers. */
@@ -84,10 +56,6 @@ class upb::pb::DecoderMethod {
/* Whether this method is native. */
bool is_native() const;
- /* Convenience method for generating a DecoderMethod without explicitly
- * creating a CodeCache. */
- static reffed_ptr<const DecoderMethod> New(const DecoderMethodOptions& opts);
-
private:
UPB_DISALLOW_POD_OPS(DecoderMethod, upb::pb::DecoderMethod)
};
@@ -147,20 +115,14 @@ class upb::pb::Decoder {
UPB_DISALLOW_POD_OPS(Decoder, upb::pb::Decoder)
};
-#endif /* __cplusplus */
-
-#ifdef __cplusplus
-
/* A class for caching protobuf processing code, whether bytecode for the
* interpreted decoder or machine code for the JIT.
*
- * This class is not thread-safe.
- *
- * TODO(haberman): move this to be heap allocated for ABI stability. */
+ * This class is not thread-safe. */
class upb::pb::CodeCache {
public:
- CodeCache();
- ~CodeCache();
+ static CodeCache* New(HandlerCache* dest);
+ static void Free(CodeCache* cache);
/* Whether the cache is allowed to generate machine code. Defaults to true.
* There is no real reason to turn it off except for testing or if you are
@@ -172,33 +134,24 @@ class upb::pb::CodeCache {
bool allow_jit() const;
/* This may only be called when the object is first constructed, and prior to
- * any code generation, otherwise returns false and does nothing. */
- bool set_allow_jit(bool allow);
+ * any code generation. */
+ void set_allow_jit(bool allow);
- /* Returns a DecoderMethod that can push data to the given handlers.
- * If a suitable method already exists, it will be returned from the cache.
- *
- * Specifying the destination handlers here allows the DecoderMethod to be
- * statically bound to the destination handlers if possible, which can allow
- * more efficient decoding. However the returned method may or may not
- * actually be statically bound. But in all cases, the returned method can
- * push data to the given handlers. */
- const DecoderMethod *GetDecoderMethod(const DecoderMethodOptions& opts);
+ /* Should the decoder push submessages to lazy handlers for fields that have
+ * them? The caller should set this iff the lazy handlers expect data that is
+ * in protobuf binary format and the caller wishes to lazy parse it. */
+ void set_lazy(bool lazy);
- /* If/when someone needs to explicitly create a dynamically-bound
- * DecoderMethod*, we can add a method to get it here. */
+ /* Returns a DecoderMethod that can push data to the given handlers.
+ * If a suitable method already exists, it will be returned from the cache. */
+ const DecoderMethod *Get(const MessageDef* md);
private:
- UPB_DISALLOW_COPY_AND_ASSIGN(CodeCache)
-#else
-struct upb_pbcodecache {
-#endif
- bool allow_jit_;
-
- /* Array of mgroups. */
- upb_inttable groups;
+ UPB_DISALLOW_POD_OPS(CodeCache, upb::pb::CodeCache)
};
+#endif
+
UPB_BEGIN_EXTERN_C
upb_pbdecoder *upb_pbdecoder_create(upb_env *e,
@@ -211,28 +164,21 @@ size_t upb_pbdecoder_maxnesting(const upb_pbdecoder *d);
bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max);
void upb_pbdecoder_reset(upb_pbdecoder *d);
-void upb_pbdecodermethodopts_init(upb_pbdecodermethodopts *opts,
- const upb_handlers *h);
-void upb_pbdecodermethodopts_setlazy(upb_pbdecodermethodopts *opts, bool lazy);
-/* Include refcounted methods like upb_pbdecodermethod_ref(). */
-UPB_REFCOUNTED_CMETHODS(upb_pbdecodermethod, upb_pbdecodermethod_upcast)
-
const upb_handlers *upb_pbdecodermethod_desthandlers(
const upb_pbdecodermethod *m);
const upb_byteshandler *upb_pbdecodermethod_inputhandler(
const upb_pbdecodermethod *m);
bool upb_pbdecodermethod_isnative(const upb_pbdecodermethod *m);
-const upb_pbdecodermethod *upb_pbdecodermethod_new(
- const upb_pbdecodermethodopts *opts, const void *owner);
-void upb_pbcodecache_init(upb_pbcodecache *c);
-void upb_pbcodecache_uninit(upb_pbcodecache *c);
+upb_pbcodecache *upb_pbcodecache_new(upb_handlercache *dest);
+void upb_pbcodecache_free(upb_pbcodecache *c);
bool upb_pbcodecache_allowjit(const upb_pbcodecache *c);
-bool upb_pbcodecache_setallowjit(upb_pbcodecache *c, bool allow);
-const upb_pbdecodermethod *upb_pbcodecache_getdecodermethod(
- upb_pbcodecache *c, const upb_pbdecodermethodopts *opts);
+void upb_pbcodecache_setallowjit(upb_pbcodecache *c, bool allow);
+void upb_pbcodecache_setlazy(upb_pbcodecache *c, bool lazy);
+const upb_pbdecodermethod *upb_pbcodecache_get(upb_pbcodecache *c,
+ const upb_msgdef *md);
UPB_END_EXTERN_C
@@ -264,13 +210,6 @@ inline bool Decoder::set_max_nesting(size_t max) {
}
inline void Decoder::Reset() { upb_pbdecoder_reset(this); }
-inline DecoderMethodOptions::DecoderMethodOptions(const Handlers* h) {
- upb_pbdecodermethodopts_init(this, h);
-}
-inline void DecoderMethodOptions::set_lazy(bool lazy) {
- upb_pbdecodermethodopts_setlazy(this, lazy);
-}
-
inline const Handlers* DecoderMethod::dest_handlers() const {
return upb_pbdecodermethod_desthandlers(this);
}
@@ -280,28 +219,21 @@ inline const BytesHandler* DecoderMethod::input_handler() const {
inline bool DecoderMethod::is_native() const {
return upb_pbdecodermethod_isnative(this);
}
-/* static */
-inline reffed_ptr<const DecoderMethod> DecoderMethod::New(
- const DecoderMethodOptions &opts) {
- const upb_pbdecodermethod *m = upb_pbdecodermethod_new(&opts, &m);
- return reffed_ptr<const DecoderMethod>(m, &m);
-}
-inline CodeCache::CodeCache() {
- upb_pbcodecache_init(this);
+inline CodeCache* CodeCache::New(HandlerCache* dest) {
+ return upb_pbcodecache_new(dest);
}
-inline CodeCache::~CodeCache() {
- upb_pbcodecache_uninit(this);
+inline void CodeCache::Free(CodeCache* cache) {
+ upb_pbcodecache_free(cache);
}
inline bool CodeCache::allow_jit() const {
return upb_pbcodecache_allowjit(this);
}
-inline bool CodeCache::set_allow_jit(bool allow) {
- return upb_pbcodecache_setallowjit(this, allow);
+inline void CodeCache::set_allow_jit(bool allow) {
+ upb_pbcodecache_setallowjit(this, allow);
}
-inline const DecoderMethod *CodeCache::GetDecoderMethod(
- const DecoderMethodOptions& opts) {
- return upb_pbcodecache_getdecodermethod(this, &opts);
+inline const DecoderMethod *CodeCache::Get(const MessageDef *md) {
+ return upb_pbcodecache_get(this, md);
}
} /* namespace pb */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback