summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJosh Haberman <jhaberman@gmail.com>2014-12-09 16:01:56 -0800
committerJosh Haberman <jhaberman@gmail.com>2014-12-09 16:01:56 -0800
commit56913be6bb57f81dbbf7baf9cc9a0a2cd1a36493 (patch)
treef4d1c17aef4e5d01578ba3fd3926ca863e2792f2 /examples
parent82be433d4188e0b3b992e463ad52ee148d3ad8de (diff)
Removed obsolete benchmarks/ and examples/ directories.
Diffstat (limited to 'examples')
-rw-r--r--examples/example.proto15
-rw-r--r--examples/msg.c59
-rw-r--r--examples/stream_transcode.c76
3 files changed, 0 insertions, 150 deletions
diff --git a/examples/example.proto b/examples/example.proto
deleted file mode 100644
index 231c455..0000000
--- a/examples/example.proto
+++ /dev/null
@@ -1,15 +0,0 @@
-//
-// upb - a minimalist implementation of protocol buffers.
-//
-// Copyright (c) 2011 Google Inc. See LICENSE for details.
-// Author: Josh Haberman <jhaberman@gmail.com>
-//
-// A .proto file for the examples in this directory.
-
-package example;
-
-message SampleMessage {
- optional string name = 1;
- optional int32 id = 2;
- optional string email = 3;
-}
diff --git a/examples/msg.c b/examples/msg.c
deleted file mode 100644
index 487e743..0000000
--- a/examples/msg.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * upb - a minimalist implementation of protocol buffers.
- *
- * Copyright (c) 2011 Google Inc. See LICENSE for details.
- * Author: Josh Haberman <jhaberman@gmail.com>
- *
- * A simple example that demonstrates creating a standard message object
- * and parsing into it, using a dynamic reflection-based approach.
- *
- * Note that with this approach there are no strongly-typed struct or class
- * definitions to use from C -- this is essentially a reflection-based
- * interface. Note that parsing and serializing are still very fast since
- * they are JIT-based.
- *
- * If this seems a bit verbose, you may prefer an approach that generates
- * strongly-typed struct definitions (upb will likely provide this, but it is
- * not yet implemented).
- *
- * TODO: make this file compiled as part of "make examples"
- * TODO: test that this actually works (WARNING: UNTESTED!)
- */
-
-#include "upb/msg.h"
-#include "upb/pb/glue.h"
-
-const char *descfile = "example.proto.pb";
-const char *type = "example.SampleMessage";
-const char *msgfile = "sample_message.pb";
-
-int main() {
- // First we load the descriptor that describes the message into a upb_msgdef.
- // This could come from a string that is compiled into the program or from a
- // separate file as we do here. Since defs always live in a symtab, we
- // create one of those also.
- upb_symtab *s = upb_symtab_new();
- upb_status status = UPB_STATUS_INIT;
- if (!upb_load_descriptor_file_into_symtab(s, descfile, &status)) {
- fprintf(stderr, "Couldn't load descriptor file '%s': %s\n", descfile,
- upb_status_getstr(&status));
- return -1;
- }
-
- const upb_msgdef *md = upb_symtab_lookupmsg(s, type);
- if (!md) {
- fprintf(stderr, "Descriptor did not contain type '%s'\n", type);
- return -1;
- }
-
- // Parse a file into a new message object.
- void *msg = upb_filetonewmsg(msgfile, md, &status);
- if (!msg) {
- fprintf(stderr, "Error parsing message file '%s': %s\n", msgfile,
- upb_status_getstr(&status));
- return -1;
- }
-
- // TODO: Inspect some fields.
- return 0;
-}
diff --git a/examples/stream_transcode.c b/examples/stream_transcode.c
deleted file mode 100644
index 21c375b..0000000
--- a/examples/stream_transcode.c
+++ /dev/null
@@ -1,76 +0,0 @@
-
-#include <stdlib.h>
-#include "upb/bytestream.h"
-#include "upb/pb/decoder.h"
-#include "upb/pb/glue.h"
-#include "upb/pb/textprinter.h"
-
-int main(int argc, char *argv[]) {
- if (argc < 3) {
- fprintf(stderr, "Usage: stream_transcode <descfile> <msgname>\n");
- return 1;
- }
-
- upb_symtab *symtab = upb_symtab_new();
- size_t desc_len;
- const char *desc = upb_readfile(argv[1], &desc_len);
- if (!desc) {
- fprintf(stderr, "Couldn't open descriptor file: %s\n", argv[1]);
- return 1;
- }
-
- upb_status status = UPB_STATUS_INIT;
- upb_load_descriptor_into_symtab(symtab, desc, desc_len, &status);
- if (!upb_ok(&status)) {
- fprintf(stderr, "Error parsing descriptor: %s", upb_status_getstr(&status));
- return 1;
- }
- free((void*)desc);
-
- const upb_def *md = upb_symtab_lookup(symtab, argv[2]);
- if (!md) {
- fprintf(stderr, "Descriptor did not contain message: %s\n", argv[2]);
- return 1;
- }
-
- const upb_msgdef *m = upb_dyncast_msgdef_const(md);
- if (!m) {
- fprintf(stderr, "Def was not a msgdef.\n");
- return 1;
- }
-
- upb_stdio in, out;
- upb_stdio_init(&in);
- upb_stdio_init(&out);
- upb_stdio_reset(&in, stdin);
- upb_stdio_reset(&out, stdout);
-
- upb_handlers *handlers = upb_handlers_new();
- upb_textprinter *p = upb_textprinter_new();
- upb_textprinter_reset(p, upb_stdio_bytesink(&out), false);
- upb_textprinter_reghandlers(handlers, m);
-
- upb_decoder d;
- upb_decoder_init(&d, handlers);
- upb_decoder_reset(&d, upb_stdio_bytesrc(&in), 0, UPB_NONDELIMITED, p);
-
- upb_status_clear(&status);
- upb_decoder_decode(&d, &status);
-
- if (!upb_ok(&status)) {
- fprintf(stderr, "Error parsing input: %s", upb_status_getstr(&status));
- }
-
- upb_status_uninit(&status);
- upb_stdio_uninit(&in);
- upb_stdio_uninit(&out);
- upb_decoder_uninit(&d);
- upb_textprinter_free(p);
- upb_def_unref(UPB_UPCAST(m));
- upb_symtab_unref(symtab);
-
- // Prevent C library from holding buffers open, so Valgrind doesn't see
- // memory leaks.
- fclose(stdin);
- fclose(stdout);
-}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback