summaryrefslogtreecommitdiff
path: root/tests/pb
diff options
context:
space:
mode:
authorJosh Haberman <jhaberman@gmail.com>2016-03-16 18:07:32 -0700
committerJosh Haberman <jhaberman@gmail.com>2016-04-05 17:52:21 -0700
commite9d79d2441732264e2b990a5b2dc76d13724db07 (patch)
tree7faaccbd62043ef5652f891e61577a218a74adbc /tests/pb
parentd0b9d0a9b782e46a483d4d72515f9ab4f72e402a (diff)
Added upb::FileDef, which represents the file defs are declared in.
It is entirely optional: MessageDef/EnumDef can still exist on their own. But this can represent a def's file when it is desirable to do so (eg. for code generators). This approach will require that we change the way we handle extensions. But I think it will be a good change overall. Specifically, we previously handled extensions by duplicating the extended message and then adding the extension as a regular field to the duplicated message. This required also duplicating any messages that could reach the extended message. In the new world we will need a way of declaring and looking up extensions separately from the message being extended. This change also involves some notable changes to the generated code: - files are now called foo.upbdefs.h instead of foo.upb.h. This reflects the fact that we might possibly generate several different output files for a .proto file, and this one is just for defs. - we no longer generate selectors in the .h file. - the upbdefs.c no longer vends a SymbolTable. Now it vends the individual messages (and possibly a FileDef later). I think this will compose better once we can generate files where one generated files imports another. We also make the descriptor reader vend a list of FileDefs now. This is the best conceptual match for parsing a FileDescriptorSet.
Diffstat (limited to 'tests/pb')
-rw-r--r--tests/pb/test_encoder.cc24
1 files changed, 22 insertions, 2 deletions
diff --git a/tests/pb/test_encoder.cc b/tests/pb/test_encoder.cc
index 8a222f4..6dd10ba 100644
--- a/tests/pb/test_encoder.cc
+++ b/tests/pb/test_encoder.cc
@@ -1,11 +1,31 @@
#include "tests/upb_test.h"
#include "upb/bindings/stdc++/string.h"
-#include "upb/descriptor/descriptor.upb.h"
+#include "upb/descriptor/descriptor.upbdefs.h"
#include "upb/pb/decoder.h"
#include "upb/pb/encoder.h"
#include "upb/pb/glue.h"
+static char *upb_readfile(const char *filename, size_t *len) {
+ long size;
+ char *buf;
+ FILE *f = fopen(filename, "rb");
+ if(!f) return NULL;
+ if(fseek(f, 0, SEEK_END) != 0) goto error;
+ size = ftell(f);
+ if(size < 0) goto error;
+ if(fseek(f, 0, SEEK_SET) != 0) goto error;
+ buf = (char*)malloc(size + 1);
+ if(size && fread(buf, size, 1, f) != 1) goto error;
+ fclose(f);
+ if (len) *len = size;
+ return buf;
+
+error:
+ fclose(f);
+ return NULL;
+}
+
std::string read_string(const char *filename) {
size_t len;
char *str = upb_readfile(filename, &len);
@@ -18,7 +38,7 @@ std::string read_string(const char *filename) {
void test_pb_roundtrip() {
upb::reffed_ptr<const upb::MessageDef> md(
- upbdefs::google::protobuf::FileDescriptorSet::MessageDef());
+ upbdefs::google::protobuf::FileDescriptorSet::get());
upb::reffed_ptr<const upb::Handlers> encoder_handlers(
upb::pb::Encoder::NewHandlers(md.get()));
upb::reffed_ptr<const upb::pb::DecoderMethod> method(
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback