Protocol Buffers - Google's data interchange format (grpc依赖)
https://developers.google.com/protocol-buffers/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.2 KiB
88 lines
2.2 KiB
/* |
|
* 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_ */
|
|
|