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.
54 lines
1.3 KiB
54 lines
1.3 KiB
|
|
#include "upb/pb/glue.h" |
|
|
|
#include "upb/descriptor/reader.h" |
|
#include "upb/pb/decoder.h" |
|
|
|
upb_filedef **upb_loaddescriptor(const char *buf, size_t n, const void *owner, |
|
upb_status *status) { |
|
/* Create handlers. */ |
|
const upb_pbdecodermethod *decoder_m; |
|
const upb_handlers *reader_h = upb_descreader_newhandlers(&reader_h); |
|
upb_env env; |
|
upb_pbdecodermethodopts opts; |
|
upb_pbdecoder *decoder; |
|
upb_descreader *reader; |
|
bool ok; |
|
size_t i; |
|
upb_filedef **ret = NULL; |
|
|
|
upb_pbdecodermethodopts_init(&opts, reader_h); |
|
decoder_m = upb_pbdecodermethod_new(&opts, &decoder_m); |
|
|
|
upb_env_init(&env); |
|
upb_env_reporterrorsto(&env, status); |
|
|
|
reader = upb_descreader_create(&env, reader_h); |
|
decoder = upb_pbdecoder_create(&env, decoder_m, upb_descreader_input(reader)); |
|
|
|
/* Push input data. */ |
|
ok = upb_bufsrc_putbuf(buf, n, upb_pbdecoder_input(decoder)); |
|
|
|
if (!ok) { |
|
goto cleanup; |
|
} |
|
|
|
ret = upb_gmalloc(sizeof (*ret) * (upb_descreader_filecount(reader) + 1)); |
|
|
|
if (!ret) { |
|
goto cleanup; |
|
} |
|
|
|
for (i = 0; i < upb_descreader_filecount(reader); i++) { |
|
ret[i] = upb_descreader_file(reader, i); |
|
upb_filedef_ref(ret[i], owner); |
|
} |
|
|
|
ret[i] = NULL; |
|
|
|
cleanup: |
|
upb_env_uninit(&env); |
|
upb_handlers_unref(reader_h, &reader_h); |
|
upb_pbdecodermethod_unref(decoder_m, &decoder_m); |
|
return ret; |
|
}
|
|
|