summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-08-03 11:16:56 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-08-03 11:16:56 -0700
commitb07b1165d30b9f23ed418505d7a4f6ecc3664794 (patch)
treebb8782772f54121e3cbee1fb70456537787b953f
parent3149d2b372ddffb91c2c6ee54fcf17a481a7570c (diff)
parent3fde2b26cda7eed5e55068e51061c99ca64bc372 (diff)
Merge branch 'master' of git@github.com:haberman/upb
-rw-r--r--descriptor/descriptor.c14
-rw-r--r--src/upb_text.c53
-rw-r--r--tools/upbc.c28
3 files changed, 37 insertions, 58 deletions
diff --git a/descriptor/descriptor.c b/descriptor/descriptor.c
index b2c68c6..6ecf2f5 100644
--- a/descriptor/descriptor.c
+++ b/descriptor/descriptor.c
@@ -1,4 +1,16 @@
-/* This file was generated by upbc (the upb compiler). Do not edit. */
+/*
+ * This file is a data dump of a protocol buffer into a C structure.
+ * It was created by the upb compiler (upbc) with the following
+ * command-line:
+ *
+ * ./tools/upbc -i upb_file_descriptor_set -o descriptor/descriptor descriptor/descriptor.proto.pb
+ *
+ * This file is a dump of 'descriptor/descriptor.proto.pb'.
+ * It contains exactly the same data, but in a C structure form
+ * instead of a serialized protobuf. This file contains no code,
+ * only data.
+ *
+ * This file was auto-generated. Do not edit. */
#include "descriptor/descriptor.h"
diff --git a/src/upb_text.c b/src/upb_text.c
index 7ca17cc..6e17777 100644
--- a/src/upb_text.c
+++ b/src/upb_text.c
@@ -78,56 +78,3 @@ void upb_text_pop(struct upb_text_printer *p,
print_indent(p, stream);
fprintf(stream, "}\n");
}
-
-#if 0
-bool upb_array_eql(struct upb_array *arr1, struct upb_array *arr2,
- struct upb_msg_field *f, bool recursive)
-{
- if(arr1->len != arr2->len) return false;
- if(upb_issubmsg(f)) {
- if(!recursive) return true;
- for(uint32_t i = 0; i < arr1->len; i++)
- if(!upb_msg_eql(arr1->elements.msg[i], arr2->elements.msg[i],
- f->ref.msg, recursive))
- return false;
- } else if(upb_isstring(f)) {
- for(uint32_t i = 0; i < arr1->len; i++)
- if(!upb_streql(arr1->elements.str[i], arr2->elements.str[i]))
- return false;
- } else {
- /* For primitive types we can compare the memory directly. */
- return memcmp(arr1->elements._void, arr2->elements._void,
- arr1->len * upb_type_info[f->type].size) == 0;
- }
- return true;
-}
-
- void *data1, struct upb_msg *m, bool single_line)
- /* Must have the same fields set. TODO: is this wrong? Should we also
- * consider absent defaults equal to explicitly set defaults? */
- if(memcmp(data1, data2, m->set_flags_bytes) != 0)
- return false;
-
- /* Possible optimization: create a mask of the bytes in the messages that
- * contain only primitive values (not strings, arrays, submessages, or
- * padding) and memcmp the masked messages. */
-
- for(uint32_t i = 0; i < m->num_fields; i++) {
- struct upb_msg_field *f = &m->fields[i];
- if(!upb_msg_is_set(data1, f)) continue;
- union upb_value_ptr p1 = upb_msg_getptr(data1, f);
- union upb_value_ptr p2 = upb_msg_getptr(data2, f);
- if(f->label == GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_REPEATED) {
- if(!upb_array_eql(*p1.arr, *p2.arr, f, recursive)) return false;
- } else {
- if(upb_issubmsg(f)) {
- if(recursive && !upb_msg_eql(p1.msg, p2.msg, f->ref.msg, recursive))
- return false;
- } else if(!upb_value_eql(p1, p2, f->type)) {
- return false;
- }
- }
- }
- return true;
-}
-#endif
diff --git a/tools/upbc.c b/tools/upbc.c
index 8eec85c..414d129 100644
--- a/tools/upbc.c
+++ b/tools/upbc.c
@@ -372,10 +372,30 @@ static void add_submsgs(void *data, struct upb_msg *m, struct upb_strtable *t)
/* write_messages_c emits a .c file that contains the data of a protobuf,
* serialized as C structures. */
static void write_message_c(void *data, struct upb_msg *m,
- char *cident, char *hfile_name, FILE *stream)
+ char *cident, char *hfile_name,
+ int argc, char *argv[], char *infile_name,
+ FILE *stream)
{
- fputs("/* This file was generated by upbc (the upb compiler). "
- "Do not edit. */\n\n", stream),
+ fputs(
+ "/*\n"
+ " * This file is a data dump of a protocol buffer into a C structure.\n"
+ " * It was created by the upb compiler (upbc) with the following\n"
+ " * command-line:\n"
+ " *\n", stream);
+ fputs(" * ", stream);
+ for(int i = 0; i < argc; i++) {
+ fputs(argv[i], stream);
+ if(i < argc-1) fputs(" ", stream);
+ }
+ fputs("\n *\n", stream);
+ fprintf(stream, " * This file is a dump of '%s'.\n", infile_name);
+ fputs(
+ " * It contains exactly the same data, but in a C structure form\n"
+ " * instead of a serialized protobuf. This file contains no code,\n"
+ " * only data.\n"
+ " *\n"
+ " * This file was auto-generated. Do not edit. */\n\n", stream);
+
fprintf(stream, "#include \"%s\"\n\n", hfile_name);
/* Gather all strings into a giant string. Use a hash to prevent adding the
@@ -652,7 +672,7 @@ int main(int argc, char *argv[])
if(cident) {
FILE *c_file = fopen(c_filename, "w");
if(!c_file) error("Failed to open .h output file");
- write_message_c(fds, c.fds_msg, cident, h_filename, c_file);
+ write_message_c(fds, c.fds_msg, cident, h_filename, argc, argv, input_file, c_file);
fclose(c_file);
}
upb_context_free(&c);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback