2 ** upb::pb::Encoder (upb_pb_encoder)
4 ** Implements a set of upb_handlers that write protobuf data to the binary wire
7 ** This encoder implementation does not have any access to any out-of-band or
8 ** precomputed lengths for submessages, so it must buffer submessages internally
9 ** before it can emit the first byte.
12 #ifndef UPB_ENCODER_H_
13 #define UPB_ENCODER_H_
25 #define UPB_PBENCODER_MAX_NESTING 100
27 /* upb_pb_encoder *************************************************************/
29 /* Preallocation hint: decoder won't allocate more bytes than this when first
30 * constructed. This hint may be an overestimate for some build configurations.
31 * But if the decoder library is upgraded without recompiling the application,
32 * it may be an underestimate. */
33 #define UPB_PB_ENCODER_SIZE 784
35 struct upb_pb_encoder;
36 typedef struct upb_pb_encoder upb_pb_encoder;
42 upb_sink upb_pb_encoder_input(upb_pb_encoder *p);
43 upb_pb_encoder* upb_pb_encoder_create(upb_arena* a, const upb_handlers* h,
44 upb_bytessink output);
46 /* Lazily builds and caches handlers that will push encoded data to a bytessink.
47 * Any msgdef objects used with this object must outlive it. */
48 upb_handlercache *upb_pb_encoder_newcache(void);
53 class upb::pb::EncoderPtr {
55 EncoderPtr(upb_pb_encoder* ptr) : ptr_(ptr) {}
57 upb_pb_encoder* ptr() { return ptr_; }
59 /* Creates a new encoder in the given environment. The Handlers must have
60 * come from NewHandlers() below. */
61 static EncoderPtr Create(Arena* arena, const Handlers* handlers,
64 upb_pb_encoder_create(arena->ptr(), handlers, output.sink()));
67 /* The input to the encoder. */
68 upb::Sink input() { return upb_pb_encoder_input(ptr()); }
70 /* Creates a new set of handlers for this MessageDef. */
71 static HandlerCache NewCache() {
72 return HandlerCache(upb_pb_encoder_newcache());
75 static const size_t kSize = UPB_PB_ENCODER_SIZE;
81 #endif /* __cplusplus */
83 #endif /* UPB_ENCODER_H_ */