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.
100 lines
3.2 KiB
100 lines
3.2 KiB
15 years ago
|
/*
|
||
|
* upb - a minimalist implementation of protocol buffers.
|
||
|
*
|
||
14 years ago
|
* Copyright (c) 2009-2010 Google Inc. See LICENSE for details.
|
||
|
* Author: Josh Haberman <jhaberman@gmail.com>
|
||
|
*
|
||
15 years ago
|
* upb_decoder implements a high performance, streaming decoder for protobuf
|
||
|
* data that works by implementing upb_src and getting its data from a
|
||
|
* upb_bytesrc.
|
||
15 years ago
|
*
|
||
15 years ago
|
* The decoder does not currently support non-blocking I/O, in the sense that
|
||
|
* if the bytesrc returns UPB_STATUS_TRYAGAIN it is not possible to resume the
|
||
|
* decoder when data becomes available again. Support for this could be added,
|
||
|
* but it would add complexity and perhaps cost efficiency also.
|
||
15 years ago
|
*/
|
||
|
|
||
|
#ifndef UPB_DECODER_H_
|
||
|
#define UPB_DECODER_H_
|
||
|
|
||
14 years ago
|
#include <setjmp.h>
|
||
15 years ago
|
#include <stdbool.h>
|
||
|
#include <stdint.h>
|
||
14 years ago
|
#include "upb/handlers.h"
|
||
15 years ago
|
|
||
|
#ifdef __cplusplus
|
||
|
extern "C" {
|
||
|
#endif
|
||
|
|
||
|
/* upb_decoder *****************************************************************/
|
||
|
|
||
14 years ago
|
struct dasm_State;
|
||
|
|
||
14 years ago
|
typedef struct _upb_decoder {
|
||
|
upb_bytesrc *bytesrc; // Source of our serialized data.
|
||
|
upb_dispatcher dispatcher; // Dispatcher to which we push parsed data.
|
||
|
upb_status *status; // Where we will store any errors that occur.
|
||
|
upb_strref strref; // For passing string data to callbacks.
|
||
14 years ago
|
|
||
14 years ago
|
// Offsets for the region we currently have ref'd.
|
||
|
uint64_t refstart_ofs, refend_ofs;
|
||
14 years ago
|
|
||
14 years ago
|
// Current buffer and its stream offset.
|
||
|
const char *buf, *ptr, *end;
|
||
|
uint64_t bufstart_ofs, bufend_ofs;
|
||
14 years ago
|
|
||
14 years ago
|
// Stream offset for the end of the top-level message, if any.
|
||
|
uint64_t end_ofs;
|
||
14 years ago
|
|
||
14 years ago
|
// Buf offset as of which we've delivered calbacks; needed for rollback on
|
||
|
// UPB_TRYAGAIN (or in the future, UPB_SUSPEND).
|
||
|
const char *completed_ptr;
|
||
14 years ago
|
|
||
14 years ago
|
// End of the delimited region, relative to ptr, or UINTPTR_MAX if not in
|
||
|
// this buf.
|
||
|
uintptr_t delim_end;
|
||
14 years ago
|
|
||
14 years ago
|
#ifdef UPB_USE_JIT_X64
|
||
|
// For JIT, which doesn't do bounds checks in the middle of parsing a field.
|
||
|
const char *jit_end, *effective_end; // == MIN(jit_end, submsg_end)
|
||
14 years ago
|
|
||
|
// JIT-generated machine code (else NULL).
|
||
|
char *jit_code;
|
||
|
size_t jit_size;
|
||
|
char *debug_info;
|
||
|
|
||
|
struct dasm_State *dynasm;
|
||
14 years ago
|
#endif
|
||
14 years ago
|
|
||
14 years ago
|
sigjmp_buf exitjmp;
|
||
|
} upb_decoder;
|
||
15 years ago
|
|
||
14 years ago
|
// Initializes/uninitializes a decoder for calling into the given handlers
|
||
|
// or to write into the given msgdef, given its accessors). Takes a ref
|
||
|
// on the handlers or msgdef.
|
||
|
void upb_decoder_initforhandlers(upb_decoder *d, upb_handlers *h);
|
||
|
|
||
|
// Equivalent to:
|
||
|
// upb_accessors_reghandlers(m, h);
|
||
|
// upb_decoder_initforhandlers(d, h);
|
||
|
// except possibly more efficient, by using cached state in the msgdef.
|
||
|
void upb_decoder_initformsgdef(upb_decoder *d, upb_msgdef *m);
|
||
14 years ago
|
void upb_decoder_uninit(upb_decoder *d);
|
||
15 years ago
|
|
||
|
// Resets the internal state of an already-allocated decoder. This puts it in a
|
||
|
// state where it has not seen any data, and expects the next data to be from
|
||
|
// the beginning of a new protobuf. Parsers must be reset before they can be
|
||
|
// used. A decoder can be reset multiple times.
|
||
14 years ago
|
//
|
||
|
// Pass UINT64_MAX for end_ofs to indicate a non-delimited top-level message.
|
||
|
void upb_decoder_reset(upb_decoder *d, upb_bytesrc *src, uint64_t start_ofs,
|
||
|
uint64_t end_ofs, void *closure);
|
||
15 years ago
|
|
||
14 years ago
|
void upb_decoder_decode(upb_decoder *d, upb_status *status);
|
||
15 years ago
|
|
||
|
#ifdef __cplusplus
|
||
|
} /* extern "C" */
|
||
|
#endif
|
||
|
|
||
|
#endif /* UPB_DECODER_H_ */
|