maps_DATA = $(SAMPLE_MAP).bin $(SAMPLE_MAP).xml
-SUFFIXES=.osm.bz2 .txt .shp .osm
+SUFFIXES=.osm.bz2 .osm.pbf .txt .shp .osm
samplemap: $(SAMPLE_MAP).bin
bzcat $< | $(maptool) $(maptool_args) $@.tmp
mv $@.tmp $@
+.osm.pbf.bin:
+ echo "Converting osm map"
+ $(maptool) --protobuf $(maptool_args) $@.tmp <$<
+ mv $@.tmp $@
+
.bin.xml:
echo '<map type="binfile" enabled="yes" data="$$NAVIT_SHAREDIR/maps/$<"/>' >$@
endif
AM_CPPFLAGS = @NAVIT_CFLAGS@ -I$(top_srcdir)/navit @ZLIB_CFLAGS@ @POSTGRESQL_CFLAGS@ -DMODULE=maptool
-libmaptool_la_SOURCES = boundaries.c buffer.c ch.c coastline.c geom.c itembin.c itembin_buffer.c misc.c osm.c osm_psql.c sourcesink.c tempfile.c tile.c zip.c maptool.h
+libmaptool_la_SOURCES = boundaries.c buffer.c ch.c coastline.c geom.c itembin.c itembin_buffer.c misc.c osm.c osm_psql.c osm_protobuf.c sourcesink.c tempfile.c tile.c zip.c maptool.h generated-code/fileformat.pb-c.c generated-code/fileformat.pb-c.h generated-code/osmformat.pb-c.c generated-code/osmformat.pb-c.h google/protobuf-c/protobuf-c.c google/protobuf-c/protobuf-c.h google/protobuf-c/protobuf-c-private.h
maptool_SOURCES = maptool.c
maptool_LDADD = libmaptool.la ../libnavit.la @NAVIT_LIBS@ @WORDEXP_LIBS@ @ZLIB_LIBS@ @POSTGRESQL_LIBS@ @CRYPTO_LIBS@ @INTLLIBS@ @LIBC_LIBS@
--- /dev/null
+option java_package = "crosby.binary";
+package OSMPBF;
+
+//protoc --java_out=../.. fileformat.proto
+
+
+//
+// STORAGE LAYER: Storing primitives.
+//
+
+message Blob {
+ optional bytes raw = 1; // No compression
+ optional int32 raw_size = 2; // When compressed, the uncompressed size
+
+ // Possible compressed versions of the data.
+ optional bytes zlib_data = 3;
+
+ // PROPOSED feature for LZMA compressed data. SUPPORT IS NOT REQUIRED.
+ optional bytes lzma_data = 4;
+
+ // Formerly used for bzip2 compressed data. Depreciated in 2010.
+ optional bytes OBSOLETE_bzip2_data = 5 [deprecated=true]; // Don't reuse this tag number.
+}
+
+/* A file contains an sequence of fileblock headers, each prefixed by
+their length in network byte order, followed by a data block
+containing the actual data. types staring with a "_" are reserved.
+*/
+
+message BlobHeader {
+ required string type = 1;
+ optional bytes indexdata = 2;
+ required int32 datasize = 3;
+}
+
+
--- /dev/null
+/* Generated by the protocol buffer compiler. DO NOT EDIT! */
+
+/* Do not generate deprecated warnings for self */
+#ifndef PROTOBUF_C_NO_DEPRECATED
+#define PROTOBUF_C_NO_DEPRECATED
+#endif
+
+#include "fileformat.pb-c.h"
+void osmpbf__blob__init
+ (OSMPBF__Blob *message)
+{
+ static OSMPBF__Blob init_value = OSMPBF__BLOB__INIT;
+ *message = init_value;
+}
+size_t osmpbf__blob__get_packed_size
+ (const OSMPBF__Blob *message)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t osmpbf__blob__pack
+ (const OSMPBF__Blob *message,
+ uint8_t *out)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t osmpbf__blob__pack_to_buffer
+ (const OSMPBF__Blob *message,
+ ProtobufCBuffer *buffer)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+OSMPBF__Blob *
+ osmpbf__blob__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data)
+{
+ return (OSMPBF__Blob *)
+ protobuf_c_message_unpack (&osmpbf__blob__descriptor,
+ allocator, len, data);
+}
+void osmpbf__blob__free_unpacked
+ (OSMPBF__Blob *message,
+ ProtobufCAllocator *allocator)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void osmpbf__blob_header__init
+ (OSMPBF__BlobHeader *message)
+{
+ static OSMPBF__BlobHeader init_value = OSMPBF__BLOB_HEADER__INIT;
+ *message = init_value;
+}
+size_t osmpbf__blob_header__get_packed_size
+ (const OSMPBF__BlobHeader *message)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t osmpbf__blob_header__pack
+ (const OSMPBF__BlobHeader *message,
+ uint8_t *out)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t osmpbf__blob_header__pack_to_buffer
+ (const OSMPBF__BlobHeader *message,
+ ProtobufCBuffer *buffer)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+OSMPBF__BlobHeader *
+ osmpbf__blob_header__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data)
+{
+ return (OSMPBF__BlobHeader *)
+ protobuf_c_message_unpack (&osmpbf__blob_header__descriptor,
+ allocator, len, data);
+}
+void osmpbf__blob_header__free_unpacked
+ (OSMPBF__BlobHeader *message,
+ ProtobufCAllocator *allocator)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__blob_header__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+static const ProtobufCFieldDescriptor osmpbf__blob__field_descriptors[5] =
+{
+ {
+ "raw",
+ 1,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_raw),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, raw),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "raw_size",
+ 2,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_raw_size),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, raw_size),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "zlib_data",
+ 3,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_zlib_data),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, zlib_data),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lzma_data",
+ 4,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_lzma_data),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, lzma_data),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "OBSOLETE_bzip2_data",
+ 5,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, has_obsolete_bzip2_data),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Blob, obsolete_bzip2_data),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+};
+static const unsigned osmpbf__blob__field_indices_by_name[] = {
+ 4, /* field[4] = OBSOLETE_bzip2_data */
+ 3, /* field[3] = lzma_data */
+ 0, /* field[0] = raw */
+ 1, /* field[1] = raw_size */
+ 2, /* field[2] = zlib_data */
+};
+static const ProtobufCIntRange osmpbf__blob__number_ranges[1 + 1] =
+{
+ { 1, 0 },
+ { 0, 5 }
+};
+const ProtobufCMessageDescriptor osmpbf__blob__descriptor =
+{
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.Blob",
+ "Blob",
+ "OSMPBF__Blob",
+ "OSMPBF",
+ sizeof(OSMPBF__Blob),
+ 5,
+ osmpbf__blob__field_descriptors,
+ osmpbf__blob__field_indices_by_name,
+ 1, osmpbf__blob__number_ranges,
+ (ProtobufCMessageInit) osmpbf__blob__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor osmpbf__blob_header__field_descriptors[3] =
+{
+ {
+ "type",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_STRING,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, type),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "indexdata",
+ 2,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, has_indexdata),
+ PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, indexdata),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "datasize",
+ 3,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_INT32,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__BlobHeader, datasize),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+};
+static const unsigned osmpbf__blob_header__field_indices_by_name[] = {
+ 2, /* field[2] = datasize */
+ 1, /* field[1] = indexdata */
+ 0, /* field[0] = type */
+};
+static const ProtobufCIntRange osmpbf__blob_header__number_ranges[1 + 1] =
+{
+ { 1, 0 },
+ { 0, 3 }
+};
+const ProtobufCMessageDescriptor osmpbf__blob_header__descriptor =
+{
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.BlobHeader",
+ "BlobHeader",
+ "OSMPBF__BlobHeader",
+ "OSMPBF",
+ sizeof(OSMPBF__BlobHeader),
+ 3,
+ osmpbf__blob_header__field_descriptors,
+ osmpbf__blob_header__field_indices_by_name,
+ 1, osmpbf__blob_header__number_ranges,
+ (ProtobufCMessageInit) osmpbf__blob_header__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
--- /dev/null
+/* Generated by the protocol buffer compiler. DO NOT EDIT! */
+
+#ifndef PROTOBUF_C_fileformat_2eproto__INCLUDED
+#define PROTOBUF_C_fileformat_2eproto__INCLUDED
+
+#include <google/protobuf-c/protobuf-c.h>
+
+PROTOBUF_C_BEGIN_DECLS
+
+
+typedef struct _OSMPBF__Blob OSMPBF__Blob;
+typedef struct _OSMPBF__BlobHeader OSMPBF__BlobHeader;
+
+
+/* --- enums --- */
+
+
+/* --- messages --- */
+
+struct _OSMPBF__Blob
+{
+ ProtobufCMessage base;
+ protobuf_c_boolean has_raw;
+ ProtobufCBinaryData raw;
+ protobuf_c_boolean has_raw_size;
+ int32_t raw_size;
+ protobuf_c_boolean has_zlib_data;
+ ProtobufCBinaryData zlib_data;
+ protobuf_c_boolean has_lzma_data;
+ ProtobufCBinaryData lzma_data;
+ protobuf_c_boolean has_obsolete_bzip2_data PROTOBUF_C_DEPRECATED;
+ ProtobufCBinaryData obsolete_bzip2_data PROTOBUF_C_DEPRECATED;
+};
+#define OSMPBF__BLOB__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&osmpbf__blob__descriptor) \
+ , 0,{0,NULL}, 0,0, 0,{0,NULL}, 0,{0,NULL}, 0,{0,NULL} }
+
+
+struct _OSMPBF__BlobHeader
+{
+ ProtobufCMessage base;
+ char *type;
+ protobuf_c_boolean has_indexdata;
+ ProtobufCBinaryData indexdata;
+ int32_t datasize;
+};
+#define OSMPBF__BLOB_HEADER__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&osmpbf__blob_header__descriptor) \
+ , NULL, 0,{0,NULL}, 0 }
+
+
+/* OSMPBF__Blob methods */
+void osmpbf__blob__init
+ (OSMPBF__Blob *message);
+size_t osmpbf__blob__get_packed_size
+ (const OSMPBF__Blob *message);
+size_t osmpbf__blob__pack
+ (const OSMPBF__Blob *message,
+ uint8_t *out);
+size_t osmpbf__blob__pack_to_buffer
+ (const OSMPBF__Blob *message,
+ ProtobufCBuffer *buffer);
+OSMPBF__Blob *
+ osmpbf__blob__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data);
+void osmpbf__blob__free_unpacked
+ (OSMPBF__Blob *message,
+ ProtobufCAllocator *allocator);
+/* OSMPBF__BlobHeader methods */
+void osmpbf__blob_header__init
+ (OSMPBF__BlobHeader *message);
+size_t osmpbf__blob_header__get_packed_size
+ (const OSMPBF__BlobHeader *message);
+size_t osmpbf__blob_header__pack
+ (const OSMPBF__BlobHeader *message,
+ uint8_t *out);
+size_t osmpbf__blob_header__pack_to_buffer
+ (const OSMPBF__BlobHeader *message,
+ ProtobufCBuffer *buffer);
+OSMPBF__BlobHeader *
+ osmpbf__blob_header__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data);
+void osmpbf__blob_header__free_unpacked
+ (OSMPBF__BlobHeader *message,
+ ProtobufCAllocator *allocator);
+/* --- per-message closures --- */
+
+typedef void (*OSMPBF__Blob_Closure)
+ (const OSMPBF__Blob *message,
+ void *closure_data);
+typedef void (*OSMPBF__BlobHeader_Closure)
+ (const OSMPBF__BlobHeader *message,
+ void *closure_data);
+
+/* --- services --- */
+
+
+/* --- descriptors --- */
+
+extern const ProtobufCMessageDescriptor osmpbf__blob__descriptor;
+extern const ProtobufCMessageDescriptor osmpbf__blob_header__descriptor;
+
+PROTOBUF_C_END_DECLS
+
+
+#endif /* PROTOBUF_fileformat_2eproto__INCLUDED */
--- /dev/null
+/* Generated by the protocol buffer compiler. DO NOT EDIT! */
+
+/* Do not generate deprecated warnings for self */
+#ifndef PROTOBUF_C_NO_DEPRECATED
+#define PROTOBUF_C_NO_DEPRECATED
+#endif
+
+#include "osmformat.pb-c.h"
+void osmpbf__header_block__init
+ (OSMPBF__HeaderBlock *message)
+{
+ static OSMPBF__HeaderBlock init_value = OSMPBF__HEADER_BLOCK__INIT;
+ *message = init_value;
+}
+size_t osmpbf__header_block__get_packed_size
+ (const OSMPBF__HeaderBlock *message)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t osmpbf__header_block__pack
+ (const OSMPBF__HeaderBlock *message,
+ uint8_t *out)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t osmpbf__header_block__pack_to_buffer
+ (const OSMPBF__HeaderBlock *message,
+ ProtobufCBuffer *buffer)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+OSMPBF__HeaderBlock *
+ osmpbf__header_block__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data)
+{
+ return (OSMPBF__HeaderBlock *)
+ protobuf_c_message_unpack (&osmpbf__header_block__descriptor,
+ allocator, len, data);
+}
+void osmpbf__header_block__free_unpacked
+ (OSMPBF__HeaderBlock *message,
+ ProtobufCAllocator *allocator)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_block__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void osmpbf__header_bbox__init
+ (OSMPBF__HeaderBBox *message)
+{
+ static OSMPBF__HeaderBBox init_value = OSMPBF__HEADER_BBOX__INIT;
+ *message = init_value;
+}
+size_t osmpbf__header_bbox__get_packed_size
+ (const OSMPBF__HeaderBBox *message)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t osmpbf__header_bbox__pack
+ (const OSMPBF__HeaderBBox *message,
+ uint8_t *out)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t osmpbf__header_bbox__pack_to_buffer
+ (const OSMPBF__HeaderBBox *message,
+ ProtobufCBuffer *buffer)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+OSMPBF__HeaderBBox *
+ osmpbf__header_bbox__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data)
+{
+ return (OSMPBF__HeaderBBox *)
+ protobuf_c_message_unpack (&osmpbf__header_bbox__descriptor,
+ allocator, len, data);
+}
+void osmpbf__header_bbox__free_unpacked
+ (OSMPBF__HeaderBBox *message,
+ ProtobufCAllocator *allocator)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__header_bbox__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void osmpbf__primitive_block__init
+ (OSMPBF__PrimitiveBlock *message)
+{
+ static OSMPBF__PrimitiveBlock init_value = OSMPBF__PRIMITIVE_BLOCK__INIT;
+ *message = init_value;
+}
+size_t osmpbf__primitive_block__get_packed_size
+ (const OSMPBF__PrimitiveBlock *message)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t osmpbf__primitive_block__pack
+ (const OSMPBF__PrimitiveBlock *message,
+ uint8_t *out)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t osmpbf__primitive_block__pack_to_buffer
+ (const OSMPBF__PrimitiveBlock *message,
+ ProtobufCBuffer *buffer)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+OSMPBF__PrimitiveBlock *
+ osmpbf__primitive_block__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data)
+{
+ return (OSMPBF__PrimitiveBlock *)
+ protobuf_c_message_unpack (&osmpbf__primitive_block__descriptor,
+ allocator, len, data);
+}
+void osmpbf__primitive_block__free_unpacked
+ (OSMPBF__PrimitiveBlock *message,
+ ProtobufCAllocator *allocator)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_block__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void osmpbf__primitive_group__init
+ (OSMPBF__PrimitiveGroup *message)
+{
+ static OSMPBF__PrimitiveGroup init_value = OSMPBF__PRIMITIVE_GROUP__INIT;
+ *message = init_value;
+}
+size_t osmpbf__primitive_group__get_packed_size
+ (const OSMPBF__PrimitiveGroup *message)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t osmpbf__primitive_group__pack
+ (const OSMPBF__PrimitiveGroup *message,
+ uint8_t *out)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t osmpbf__primitive_group__pack_to_buffer
+ (const OSMPBF__PrimitiveGroup *message,
+ ProtobufCBuffer *buffer)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+OSMPBF__PrimitiveGroup *
+ osmpbf__primitive_group__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data)
+{
+ return (OSMPBF__PrimitiveGroup *)
+ protobuf_c_message_unpack (&osmpbf__primitive_group__descriptor,
+ allocator, len, data);
+}
+void osmpbf__primitive_group__free_unpacked
+ (OSMPBF__PrimitiveGroup *message,
+ ProtobufCAllocator *allocator)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__primitive_group__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void osmpbf__string_table__init
+ (OSMPBF__StringTable *message)
+{
+ static OSMPBF__StringTable init_value = OSMPBF__STRING_TABLE__INIT;
+ *message = init_value;
+}
+size_t osmpbf__string_table__get_packed_size
+ (const OSMPBF__StringTable *message)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t osmpbf__string_table__pack
+ (const OSMPBF__StringTable *message,
+ uint8_t *out)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t osmpbf__string_table__pack_to_buffer
+ (const OSMPBF__StringTable *message,
+ ProtobufCBuffer *buffer)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+OSMPBF__StringTable *
+ osmpbf__string_table__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data)
+{
+ return (OSMPBF__StringTable *)
+ protobuf_c_message_unpack (&osmpbf__string_table__descriptor,
+ allocator, len, data);
+}
+void osmpbf__string_table__free_unpacked
+ (OSMPBF__StringTable *message,
+ ProtobufCAllocator *allocator)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__string_table__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void osmpbf__info__init
+ (OSMPBF__Info *message)
+{
+ static OSMPBF__Info init_value = OSMPBF__INFO__INIT;
+ *message = init_value;
+}
+size_t osmpbf__info__get_packed_size
+ (const OSMPBF__Info *message)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t osmpbf__info__pack
+ (const OSMPBF__Info *message,
+ uint8_t *out)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t osmpbf__info__pack_to_buffer
+ (const OSMPBF__Info *message,
+ ProtobufCBuffer *buffer)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+OSMPBF__Info *
+ osmpbf__info__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data)
+{
+ return (OSMPBF__Info *)
+ protobuf_c_message_unpack (&osmpbf__info__descriptor,
+ allocator, len, data);
+}
+void osmpbf__info__free_unpacked
+ (OSMPBF__Info *message,
+ ProtobufCAllocator *allocator)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__info__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void osmpbf__dense_info__init
+ (OSMPBF__DenseInfo *message)
+{
+ static OSMPBF__DenseInfo init_value = OSMPBF__DENSE_INFO__INIT;
+ *message = init_value;
+}
+size_t osmpbf__dense_info__get_packed_size
+ (const OSMPBF__DenseInfo *message)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t osmpbf__dense_info__pack
+ (const OSMPBF__DenseInfo *message,
+ uint8_t *out)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t osmpbf__dense_info__pack_to_buffer
+ (const OSMPBF__DenseInfo *message,
+ ProtobufCBuffer *buffer)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+OSMPBF__DenseInfo *
+ osmpbf__dense_info__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data)
+{
+ return (OSMPBF__DenseInfo *)
+ protobuf_c_message_unpack (&osmpbf__dense_info__descriptor,
+ allocator, len, data);
+}
+void osmpbf__dense_info__free_unpacked
+ (OSMPBF__DenseInfo *message,
+ ProtobufCAllocator *allocator)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_info__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void osmpbf__change_set__init
+ (OSMPBF__ChangeSet *message)
+{
+ static OSMPBF__ChangeSet init_value = OSMPBF__CHANGE_SET__INIT;
+ *message = init_value;
+}
+size_t osmpbf__change_set__get_packed_size
+ (const OSMPBF__ChangeSet *message)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t osmpbf__change_set__pack
+ (const OSMPBF__ChangeSet *message,
+ uint8_t *out)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t osmpbf__change_set__pack_to_buffer
+ (const OSMPBF__ChangeSet *message,
+ ProtobufCBuffer *buffer)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+OSMPBF__ChangeSet *
+ osmpbf__change_set__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data)
+{
+ return (OSMPBF__ChangeSet *)
+ protobuf_c_message_unpack (&osmpbf__change_set__descriptor,
+ allocator, len, data);
+}
+void osmpbf__change_set__free_unpacked
+ (OSMPBF__ChangeSet *message,
+ ProtobufCAllocator *allocator)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__change_set__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void osmpbf__node__init
+ (OSMPBF__Node *message)
+{
+ static OSMPBF__Node init_value = OSMPBF__NODE__INIT;
+ *message = init_value;
+}
+size_t osmpbf__node__get_packed_size
+ (const OSMPBF__Node *message)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t osmpbf__node__pack
+ (const OSMPBF__Node *message,
+ uint8_t *out)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t osmpbf__node__pack_to_buffer
+ (const OSMPBF__Node *message,
+ ProtobufCBuffer *buffer)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+OSMPBF__Node *
+ osmpbf__node__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data)
+{
+ return (OSMPBF__Node *)
+ protobuf_c_message_unpack (&osmpbf__node__descriptor,
+ allocator, len, data);
+}
+void osmpbf__node__free_unpacked
+ (OSMPBF__Node *message,
+ ProtobufCAllocator *allocator)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__node__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void osmpbf__dense_nodes__init
+ (OSMPBF__DenseNodes *message)
+{
+ static OSMPBF__DenseNodes init_value = OSMPBF__DENSE_NODES__INIT;
+ *message = init_value;
+}
+size_t osmpbf__dense_nodes__get_packed_size
+ (const OSMPBF__DenseNodes *message)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t osmpbf__dense_nodes__pack
+ (const OSMPBF__DenseNodes *message,
+ uint8_t *out)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t osmpbf__dense_nodes__pack_to_buffer
+ (const OSMPBF__DenseNodes *message,
+ ProtobufCBuffer *buffer)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+OSMPBF__DenseNodes *
+ osmpbf__dense_nodes__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data)
+{
+ return (OSMPBF__DenseNodes *)
+ protobuf_c_message_unpack (&osmpbf__dense_nodes__descriptor,
+ allocator, len, data);
+}
+void osmpbf__dense_nodes__free_unpacked
+ (OSMPBF__DenseNodes *message,
+ ProtobufCAllocator *allocator)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__dense_nodes__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void osmpbf__way__init
+ (OSMPBF__Way *message)
+{
+ static OSMPBF__Way init_value = OSMPBF__WAY__INIT;
+ *message = init_value;
+}
+size_t osmpbf__way__get_packed_size
+ (const OSMPBF__Way *message)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t osmpbf__way__pack
+ (const OSMPBF__Way *message,
+ uint8_t *out)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t osmpbf__way__pack_to_buffer
+ (const OSMPBF__Way *message,
+ ProtobufCBuffer *buffer)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+OSMPBF__Way *
+ osmpbf__way__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data)
+{
+ return (OSMPBF__Way *)
+ protobuf_c_message_unpack (&osmpbf__way__descriptor,
+ allocator, len, data);
+}
+void osmpbf__way__free_unpacked
+ (OSMPBF__Way *message,
+ ProtobufCAllocator *allocator)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__way__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+void osmpbf__relation__init
+ (OSMPBF__Relation *message)
+{
+ static OSMPBF__Relation init_value = OSMPBF__RELATION__INIT;
+ *message = init_value;
+}
+size_t osmpbf__relation__get_packed_size
+ (const OSMPBF__Relation *message)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
+ return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
+}
+size_t osmpbf__relation__pack
+ (const OSMPBF__Relation *message,
+ uint8_t *out)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
+ return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
+}
+size_t osmpbf__relation__pack_to_buffer
+ (const OSMPBF__Relation *message,
+ ProtobufCBuffer *buffer)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
+ return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
+}
+OSMPBF__Relation *
+ osmpbf__relation__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data)
+{
+ return (OSMPBF__Relation *)
+ protobuf_c_message_unpack (&osmpbf__relation__descriptor,
+ allocator, len, data);
+}
+void osmpbf__relation__free_unpacked
+ (OSMPBF__Relation *message,
+ ProtobufCAllocator *allocator)
+{
+ PROTOBUF_C_ASSERT (message->base.descriptor == &osmpbf__relation__descriptor);
+ protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
+}
+static const ProtobufCFieldDescriptor osmpbf__header_block__field_descriptors[5] =
+{
+ {
+ "bbox",
+ 1,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, bbox),
+ &osmpbf__header_bbox__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "required_features",
+ 4,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_STRING,
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, n_required_features),
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, required_features),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "optional_features",
+ 5,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_STRING,
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, n_optional_features),
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, optional_features),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "writingprogram",
+ 16,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_STRING,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, writingprogram),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "source",
+ 17,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_STRING,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBlock, source),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+};
+static const unsigned osmpbf__header_block__field_indices_by_name[] = {
+ 0, /* field[0] = bbox */
+ 2, /* field[2] = optional_features */
+ 1, /* field[1] = required_features */
+ 4, /* field[4] = source */
+ 3, /* field[3] = writingprogram */
+};
+static const ProtobufCIntRange osmpbf__header_block__number_ranges[3 + 1] =
+{
+ { 1, 0 },
+ { 4, 1 },
+ { 16, 3 },
+ { 0, 5 }
+};
+const ProtobufCMessageDescriptor osmpbf__header_block__descriptor =
+{
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.HeaderBlock",
+ "HeaderBlock",
+ "OSMPBF__HeaderBlock",
+ "OSMPBF",
+ sizeof(OSMPBF__HeaderBlock),
+ 5,
+ osmpbf__header_block__field_descriptors,
+ osmpbf__header_block__field_indices_by_name,
+ 3, osmpbf__header_block__number_ranges,
+ (ProtobufCMessageInit) osmpbf__header_block__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor osmpbf__header_bbox__field_descriptors[4] =
+{
+ {
+ "left",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, left),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "right",
+ 2,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, right),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "top",
+ 3,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, top),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "bottom",
+ 4,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__HeaderBBox, bottom),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+};
+static const unsigned osmpbf__header_bbox__field_indices_by_name[] = {
+ 3, /* field[3] = bottom */
+ 0, /* field[0] = left */
+ 1, /* field[1] = right */
+ 2, /* field[2] = top */
+};
+static const ProtobufCIntRange osmpbf__header_bbox__number_ranges[1 + 1] =
+{
+ { 1, 0 },
+ { 0, 4 }
+};
+const ProtobufCMessageDescriptor osmpbf__header_bbox__descriptor =
+{
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.HeaderBBox",
+ "HeaderBBox",
+ "OSMPBF__HeaderBBox",
+ "OSMPBF",
+ sizeof(OSMPBF__HeaderBBox),
+ 4,
+ osmpbf__header_bbox__field_descriptors,
+ osmpbf__header_bbox__field_indices_by_name,
+ 1, osmpbf__header_bbox__number_ranges,
+ (ProtobufCMessageInit) osmpbf__header_bbox__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+static const int32_t osmpbf__primitive_block__granularity__default_value = 100;
+static const int64_t osmpbf__primitive_block__lat_offset__default_value = 0;
+static const int64_t osmpbf__primitive_block__lon_offset__default_value = 0;
+static const int32_t osmpbf__primitive_block__date_granularity__default_value = 1000;
+static const ProtobufCFieldDescriptor osmpbf__primitive_block__field_descriptors[6] =
+{
+ {
+ "stringtable",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, stringtable),
+ &osmpbf__string_table__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "primitivegroup",
+ 2,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, n_primitivegroup),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, primitivegroup),
+ &osmpbf__primitive_group__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "granularity",
+ 17,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_granularity),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, granularity),
+ NULL,
+ &osmpbf__primitive_block__granularity__default_value,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "date_granularity",
+ 18,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_date_granularity),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, date_granularity),
+ NULL,
+ &osmpbf__primitive_block__date_granularity__default_value,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lat_offset",
+ 19,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_lat_offset),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, lat_offset),
+ NULL,
+ &osmpbf__primitive_block__lat_offset__default_value,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lon_offset",
+ 20,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, has_lon_offset),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveBlock, lon_offset),
+ NULL,
+ &osmpbf__primitive_block__lon_offset__default_value,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+};
+static const unsigned osmpbf__primitive_block__field_indices_by_name[] = {
+ 3, /* field[3] = date_granularity */
+ 2, /* field[2] = granularity */
+ 4, /* field[4] = lat_offset */
+ 5, /* field[5] = lon_offset */
+ 1, /* field[1] = primitivegroup */
+ 0, /* field[0] = stringtable */
+};
+static const ProtobufCIntRange osmpbf__primitive_block__number_ranges[2 + 1] =
+{
+ { 1, 0 },
+ { 17, 2 },
+ { 0, 6 }
+};
+const ProtobufCMessageDescriptor osmpbf__primitive_block__descriptor =
+{
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.PrimitiveBlock",
+ "PrimitiveBlock",
+ "OSMPBF__PrimitiveBlock",
+ "OSMPBF",
+ sizeof(OSMPBF__PrimitiveBlock),
+ 6,
+ osmpbf__primitive_block__field_descriptors,
+ osmpbf__primitive_block__field_indices_by_name,
+ 2, osmpbf__primitive_block__number_ranges,
+ (ProtobufCMessageInit) osmpbf__primitive_block__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor osmpbf__primitive_group__field_descriptors[5] =
+{
+ {
+ "nodes",
+ 1,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_nodes),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, nodes),
+ &osmpbf__node__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "dense",
+ 2,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, dense),
+ &osmpbf__dense_nodes__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "ways",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_ways),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, ways),
+ &osmpbf__way__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "relations",
+ 4,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_relations),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, relations),
+ &osmpbf__relation__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "changesets",
+ 5,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_MESSAGE,
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, n_changesets),
+ PROTOBUF_C_OFFSETOF(OSMPBF__PrimitiveGroup, changesets),
+ &osmpbf__change_set__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+};
+static const unsigned osmpbf__primitive_group__field_indices_by_name[] = {
+ 4, /* field[4] = changesets */
+ 1, /* field[1] = dense */
+ 0, /* field[0] = nodes */
+ 3, /* field[3] = relations */
+ 2, /* field[2] = ways */
+};
+static const ProtobufCIntRange osmpbf__primitive_group__number_ranges[1 + 1] =
+{
+ { 1, 0 },
+ { 0, 5 }
+};
+const ProtobufCMessageDescriptor osmpbf__primitive_group__descriptor =
+{
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.PrimitiveGroup",
+ "PrimitiveGroup",
+ "OSMPBF__PrimitiveGroup",
+ "OSMPBF",
+ sizeof(OSMPBF__PrimitiveGroup),
+ 5,
+ osmpbf__primitive_group__field_descriptors,
+ osmpbf__primitive_group__field_indices_by_name,
+ 1, osmpbf__primitive_group__number_ranges,
+ (ProtobufCMessageInit) osmpbf__primitive_group__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor osmpbf__string_table__field_descriptors[1] =
+{
+ {
+ "s",
+ 1,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_BYTES,
+ PROTOBUF_C_OFFSETOF(OSMPBF__StringTable, n_s),
+ PROTOBUF_C_OFFSETOF(OSMPBF__StringTable, s),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+};
+static const unsigned osmpbf__string_table__field_indices_by_name[] = {
+ 0, /* field[0] = s */
+};
+static const ProtobufCIntRange osmpbf__string_table__number_ranges[1 + 1] =
+{
+ { 1, 0 },
+ { 0, 1 }
+};
+const ProtobufCMessageDescriptor osmpbf__string_table__descriptor =
+{
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.StringTable",
+ "StringTable",
+ "OSMPBF__StringTable",
+ "OSMPBF",
+ sizeof(OSMPBF__StringTable),
+ 1,
+ osmpbf__string_table__field_descriptors,
+ osmpbf__string_table__field_indices_by_name,
+ 1, osmpbf__string_table__number_ranges,
+ (ProtobufCMessageInit) osmpbf__string_table__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+static const int32_t osmpbf__info__version__default_value = -1;
+static const ProtobufCFieldDescriptor osmpbf__info__field_descriptors[5] =
+{
+ {
+ "version",
+ 1,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_version),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, version),
+ NULL,
+ &osmpbf__info__version__default_value,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "timestamp",
+ 2,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_timestamp),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, timestamp),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "changeset",
+ 3,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_changeset),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, changeset),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "uid",
+ 4,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_uid),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, uid),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "user_sid",
+ 5,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, has_user_sid),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Info, user_sid),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+};
+static const unsigned osmpbf__info__field_indices_by_name[] = {
+ 2, /* field[2] = changeset */
+ 1, /* field[1] = timestamp */
+ 3, /* field[3] = uid */
+ 4, /* field[4] = user_sid */
+ 0, /* field[0] = version */
+};
+static const ProtobufCIntRange osmpbf__info__number_ranges[1 + 1] =
+{
+ { 1, 0 },
+ { 0, 5 }
+};
+const ProtobufCMessageDescriptor osmpbf__info__descriptor =
+{
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.Info",
+ "Info",
+ "OSMPBF__Info",
+ "OSMPBF",
+ sizeof(OSMPBF__Info),
+ 5,
+ osmpbf__info__field_descriptors,
+ osmpbf__info__field_indices_by_name,
+ 1, osmpbf__info__number_ranges,
+ (ProtobufCMessageInit) osmpbf__info__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor osmpbf__dense_info__field_descriptors[5] =
+{
+ {
+ "version",
+ 1,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_version),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, version),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "timestamp",
+ 2,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_timestamp),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, timestamp),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "changeset",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_changeset),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, changeset),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "uid",
+ 4,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_uid),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, uid),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "user_sid",
+ 5,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, n_user_sid),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseInfo, user_sid),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+};
+static const unsigned osmpbf__dense_info__field_indices_by_name[] = {
+ 2, /* field[2] = changeset */
+ 1, /* field[1] = timestamp */
+ 3, /* field[3] = uid */
+ 4, /* field[4] = user_sid */
+ 0, /* field[0] = version */
+};
+static const ProtobufCIntRange osmpbf__dense_info__number_ranges[1 + 1] =
+{
+ { 1, 0 },
+ { 0, 5 }
+};
+const ProtobufCMessageDescriptor osmpbf__dense_info__descriptor =
+{
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.DenseInfo",
+ "DenseInfo",
+ "OSMPBF__DenseInfo",
+ "OSMPBF",
+ sizeof(OSMPBF__DenseInfo),
+ 5,
+ osmpbf__dense_info__field_descriptors,
+ osmpbf__dense_info__field_indices_by_name,
+ 1, osmpbf__dense_info__number_ranges,
+ (ProtobufCMessageInit) osmpbf__dense_info__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor osmpbf__change_set__field_descriptors[1] =
+{
+ {
+ "id",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_INT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__ChangeSet, id),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+};
+static const unsigned osmpbf__change_set__field_indices_by_name[] = {
+ 0, /* field[0] = id */
+};
+static const ProtobufCIntRange osmpbf__change_set__number_ranges[1 + 1] =
+{
+ { 1, 0 },
+ { 0, 1 }
+};
+const ProtobufCMessageDescriptor osmpbf__change_set__descriptor =
+{
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.ChangeSet",
+ "ChangeSet",
+ "OSMPBF__ChangeSet",
+ "OSMPBF",
+ sizeof(OSMPBF__ChangeSet),
+ 1,
+ osmpbf__change_set__field_descriptors,
+ osmpbf__change_set__field_indices_by_name,
+ 1, osmpbf__change_set__number_ranges,
+ (ProtobufCMessageInit) osmpbf__change_set__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor osmpbf__node__field_descriptors[6] =
+{
+ {
+ "id",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, id),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "keys",
+ 2,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, n_keys),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, keys),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "vals",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, n_vals),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, vals),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "info",
+ 4,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, info),
+ &osmpbf__info__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lat",
+ 8,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, lat),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lon",
+ 9,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_SINT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Node, lon),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+};
+static const unsigned osmpbf__node__field_indices_by_name[] = {
+ 0, /* field[0] = id */
+ 3, /* field[3] = info */
+ 1, /* field[1] = keys */
+ 4, /* field[4] = lat */
+ 5, /* field[5] = lon */
+ 2, /* field[2] = vals */
+};
+static const ProtobufCIntRange osmpbf__node__number_ranges[2 + 1] =
+{
+ { 1, 0 },
+ { 8, 4 },
+ { 0, 6 }
+};
+const ProtobufCMessageDescriptor osmpbf__node__descriptor =
+{
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.Node",
+ "Node",
+ "OSMPBF__Node",
+ "OSMPBF",
+ sizeof(OSMPBF__Node),
+ 6,
+ osmpbf__node__field_descriptors,
+ osmpbf__node__field_indices_by_name,
+ 2, osmpbf__node__number_ranges,
+ (ProtobufCMessageInit) osmpbf__node__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor osmpbf__dense_nodes__field_descriptors[5] =
+{
+ {
+ "id",
+ 1,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_id),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, id),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "denseinfo",
+ 5,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, denseinfo),
+ &osmpbf__dense_info__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lat",
+ 8,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_lat),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, lat),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "lon",
+ 9,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_lon),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, lon),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "keys_vals",
+ 10,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, n_keys_vals),
+ PROTOBUF_C_OFFSETOF(OSMPBF__DenseNodes, keys_vals),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+};
+static const unsigned osmpbf__dense_nodes__field_indices_by_name[] = {
+ 1, /* field[1] = denseinfo */
+ 0, /* field[0] = id */
+ 4, /* field[4] = keys_vals */
+ 2, /* field[2] = lat */
+ 3, /* field[3] = lon */
+};
+static const ProtobufCIntRange osmpbf__dense_nodes__number_ranges[3 + 1] =
+{
+ { 1, 0 },
+ { 5, 1 },
+ { 8, 2 },
+ { 0, 5 }
+};
+const ProtobufCMessageDescriptor osmpbf__dense_nodes__descriptor =
+{
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.DenseNodes",
+ "DenseNodes",
+ "OSMPBF__DenseNodes",
+ "OSMPBF",
+ sizeof(OSMPBF__DenseNodes),
+ 5,
+ osmpbf__dense_nodes__field_descriptors,
+ osmpbf__dense_nodes__field_indices_by_name,
+ 3, osmpbf__dense_nodes__number_ranges,
+ (ProtobufCMessageInit) osmpbf__dense_nodes__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+static const ProtobufCFieldDescriptor osmpbf__way__field_descriptors[5] =
+{
+ {
+ "id",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_INT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, id),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "keys",
+ 2,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, n_keys),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, keys),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "vals",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, n_vals),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, vals),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "info",
+ 4,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, info),
+ &osmpbf__info__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "refs",
+ 8,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, n_refs),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Way, refs),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+};
+static const unsigned osmpbf__way__field_indices_by_name[] = {
+ 0, /* field[0] = id */
+ 3, /* field[3] = info */
+ 1, /* field[1] = keys */
+ 4, /* field[4] = refs */
+ 2, /* field[2] = vals */
+};
+static const ProtobufCIntRange osmpbf__way__number_ranges[2 + 1] =
+{
+ { 1, 0 },
+ { 8, 4 },
+ { 0, 5 }
+};
+const ProtobufCMessageDescriptor osmpbf__way__descriptor =
+{
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.Way",
+ "Way",
+ "OSMPBF__Way",
+ "OSMPBF",
+ sizeof(OSMPBF__Way),
+ 5,
+ osmpbf__way__field_descriptors,
+ osmpbf__way__field_indices_by_name,
+ 2, osmpbf__way__number_ranges,
+ (ProtobufCMessageInit) osmpbf__way__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
+const ProtobufCEnumValue osmpbf__relation__member_type__enum_values_by_number[3] =
+{
+ { "NODE", "OSMPBF__RELATION__MEMBER_TYPE__NODE", 0 },
+ { "WAY", "OSMPBF__RELATION__MEMBER_TYPE__WAY", 1 },
+ { "RELATION", "OSMPBF__RELATION__MEMBER_TYPE__RELATION", 2 },
+};
+static const ProtobufCIntRange osmpbf__relation__member_type__value_ranges[] = {
+{0, 0},{0, 3}
+};
+const ProtobufCEnumValueIndex osmpbf__relation__member_type__enum_values_by_name[3] =
+{
+ { "NODE", 0 },
+ { "RELATION", 2 },
+ { "WAY", 1 },
+};
+const ProtobufCEnumDescriptor osmpbf__relation__member_type__descriptor =
+{
+ PROTOBUF_C_ENUM_DESCRIPTOR_MAGIC,
+ "OSMPBF.Relation.MemberType",
+ "MemberType",
+ "OSMPBF__Relation__MemberType",
+ "OSMPBF",
+ 3,
+ osmpbf__relation__member_type__enum_values_by_number,
+ 3,
+ osmpbf__relation__member_type__enum_values_by_name,
+ 1,
+ osmpbf__relation__member_type__value_ranges,
+ NULL,NULL,NULL,NULL /* reserved[1234] */
+};
+static const ProtobufCFieldDescriptor osmpbf__relation__field_descriptors[7] =
+{
+ {
+ "id",
+ 1,
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_TYPE_INT64,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, id),
+ NULL,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "keys",
+ 2,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_keys),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, keys),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "vals",
+ 3,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_vals),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, vals),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "info",
+ 4,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_TYPE_MESSAGE,
+ 0, /* quantifier_offset */
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, info),
+ &osmpbf__info__descriptor,
+ NULL,
+ 0, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "roles_sid",
+ 8,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_roles_sid),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, roles_sid),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "memids",
+ 9,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_memids),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, memids),
+ NULL,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+ {
+ "types",
+ 10,
+ PROTOBUF_C_LABEL_REPEATED,
+ PROTOBUF_C_TYPE_ENUM,
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, n_types),
+ PROTOBUF_C_OFFSETOF(OSMPBF__Relation, types),
+ &osmpbf__relation__member_type__descriptor,
+ NULL,
+ 1, /* packed */
+ 0,NULL,NULL /* reserved1,reserved2, etc */
+ },
+};
+static const unsigned osmpbf__relation__field_indices_by_name[] = {
+ 0, /* field[0] = id */
+ 3, /* field[3] = info */
+ 1, /* field[1] = keys */
+ 5, /* field[5] = memids */
+ 4, /* field[4] = roles_sid */
+ 6, /* field[6] = types */
+ 2, /* field[2] = vals */
+};
+static const ProtobufCIntRange osmpbf__relation__number_ranges[2 + 1] =
+{
+ { 1, 0 },
+ { 8, 4 },
+ { 0, 7 }
+};
+const ProtobufCMessageDescriptor osmpbf__relation__descriptor =
+{
+ PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC,
+ "OSMPBF.Relation",
+ "Relation",
+ "OSMPBF__Relation",
+ "OSMPBF",
+ sizeof(OSMPBF__Relation),
+ 7,
+ osmpbf__relation__field_descriptors,
+ osmpbf__relation__field_indices_by_name,
+ 2, osmpbf__relation__number_ranges,
+ (ProtobufCMessageInit) osmpbf__relation__init,
+ NULL,NULL,NULL /* reserved[123] */
+};
--- /dev/null
+/* Generated by the protocol buffer compiler. DO NOT EDIT! */
+
+#ifndef PROTOBUF_C_osmformat_2eproto__INCLUDED
+#define PROTOBUF_C_osmformat_2eproto__INCLUDED
+
+#include <google/protobuf-c/protobuf-c.h>
+
+PROTOBUF_C_BEGIN_DECLS
+
+
+typedef struct _OSMPBF__HeaderBlock OSMPBF__HeaderBlock;
+typedef struct _OSMPBF__HeaderBBox OSMPBF__HeaderBBox;
+typedef struct _OSMPBF__PrimitiveBlock OSMPBF__PrimitiveBlock;
+typedef struct _OSMPBF__PrimitiveGroup OSMPBF__PrimitiveGroup;
+typedef struct _OSMPBF__StringTable OSMPBF__StringTable;
+typedef struct _OSMPBF__Info OSMPBF__Info;
+typedef struct _OSMPBF__DenseInfo OSMPBF__DenseInfo;
+typedef struct _OSMPBF__ChangeSet OSMPBF__ChangeSet;
+typedef struct _OSMPBF__Node OSMPBF__Node;
+typedef struct _OSMPBF__DenseNodes OSMPBF__DenseNodes;
+typedef struct _OSMPBF__Way OSMPBF__Way;
+typedef struct _OSMPBF__Relation OSMPBF__Relation;
+
+
+/* --- enums --- */
+
+typedef enum _OSMPBF__Relation__MemberType {
+ OSMPBF__RELATION__MEMBER_TYPE__NODE = 0,
+ OSMPBF__RELATION__MEMBER_TYPE__WAY = 1,
+ OSMPBF__RELATION__MEMBER_TYPE__RELATION = 2
+} OSMPBF__Relation__MemberType;
+
+/* --- messages --- */
+
+struct _OSMPBF__HeaderBlock
+{
+ ProtobufCMessage base;
+ OSMPBF__HeaderBBox *bbox;
+ size_t n_required_features;
+ char **required_features;
+ size_t n_optional_features;
+ char **optional_features;
+ char *writingprogram;
+ char *source;
+};
+#define OSMPBF__HEADER_BLOCK__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&osmpbf__header_block__descriptor) \
+ , NULL, 0,NULL, 0,NULL, NULL, NULL }
+
+
+struct _OSMPBF__HeaderBBox
+{
+ ProtobufCMessage base;
+ int64_t left;
+ int64_t right;
+ int64_t top;
+ int64_t bottom;
+};
+#define OSMPBF__HEADER_BBOX__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&osmpbf__header_bbox__descriptor) \
+ , 0, 0, 0, 0 }
+
+
+struct _OSMPBF__PrimitiveBlock
+{
+ ProtobufCMessage base;
+ OSMPBF__StringTable *stringtable;
+ size_t n_primitivegroup;
+ OSMPBF__PrimitiveGroup **primitivegroup;
+ protobuf_c_boolean has_granularity;
+ int32_t granularity;
+ protobuf_c_boolean has_lat_offset;
+ int64_t lat_offset;
+ protobuf_c_boolean has_lon_offset;
+ int64_t lon_offset;
+ protobuf_c_boolean has_date_granularity;
+ int32_t date_granularity;
+};
+#define OSMPBF__PRIMITIVE_BLOCK__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&osmpbf__primitive_block__descriptor) \
+ , NULL, 0,NULL, 0,100, 0,0, 0,0, 0,1000 }
+
+
+struct _OSMPBF__PrimitiveGroup
+{
+ ProtobufCMessage base;
+ size_t n_nodes;
+ OSMPBF__Node **nodes;
+ OSMPBF__DenseNodes *dense;
+ size_t n_ways;
+ OSMPBF__Way **ways;
+ size_t n_relations;
+ OSMPBF__Relation **relations;
+ size_t n_changesets;
+ OSMPBF__ChangeSet **changesets;
+};
+#define OSMPBF__PRIMITIVE_GROUP__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&osmpbf__primitive_group__descriptor) \
+ , 0,NULL, NULL, 0,NULL, 0,NULL, 0,NULL }
+
+
+struct _OSMPBF__StringTable
+{
+ ProtobufCMessage base;
+ size_t n_s;
+ ProtobufCBinaryData *s;
+};
+#define OSMPBF__STRING_TABLE__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&osmpbf__string_table__descriptor) \
+ , 0,NULL }
+
+
+struct _OSMPBF__Info
+{
+ ProtobufCMessage base;
+ protobuf_c_boolean has_version;
+ int32_t version;
+ protobuf_c_boolean has_timestamp;
+ int64_t timestamp;
+ protobuf_c_boolean has_changeset;
+ int64_t changeset;
+ protobuf_c_boolean has_uid;
+ int32_t uid;
+ protobuf_c_boolean has_user_sid;
+ uint32_t user_sid;
+};
+#define OSMPBF__INFO__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&osmpbf__info__descriptor) \
+ , 0,-1, 0,0, 0,0, 0,0, 0,0 }
+
+
+struct _OSMPBF__DenseInfo
+{
+ ProtobufCMessage base;
+ size_t n_version;
+ int32_t *version;
+ size_t n_timestamp;
+ int64_t *timestamp;
+ size_t n_changeset;
+ int64_t *changeset;
+ size_t n_uid;
+ int32_t *uid;
+ size_t n_user_sid;
+ int32_t *user_sid;
+};
+#define OSMPBF__DENSE_INFO__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&osmpbf__dense_info__descriptor) \
+ , 0,NULL, 0,NULL, 0,NULL, 0,NULL, 0,NULL }
+
+
+struct _OSMPBF__ChangeSet
+{
+ ProtobufCMessage base;
+ int64_t id;
+};
+#define OSMPBF__CHANGE_SET__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&osmpbf__change_set__descriptor) \
+ , 0 }
+
+
+struct _OSMPBF__Node
+{
+ ProtobufCMessage base;
+ int64_t id;
+ size_t n_keys;
+ uint32_t *keys;
+ size_t n_vals;
+ uint32_t *vals;
+ OSMPBF__Info *info;
+ int64_t lat;
+ int64_t lon;
+};
+#define OSMPBF__NODE__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&osmpbf__node__descriptor) \
+ , 0, 0,NULL, 0,NULL, NULL, 0, 0 }
+
+
+struct _OSMPBF__DenseNodes
+{
+ ProtobufCMessage base;
+ size_t n_id;
+ int64_t *id;
+ OSMPBF__DenseInfo *denseinfo;
+ size_t n_lat;
+ int64_t *lat;
+ size_t n_lon;
+ int64_t *lon;
+ size_t n_keys_vals;
+ int32_t *keys_vals;
+};
+#define OSMPBF__DENSE_NODES__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&osmpbf__dense_nodes__descriptor) \
+ , 0,NULL, NULL, 0,NULL, 0,NULL, 0,NULL }
+
+
+struct _OSMPBF__Way
+{
+ ProtobufCMessage base;
+ int64_t id;
+ size_t n_keys;
+ uint32_t *keys;
+ size_t n_vals;
+ uint32_t *vals;
+ OSMPBF__Info *info;
+ size_t n_refs;
+ int64_t *refs;
+};
+#define OSMPBF__WAY__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&osmpbf__way__descriptor) \
+ , 0, 0,NULL, 0,NULL, NULL, 0,NULL }
+
+
+struct _OSMPBF__Relation
+{
+ ProtobufCMessage base;
+ int64_t id;
+ size_t n_keys;
+ uint32_t *keys;
+ size_t n_vals;
+ uint32_t *vals;
+ OSMPBF__Info *info;
+ size_t n_roles_sid;
+ int32_t *roles_sid;
+ size_t n_memids;
+ int64_t *memids;
+ size_t n_types;
+ OSMPBF__Relation__MemberType *types;
+};
+#define OSMPBF__RELATION__INIT \
+ { PROTOBUF_C_MESSAGE_INIT (&osmpbf__relation__descriptor) \
+ , 0, 0,NULL, 0,NULL, NULL, 0,NULL, 0,NULL, 0,NULL }
+
+
+/* OSMPBF__HeaderBlock methods */
+void osmpbf__header_block__init
+ (OSMPBF__HeaderBlock *message);
+size_t osmpbf__header_block__get_packed_size
+ (const OSMPBF__HeaderBlock *message);
+size_t osmpbf__header_block__pack
+ (const OSMPBF__HeaderBlock *message,
+ uint8_t *out);
+size_t osmpbf__header_block__pack_to_buffer
+ (const OSMPBF__HeaderBlock *message,
+ ProtobufCBuffer *buffer);
+OSMPBF__HeaderBlock *
+ osmpbf__header_block__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data);
+void osmpbf__header_block__free_unpacked
+ (OSMPBF__HeaderBlock *message,
+ ProtobufCAllocator *allocator);
+/* OSMPBF__HeaderBBox methods */
+void osmpbf__header_bbox__init
+ (OSMPBF__HeaderBBox *message);
+size_t osmpbf__header_bbox__get_packed_size
+ (const OSMPBF__HeaderBBox *message);
+size_t osmpbf__header_bbox__pack
+ (const OSMPBF__HeaderBBox *message,
+ uint8_t *out);
+size_t osmpbf__header_bbox__pack_to_buffer
+ (const OSMPBF__HeaderBBox *message,
+ ProtobufCBuffer *buffer);
+OSMPBF__HeaderBBox *
+ osmpbf__header_bbox__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data);
+void osmpbf__header_bbox__free_unpacked
+ (OSMPBF__HeaderBBox *message,
+ ProtobufCAllocator *allocator);
+/* OSMPBF__PrimitiveBlock methods */
+void osmpbf__primitive_block__init
+ (OSMPBF__PrimitiveBlock *message);
+size_t osmpbf__primitive_block__get_packed_size
+ (const OSMPBF__PrimitiveBlock *message);
+size_t osmpbf__primitive_block__pack
+ (const OSMPBF__PrimitiveBlock *message,
+ uint8_t *out);
+size_t osmpbf__primitive_block__pack_to_buffer
+ (const OSMPBF__PrimitiveBlock *message,
+ ProtobufCBuffer *buffer);
+OSMPBF__PrimitiveBlock *
+ osmpbf__primitive_block__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data);
+void osmpbf__primitive_block__free_unpacked
+ (OSMPBF__PrimitiveBlock *message,
+ ProtobufCAllocator *allocator);
+/* OSMPBF__PrimitiveGroup methods */
+void osmpbf__primitive_group__init
+ (OSMPBF__PrimitiveGroup *message);
+size_t osmpbf__primitive_group__get_packed_size
+ (const OSMPBF__PrimitiveGroup *message);
+size_t osmpbf__primitive_group__pack
+ (const OSMPBF__PrimitiveGroup *message,
+ uint8_t *out);
+size_t osmpbf__primitive_group__pack_to_buffer
+ (const OSMPBF__PrimitiveGroup *message,
+ ProtobufCBuffer *buffer);
+OSMPBF__PrimitiveGroup *
+ osmpbf__primitive_group__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data);
+void osmpbf__primitive_group__free_unpacked
+ (OSMPBF__PrimitiveGroup *message,
+ ProtobufCAllocator *allocator);
+/* OSMPBF__StringTable methods */
+void osmpbf__string_table__init
+ (OSMPBF__StringTable *message);
+size_t osmpbf__string_table__get_packed_size
+ (const OSMPBF__StringTable *message);
+size_t osmpbf__string_table__pack
+ (const OSMPBF__StringTable *message,
+ uint8_t *out);
+size_t osmpbf__string_table__pack_to_buffer
+ (const OSMPBF__StringTable *message,
+ ProtobufCBuffer *buffer);
+OSMPBF__StringTable *
+ osmpbf__string_table__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data);
+void osmpbf__string_table__free_unpacked
+ (OSMPBF__StringTable *message,
+ ProtobufCAllocator *allocator);
+/* OSMPBF__Info methods */
+void osmpbf__info__init
+ (OSMPBF__Info *message);
+size_t osmpbf__info__get_packed_size
+ (const OSMPBF__Info *message);
+size_t osmpbf__info__pack
+ (const OSMPBF__Info *message,
+ uint8_t *out);
+size_t osmpbf__info__pack_to_buffer
+ (const OSMPBF__Info *message,
+ ProtobufCBuffer *buffer);
+OSMPBF__Info *
+ osmpbf__info__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data);
+void osmpbf__info__free_unpacked
+ (OSMPBF__Info *message,
+ ProtobufCAllocator *allocator);
+/* OSMPBF__DenseInfo methods */
+void osmpbf__dense_info__init
+ (OSMPBF__DenseInfo *message);
+size_t osmpbf__dense_info__get_packed_size
+ (const OSMPBF__DenseInfo *message);
+size_t osmpbf__dense_info__pack
+ (const OSMPBF__DenseInfo *message,
+ uint8_t *out);
+size_t osmpbf__dense_info__pack_to_buffer
+ (const OSMPBF__DenseInfo *message,
+ ProtobufCBuffer *buffer);
+OSMPBF__DenseInfo *
+ osmpbf__dense_info__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data);
+void osmpbf__dense_info__free_unpacked
+ (OSMPBF__DenseInfo *message,
+ ProtobufCAllocator *allocator);
+/* OSMPBF__ChangeSet methods */
+void osmpbf__change_set__init
+ (OSMPBF__ChangeSet *message);
+size_t osmpbf__change_set__get_packed_size
+ (const OSMPBF__ChangeSet *message);
+size_t osmpbf__change_set__pack
+ (const OSMPBF__ChangeSet *message,
+ uint8_t *out);
+size_t osmpbf__change_set__pack_to_buffer
+ (const OSMPBF__ChangeSet *message,
+ ProtobufCBuffer *buffer);
+OSMPBF__ChangeSet *
+ osmpbf__change_set__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data);
+void osmpbf__change_set__free_unpacked
+ (OSMPBF__ChangeSet *message,
+ ProtobufCAllocator *allocator);
+/* OSMPBF__Node methods */
+void osmpbf__node__init
+ (OSMPBF__Node *message);
+size_t osmpbf__node__get_packed_size
+ (const OSMPBF__Node *message);
+size_t osmpbf__node__pack
+ (const OSMPBF__Node *message,
+ uint8_t *out);
+size_t osmpbf__node__pack_to_buffer
+ (const OSMPBF__Node *message,
+ ProtobufCBuffer *buffer);
+OSMPBF__Node *
+ osmpbf__node__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data);
+void osmpbf__node__free_unpacked
+ (OSMPBF__Node *message,
+ ProtobufCAllocator *allocator);
+/* OSMPBF__DenseNodes methods */
+void osmpbf__dense_nodes__init
+ (OSMPBF__DenseNodes *message);
+size_t osmpbf__dense_nodes__get_packed_size
+ (const OSMPBF__DenseNodes *message);
+size_t osmpbf__dense_nodes__pack
+ (const OSMPBF__DenseNodes *message,
+ uint8_t *out);
+size_t osmpbf__dense_nodes__pack_to_buffer
+ (const OSMPBF__DenseNodes *message,
+ ProtobufCBuffer *buffer);
+OSMPBF__DenseNodes *
+ osmpbf__dense_nodes__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data);
+void osmpbf__dense_nodes__free_unpacked
+ (OSMPBF__DenseNodes *message,
+ ProtobufCAllocator *allocator);
+/* OSMPBF__Way methods */
+void osmpbf__way__init
+ (OSMPBF__Way *message);
+size_t osmpbf__way__get_packed_size
+ (const OSMPBF__Way *message);
+size_t osmpbf__way__pack
+ (const OSMPBF__Way *message,
+ uint8_t *out);
+size_t osmpbf__way__pack_to_buffer
+ (const OSMPBF__Way *message,
+ ProtobufCBuffer *buffer);
+OSMPBF__Way *
+ osmpbf__way__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data);
+void osmpbf__way__free_unpacked
+ (OSMPBF__Way *message,
+ ProtobufCAllocator *allocator);
+/* OSMPBF__Relation methods */
+void osmpbf__relation__init
+ (OSMPBF__Relation *message);
+size_t osmpbf__relation__get_packed_size
+ (const OSMPBF__Relation *message);
+size_t osmpbf__relation__pack
+ (const OSMPBF__Relation *message,
+ uint8_t *out);
+size_t osmpbf__relation__pack_to_buffer
+ (const OSMPBF__Relation *message,
+ ProtobufCBuffer *buffer);
+OSMPBF__Relation *
+ osmpbf__relation__unpack
+ (ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data);
+void osmpbf__relation__free_unpacked
+ (OSMPBF__Relation *message,
+ ProtobufCAllocator *allocator);
+/* --- per-message closures --- */
+
+typedef void (*OSMPBF__HeaderBlock_Closure)
+ (const OSMPBF__HeaderBlock *message,
+ void *closure_data);
+typedef void (*OSMPBF__HeaderBBox_Closure)
+ (const OSMPBF__HeaderBBox *message,
+ void *closure_data);
+typedef void (*OSMPBF__PrimitiveBlock_Closure)
+ (const OSMPBF__PrimitiveBlock *message,
+ void *closure_data);
+typedef void (*OSMPBF__PrimitiveGroup_Closure)
+ (const OSMPBF__PrimitiveGroup *message,
+ void *closure_data);
+typedef void (*OSMPBF__StringTable_Closure)
+ (const OSMPBF__StringTable *message,
+ void *closure_data);
+typedef void (*OSMPBF__Info_Closure)
+ (const OSMPBF__Info *message,
+ void *closure_data);
+typedef void (*OSMPBF__DenseInfo_Closure)
+ (const OSMPBF__DenseInfo *message,
+ void *closure_data);
+typedef void (*OSMPBF__ChangeSet_Closure)
+ (const OSMPBF__ChangeSet *message,
+ void *closure_data);
+typedef void (*OSMPBF__Node_Closure)
+ (const OSMPBF__Node *message,
+ void *closure_data);
+typedef void (*OSMPBF__DenseNodes_Closure)
+ (const OSMPBF__DenseNodes *message,
+ void *closure_data);
+typedef void (*OSMPBF__Way_Closure)
+ (const OSMPBF__Way *message,
+ void *closure_data);
+typedef void (*OSMPBF__Relation_Closure)
+ (const OSMPBF__Relation *message,
+ void *closure_data);
+
+/* --- services --- */
+
+
+/* --- descriptors --- */
+
+extern const ProtobufCMessageDescriptor osmpbf__header_block__descriptor;
+extern const ProtobufCMessageDescriptor osmpbf__header_bbox__descriptor;
+extern const ProtobufCMessageDescriptor osmpbf__primitive_block__descriptor;
+extern const ProtobufCMessageDescriptor osmpbf__primitive_group__descriptor;
+extern const ProtobufCMessageDescriptor osmpbf__string_table__descriptor;
+extern const ProtobufCMessageDescriptor osmpbf__info__descriptor;
+extern const ProtobufCMessageDescriptor osmpbf__dense_info__descriptor;
+extern const ProtobufCMessageDescriptor osmpbf__change_set__descriptor;
+extern const ProtobufCMessageDescriptor osmpbf__node__descriptor;
+extern const ProtobufCMessageDescriptor osmpbf__dense_nodes__descriptor;
+extern const ProtobufCMessageDescriptor osmpbf__way__descriptor;
+extern const ProtobufCMessageDescriptor osmpbf__relation__descriptor;
+extern const ProtobufCEnumDescriptor osmpbf__relation__member_type__descriptor;
+
+PROTOBUF_C_END_DECLS
+
+
+#endif /* PROTOBUF_osmformat_2eproto__INCLUDED */
--- /dev/null
+/* --- protobuf-c-private.h: private structures and functions --- */
+/*
+ * Copyright 2008, Dave Benson.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License
+ * at http://www.apache.org/licenses/LICENSE-2.0 Unless
+ * required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+/* === needs to be declared for the PROTOBUF_C_BUFFER_SIMPLE_INIT macro === */
+
+void protobuf_c_buffer_simple_append (ProtobufCBuffer *buffer,
+ size_t len,
+ const unsigned char *data);
+
+/* === stuff which needs to be declared for use in the generated code === */
+
+struct _ProtobufCEnumValueIndex
+{
+ const char *name;
+ unsigned index; /* into values[] array */
+};
+
+/* IntRange: helper structure for optimizing
+ int => index lookups
+ in the case where the keys are mostly consecutive values,
+ as they presumably are for enums and fields.
+
+ The data structures assumes that the values in the original
+ array are sorted */
+struct _ProtobufCIntRange
+{
+ int start_value;
+ unsigned orig_index;
+ /* NOTE: the number of values in the range can
+ be inferred by looking at the next element's orig_index.
+ a dummy element is added to make this simple */
+};
+
+
+/* === declared for exposition on ProtobufCIntRange === */
+/* note: ranges must have an extra sentinel IntRange at the end whose
+ orig_index is set to the number of actual values in the original array */
+/* returns -1 if no orig_index found */
+int protobuf_c_int_ranges_lookup (unsigned n_ranges,
+ ProtobufCIntRange *ranges);
+
+#define PROTOBUF_C_SERVICE_DESCRIPTOR_MAGIC 0x14159bc3
+#define PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC 0x28aaeef9
+#define PROTOBUF_C_ENUM_DESCRIPTOR_MAGIC 0x114315af
+
+/* === behind the scenes on the generated service's __init functions */
+typedef void (*ProtobufCServiceDestroy) (ProtobufCService *service);
+void
+protobuf_c_service_generated_init (ProtobufCService *service,
+ const ProtobufCServiceDescriptor *descriptor,
+ ProtobufCServiceDestroy destroy);
+
+void
+protobuf_c_service_invoke_internal(ProtobufCService *service,
+ unsigned method_index,
+ const ProtobufCMessage *input,
+ ProtobufCClosure closure,
+ void *closure_data);
--- /dev/null
+/* --- protobuf-c.c: public protobuf c runtime implementation --- */
+
+/*
+ * Copyright 2008, Dave Benson.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License
+ * at http://www.apache.org/licenses/LICENSE-2.0 Unless
+ * required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* TODO items:
+
+ * 64-BIT OPTIMIZATION: certain implementations use 32-bit math even on 64-bit platforms
+ (uint64_size, uint64_pack, parse_uint64)
+
+ * get_packed_size and pack seem to use type-prefixed names,
+ whereas parse uses type-suffixed names. pick one and stick with it.
+ Decision: go with type-suffixed, since the type (or its instance)
+ is typically the object of the verb.
+ NOTE: perhaps the "parse" methods should be reanemd to "unpack"
+ at the same time. (this only affects internal (static) functions)
+
+ * use TRUE and FALSE instead of 1 and 0 as appropriate
+
+ * use size_t consistently
+ */
+
+#include <stdio.h> /* for occasional printf()s */
+#include <stdlib.h> /* for abort(), malloc() etc */
+#include <string.h> /* for strlen(), memcpy(), memmove() */
+
+#ifndef PRINT_UNPACK_ERRORS
+#define PRINT_UNPACK_ERRORS 1
+#endif
+
+#include "protobuf-c.h"
+
+#define MAX_UINT64_ENCODED_SIZE 10
+
+/* convenience macros */
+#define TMPALLOC(allocator, size) ((allocator)->tmp_alloc ((allocator)->allocator_data, (size)))
+#define FREE(allocator, ptr) \
+ do { if ((ptr) != NULL) ((allocator)->free ((allocator)->allocator_data, (ptr))); } while(0)
+#define UNALIGNED_ALLOC(allocator, size) ALLOC (allocator, size) /* placeholder */
+#define STRUCT_MEMBER_P(struct_p, struct_offset) \
+ ((void *) ((uint8_t*) (struct_p) + (struct_offset)))
+#define STRUCT_MEMBER(member_type, struct_p, struct_offset) \
+ (*(member_type*) STRUCT_MEMBER_P ((struct_p), (struct_offset)))
+#define STRUCT_MEMBER_PTR(member_type, struct_p, struct_offset) \
+ ((member_type*) STRUCT_MEMBER_P ((struct_p), (struct_offset)))
+#define TRUE 1
+#define FALSE 0
+
+static void
+alloc_failed_warning (unsigned size, const char *filename, unsigned line)
+{
+ fprintf (stderr,
+ "WARNING: out-of-memory allocating a block of size %u (%s:%u)\n",
+ size, filename, line);
+}
+
+/* Try to allocate memory, running some special code if it fails. */
+#define DO_ALLOC(dst, allocator, size, fail_code) \
+{ size_t da__allocation_size = (size); \
+ if (da__allocation_size == 0) \
+ dst = NULL; \
+ else if ((dst=((allocator)->alloc ((allocator)->allocator_data, \
+ da__allocation_size))) == NULL) \
+ { \
+ alloc_failed_warning (da__allocation_size, __FILE__, __LINE__); \
+ fail_code; \
+ } \
+}
+#define DO_UNALIGNED_ALLOC DO_ALLOC /* placeholder */
+
+
+
+#define ASSERT_IS_ENUM_DESCRIPTOR(desc) \
+ assert((desc)->magic == PROTOBUF_C_ENUM_DESCRIPTOR_MAGIC)
+#define ASSERT_IS_MESSAGE_DESCRIPTOR(desc) \
+ assert((desc)->magic == PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC)
+#define ASSERT_IS_MESSAGE(message) \
+ ASSERT_IS_MESSAGE_DESCRIPTOR((message)->descriptor)
+#define ASSERT_IS_SERVICE_DESCRIPTOR(desc) \
+ assert((desc)->magic == PROTOBUF_C_SERVICE_DESCRIPTOR_MAGIC)
+
+/* --- allocator --- */
+
+static void protobuf_c_out_of_memory_default (void)
+{
+ fprintf (stderr, "Out Of Memory!!!\n");
+ abort ();
+}
+void (*protobuf_c_out_of_memory) (void) = protobuf_c_out_of_memory_default;
+
+static void *system_alloc(void *allocator_data, size_t size)
+{
+ void *rv;
+ (void) allocator_data;
+ if (size == 0)
+ return NULL;
+ rv = malloc (size);
+ if (rv == NULL)
+ protobuf_c_out_of_memory ();
+ return rv;
+}
+
+static void system_free (void *allocator_data, void *data)
+{
+ (void) allocator_data;
+ if (data)
+ free (data);
+}
+
+/* Some users may configure the default allocator;
+ providing your own allocator to unpack() is prefered.
+ this allocator is still used for packing nested messages. */
+ProtobufCAllocator protobuf_c_default_allocator =
+{
+ system_alloc,
+ system_free,
+ NULL,
+ 8192,
+ NULL
+};
+
+/* Users should NOT modify this structure,
+ but it's difficult to prevent.
+
+ please modify protobuf_c_default_allocator instead. */
+ProtobufCAllocator protobuf_c_system_allocator =
+{
+ system_alloc,
+ system_free,
+ NULL,
+ 8192,
+ NULL
+};
+
+/* === buffer-simple === */
+void
+protobuf_c_buffer_simple_append (ProtobufCBuffer *buffer,
+ size_t len,
+ const uint8_t *data)
+{
+ ProtobufCBufferSimple *simp = (ProtobufCBufferSimple *) buffer;
+ size_t new_len = simp->len + len;
+ if (new_len > simp->alloced)
+ {
+ size_t new_alloced = simp->alloced * 2;
+ uint8_t *new_data;
+ while (new_alloced < new_len)
+ new_alloced += new_alloced;
+ DO_ALLOC (new_data, &protobuf_c_default_allocator, new_alloced, return);
+ memcpy (new_data, simp->data, simp->len);
+ if (simp->must_free_data)
+ FREE (&protobuf_c_default_allocator, simp->data);
+ else
+ simp->must_free_data = 1;
+ simp->data = new_data;
+ simp->alloced = new_alloced;
+ }
+ memcpy (simp->data + simp->len, data, len);
+ simp->len = new_len;
+}
+
+/* === get_packed_size() === */
+
+/* Return the number of bytes required to store the
+ tag for the field (which includes 3 bits for
+ the wire-type, and a single bit that denotes the end-of-tag. */
+static inline size_t
+get_tag_size (unsigned number)
+{
+ if (number < (1<<4))
+ return 1;
+ else if (number < (1<<11))
+ return 2;
+ else if (number < (1<<18))
+ return 3;
+ else if (number < (1<<25))
+ return 4;
+ else
+ return 5;
+}
+
+/* Return the number of bytes required to store
+ a variable-length unsigned integer that fits in 32-bit uint
+ in base-128 encoding. */
+static inline size_t
+uint32_size (uint32_t v)
+{
+ if (v < (1<<7))
+ return 1;
+ else if (v < (1<<14))
+ return 2;
+ else if (v < (1<<21))
+ return 3;
+ else if (v < (1<<28))
+ return 4;
+ else
+ return 5;
+}
+/* Return the number of bytes required to store
+ a variable-length signed integer that fits in 32-bit int
+ in base-128 encoding. */
+static inline size_t
+int32_size (int32_t v)
+{
+ if (v < 0)
+ return 10;
+ else if (v < (1<<7))
+ return 1;
+ else if (v < (1<<14))
+ return 2;
+ else if (v < (1<<21))
+ return 3;
+ else if (v < (1<<28))
+ return 4;
+ else
+ return 5;
+}
+/* return the zigzag-encoded 32-bit unsigned int from a 32-bit signed int */
+static inline uint32_t
+zigzag32 (int32_t v)
+{
+ if (v < 0)
+ return ((uint32_t)(-v)) * 2 - 1;
+ else
+ return v * 2;
+}
+/* Return the number of bytes required to store
+ a variable-length signed integer that fits in 32-bit int,
+ converted to unsigned via the zig-zag algorithm,
+ then packed using base-128 encoding. */
+static inline size_t
+sint32_size (int32_t v)
+{
+ return uint32_size(zigzag32(v));
+}
+
+/* Return the number of bytes required to store
+ a variable-length unsigned integer that fits in 64-bit uint
+ in base-128 encoding. */
+static inline size_t
+uint64_size (uint64_t v)
+{
+ uint32_t upper_v = (v>>32);
+ if (upper_v == 0)
+ return uint32_size ((uint32_t)v);
+ else if (upper_v < (1<<3))
+ return 5;
+ else if (upper_v < (1<<10))
+ return 6;
+ else if (upper_v < (1<<17))
+ return 7;
+ else if (upper_v < (1<<24))
+ return 8;
+ else if (upper_v < (1U<<31))
+ return 9;
+ else
+ return 10;
+}
+
+/* return the zigzag-encoded 64-bit unsigned int from a 64-bit signed int */
+static inline uint64_t
+zigzag64 (int64_t v)
+{
+ if (v < 0)
+ return ((uint64_t)(-v)) * 2 - 1;
+ else
+ return v * 2;
+}
+
+/* Return the number of bytes required to store
+ a variable-length signed integer that fits in 64-bit int,
+ converted to unsigned via the zig-zag algorithm,
+ then packed using base-128 encoding. */
+static inline size_t
+sint64_size (int64_t v)
+{
+ return uint64_size(zigzag64(v));
+}
+
+/* Get serialized size of a single field in the message,
+ including the space needed by the identifying tag. */
+static size_t
+required_field_get_packed_size (const ProtobufCFieldDescriptor *field,
+ const void *member)
+{
+ size_t rv = get_tag_size (field->id);
+ switch (field->type)
+ {
+ case PROTOBUF_C_TYPE_SINT32:
+ return rv + sint32_size (*(const int32_t *) member);
+ case PROTOBUF_C_TYPE_INT32:
+ return rv + int32_size (*(const uint32_t *) member);
+ case PROTOBUF_C_TYPE_UINT32:
+ return rv + uint32_size (*(const uint32_t *) member);
+ case PROTOBUF_C_TYPE_SINT64:
+ return rv + sint64_size (*(const int64_t *) member);
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_UINT64:
+ return rv + uint64_size (*(const uint64_t *) member);
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ return rv + 4;
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ return rv + 8;
+ case PROTOBUF_C_TYPE_BOOL:
+ return rv + 1;
+ case PROTOBUF_C_TYPE_FLOAT:
+ return rv + 4;
+ case PROTOBUF_C_TYPE_DOUBLE:
+ return rv + 8;
+ case PROTOBUF_C_TYPE_ENUM:
+ // TODO: is this correct for negative-valued enums?
+ return rv + uint32_size (*(const uint32_t *) member);
+ case PROTOBUF_C_TYPE_STRING:
+ {
+ const char *str = *(char * const *) member;
+ size_t len = str ? strlen (str) : 0;
+ return rv + uint32_size (len) + len;
+ }
+ case PROTOBUF_C_TYPE_BYTES:
+ {
+ size_t len = ((const ProtobufCBinaryData*) member)->len;
+ return rv + uint32_size (len) + len;
+ }
+ //case PROTOBUF_C_TYPE_GROUP:
+ case PROTOBUF_C_TYPE_MESSAGE:
+ {
+ const ProtobufCMessage *msg = * (ProtobufCMessage * const *) member;
+ size_t subrv = msg ? protobuf_c_message_get_packed_size (msg) : 0;
+ return rv + uint32_size (subrv) + subrv;
+ }
+ }
+ PROTOBUF_C_ASSERT_NOT_REACHED ();
+ return 0;
+}
+
+/* Get serialized size of a single optional field in the message,
+ including the space needed by the identifying tag.
+ Returns 0 if the optional field isn't set. */
+static size_t
+optional_field_get_packed_size (const ProtobufCFieldDescriptor *field,
+ const protobuf_c_boolean *has,
+ const void *member)
+{
+ if (field->type == PROTOBUF_C_TYPE_MESSAGE
+ || field->type == PROTOBUF_C_TYPE_STRING)
+ {
+ const void *ptr = * (const void * const *) member;
+ if (ptr == NULL
+ || ptr == field->default_value)
+ return 0;
+ }
+ else
+ {
+ if (!*has)
+ return 0;
+ }
+ return required_field_get_packed_size (field, member);
+}
+
+/* Get serialized size of a repeated field in the message,
+ which may consist of any number of values (including 0).
+ Includes the space needed by the identifying tags (as needed). */
+static size_t
+repeated_field_get_packed_size (const ProtobufCFieldDescriptor *field,
+ size_t count,
+ const void *member)
+{
+ size_t header_size;
+ size_t rv = 0;
+ unsigned i;
+ void *array = * (void * const *) member;
+ if (count == 0)
+ return 0;
+ header_size = get_tag_size (field->id);
+ if (!field->packed)
+ header_size *= count;
+ switch (field->type)
+ {
+ case PROTOBUF_C_TYPE_SINT32:
+ for (i = 0; i < count; i++)
+ rv += sint32_size (((int32_t*)array)[i]);
+ break;
+ case PROTOBUF_C_TYPE_INT32:
+ for (i = 0; i < count; i++)
+ rv += int32_size (((uint32_t*)array)[i]);
+ break;
+ case PROTOBUF_C_TYPE_UINT32:
+ case PROTOBUF_C_TYPE_ENUM:
+ for (i = 0; i < count; i++)
+ rv += uint32_size (((uint32_t*)array)[i]);
+ break;
+ case PROTOBUF_C_TYPE_SINT64:
+ for (i = 0; i < count; i++)
+ rv += sint64_size (((int64_t*)array)[i]);
+ break;
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_UINT64:
+ for (i = 0; i < count; i++)
+ rv += uint64_size (((uint64_t*)array)[i]);
+ break;
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
+ rv += 4 * count;
+ break;
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
+ rv += 8 * count;
+ break;
+ case PROTOBUF_C_TYPE_BOOL:
+ rv += count;
+ break;
+ case PROTOBUF_C_TYPE_STRING:
+ for (i = 0; i < count; i++)
+ {
+ size_t len = strlen (((char**) array)[i]);
+ rv += uint32_size (len) + len;
+ }
+ break;
+
+ case PROTOBUF_C_TYPE_BYTES:
+ for (i = 0; i < count; i++)
+ {
+ size_t len = ((ProtobufCBinaryData*) array)[i].len;
+ rv += uint32_size (len) + len;
+ }
+ break;
+ case PROTOBUF_C_TYPE_MESSAGE:
+ for (i = 0; i < count; i++)
+ {
+ size_t len = protobuf_c_message_get_packed_size (((ProtobufCMessage **) array)[i]);
+ rv += uint32_size (len) + len;
+ }
+ break;
+ //case PROTOBUF_C_TYPE_GROUP: // NOT SUPPORTED
+ }
+ if (field->packed)
+ header_size += uint32_size (rv);
+ return header_size + rv;
+}
+
+/* Get the packed size of a unknown field (meaning one that
+ is passed through mostly uninterpreted... this is done
+ for forward compatibilty with the addition of new fields). */
+static inline size_t
+unknown_field_get_packed_size (const ProtobufCMessageUnknownField *field)
+{
+ return get_tag_size (field->tag) + field->len;
+}
+
+/* Get the number of bytes that the message will occupy once serialized. */
+size_t
+protobuf_c_message_get_packed_size(const ProtobufCMessage *message)
+{
+ unsigned i;
+ size_t rv = 0;
+ ASSERT_IS_MESSAGE (message);
+ for (i = 0; i < message->descriptor->n_fields; i++)
+ {
+ const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
+ const void *member = ((const char *) message) + field->offset;
+ const void *qmember = ((const char *) message) + field->quantifier_offset;
+
+ if (field->label == PROTOBUF_C_LABEL_REQUIRED)
+ rv += required_field_get_packed_size (field, member);
+ else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
+ rv += optional_field_get_packed_size (field, qmember, member);
+ else
+ rv += repeated_field_get_packed_size (field, * (const size_t *) qmember, member);
+ }
+ for (i = 0; i < message->n_unknown_fields; i++)
+ rv += unknown_field_get_packed_size (&message->unknown_fields[i]);
+ return rv;
+}
+/* === pack() === */
+/* Pack an unsigned 32-bit integer in base-128 encoding, and return the number of bytes needed:
+ this will be 5 or less. */
+static inline size_t
+uint32_pack (uint32_t value, uint8_t *out)
+{
+ unsigned rv = 0;
+ if (value >= 0x80)
+ {
+ out[rv++] = value | 0x80;
+ value >>= 7;
+ if (value >= 0x80)
+ {
+ out[rv++] = value | 0x80;
+ value >>= 7;
+ if (value >= 0x80)
+ {
+ out[rv++] = value | 0x80;
+ value >>= 7;
+ if (value >= 0x80)
+ {
+ out[rv++] = value | 0x80;
+ value >>= 7;
+ }
+ }
+ }
+ }
+ /* assert: value<128 */
+ out[rv++] = value;
+ return rv;
+}
+
+/* Pack a 32-bit signed integer, returning the number of bytes needed.
+ Negative numbers are packed as twos-complement 64-bit integers. */
+static inline size_t
+int32_pack (int32_t value, uint8_t *out)
+{
+ if (value < 0)
+ {
+ out[0] = value | 0x80;
+ out[1] = (value>>7) | 0x80;
+ out[2] = (value>>14) | 0x80;
+ out[3] = (value>>21) | 0x80;
+ out[4] = (value>>28) | 0x80;
+ out[5] = out[6] = out[7] = out[8] = 0xff;
+ out[9] = 0x01;
+ return 10;
+ }
+ else
+ return uint32_pack (value, out);
+}
+
+/* Pack a 32-bit integer in zigwag encoding. */
+static inline size_t
+sint32_pack (int32_t value, uint8_t *out)
+{
+ return uint32_pack (zigzag32 (value), out);
+}
+
+/* Pack a 64-bit unsigned integer that fits in a 64-bit uint,
+ using base-128 encoding. */
+static size_t
+uint64_pack (uint64_t value, uint8_t *out)
+{
+ uint32_t hi = value>>32;
+ uint32_t lo = value;
+ unsigned rv;
+ if (hi == 0)
+ return uint32_pack ((uint32_t)lo, out);
+ out[0] = (lo) | 0x80;
+ out[1] = (lo>>7) | 0x80;
+ out[2] = (lo>>14) | 0x80;
+ out[3] = (lo>>21) | 0x80;
+ if (hi < 8)
+ {
+ out[4] = (hi<<4) | (lo>>28);
+ return 5;
+ }
+ else
+ {
+ out[4] = ((hi&7)<<4) | (lo>>28) | 0x80;
+ hi >>= 3;
+ }
+ rv = 5;
+ while (hi >= 128)
+ {
+ out[rv++] = hi | 0x80;
+ hi >>= 7;
+ }
+ out[rv++] = hi;
+ return rv;
+}
+
+/* Pack a 64-bit signed integer in zigzan encoding,
+ return the size of the packed output.
+ (Max returned value is 10) */
+static inline size_t
+sint64_pack (int64_t value, uint8_t *out)
+{
+ return uint64_pack (zigzag64 (value), out);
+}
+
+/* Pack a 32-bit value, little-endian.
+ Used for fixed32, sfixed32, float) */
+static inline size_t
+fixed32_pack (uint32_t value, uint8_t *out)
+{
+#if IS_LITTLE_ENDIAN
+ memcpy (out, &value, 4);
+#else
+ out[0] = value;
+ out[1] = value>>8;
+ out[2] = value>>16;
+ out[3] = value>>24;
+#endif
+ return 4;
+}
+
+/* Pack a 64-bit fixed-length value.
+ (Used for fixed64, sfixed64, double) */
+/* XXX: the big-endian impl is really only good for 32-bit machines,
+ a 64-bit version would be appreciated, plus a way
+ to decide to use 64-bit math where convenient. */
+static inline size_t
+fixed64_pack (uint64_t value, uint8_t *out)
+{
+#if IS_LITTLE_ENDIAN
+ memcpy (out, &value, 8);
+#else
+ fixed32_pack (value, out);
+ fixed32_pack (value>>32, out+4);
+#endif
+ return 8;
+}
+
+
+/* Pack a boolean as 0 or 1, even though the protobuf_c_boolean
+ can really assume any integer value. */
+/* XXX: perhaps on some platforms "*out = !!value" would be
+ a better impl, b/c that is idiotmatic c++ in some stl impls. */
+static inline size_t
+boolean_pack (protobuf_c_boolean value, uint8_t *out)
+{
+ *out = value ? 1 : 0;
+ return 1;
+}
+
+/* Pack a length-prefixed string.
+ The input string is NUL-terminated.
+
+ The NULL pointer is treated as an empty string.
+ This isn't really necessary, but it allows people
+ to leave required strings blank.
+ (See Issue 13 in the bug tracker for a
+ little more explanation).
+ */
+static inline size_t
+string_pack (const char * str, uint8_t *out)
+{
+ if (str == NULL)
+ {
+ out[0] = 0;
+ return 1;
+ }
+ else
+ {
+ size_t len = strlen (str);
+ size_t rv = uint32_pack (len, out);
+ memcpy (out + rv, str, len);
+ return rv + len;
+ }
+}
+
+static inline size_t
+binary_data_pack (const ProtobufCBinaryData *bd, uint8_t *out)
+{
+ size_t len = bd->len;
+ size_t rv = uint32_pack (len, out);
+ memcpy (out + rv, bd->data, len);
+ return rv + len;
+}
+
+static inline size_t
+prefixed_message_pack (const ProtobufCMessage *message, uint8_t *out)
+{
+ if (message == NULL)
+ {
+ out[0] = 0;
+ return 1;
+ }
+ else
+ {
+ size_t rv = protobuf_c_message_pack (message, out + 1);
+ uint32_t rv_packed_size = uint32_size (rv);
+ if (rv_packed_size != 1)
+ memmove (out + rv_packed_size, out + 1, rv);
+ return uint32_pack (rv, out) + rv;
+ }
+}
+
+/* wire-type will be added in required_field_pack() */
+/* XXX: just call uint64_pack on 64-bit platforms. */
+static size_t
+tag_pack (uint32_t id, uint8_t *out)
+{
+ if (id < (1<<(32-3)))
+ return uint32_pack (id<<3, out);
+ else
+ return uint64_pack (((uint64_t)id) << 3, out);
+}
+
+static size_t
+required_field_pack (const ProtobufCFieldDescriptor *field,
+ const void *member,
+ uint8_t *out)
+{
+ size_t rv = tag_pack (field->id, out);
+ switch (field->type)
+ {
+ case PROTOBUF_C_TYPE_SINT32:
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + sint32_pack (*(const int32_t *) member, out + rv);
+ case PROTOBUF_C_TYPE_INT32:
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + int32_pack (*(const uint32_t *) member, out + rv);
+ case PROTOBUF_C_TYPE_UINT32:
+ case PROTOBUF_C_TYPE_ENUM:
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + uint32_pack (*(const uint32_t *) member, out + rv);
+ case PROTOBUF_C_TYPE_SINT64:
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + sint64_pack (*(const int64_t *) member, out + rv);
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_UINT64:
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + uint64_pack (*(const uint64_t *) member, out + rv);
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
+ out[0] |= PROTOBUF_C_WIRE_TYPE_32BIT;
+ return rv + fixed32_pack (*(const uint32_t *) member, out + rv);
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
+ out[0] |= PROTOBUF_C_WIRE_TYPE_64BIT;
+ return rv + fixed64_pack (*(const uint64_t *) member, out + rv);
+ case PROTOBUF_C_TYPE_BOOL:
+ out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ return rv + boolean_pack (*(const protobuf_c_boolean *) member, out + rv);
+ case PROTOBUF_C_TYPE_STRING:
+ {
+ out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
+ return rv + string_pack (*(char * const *) member, out + rv);
+ }
+
+ case PROTOBUF_C_TYPE_BYTES:
+ {
+ const ProtobufCBinaryData * bd = ((const ProtobufCBinaryData*) member);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
+ return rv + binary_data_pack (bd, out + rv);
+ }
+ //case PROTOBUF_C_TYPE_GROUP: // NOT SUPPORTED
+ case PROTOBUF_C_TYPE_MESSAGE:
+ {
+ out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
+ return rv + prefixed_message_pack (*(ProtobufCMessage * const *) member,
+ out + rv);
+ }
+ }
+ PROTOBUF_C_ASSERT_NOT_REACHED ();
+ return 0;
+}
+static size_t
+optional_field_pack (const ProtobufCFieldDescriptor *field,
+ const protobuf_c_boolean *has,
+ const void *member,
+ uint8_t *out)
+{
+ if (field->type == PROTOBUF_C_TYPE_MESSAGE
+ || field->type == PROTOBUF_C_TYPE_STRING)
+ {
+ const void *ptr = * (const void * const *) member;
+ if (ptr == NULL
+ || ptr == field->default_value)
+ return 0;
+ }
+ else
+ {
+ if (!*has)
+ return 0;
+ }
+ return required_field_pack (field, member, out);
+}
+
+/* TODO: implement as a table lookup */
+static inline size_t
+sizeof_elt_in_repeated_array (ProtobufCType type)
+{
+ switch (type)
+ {
+ case PROTOBUF_C_TYPE_SINT32:
+ case PROTOBUF_C_TYPE_INT32:
+ case PROTOBUF_C_TYPE_UINT32:
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
+ case PROTOBUF_C_TYPE_ENUM:
+ return 4;
+ case PROTOBUF_C_TYPE_SINT64:
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_UINT64:
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
+ return 8;
+ case PROTOBUF_C_TYPE_BOOL:
+ return sizeof (protobuf_c_boolean);
+ case PROTOBUF_C_TYPE_STRING:
+ case PROTOBUF_C_TYPE_MESSAGE:
+ return sizeof (void *);
+ case PROTOBUF_C_TYPE_BYTES:
+ return sizeof (ProtobufCBinaryData);
+ }
+ PROTOBUF_C_ASSERT_NOT_REACHED ();
+ return 0;
+}
+
+static void
+copy_to_little_endian_32 (void *out, const void *in, unsigned N)
+{
+#if IS_LITTLE_ENDIAN
+ memcpy (out, in, N * 4);
+#else
+ unsigned i;
+ const uint32_t *ini = in;
+ for (i = 0; i < N; i++)
+ fixed32_pack (ini[i], (uint32_t*)out + i);
+#endif
+}
+static void
+copy_to_little_endian_64 (void *out, const void *in, unsigned N)
+{
+#if IS_LITTLE_ENDIAN
+ memcpy (out, in, N * 8);
+#else
+ unsigned i;
+ const uint64_t *ini = in;
+ for (i = 0; i < N; i++)
+ fixed64_pack (ini[i], (uint64_t*)out + i);
+#endif
+}
+
+static unsigned
+get_type_min_size (ProtobufCType type)
+{
+ if (type == PROTOBUF_C_TYPE_SFIXED32
+ || type == PROTOBUF_C_TYPE_FIXED32
+ || type == PROTOBUF_C_TYPE_FLOAT)
+ return 4;
+ if (type == PROTOBUF_C_TYPE_SFIXED64
+ || type == PROTOBUF_C_TYPE_FIXED64
+ || type == PROTOBUF_C_TYPE_DOUBLE)
+ return 8;
+ return 1;
+}
+
+static size_t
+repeated_field_pack (const ProtobufCFieldDescriptor *field,
+ size_t count,
+ const void *member,
+ uint8_t *out)
+{
+ char *array = * (char * const *) member;
+ unsigned i;
+ if (field->packed)
+ {
+ unsigned header_len;
+ unsigned len_start;
+ unsigned min_length;
+ unsigned payload_len;
+ unsigned length_size_min;
+ unsigned actual_length_size;
+ uint8_t *payload_at;
+ if (count == 0)
+ return 0;
+ header_len = tag_pack (field->id, out);
+ out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
+ len_start = header_len;
+ min_length = get_type_min_size (field->type) * count;
+ length_size_min = uint32_size (min_length);
+ header_len += length_size_min;
+ payload_at = out + header_len;
+ switch (field->type)
+ {
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
+ copy_to_little_endian_32 (payload_at, array, count);
+ payload_at += count * 4;
+ break;
+
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
+ copy_to_little_endian_64 (payload_at, array, count);
+ payload_at += count * 8;
+ break;
+
+ case PROTOBUF_C_TYPE_INT32:
+ {
+ const int32_t *arr = (const int32_t *) array;
+ for (i = 0; i < count; i++)
+ payload_at += int32_pack (arr[i], payload_at);
+ }
+ break;
+
+ case PROTOBUF_C_TYPE_SINT32:
+ {
+ const int32_t *arr = (const int32_t *) array;
+ for (i = 0; i < count; i++)
+ payload_at += sint32_pack (arr[i], payload_at);
+ }
+ break;
+
+ case PROTOBUF_C_TYPE_SINT64:
+ {
+ const int64_t *arr = (const int64_t *) array;
+ for (i = 0; i < count; i++)
+ payload_at += sint64_pack (arr[i], payload_at);
+ }
+ break;
+ case PROTOBUF_C_TYPE_ENUM:
+ case PROTOBUF_C_TYPE_UINT32:
+ {
+ const uint32_t *arr = (const uint32_t *) array;
+ for (i = 0; i < count; i++)
+ payload_at += uint32_pack (arr[i], payload_at);
+ }
+ break;
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_UINT64:
+ {
+ const uint64_t *arr = (const uint64_t *) array;
+ for (i = 0; i < count; i++)
+ payload_at += uint64_pack (arr[i], payload_at);
+ }
+ break;
+ case PROTOBUF_C_TYPE_BOOL:
+ {
+ const protobuf_c_boolean *arr = (const protobuf_c_boolean *) array;
+ for (i = 0; i < count; i++)
+ payload_at += boolean_pack (arr[i], payload_at);
+ }
+ break;
+
+ default:
+ assert (0);
+ }
+ payload_len = payload_at - (out + header_len);
+ actual_length_size = uint32_size (payload_len);
+ if (length_size_min != actual_length_size)
+ {
+ assert (actual_length_size == length_size_min + 1);
+ memmove (out + header_len + 1, out + header_len, payload_len);
+ header_len++;
+ }
+ uint32_pack (payload_len, out + len_start);
+ return header_len + payload_len;
+ }
+ else
+ {
+ /* CONSIDER: optimize this case a bit (by putting the loop inside the switch) */
+ size_t rv = 0;
+ unsigned siz = sizeof_elt_in_repeated_array (field->type);
+ for (i = 0; i < count; i++)
+ {
+ rv += required_field_pack (field, array, out + rv);
+ array += siz;
+ }
+ return rv;
+ }
+}
+static size_t
+unknown_field_pack (const ProtobufCMessageUnknownField *field,
+ uint8_t *out)
+{
+ size_t rv = tag_pack (field->tag, out);
+ out[0] |= field->wire_type;
+ memcpy (out + rv, field->data, field->len);
+ return rv + field->len;
+}
+
+size_t
+protobuf_c_message_pack (const ProtobufCMessage *message,
+ uint8_t *out)
+{
+ unsigned i;
+ size_t rv = 0;
+ ASSERT_IS_MESSAGE (message);
+ for (i = 0; i < message->descriptor->n_fields; i++)
+ {
+ const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
+ const void *member = ((const char *) message) + field->offset;
+
+ /* it doesn't hurt to compute qmember (a pointer to the quantifier
+ field of the structure), but the pointer is only valid if
+ the field is one of:
+ - a repeated field
+ - an optional field that isn't a pointer type
+ (meaning: not a message or a string) */
+ const void *qmember = ((const char *) message) + field->quantifier_offset;
+
+ if (field->label == PROTOBUF_C_LABEL_REQUIRED)
+ rv += required_field_pack (field, member, out + rv);
+ else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
+ /* note that qmember is bogus for strings and messages,
+ but it isn't used */
+ rv += optional_field_pack (field, qmember, member, out + rv);
+ else
+ rv += repeated_field_pack (field, * (const size_t *) qmember, member, out + rv);
+ }
+ for (i = 0; i < message->n_unknown_fields; i++)
+ rv += unknown_field_pack (&message->unknown_fields[i], out + rv);
+ return rv;
+}
+
+/* === pack_to_buffer() === */
+static size_t
+required_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
+ const void *member,
+ ProtobufCBuffer *buffer)
+{
+ size_t rv;
+ uint8_t scratch[MAX_UINT64_ENCODED_SIZE * 2];
+ rv = tag_pack (field->id, scratch);
+ switch (field->type)
+ {
+ case PROTOBUF_C_TYPE_SINT32:
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += sint32_pack (*(const int32_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
+ case PROTOBUF_C_TYPE_INT32:
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += int32_pack (*(const uint32_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
+ case PROTOBUF_C_TYPE_UINT32:
+ case PROTOBUF_C_TYPE_ENUM:
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += uint32_pack (*(const uint32_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
+ case PROTOBUF_C_TYPE_SINT64:
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += sint64_pack (*(const int64_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_UINT64:
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += uint64_pack (*(const uint64_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_32BIT;
+ rv += fixed32_pack (*(const uint32_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_64BIT;
+ rv += fixed64_pack (*(const uint64_t *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
+ case PROTOBUF_C_TYPE_BOOL:
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
+ rv += boolean_pack (*(const protobuf_c_boolean *) member, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ break;
+ case PROTOBUF_C_TYPE_STRING:
+ {
+ const char *str = *(char * const *) member;
+ size_t sublen = str ? strlen (str) : 0;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
+ rv += uint32_pack (sublen, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ buffer->append (buffer, sublen, (const uint8_t *) str);
+ rv += sublen;
+ break;
+ }
+
+ case PROTOBUF_C_TYPE_BYTES:
+ {
+ const ProtobufCBinaryData * bd = ((const ProtobufCBinaryData*) member);
+ size_t sublen = bd->len;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
+ rv += uint32_pack (sublen, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ buffer->append (buffer, sublen, bd->data);
+ rv += sublen;
+ break;
+ }
+ //PROTOBUF_C_TYPE_GROUP, // NOT SUPPORTED
+ case PROTOBUF_C_TYPE_MESSAGE:
+ {
+ uint8_t simple_buffer_scratch[256];
+ size_t sublen;
+ ProtobufCBufferSimple simple_buffer
+ = PROTOBUF_C_BUFFER_SIMPLE_INIT (simple_buffer_scratch);
+ const ProtobufCMessage *msg = *(ProtobufCMessage * const *) member;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
+ if (msg == NULL)
+ sublen = 0;
+ else
+ sublen = protobuf_c_message_pack_to_buffer (msg, &simple_buffer.base);
+ rv += uint32_pack (sublen, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ buffer->append (buffer, sublen, simple_buffer.data);
+ rv += sublen;
+ PROTOBUF_C_BUFFER_SIMPLE_CLEAR (&simple_buffer);
+ break;
+ }
+ default:
+ PROTOBUF_C_ASSERT_NOT_REACHED ();
+ }
+ return rv;
+}
+static size_t
+optional_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
+ const protobuf_c_boolean *has,
+ const void *member,
+ ProtobufCBuffer *buffer)
+{
+ if (field->type == PROTOBUF_C_TYPE_MESSAGE
+ || field->type == PROTOBUF_C_TYPE_STRING)
+ {
+ const void *ptr = * (const void * const *) member;
+ if (ptr == NULL
+ || ptr == field->default_value)
+ return 0;
+ }
+ else
+ {
+ if (!*has)
+ return 0;
+ }
+ return required_field_pack_to_buffer (field, member, buffer);
+}
+
+static size_t
+get_packed_payload_length (const ProtobufCFieldDescriptor *field,
+ unsigned count,
+ const void *array)
+{
+ unsigned rv = 0;
+ unsigned i;
+ switch (field->type)
+ {
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
+ return count * 4;
+
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
+ return count * 8;
+
+ case PROTOBUF_C_TYPE_INT32:
+ {
+ const int32_t *arr = (const int32_t *) array;
+ for (i = 0; i < count; i++)
+ rv += int32_size (arr[i]);
+ }
+ break;
+
+ case PROTOBUF_C_TYPE_SINT32:
+ {
+ const int32_t *arr = (const int32_t *) array;
+ for (i = 0; i < count; i++)
+ rv += sint32_size (arr[i]);
+ }
+ break;
+ case PROTOBUF_C_TYPE_ENUM:
+ case PROTOBUF_C_TYPE_UINT32:
+ {
+ const uint32_t *arr = (const uint32_t *) array;
+ for (i = 0; i < count; i++)
+ rv += uint32_size (arr[i]);
+ }
+ break;
+
+ case PROTOBUF_C_TYPE_SINT64:
+ {
+ const int64_t *arr = (const int64_t *) array;
+ for (i = 0; i < count; i++)
+ rv += sint64_size (arr[i]);
+ }
+ break;
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_UINT64:
+ {
+ const uint64_t *arr = (const uint64_t *) array;
+ for (i = 0; i < count; i++)
+ rv += uint64_size (arr[i]);
+ }
+ break;
+ case PROTOBUF_C_TYPE_BOOL:
+ return count;
+ default:
+ assert (0);
+ }
+ return rv;
+}
+static size_t
+pack_buffer_packed_payload (const ProtobufCFieldDescriptor *field,
+ unsigned count,
+ const void *array,
+ ProtobufCBuffer *buffer)
+{
+ uint8_t scratch[16];
+ size_t rv = 0;
+ unsigned i;
+ switch (field->type)
+ {
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
+#if IS_LITTLE_ENDIAN
+ rv = count * 4;
+ goto no_packing_needed;
+#else
+ for (i = 0; i < count; i++)
+ {
+ unsigned len = fixed32_pack (((uint32_t*)array)[i], scratch);
+ buffer->append (buffer, len, scratch);
+ rv += len;
+ }
+#endif
+ break;
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
+#if IS_LITTLE_ENDIAN
+ rv = count * 8;
+ goto no_packing_needed;
+#else
+ for (i = 0; i < count; i++)
+ {
+ unsigned len = fixed64_pack (((uint64_t*)array)[i], scratch);
+ buffer->append (buffer, len, scratch);
+ rv += len;
+ }
+ break;
+#endif
+ case PROTOBUF_C_TYPE_INT32:
+ for (i = 0; i < count; i++)
+ {
+ unsigned len = int32_pack (((int32_t*)array)[i], scratch);
+ buffer->append (buffer, len, scratch);
+ rv += len;
+ }
+ break;
+
+ case PROTOBUF_C_TYPE_SINT32:
+ for (i = 0; i < count; i++)
+ {
+ unsigned len = sint32_pack (((int32_t*)array)[i], scratch);
+ buffer->append (buffer, len, scratch);
+ rv += len;
+ }
+ break;
+ case PROTOBUF_C_TYPE_ENUM:
+ case PROTOBUF_C_TYPE_UINT32:
+ for (i = 0; i < count; i++)
+ {
+ unsigned len = uint32_pack (((uint32_t*)array)[i], scratch);
+ buffer->append (buffer, len, scratch);
+ rv += len;
+ }
+ break;
+
+ case PROTOBUF_C_TYPE_SINT64:
+ for (i = 0; i < count; i++)
+ {
+ unsigned len = sint64_pack (((int64_t*)array)[i], scratch);
+ buffer->append (buffer, len, scratch);
+ rv += len;
+ }
+ break;
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_UINT64:
+ for (i = 0; i < count; i++)
+ {
+ unsigned len = uint64_pack (((uint64_t*)array)[i], scratch);
+ buffer->append (buffer, len, scratch);
+ rv += len;
+ }
+ break;
+ case PROTOBUF_C_TYPE_BOOL:
+ for (i = 0; i < count; i++)
+ {
+ unsigned len = boolean_pack (((protobuf_c_boolean*)array)[i], scratch);
+ buffer->append (buffer, len, scratch);
+ rv += len;
+ }
+ return count;
+ default:
+ assert(0);
+ }
+ return rv;
+
+no_packing_needed:
+ buffer->append (buffer, rv, array);
+ return rv;
+}
+
+static size_t
+repeated_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
+ unsigned count,
+ const void *member,
+ ProtobufCBuffer *buffer)
+{
+ char *array = * (char * const *) member;
+ if (count == 0)
+ return 0;
+ if (field->packed)
+ {
+ uint8_t scratch[MAX_UINT64_ENCODED_SIZE * 2];
+ size_t rv = tag_pack (field->id, scratch);
+ size_t payload_len = get_packed_payload_length (field, count, array);
+ size_t tmp;
+ scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
+ rv += uint32_pack (payload_len, scratch + rv);
+ buffer->append (buffer, rv, scratch);
+ tmp = pack_buffer_packed_payload (field, count, array, buffer);
+ assert (tmp == payload_len);
+ return rv + payload_len;
+ }
+ else
+ {
+ size_t siz;
+ unsigned i;
+ /* CONSIDER: optimize this case a bit (by putting the loop inside the switch) */
+ unsigned rv = 0;
+ siz = sizeof_elt_in_repeated_array (field->type);
+ for (i = 0; i < count; i++)
+ {
+ rv += required_field_pack_to_buffer (field, array, buffer);
+ array += siz;
+ }
+ return rv;
+ }
+}
+
+static size_t
+unknown_field_pack_to_buffer (const ProtobufCMessageUnknownField *field,
+ ProtobufCBuffer *buffer)
+{
+ uint8_t header[MAX_UINT64_ENCODED_SIZE];
+ size_t rv = tag_pack (field->tag, header);
+ header[0] |= field->wire_type;
+ buffer->append (buffer, rv, header);
+ buffer->append (buffer, field->len, field->data);
+ return rv + field->len;
+}
+
+size_t
+protobuf_c_message_pack_to_buffer (const ProtobufCMessage *message,
+ ProtobufCBuffer *buffer)
+{
+ unsigned i;
+ size_t rv = 0;
+ ASSERT_IS_MESSAGE (message);
+ for (i = 0; i < message->descriptor->n_fields; i++)
+ {
+ const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
+ const void *member = ((const char *) message) + field->offset;
+ const void *qmember = ((const char *) message) + field->quantifier_offset;
+
+ if (field->label == PROTOBUF_C_LABEL_REQUIRED)
+ rv += required_field_pack_to_buffer (field, member, buffer);
+ else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
+ rv += optional_field_pack_to_buffer (field, qmember, member, buffer);
+ else
+ rv += repeated_field_pack_to_buffer (field, * (const size_t *) qmember, member, buffer);
+ }
+ for (i = 0; i < message->n_unknown_fields; i++)
+ rv += unknown_field_pack_to_buffer (&message->unknown_fields[i], buffer);
+
+ return rv;
+}
+
+/* === unpacking === */
+#if PRINT_UNPACK_ERRORS
+# define UNPACK_ERROR(args) do { printf args;printf("\n"); }while(0)
+#else
+# define UNPACK_ERROR(args) do { } while (0)
+#endif
+
+static inline int
+int_range_lookup (unsigned n_ranges,
+ const ProtobufCIntRange *ranges,
+ int value)
+{
+ unsigned start, n;
+ if (n_ranges == 0)
+ return -1;
+ start = 0;
+ n = n_ranges;
+ while (n > 1)
+ {
+ unsigned mid = start + n / 2;
+ if (value < ranges[mid].start_value)
+ {
+ n = mid - start;
+ }
+ else if (value >= ranges[mid].start_value + (int)(ranges[mid+1].orig_index-ranges[mid].orig_index))
+ {
+ unsigned new_start = mid + 1;
+ n = start + n - new_start;
+ start = new_start;
+ }
+ else
+ return (value - ranges[mid].start_value) + ranges[mid].orig_index;
+ }
+ if (n > 0)
+ {
+ unsigned start_orig_index = ranges[start].orig_index;
+ unsigned range_size = ranges[start+1].orig_index - start_orig_index;
+
+ if (ranges[start].start_value <= value
+ && value < (int)(ranges[start].start_value + range_size))
+ return (value - ranges[start].start_value) + start_orig_index;
+ }
+ return -1;
+}
+
+static size_t
+parse_tag_and_wiretype (size_t len,
+ const uint8_t *data,
+ uint32_t *tag_out,
+ ProtobufCWireType *wiretype_out)
+{
+ unsigned max_rv = len > 5 ? 5 : len;
+ uint32_t tag = (data[0]&0x7f) >> 3;
+ unsigned shift = 4;
+ unsigned rv;
+ *wiretype_out = data[0] & 7;
+ if ((data[0] & 0x80) == 0)
+ {
+ *tag_out = tag;
+ return 1;
+ }
+ for (rv = 1; rv < max_rv; rv++)
+ if (data[rv] & 0x80)
+ {
+ tag |= (data[rv] & 0x7f) << shift;
+ shift += 7;
+ }
+ else
+ {
+ tag |= data[rv] << shift;
+ *tag_out = tag;
+ return rv + 1;
+ }
+ return 0; /* error: bad header */
+}
+
+/* sizeof(ScannedMember) must be <= (1<<BOUND_SIZEOF_SCANNED_MEMBER_LOG2) */
+#define BOUND_SIZEOF_SCANNED_MEMBER_LOG2 5
+typedef struct _ScannedMember ScannedMember;
+struct _ScannedMember
+{
+ uint32_t tag;
+ uint8_t wire_type;
+ uint8_t length_prefix_len;
+ const ProtobufCFieldDescriptor *field;
+ size_t len;
+ const uint8_t *data;
+};
+
+static inline uint32_t
+scan_length_prefixed_data (size_t len, const uint8_t *data, size_t *prefix_len_out)
+{
+ unsigned hdr_max = len < 5 ? len : 5;
+ unsigned hdr_len;
+ uint32_t val = 0;
+ unsigned i;
+ unsigned shift = 0;
+ for (i = 0; i < hdr_max; i++)
+ {
+ val |= (data[i] & 0x7f) << shift;
+ shift += 7;
+ if ((data[i] & 0x80) == 0)
+ break;
+ }
+ if (i == hdr_max)
+ {
+ UNPACK_ERROR (("error parsing length for length-prefixed data"));
+ return 0;
+ }
+ hdr_len = i + 1;
+ *prefix_len_out = hdr_len;
+ if (hdr_len + val > len)
+ {
+ UNPACK_ERROR (("data too short after length-prefix of %u",
+ val));
+ return 0;
+ }
+ return hdr_len + val;
+}
+
+static size_t
+max_b128_numbers (size_t len, const uint8_t *data)
+{
+ size_t rv = 0;
+ while (len--)
+ if ((*data++ & 0x80) == 0)
+ ++rv;
+ return rv;
+}
+
+
+/* Given a raw slab of packed-repeated values,
+ determine the number of elements.
+ This function detects certain kinds of errors
+ but not others; the remaining error checking is done by
+ parse_packed_repeated_member() */
+static protobuf_c_boolean
+count_packed_elements (ProtobufCType type,
+ size_t len,
+ const uint8_t *data,
+ size_t *count_out)
+{
+ switch (type)
+ {
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
+ if (len % 4 != 0)
+ {
+ UNPACK_ERROR (("length must be a multiple of 4 for fixed-length 32-bit types"));
+ return FALSE;
+ }
+ *count_out = len / 4;
+ return TRUE;
+
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
+ if (len % 8 != 0)
+ {
+ UNPACK_ERROR (("length must be a multiple of 8 for fixed-length 64-bit types"));
+ return FALSE;
+ }
+ *count_out = len / 8;
+ return TRUE;
+
+ case PROTOBUF_C_TYPE_INT32:
+ case PROTOBUF_C_TYPE_SINT32:
+ case PROTOBUF_C_TYPE_ENUM:
+ case PROTOBUF_C_TYPE_UINT32:
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_SINT64:
+ case PROTOBUF_C_TYPE_UINT64:
+ *count_out = max_b128_numbers (len, data);
+ return TRUE;
+ case PROTOBUF_C_TYPE_BOOL:
+ *count_out = len;
+ return TRUE;
+
+ case PROTOBUF_C_TYPE_STRING:
+ case PROTOBUF_C_TYPE_BYTES:
+ case PROTOBUF_C_TYPE_MESSAGE:
+ default:
+ UNPACK_ERROR (("bad protobuf-c type %u for packed-repeated", type));
+ return FALSE;
+ }
+}
+
+static inline uint32_t
+parse_uint32 (unsigned len, const uint8_t *data)
+{
+ unsigned rv = data[0] & 0x7f;
+ if (len > 1)
+ {
+ rv |= ((data[1] & 0x7f) << 7);
+ if (len > 2)
+ {
+ rv |= ((data[2] & 0x7f) << 14);
+ if (len > 3)
+ {
+ rv |= ((data[3] & 0x7f) << 21);
+ if (len > 4)
+ rv |= (data[4] << 28);
+ }
+ }
+ }
+ return rv;
+}
+static inline uint32_t
+parse_int32 (unsigned len, const uint8_t *data)
+{
+ return parse_uint32 (len, data);
+}
+static inline int32_t
+unzigzag32 (uint32_t v)
+{
+ if (v&1)
+ return -(v>>1) - 1;
+ else
+ return v>>1;
+}
+static inline uint32_t
+parse_fixed_uint32 (const uint8_t *data)
+{
+#if IS_LITTLE_ENDIAN
+ uint32_t t;
+ memcpy (&t, data, 4);
+ return t;
+#else
+ return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
+#endif
+}
+static uint64_t
+parse_uint64 (unsigned len, const uint8_t *data)
+{
+ unsigned shift, i;
+ if (len < 5)
+ return parse_uint32 (len, data);
+ uint64_t rv = ((data[0] & 0x7f))
+ | ((data[1] & 0x7f)<<7)
+ | ((data[2] & 0x7f)<<14)
+ | ((data[3] & 0x7f)<<21);
+ shift = 28;
+ for (i = 4; i < len; i++)
+ {
+ rv |= (((uint64_t)(data[i]&0x7f)) << shift);
+ shift += 7;
+ }
+ return rv;
+}
+static inline int64_t
+unzigzag64 (uint64_t v)
+{
+ if (v&1)
+ return -(v>>1) - 1;
+ else
+ return v>>1;
+}
+static inline uint64_t
+parse_fixed_uint64 (const uint8_t *data)
+{
+#if IS_LITTLE_ENDIAN
+ uint64_t t;
+ memcpy (&t, data, 8);
+ return t;
+#else
+ return (uint64_t)parse_fixed_uint32 (data)
+ | (((uint64_t)parse_fixed_uint32(data+4)) << 32);
+#endif
+}
+static protobuf_c_boolean
+parse_boolean (unsigned len, const uint8_t *data)
+{
+ unsigned i;
+ for (i = 0; i < len; i++)
+ if (data[i] & 0x7f)
+ return 1;
+ return 0;
+}
+static protobuf_c_boolean
+parse_required_member (ScannedMember *scanned_member,
+ void *member,
+ ProtobufCAllocator *allocator,
+ protobuf_c_boolean maybe_clear)
+{
+ unsigned len = scanned_member->len;
+ const uint8_t *data = scanned_member->data;
+ ProtobufCWireType wire_type = scanned_member->wire_type;
+ switch (scanned_member->field->type)
+ {
+ case PROTOBUF_C_TYPE_INT32:
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(uint32_t*)member = parse_int32 (len, data);
+ return 1;
+ case PROTOBUF_C_TYPE_UINT32:
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(uint32_t*)member = parse_uint32 (len, data);
+ return 1;
+ case PROTOBUF_C_TYPE_SINT32:
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(int32_t*)member = unzigzag32 (parse_uint32 (len, data));
+ return 1;
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_32BIT)
+ return 0;
+ *(uint32_t*)member = parse_fixed_uint32 (data);
+ return 1;
+
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_UINT64:
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(uint64_t*)member = parse_uint64 (len, data);
+ return 1;
+ case PROTOBUF_C_TYPE_SINT64:
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(int64_t*)member = unzigzag64 (parse_uint64 (len, data));
+ return 1;
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_64BIT)
+ return 0;
+ *(uint64_t*)member = parse_fixed_uint64 (data);
+ return 1;
+
+ case PROTOBUF_C_TYPE_BOOL:
+ *(protobuf_c_boolean*)member = parse_boolean (len, data);
+ return 1;
+
+ case PROTOBUF_C_TYPE_ENUM:
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT)
+ return 0;
+ *(uint32_t*)member = parse_uint32 (len, data);
+ return 1;
+
+ case PROTOBUF_C_TYPE_STRING:
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
+ return 0;
+ {
+ char **pstr = member;
+ unsigned pref_len = scanned_member->length_prefix_len;
+ if (maybe_clear && *pstr != NULL)
+ {
+ const char *def = scanned_member->field->default_value;
+ if (*pstr != NULL && *pstr != def)
+ FREE (allocator, *pstr);
+ }
+ DO_ALLOC (*pstr, allocator, len - pref_len + 1, return 0);
+ memcpy (*pstr, data + pref_len, len - pref_len);
+ (*pstr)[len-pref_len] = 0;
+ return 1;
+ }
+ case PROTOBUF_C_TYPE_BYTES:
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
+ return 0;
+ {
+ ProtobufCBinaryData *bd = member;
+ const ProtobufCBinaryData *def_bd;
+ unsigned pref_len = scanned_member->length_prefix_len;
+ def_bd = scanned_member->field->default_value;
+ if (maybe_clear && bd->data != NULL && bd->data != def_bd->data)
+ FREE (allocator, bd->data);
+ DO_ALLOC (bd->data, allocator, len - pref_len, return 0);
+ memcpy (bd->data, data + pref_len, len - pref_len);
+ bd->len = len - pref_len;
+ return 1;
+ }
+ //case PROTOBUF_C_TYPE_GROUP, // NOT SUPPORTED
+ case PROTOBUF_C_TYPE_MESSAGE:
+ if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
+ return 0;
+ {
+ ProtobufCMessage **pmessage = member;
+ ProtobufCMessage *subm;
+ const ProtobufCMessage *def_mess;
+ unsigned pref_len = scanned_member->length_prefix_len;
+ def_mess = scanned_member->field->default_value;
+ if (maybe_clear && *pmessage != NULL && *pmessage != def_mess)
+ protobuf_c_message_free_unpacked (*pmessage, allocator);
+ subm = protobuf_c_message_unpack (scanned_member->field->descriptor,
+ allocator,
+ len - pref_len, data + pref_len);
+ *pmessage = subm; /* since we freed the message we must clear the field, even if NULL */
+ if (subm == NULL)
+ return 0;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static protobuf_c_boolean
+parse_optional_member (ScannedMember *scanned_member,
+ void *member,
+ ProtobufCMessage *message,
+ ProtobufCAllocator *allocator)
+{
+ if (!parse_required_member (scanned_member, member, allocator, TRUE))
+ return 0;
+ if (scanned_member->field->quantifier_offset != 0)
+ STRUCT_MEMBER (protobuf_c_boolean,
+ message,
+ scanned_member->field->quantifier_offset) = 1;
+ return 1;
+}
+
+static protobuf_c_boolean
+parse_repeated_member (ScannedMember *scanned_member,
+ void *member,
+ ProtobufCMessage *message,
+ ProtobufCAllocator *allocator)
+{
+ const ProtobufCFieldDescriptor *field = scanned_member->field;
+ size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset);
+ size_t siz = sizeof_elt_in_repeated_array (field->type);
+ char *array = *(char**)member;
+ if (!parse_required_member (scanned_member,
+ array + siz * (*p_n),
+ allocator,
+ FALSE))
+ return 0;
+ *p_n += 1;
+ return 1;
+}
+
+static unsigned scan_varint (unsigned len, const uint8_t *data)
+{
+ unsigned i;
+ if (len > 10)
+ len = 10;
+ for (i = 0; i < len; i++)
+ if ((data[i] & 0x80) == 0)
+ break;
+ if (i == len)
+ return 0;
+ return i + 1;
+}
+
+static protobuf_c_boolean
+parse_packed_repeated_member (ScannedMember *scanned_member,
+ void *member,
+ ProtobufCMessage *message)
+{
+ const ProtobufCFieldDescriptor *field = scanned_member->field;
+ size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset);
+ size_t siz = sizeof_elt_in_repeated_array (field->type);
+ char *array = *(char**)member + siz * (*p_n);
+ const uint8_t *at = scanned_member->data + scanned_member->length_prefix_len;
+ size_t rem = scanned_member->len - scanned_member->length_prefix_len;
+ size_t count = 0;
+ unsigned i;
+ switch (field->type)
+ {
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
+ count = (scanned_member->len - scanned_member->length_prefix_len) / 4;
+#if IS_LITTLE_ENDIAN
+ goto no_unpacking_needed;
+#else
+ for (i = 0; i < count; i++)
+ {
+ ((uint32_t*)array)[i] = parse_fixed_uint32 (at);
+ at += 4;
+ }
+#endif
+ break;
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
+ count = (scanned_member->len - scanned_member->length_prefix_len) / 8;
+#if IS_LITTLE_ENDIAN
+ goto no_unpacking_needed;
+#else
+ for (i = 0; i < count; i++)
+ {
+ ((uint64_t*)array)[i] = parse_fixed_uint64 (at);
+ at += 8;
+ }
+ break;
+#endif
+ case PROTOBUF_C_TYPE_INT32:
+ while (rem > 0)
+ {
+ unsigned s = scan_varint (rem, at);
+ if (s == 0)
+ {
+ UNPACK_ERROR (("bad packed-repeated int32 value"));
+ return FALSE;
+ }
+ ((int32_t*)array)[count++] = parse_int32 (s, at);
+ at += s;
+ rem -= s;
+ }
+ break;
+
+ case PROTOBUF_C_TYPE_SINT32:
+ while (rem > 0)
+ {
+ unsigned s = scan_varint (rem, at);
+ if (s == 0)
+ {
+ UNPACK_ERROR (("bad packed-repeated sint32 value"));
+ return FALSE;
+ }
+ ((int32_t*)array)[count++] = unzigzag32 (parse_uint32 (s, at));
+ at += s;
+ rem -= s;
+ }
+ break;
+ case PROTOBUF_C_TYPE_ENUM:
+ case PROTOBUF_C_TYPE_UINT32:
+ while (rem > 0)
+ {
+ unsigned s = scan_varint (rem, at);
+ if (s == 0)
+ {
+ UNPACK_ERROR (("bad packed-repeated enum or uint32 value"));
+ return FALSE;
+ }
+ ((uint32_t*)array)[count++] = parse_uint32 (s, at);
+ at += s;
+ rem -= s;
+ }
+ break;
+
+ case PROTOBUF_C_TYPE_SINT64:
+ while (rem > 0)
+ {
+ unsigned s = scan_varint (rem, at);
+ if (s == 0)
+ {
+ UNPACK_ERROR (("bad packed-repeated sint64 value"));
+ return FALSE;
+ }
+ ((int64_t*)array)[count++] = unzigzag64 (parse_uint64 (s, at));
+ at += s;
+ rem -= s;
+ }
+ break;
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_UINT64:
+ while (rem > 0)
+ {
+ unsigned s = scan_varint (rem, at);
+ if (s == 0)
+ {
+ UNPACK_ERROR (("bad packed-repeated int64/uint64 value"));
+ return FALSE;
+ }
+ ((int64_t*)array)[count++] = parse_uint64 (s, at);
+ at += s;
+ rem -= s;
+ }
+ break;
+ case PROTOBUF_C_TYPE_BOOL:
+ count = rem;
+ for (i = 0; i < count; i++)
+ {
+ if (at[i] > 1)
+ {
+ UNPACK_ERROR (("bad packed-repeated boolean value"));
+ return FALSE;
+ }
+ ((protobuf_c_boolean*)array)[i] = at[i];
+ }
+ break;
+ default:
+ assert(0);
+ }
+ *p_n += count;
+ return TRUE;
+
+no_unpacking_needed:
+ memcpy (array, at, count * siz);
+ *p_n += count;
+ return TRUE;
+}
+
+static protobuf_c_boolean
+parse_member (ScannedMember *scanned_member,
+ ProtobufCMessage *message,
+ ProtobufCAllocator *allocator)
+{
+ const ProtobufCFieldDescriptor *field = scanned_member->field;
+ void *member;
+ if (field == NULL)
+ {
+ ProtobufCMessageUnknownField *ufield = message->unknown_fields + (message->n_unknown_fields++);
+ ufield->tag = scanned_member->tag;
+ ufield->wire_type = scanned_member->wire_type;
+ ufield->len = scanned_member->len;
+ DO_UNALIGNED_ALLOC (ufield->data, allocator, scanned_member->len, return 0);
+ memcpy (ufield->data, scanned_member->data, ufield->len);
+ return 1;
+ }
+ member = (char*)message + field->offset;
+ switch (field->label)
+ {
+ case PROTOBUF_C_LABEL_REQUIRED:
+ return parse_required_member (scanned_member, member, allocator, TRUE);
+ case PROTOBUF_C_LABEL_OPTIONAL:
+ return parse_optional_member (scanned_member, member, message, allocator);
+ case PROTOBUF_C_LABEL_REPEATED:
+ if (field->packed
+ && scanned_member->wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
+ return parse_packed_repeated_member (scanned_member, member, message);
+ else
+ return parse_repeated_member (scanned_member, member, message, allocator);
+ }
+ PROTOBUF_C_ASSERT_NOT_REACHED ();
+ return 0;
+}
+
+
+/* TODO: expose/use this function if desc->message_init==NULL
+ (which occurs for old code, and may be useful for certain
+ programatic techniques for generating descriptors). */
+void
+protobuf_c_message_init_generic (const ProtobufCMessageDescriptor *desc,
+ ProtobufCMessage *message)
+{
+ unsigned i;
+ memset (message, 0, desc->sizeof_message);
+ message->descriptor = desc;
+ for (i = 0; i < desc->n_fields; i++)
+ if (desc->fields[i].default_value != NULL
+ && desc->fields[i].label != PROTOBUF_C_LABEL_REPEATED)
+ {
+ void *field = STRUCT_MEMBER_P (message, desc->fields[i].offset);
+ const void *dv = desc->fields[i].default_value;
+ switch (desc->fields[i].type)
+ {
+ case PROTOBUF_C_TYPE_INT32:
+ case PROTOBUF_C_TYPE_SINT32:
+ case PROTOBUF_C_TYPE_SFIXED32:
+ case PROTOBUF_C_TYPE_UINT32:
+ case PROTOBUF_C_TYPE_FIXED32:
+ case PROTOBUF_C_TYPE_FLOAT:
+ case PROTOBUF_C_TYPE_ENUM:
+ memcpy (field, dv, 4);
+ break;
+
+ case PROTOBUF_C_TYPE_INT64:
+ case PROTOBUF_C_TYPE_SINT64:
+ case PROTOBUF_C_TYPE_SFIXED64:
+ case PROTOBUF_C_TYPE_UINT64:
+ case PROTOBUF_C_TYPE_FIXED64:
+ case PROTOBUF_C_TYPE_DOUBLE:
+ memcpy (field, dv, 8);
+ break;
+
+ case PROTOBUF_C_TYPE_BOOL:
+ memcpy (field, dv, sizeof (protobuf_c_boolean));
+ break;
+
+ case PROTOBUF_C_TYPE_BYTES:
+ memcpy (field, dv, sizeof (ProtobufCBinaryData));
+ break;
+
+ case PROTOBUF_C_TYPE_STRING:
+ case PROTOBUF_C_TYPE_MESSAGE:
+ /* the next line essentially implements a cast from const,
+ which is totally unavoidable. */
+ *(const void**)field = dv;
+ break;
+ }
+ }
+}
+
+/* ScannedMember slabs (an unpacking implementation detail).
+ Before doing real unpacking, we first scan through the
+ elements to see how many there are (for repeated fields),
+ and which field to use (for non-repeated fields given twice).
+
+ * In order to avoid allocations for small messages,
+ we keep a stack-allocated slab of ScannedMembers of
+ size FIRST_SCANNED_MEMBER_SLAB_SIZE (16).
+ After we fill that up, we allocate each slab twice
+ as large as the previous one. */
+#define FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2 4
+
+/* The number of slabs, including the stack-allocated ones;
+ choose the number so that we would overflow if we needed
+ a slab larger than provided. */
+#define MAX_SCANNED_MEMBER_SLAB \
+ (sizeof(void*)*8 - 1 \
+ - BOUND_SIZEOF_SCANNED_MEMBER_LOG2 \
+ - FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2)
+
+ProtobufCMessage *
+protobuf_c_message_unpack (const ProtobufCMessageDescriptor *desc,
+ ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data)
+{
+ ProtobufCMessage *rv;
+ size_t rem = len;
+ const uint8_t *at = data;
+ const ProtobufCFieldDescriptor *last_field = desc->fields + 0;
+ ScannedMember first_member_slab[1<<FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2];
+
+ /* scanned_member_slabs[i] is an array of arrays of ScannedMember.
+ The first slab (scanned_member_slabs[0] is just a pointer to
+ first_member_slab), above. All subsequent slabs will be allocated
+ using the allocator. */
+ ScannedMember *scanned_member_slabs[MAX_SCANNED_MEMBER_SLAB+1];
+ unsigned which_slab = 0; /* the slab we are currently populating */
+ unsigned in_slab_index = 0; /* number of members in the slab */
+ size_t n_unknown = 0;
+ unsigned f;
+ unsigned i_slab;
+ unsigned last_field_index = 0;
+ unsigned long *required_fields_bitmap;
+ unsigned required_fields_bitmap_len;
+ static const unsigned word_bits = sizeof(long) * 8;
+
+ ASSERT_IS_MESSAGE_DESCRIPTOR (desc);
+
+ if (allocator == NULL)
+ allocator = &protobuf_c_default_allocator;
+
+ required_fields_bitmap_len = (desc->n_fields + word_bits - 1) / word_bits;
+ required_fields_bitmap = alloca(required_fields_bitmap_len * sizeof(long));
+ memset(required_fields_bitmap, 0, required_fields_bitmap_len * sizeof(long));
+
+ DO_ALLOC (rv, allocator, desc->sizeof_message, return NULL);
+ scanned_member_slabs[0] = first_member_slab;
+
+ /* Generated code always defines "message_init".
+ However, we provide a fallback for (1) users of old protobuf-c
+ generated-code that do not provide the function,
+ and (2) descriptors constructed from some other source
+ (most likely, direct construction from the .proto file) */
+ if (desc->message_init != NULL)
+ protobuf_c_message_init (desc, rv);
+ else
+ protobuf_c_message_init_generic (desc, rv);
+
+ while (rem > 0)
+ {
+ uint32_t tag;
+ ProtobufCWireType wire_type;
+ size_t used = parse_tag_and_wiretype (rem, at, &tag, &wire_type);
+ const ProtobufCFieldDescriptor *field;
+ ScannedMember tmp;
+ if (used == 0)
+ {
+ UNPACK_ERROR (("error parsing tag/wiretype at offset %u",
+ (unsigned)(at-data)));
+ goto error_cleanup_during_scan;
+ }
+ /* XXX: consider optimizing for field[1].id == tag, if field[1] exists! */
+ if (last_field->id != tag)
+ {
+ /* lookup field */
+ int field_index = int_range_lookup (desc->n_field_ranges,
+ desc->field_ranges,
+ tag);
+ if (field_index < 0)
+ {
+ field = NULL;
+ n_unknown++;
+ }
+ else
+ {
+ field = desc->fields + field_index;
+ last_field = field;
+ last_field_index = field_index;
+ }
+ }
+ else
+ field = last_field;
+
+ if (field != NULL && field->label == PROTOBUF_C_LABEL_REQUIRED)
+ required_fields_bitmap[last_field_index / word_bits] |= (1UL << (last_field_index % word_bits));
+
+ at += used;
+ rem -= used;
+ tmp.tag = tag;
+ tmp.wire_type = wire_type;
+ tmp.field = field;
+ tmp.data = at;
+ switch (wire_type)
+ {
+ case PROTOBUF_C_WIRE_TYPE_VARINT:
+ {
+ unsigned max_len = rem < 10 ? rem : 10;
+ unsigned i;
+ for (i = 0; i < max_len; i++)
+ if ((at[i] & 0x80) == 0)
+ break;
+ if (i == max_len)
+ {
+ UNPACK_ERROR (("unterminated varint at offset %u",
+ (unsigned)(at-data)));
+ goto error_cleanup_during_scan;
+ }
+ tmp.len = i + 1;
+ }
+ break;
+ case PROTOBUF_C_WIRE_TYPE_64BIT:
+ if (rem < 8)
+ {
+ UNPACK_ERROR (("too short after 64bit wiretype at offset %u",
+ (unsigned)(at-data)));
+ goto error_cleanup_during_scan;
+ }
+ tmp.len = 8;
+ break;
+ case PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED:
+ {
+ size_t pref_len;
+ tmp.len = scan_length_prefixed_data (rem, at, &pref_len);
+ if (tmp.len == 0)
+ {
+ /* NOTE: scan_length_prefixed_data calls UNPACK_ERROR */
+ goto error_cleanup_during_scan;
+ }
+ tmp.length_prefix_len = pref_len;
+ break;
+ }
+ case PROTOBUF_C_WIRE_TYPE_32BIT:
+ if (rem < 4)
+ {
+ UNPACK_ERROR (("too short after 32bit wiretype at offset %u",
+ (unsigned)(at-data)));
+ goto error_cleanup_during_scan;
+ }
+ tmp.len = 4;
+ break;
+ default:
+ UNPACK_ERROR (("unsupported tag %u at offset %u",
+ wire_type, (unsigned)(at-data)));
+ goto error_cleanup_during_scan;
+ }
+ if (in_slab_index == (1U<<(which_slab+FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2)))
+ {
+ size_t size;
+ in_slab_index = 0;
+ if (which_slab == MAX_SCANNED_MEMBER_SLAB)
+ {
+ UNPACK_ERROR (("too many fields"));
+ goto error_cleanup_during_scan;
+ }
+ which_slab++;
+ size = sizeof(ScannedMember) << (which_slab+FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2);
+ /* TODO: consider using alloca() ! */
+ if (allocator->tmp_alloc != NULL)
+ scanned_member_slabs[which_slab] = TMPALLOC(allocator, size);
+ else
+ DO_ALLOC (scanned_member_slabs[which_slab], allocator, size, goto error_cleanup_during_scan);
+ }
+ scanned_member_slabs[which_slab][in_slab_index++] = tmp;
+
+ if (field != NULL && field->label == PROTOBUF_C_LABEL_REPEATED)
+ {
+ size_t *n = STRUCT_MEMBER_PTR (size_t, rv, field->quantifier_offset);
+ if (field->packed
+ && wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
+ {
+ size_t count;
+ if (!count_packed_elements (field->type,
+ tmp.len - tmp.length_prefix_len,
+ tmp.data + tmp.length_prefix_len,
+ &count))
+ {
+ UNPACK_ERROR (("counting packed elements"));
+ goto error_cleanup_during_scan;
+ }
+ *n += count;
+ }
+ else
+ *n += 1;
+ }
+
+ at += tmp.len;
+ rem -= tmp.len;
+ }
+
+ /* allocate space for repeated fields, also check that all required fields have been set */
+ for (f = 0; f < desc->n_fields; f++)
+ {
+ const ProtobufCFieldDescriptor *field = desc->fields + f;
+ if (field->label == PROTOBUF_C_LABEL_REPEATED)
+ {
+ size_t siz = sizeof_elt_in_repeated_array (field->type);
+ size_t *n_ptr = STRUCT_MEMBER_PTR (size_t, rv, field->quantifier_offset);
+ if (*n_ptr != 0)
+ {
+ unsigned n = *n_ptr;
+ *n_ptr = 0;
+ assert(rv->descriptor != NULL);
+#define CLEAR_REMAINING_N_PTRS() \
+ for(f++;f < desc->n_fields; f++) \
+ { \
+ field = desc->fields + f; \
+ if (field->label == PROTOBUF_C_LABEL_REPEATED) \
+ STRUCT_MEMBER (size_t, rv, field->quantifier_offset) = 0; \
+ }
+ DO_ALLOC (STRUCT_MEMBER (void *, rv, field->offset),
+ allocator, siz * n,
+ CLEAR_REMAINING_N_PTRS (); goto error_cleanup);
+#undef CLEAR_REMAINING_N_PTRS
+ }
+ }
+ else if (field->label == PROTOBUF_C_LABEL_REQUIRED)
+ {
+ if (field->default_value == NULL && 0 == (required_fields_bitmap[f / word_bits] & (1UL << (f % word_bits))))
+ {
+ UNPACK_ERROR (("message '%s': missing required field '%s'", desc->name, field->name));
+ goto error_cleanup;
+ }
+ }
+ }
+
+ /* allocate space for unknown fields */
+ if (n_unknown)
+ {
+ DO_ALLOC (rv->unknown_fields,
+ allocator, n_unknown * sizeof (ProtobufCMessageUnknownField),
+ goto error_cleanup);
+ }
+
+ /* do real parsing */
+ for (i_slab = 0; i_slab <= which_slab; i_slab++)
+ {
+ unsigned max = (i_slab == which_slab) ? in_slab_index : (1U<<(i_slab+4));
+ ScannedMember *slab = scanned_member_slabs[i_slab];
+ unsigned j;
+ for (j = 0; j < max; j++)
+ {
+ if (!parse_member (slab + j, rv, allocator))
+ {
+ UNPACK_ERROR (("error parsing member %s of %s",
+ slab->field ? slab->field->name : "*unknown-field*", desc->name));
+ goto error_cleanup;
+ }
+ }
+ }
+
+ /* cleanup */
+ if (allocator->tmp_alloc == NULL)
+ {
+ unsigned j;
+ for (j = 1; j <= which_slab; j++)
+ FREE (allocator, scanned_member_slabs[j]);
+ }
+
+ return rv;
+
+error_cleanup:
+ protobuf_c_message_free_unpacked (rv, allocator);
+ if (allocator->tmp_alloc == NULL)
+ {
+ unsigned j;
+ for (j = 1; j <= which_slab; j++)
+ FREE (allocator, scanned_member_slabs[j]);
+ }
+ return NULL;
+
+error_cleanup_during_scan:
+ FREE (allocator, rv);
+ if (allocator->tmp_alloc == NULL)
+ {
+ unsigned j;
+ for (j = 1; j <= which_slab; j++)
+ FREE (allocator, scanned_member_slabs[j]);
+ }
+ return NULL;
+}
+
+/* === free_unpacked === */
+void
+protobuf_c_message_free_unpacked (ProtobufCMessage *message,
+ ProtobufCAllocator *allocator)
+{
+ const ProtobufCMessageDescriptor *desc = message->descriptor;
+ unsigned f;
+ ASSERT_IS_MESSAGE (message);
+ if (allocator == NULL)
+ allocator = &protobuf_c_default_allocator;
+ message->descriptor = NULL;
+ for (f = 0; f < desc->n_fields; f++)
+ {
+ if (desc->fields[f].label == PROTOBUF_C_LABEL_REPEATED)
+ {
+ size_t n = STRUCT_MEMBER (size_t, message, desc->fields[f].quantifier_offset);
+ void * arr = STRUCT_MEMBER (void *, message, desc->fields[f].offset);
+ if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING)
+ {
+ unsigned i;
+ for (i = 0; i < n; i++)
+ FREE (allocator, ((char**)arr)[i]);
+ }
+ else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES)
+ {
+ unsigned i;
+ for (i = 0; i < n; i++)
+ FREE (allocator, ((ProtobufCBinaryData*)arr)[i].data);
+ }
+ else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE)
+ {
+ unsigned i;
+ for (i = 0; i < n; i++)
+ protobuf_c_message_free_unpacked (((ProtobufCMessage**)arr)[i], allocator);
+ }
+ if (arr != NULL)
+ FREE (allocator, arr);
+ }
+ else if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING)
+ {
+ char *str = STRUCT_MEMBER (char *, message, desc->fields[f].offset);
+ if (str && str != desc->fields[f].default_value)
+ FREE (allocator, str);
+ }
+ else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES)
+ {
+ void *data = STRUCT_MEMBER (ProtobufCBinaryData, message, desc->fields[f].offset).data;
+ const ProtobufCBinaryData *default_bd;
+ default_bd = desc->fields[f].default_value;
+ if (data != NULL
+ && (default_bd == NULL || default_bd->data != data))
+ FREE (allocator, data);
+ }
+ else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE)
+ {
+ ProtobufCMessage *sm;
+ sm = STRUCT_MEMBER (ProtobufCMessage *, message,desc->fields[f].offset);
+ if (sm && sm != desc->fields[f].default_value)
+ protobuf_c_message_free_unpacked (sm, allocator);
+ }
+ }
+
+ for (f = 0; f < message->n_unknown_fields; f++)
+ FREE (allocator, message->unknown_fields[f].data);
+ if (message->unknown_fields != NULL)
+ FREE (allocator, message->unknown_fields);
+
+ FREE (allocator, message);
+}
+
+/* === services === */
+typedef void (*GenericHandler)(void *service,
+ const ProtobufCMessage *input,
+ ProtobufCClosure closure,
+ void *closure_data);
+void
+protobuf_c_service_invoke_internal(ProtobufCService *service,
+ unsigned method_index,
+ const ProtobufCMessage *input,
+ ProtobufCClosure closure,
+ void *closure_data)
+{
+ GenericHandler *handlers;
+ GenericHandler handler;
+
+ /* Verify that method_index is within range.
+ If this fails, you are likely invoking a newly added
+ method on an old service. (Although other memory corruption
+ bugs can cause this assertion too) */
+ PROTOBUF_C_ASSERT (method_index < service->descriptor->n_methods);
+
+ /* Get the array of virtual methods (which are enumerated by
+ the generated code) */
+ handlers = (GenericHandler *) (service + 1);
+
+ /* get our method and invoke it */
+ /* TODO: seems like handler==NULL is a situation that
+ needs handling */
+ handler = handlers[method_index];
+ (*handler) (service, input, closure, closure_data);
+}
+
+void
+protobuf_c_service_generated_init (ProtobufCService *service,
+ const ProtobufCServiceDescriptor *descriptor,
+ ProtobufCServiceDestroy destroy)
+{
+ ASSERT_IS_SERVICE_DESCRIPTOR(descriptor);
+ service->descriptor = descriptor;
+ service->destroy = destroy;
+ service->invoke = protobuf_c_service_invoke_internal;
+ memset (service + 1, 0, descriptor->n_methods * sizeof (GenericHandler));
+}
+
+void protobuf_c_service_destroy (ProtobufCService *service)
+{
+ service->destroy (service);
+}
+
+/* --- querying the descriptors --- */
+const ProtobufCEnumValue *
+protobuf_c_enum_descriptor_get_value_by_name
+ (const ProtobufCEnumDescriptor *desc,
+ const char *name)
+{
+ unsigned start = 0, count = desc->n_value_names;
+ while (count > 1)
+ {
+ unsigned mid = start + count / 2;
+ int rv = strcmp (desc->values_by_name[mid].name, name);
+ if (rv == 0)
+ return desc->values + desc->values_by_name[mid].index;
+ else if (rv < 0)
+ {
+ count = start + count - (mid + 1);
+ start = mid + 1;
+ }
+ else
+ count = mid - start;
+ }
+ if (count == 0)
+ return NULL;
+ if (strcmp (desc->values_by_name[start].name, name) == 0)
+ return desc->values + desc->values_by_name[start].index;
+ return NULL;
+}
+const ProtobufCEnumValue *
+protobuf_c_enum_descriptor_get_value
+ (const ProtobufCEnumDescriptor *desc,
+ int value)
+{
+ int rv = int_range_lookup (desc->n_value_ranges, desc->value_ranges, value);
+ if (rv < 0)
+ return NULL;
+ return desc->values + rv;
+}
+
+const ProtobufCFieldDescriptor *
+protobuf_c_message_descriptor_get_field_by_name
+ (const ProtobufCMessageDescriptor *desc,
+ const char *name)
+{
+ unsigned start = 0, count = desc->n_fields;
+ const ProtobufCFieldDescriptor *field;
+ while (count > 1)
+ {
+ unsigned mid = start + count / 2;
+ int rv;
+ field = desc->fields + desc->fields_sorted_by_name[mid];
+ rv = strcmp (field->name, name);
+ if (rv == 0)
+ return field;
+ else if (rv < 0)
+ {
+ count = start + count - (mid + 1);
+ start = mid + 1;
+ }
+ else
+ count = mid - start;
+ }
+ if (count == 0)
+ return NULL;
+ field = desc->fields + desc->fields_sorted_by_name[start];
+ if (strcmp (field->name, name) == 0)
+ return field;
+ return NULL;
+}
+
+const ProtobufCFieldDescriptor *
+protobuf_c_message_descriptor_get_field
+ (const ProtobufCMessageDescriptor *desc,
+ unsigned value)
+{
+ int rv = int_range_lookup (desc->n_field_ranges,
+ desc->field_ranges,
+ value);
+ if (rv < 0)
+ return NULL;
+ return desc->fields + rv;
+}
+
+const ProtobufCMethodDescriptor *
+protobuf_c_service_descriptor_get_method_by_name
+ (const ProtobufCServiceDescriptor *desc,
+ const char *name)
+{
+ unsigned start = 0, count = desc->n_methods;
+ while (count > 1)
+ {
+ unsigned mid = start + count / 2;
+ unsigned mid_index = desc->method_indices_by_name[mid];
+ const char *mid_name = desc->methods[mid_index].name;
+ int rv = strcmp (mid_name, name);
+ if (rv == 0)
+ return desc->methods + desc->method_indices_by_name[mid];
+ if (rv < 0)
+ {
+ count = start + count - (mid + 1);
+ start = mid + 1;
+ }
+ else
+ {
+ count = mid - start;
+ }
+ }
+ if (count == 0)
+ return NULL;
+ if (strcmp (desc->methods[desc->method_indices_by_name[start]].name, name) == 0)
+ return desc->methods + desc->method_indices_by_name[start];
+ return NULL;
+}
--- /dev/null
+/* --- protobuf-c.h: public protobuf c runtime api --- */
+
+/*
+ * Copyright 2008, Dave Benson.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License
+ * at http://www.apache.org/licenses/LICENSE-2.0 Unless
+ * required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __PROTOBUF_C_RUNTIME_H_
+#define __PROTOBUF_C_RUNTIME_H_
+
+#include <stddef.h>
+#include <assert.h>
+
+#ifdef __cplusplus
+# define PROTOBUF_C_BEGIN_DECLS extern "C" {
+# define PROTOBUF_C_END_DECLS }
+#else
+# define PROTOBUF_C_BEGIN_DECLS
+# define PROTOBUF_C_END_DECLS
+#endif
+
+#if !defined(PROTOBUF_C_NO_DEPRECATED) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
+#define PROTOBUF_C_DEPRECATED __attribute__((__deprecated__))
+#else
+#define PROTOBUF_C_DEPRECATED
+#endif
+
+/* Define int32_t, int64_t, uint32_t, uint64_t, uint8_t.
+
+ Usually, just include <inttypes.h> to do the work.
+ XXX: should we use stdint.h?
+ */
+#ifndef PROTOBUF_C_SKIP_INTTYPES_H
+# if defined(_MSC_VER)
+ /* On windows, in ms visual studio, define the types ourselves */
+# define int32_t signed __int32
+# define uint32_t unsigned __int32
+# define int64_t signed __int64
+# define uint64_t unsigned __int64
+# define uint8_t unsigned char
+# else
+ /* Use the system inttypes.h */
+# include <inttypes.h>
+# endif
+#endif
+
+PROTOBUF_C_BEGIN_DECLS
+
+typedef enum
+{
+ PROTOBUF_C_LABEL_REQUIRED,
+ PROTOBUF_C_LABEL_OPTIONAL,
+ PROTOBUF_C_LABEL_REPEATED
+} ProtobufCLabel;
+
+typedef enum
+{
+ PROTOBUF_C_TYPE_INT32,
+ PROTOBUF_C_TYPE_SINT32,
+ PROTOBUF_C_TYPE_SFIXED32,
+ PROTOBUF_C_TYPE_INT64,
+ PROTOBUF_C_TYPE_SINT64,
+ PROTOBUF_C_TYPE_SFIXED64,
+ PROTOBUF_C_TYPE_UINT32,
+ PROTOBUF_C_TYPE_FIXED32,
+ PROTOBUF_C_TYPE_UINT64,
+ PROTOBUF_C_TYPE_FIXED64,
+ PROTOBUF_C_TYPE_FLOAT,
+ PROTOBUF_C_TYPE_DOUBLE,
+ PROTOBUF_C_TYPE_BOOL,
+ PROTOBUF_C_TYPE_ENUM,
+ PROTOBUF_C_TYPE_STRING,
+ PROTOBUF_C_TYPE_BYTES,
+ //PROTOBUF_C_TYPE_GROUP, // NOT SUPPORTED
+ PROTOBUF_C_TYPE_MESSAGE,
+} ProtobufCType;
+
+typedef int protobuf_c_boolean;
+#define PROTOBUF_C_OFFSETOF(struct, member) offsetof(struct, member)
+
+#define PROTOBUF_C_ASSERT(condition) assert(condition)
+#define PROTOBUF_C_ASSERT_NOT_REACHED() assert(0)
+
+typedef struct _ProtobufCBinaryData ProtobufCBinaryData;
+struct _ProtobufCBinaryData
+{
+ size_t len;
+ uint8_t *data;
+};
+
+typedef struct _ProtobufCIntRange ProtobufCIntRange; /* private */
+
+/* --- memory management --- */
+typedef struct _ProtobufCAllocator ProtobufCAllocator;
+struct _ProtobufCAllocator
+{
+ void *(*alloc)(void *allocator_data, size_t size);
+ void (*free)(void *allocator_data, void *pointer);
+ void *(*tmp_alloc)(void *allocator_data, size_t size);
+ unsigned max_alloca;
+ void *allocator_data;
+};
+
+/* This is a configurable allocator.
+ * By default, it uses the system allocator (meaning malloc() and free()).
+ * This is typically changed to adapt to frameworks that provide
+ * some nonstandard allocation functions.
+ *
+ * NOTE: you may modify this allocator.
+ */
+extern ProtobufCAllocator protobuf_c_default_allocator; /* settable */
+
+/* This is the system allocator, meaning it uses malloc() and free().
+ *
+ * NOTE: please do NOT modify this allocator.
+ */
+extern ProtobufCAllocator protobuf_c_system_allocator; /* use malloc, free etc */
+
+/* This is the function that our default allocators call when they
+ run out-of-memory. The default behavior of this function is to
+ terminate your program. */
+extern void (*protobuf_c_out_of_memory) (void);
+
+/* --- append-only data buffer --- */
+typedef struct _ProtobufCBuffer ProtobufCBuffer;
+struct _ProtobufCBuffer
+{
+ void (*append)(ProtobufCBuffer *buffer,
+ size_t len,
+ const uint8_t *data);
+};
+/* --- enums --- */
+typedef struct _ProtobufCEnumValue ProtobufCEnumValue;
+typedef struct _ProtobufCEnumValueIndex ProtobufCEnumValueIndex;
+typedef struct _ProtobufCEnumDescriptor ProtobufCEnumDescriptor;
+
+/* ProtobufCEnumValue: this represents a single value of
+ * an enumeration.
+ * 'name' is the string identifying this value, as given in the .proto file.
+ * 'c_name' is the full name of the C enumeration value.
+ * 'value' is the number assigned to this value, as given in the .proto file.
+ */
+struct _ProtobufCEnumValue
+{
+ const char *name;
+ const char *c_name;
+ int value;
+};
+
+/* ProtobufCEnumDescriptor: the represents the enum as a whole,
+ * with all its values.
+ * 'magic' is a code we check to ensure that the api is used correctly.
+ * 'name' is the qualified name (e.g. "namespace.Type").
+ * 'short_name' is the unqualified name ("Type"), as given in the .proto file.
+ * 'package_name' is the '.'-separated namespace
+ * 'n_values' is the number of distinct values.
+ * 'values' is the array of distinct values.
+ * 'n_value_names' number of named values (including aliases).
+ * 'value_names' are the named values (including aliases).
+ *
+ * The rest of the values are private essentially.
+ *
+ * see also: Use protobuf_c_enum_descriptor_get_value_by_name()
+ * and protobuf_c_enum_descriptor_get_value() to efficiently
+ * lookup values in the descriptor.
+ */
+struct _ProtobufCEnumDescriptor
+{
+ uint32_t magic;
+
+ const char *name;
+ const char *short_name;
+ const char *c_name;
+ const char *package_name;
+
+ /* sorted by value */
+ unsigned n_values;
+ const ProtobufCEnumValue *values;
+
+ /* sorted by name */
+ unsigned n_value_names;
+ const ProtobufCEnumValueIndex *values_by_name;
+
+ /* value-ranges, for faster lookups by number */
+ unsigned n_value_ranges;
+ const ProtobufCIntRange *value_ranges;
+
+ void *reserved1;
+ void *reserved2;
+ void *reserved3;
+ void *reserved4;
+};
+
+/* --- messages --- */
+typedef struct _ProtobufCMessageDescriptor ProtobufCMessageDescriptor;
+typedef struct _ProtobufCFieldDescriptor ProtobufCFieldDescriptor;
+typedef struct _ProtobufCMessage ProtobufCMessage;
+typedef void (*ProtobufCMessageInit)(ProtobufCMessage *);
+/* ProtobufCFieldDescriptor: description of a single field
+ * in a message.
+ * 'name' is the name of the field, as given in the .proto file.
+ * 'id' is the code representing the field, as given in the .proto file.
+ * 'label' is one of PROTOBUF_C_LABEL_{REQUIRED,OPTIONAL,REPEATED}
+ * 'type' is the type of field.
+ * 'quantifier_offset' is the offset in bytes into the message's C structure
+ * for this member's "has_MEMBER" field (for optional members) or
+ * "n_MEMBER" field (for repeated members).
+ * 'offset' is the offset in bytes into the message's C structure
+ * for the member itself.
+ * 'descriptor' is a pointer to a ProtobufC{Enum,Message}Descriptor
+ * if type is PROTOBUF_C_TYPE_{ENUM,MESSAGE} respectively,
+ * otherwise NULL.
+ * 'default_value' is a pointer to a default value for this field,
+ * where allowed.
+ */
+struct _ProtobufCFieldDescriptor
+{
+ const char *name;
+ uint32_t id;
+ ProtobufCLabel label;
+ ProtobufCType type;
+ unsigned quantifier_offset;
+ unsigned offset;
+ const void *descriptor; /* for MESSAGE and ENUM types */
+ const void *default_value; /* or NULL if no default-value */
+ protobuf_c_boolean packed;
+
+ unsigned reserved_flags;
+ void *reserved2;
+ void *reserved3;
+};
+/* ProtobufCMessageDescriptor: description of a message.
+ *
+ * 'magic' is a code we check to ensure that the api is used correctly.
+ * 'name' is the qualified name (e.g. "namespace.Type").
+ * 'short_name' is the unqualified name ("Type"), as given in the .proto file.
+ * 'c_name' is the c-formatted name of the structure
+ * 'package_name' is the '.'-separated namespace
+ * 'sizeof_message' is the size in bytes of the C structure
+ * representing an instance of this type of message.
+ * 'n_fields' is the number of known fields in this message.
+ * 'fields' is the fields sorted by id number.
+ * 'fields_sorted_by_name', 'n_field_ranges' and 'field_ranges'
+ * are used for looking up fields by name and id. (private)
+ */
+struct _ProtobufCMessageDescriptor
+{
+ uint32_t magic;
+
+ const char *name;
+ const char *short_name;
+ const char *c_name;
+ const char *package_name;
+
+ size_t sizeof_message;
+
+ /* sorted by field-id */
+ unsigned n_fields;
+ const ProtobufCFieldDescriptor *fields;
+ const unsigned *fields_sorted_by_name;
+
+ /* ranges, optimization for looking up fields */
+ unsigned n_field_ranges;
+ const ProtobufCIntRange *field_ranges;
+
+ ProtobufCMessageInit message_init;
+ void *reserved1;
+ void *reserved2;
+ void *reserved3;
+};
+
+
+/* ProtobufCMessage: an instance of a message.
+ *
+ * ProtobufCMessage is sort-of a lightweight
+ * base-class for all messages.
+ *
+ * In particular, ProtobufCMessage doesn't have
+ * any allocation policy associated with it.
+ * That's because it is common to create ProtobufCMessage's
+ * on the stack. In fact, we that's what we recommend
+ * for sending messages (because if you just allocate from the
+ * stack, then you can't really have a memory leak).
+ *
+ * This means that functions like protobuf_c_message_unpack()
+ * which return a ProtobufCMessage must be paired
+ * with a free function, like protobuf_c_message_free_unpacked().
+ *
+ * 'descriptor' gives the locations and types of the members of message
+ * 'n_unknown_fields' is the number of fields we didn't recognize.
+ * 'unknown_fields' are fields we didn't recognize.
+ */
+typedef struct _ProtobufCMessageUnknownField ProtobufCMessageUnknownField;
+struct _ProtobufCMessage
+{
+ const ProtobufCMessageDescriptor *descriptor;
+ unsigned n_unknown_fields;
+ ProtobufCMessageUnknownField *unknown_fields;
+};
+#define PROTOBUF_C_MESSAGE_INIT(descriptor) { descriptor, 0, NULL }
+
+/* To pack a message: you have two options:
+ (1) you can compute the size of the message
+ using protobuf_c_message_get_packed_size()
+ then pass protobuf_c_message_pack() a buffer of
+ that length.
+ (2) Provide a virtual buffer (a ProtobufCBuffer) to
+ accept data as we scan through it.
+ */
+size_t protobuf_c_message_get_packed_size(const ProtobufCMessage *message);
+size_t protobuf_c_message_pack (const ProtobufCMessage *message,
+ uint8_t *out);
+size_t protobuf_c_message_pack_to_buffer (const ProtobufCMessage *message,
+ ProtobufCBuffer *buffer);
+
+ProtobufCMessage *
+ protobuf_c_message_unpack (const ProtobufCMessageDescriptor *,
+ ProtobufCAllocator *allocator,
+ size_t len,
+ const uint8_t *data);
+void protobuf_c_message_free_unpacked (ProtobufCMessage *message,
+ ProtobufCAllocator *allocator);
+
+/* WARNING: 'message' must be a block of memory
+ of size descriptor->sizeof_message. */
+#define protobuf_c_message_init(descriptor, message) ((descriptor)->message_init((ProtobufCMessage*) (message)))
+
+/* --- services --- */
+typedef struct _ProtobufCMethodDescriptor ProtobufCMethodDescriptor;
+typedef struct _ProtobufCServiceDescriptor ProtobufCServiceDescriptor;
+
+struct _ProtobufCMethodDescriptor
+{
+ const char *name;
+ const ProtobufCMessageDescriptor *input;
+ const ProtobufCMessageDescriptor *output;
+};
+struct _ProtobufCServiceDescriptor
+{
+ uint32_t magic;
+
+ const char *name;
+ const char *short_name;
+ const char *c_name;
+ const char *package;
+ unsigned n_methods;
+ const ProtobufCMethodDescriptor *methods; /* in order from .proto file */
+ const unsigned *method_indices_by_name;
+};
+
+typedef struct _ProtobufCService ProtobufCService;
+typedef void (*ProtobufCClosure)(const ProtobufCMessage *message,
+ void *closure_data);
+struct _ProtobufCService
+{
+ const ProtobufCServiceDescriptor *descriptor;
+ void (*invoke)(ProtobufCService *service,
+ unsigned method_index,
+ const ProtobufCMessage *input,
+ ProtobufCClosure closure,
+ void *closure_data);
+ void (*destroy) (ProtobufCService *service);
+};
+
+
+void protobuf_c_service_destroy (ProtobufCService *);
+
+
+/* --- querying the descriptors --- */
+const ProtobufCEnumValue *
+protobuf_c_enum_descriptor_get_value_by_name
+ (const ProtobufCEnumDescriptor *desc,
+ const char *name);
+const ProtobufCEnumValue *
+protobuf_c_enum_descriptor_get_value
+ (const ProtobufCEnumDescriptor *desc,
+ int value);
+const ProtobufCFieldDescriptor *
+protobuf_c_message_descriptor_get_field_by_name
+ (const ProtobufCMessageDescriptor *desc,
+ const char *name);
+const ProtobufCFieldDescriptor *
+protobuf_c_message_descriptor_get_field
+ (const ProtobufCMessageDescriptor *desc,
+ unsigned value);
+const ProtobufCMethodDescriptor *
+protobuf_c_service_descriptor_get_method_by_name
+ (const ProtobufCServiceDescriptor *desc,
+ const char *name);
+
+/* --- wire format enums --- */
+typedef enum
+{
+ PROTOBUF_C_WIRE_TYPE_VARINT,
+ PROTOBUF_C_WIRE_TYPE_64BIT,
+ PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED,
+ PROTOBUF_C_WIRE_TYPE_START_GROUP, /* unsupported */
+ PROTOBUF_C_WIRE_TYPE_END_GROUP, /* unsupported */
+ PROTOBUF_C_WIRE_TYPE_32BIT
+} ProtobufCWireType;
+
+/* --- unknown message fields --- */
+struct _ProtobufCMessageUnknownField
+{
+ uint32_t tag;
+ ProtobufCWireType wire_type;
+ size_t len;
+ uint8_t *data;
+};
+
+/* --- extra (superfluous) api: trivial buffer --- */
+typedef struct _ProtobufCBufferSimple ProtobufCBufferSimple;
+struct _ProtobufCBufferSimple
+{
+ ProtobufCBuffer base;
+ size_t alloced;
+ size_t len;
+ uint8_t *data;
+ protobuf_c_boolean must_free_data;
+};
+#define PROTOBUF_C_BUFFER_SIMPLE_INIT(array_of_bytes) \
+{ { protobuf_c_buffer_simple_append }, \
+ sizeof(array_of_bytes), 0, (array_of_bytes), 0 }
+#define PROTOBUF_C_BUFFER_SIMPLE_CLEAR(simp_buf) \
+ do { if ((simp_buf)->must_free_data) \
+ protobuf_c_default_allocator.free (&protobuf_c_default_allocator.allocator_data, (simp_buf)->data); } while (0)
+
+/* ====== private ====== */
+#include "protobuf-c-private.h"
+
+
+PROTOBUF_C_END_DECLS
+
+#endif /* __PROTOBUF_C_RUNTIME_H_ */
fprintf(f,"-e (--end) : end at specified phase\n");
fprintf(f,"-k (--keep-tmpfiles) : do not delete tmp files after processing. useful to reuse them\n\n");
fprintf(f,"-o (--coverage) : map every street to item coverage\n");
+ fprintf(f,"-P (--protobuf) : input file is protobuf\n");
fprintf(f,"-s (--start) : start at specified phase\n");
fprintf(f,"-i (--input-file) : specify the input file name (OSM), overrules default stdin\n");
fprintf(f,"-w (--dedupe-ways) : ensure no duplicate ways or nodes. useful when using several input files\n");
int zip64=0;
int output=0;
int input=0;
+ int protobuf=0;
int f,pos;
char *result,*optarg_cp,*attr_name,*attr_value;
#ifdef HAVE_POSTGRESQL
{"nodes-only", 0, 0, 'N'},
{"map", 1, 0, 'm'},
{"plugin", 1, 0, 'p'},
+ {"protobuf", 0, 0, 'P'},
{"start", 1, 0, 's'},
{"input-file", 1, 0, 'i'},
{"ignore-unknown", 0, 0, 'n'},
case 'R':
process_relations=0;
break;
+ case 'P':
+ protobuf=1;
+ break;
case 'S':
slice_size=atoll(optarg);
break;
l=g_list_next(l);
}
}
+ else if (protobuf)
+ map_collect_data_osm_protobuf(input_file,ways,nodes,turn_restrictions,boundaries);
else
map_collect_data_osm(input_file,ways,nodes,turn_restrictions,boundaries);
if (slices) {
void osm_add_way(osmid id);
void osm_add_relation(osmid id);
void osm_end_relation(FILE *turn_restrictions, FILE *boundaries);
+void osm_add_member(int type, osmid ref, char *role);
void osm_end_way(FILE *out);
void osm_end_node(FILE *out);
void osm_add_nd(osmid ref);
/* osm_psql.c */
int map_collect_data_osm_db(char *dbstr, FILE *out_ways, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries);
+/* osm_protobuf.c */
+int map_collect_data_osm_protobuf(FILE *in, FILE *out_ways, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries);
+
/* sourcesink.c */
struct item_bin_sink *item_bin_sink_new(void);
item_bin_write(item_bin, turn_restrictions);
}
+void
+osm_add_member(int type, osmid ref, char *role)
+{
+ char member_buffer[BUFFER_SIZE*3+3];
+ struct attr memberattr = { attr_osm_member };
+
+ sprintf(member_buffer,"%d:%Ld:%s", type, (long long) ref, role);
+ memberattr.u.str=member_buffer;
+ item_bin_add_attr(item_bin, &memberattr);
+}
+
static int
parse_member(char *p)
{
char type_buffer[BUFFER_SIZE];
char ref_buffer[BUFFER_SIZE];
char role_buffer[BUFFER_SIZE];
- char member_buffer[BUFFER_SIZE*3+3];
int type;
- struct attr memberattr = { attr_osm_member };
if (!xml_get_attribute(p, "type", type_buffer, BUFFER_SIZE))
return 0;
if (!xml_get_attribute(p, "ref", ref_buffer, BUFFER_SIZE))
fprintf(stderr,"Unknown type %s\n",type_buffer);
type=0;
}
- sprintf(member_buffer,"%d:%s:%s", type, ref_buffer, role_buffer);
- memberattr.u.str=member_buffer;
- item_bin_add_attr(item_bin, &memberattr);
+ osm_add_member(type, atoll(ref_buffer), role_buffer);
return 1;
}
--- /dev/null
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+#include <unistd.h>
+#include <time.h>
+#include <zlib.h>
+#include "maptool.h"
+#include "debug.h"
+#include "linguistics.h"
+#include "file.h"
+#include "generated-code/fileformat.pb-c.h"
+#include "generated-code/osmformat.pb-c.h"
+
+
+unsigned char buffer[65536];
+double latlon_scale=10000000.0;
+double timestamp_scale=1000.0;
+
+OSMPBF__BlobHeader *
+read_header(FILE *f)
+{
+ unsigned char *buffer,lenb[4];
+ int len;
+
+ len=sizeof(lenb);
+ if (fread(lenb, 4, 1, f) != 1)
+ return NULL;
+ len=(lenb[0] << 24) | (lenb[1] << 16) | (lenb[2] << 8) | lenb[3];
+ buffer=alloca(len);
+ if (fread(buffer, len, 1, f) != 1)
+ return NULL;
+ return osmpbf__blob_header__unpack(&protobuf_c_system_allocator, len, buffer);
+}
+
+
+OSMPBF__Blob *
+read_blob(OSMPBF__BlobHeader *header, FILE *f)
+{
+ unsigned char *buffer;
+ int len=header->datasize;
+
+ buffer=alloca(len);
+ if (fread(buffer, len, 1, f) != 1)
+ return NULL;
+ return osmpbf__blob__unpack(&protobuf_c_system_allocator, len, buffer);
+}
+
+unsigned char *
+uncompress_blob(OSMPBF__Blob *blob)
+{
+ unsigned char *ret=malloc(blob->raw_size);
+ int zerr;
+ z_stream strm;
+
+ if (!ret)
+ return NULL;
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+ strm.avail_in=blob->zlib_data.len;
+ strm.next_in=blob->zlib_data.data;
+ strm.avail_out=blob->raw_size;
+ strm.next_out=ret;
+ zerr = inflateInit(&strm);
+ if (zerr != Z_OK) {
+ free(ret);
+ return NULL;
+ }
+ zerr = inflate(&strm, Z_NO_FLUSH);
+ if (zerr != Z_STREAM_END) {
+ free(ret);
+ return NULL;
+ }
+ inflateEnd(&strm);
+ return ret;
+}
+
+int
+get_string(char *buffer, int buffer_size, OSMPBF__PrimitiveBlock *primitive_block, int id, int escape)
+{
+ int len=primitive_block->stringtable->s[id].len;
+ char *data=(char *)primitive_block->stringtable->s[id].data;
+ if (primitive_block->stringtable->s[id].len >= buffer_size) {
+ buffer[0]='\0';
+ return 0;
+ }
+ if (escape) {
+ int i;
+ char *p=buffer;
+ for (i = 0 ; i < len ; i++) {
+ switch(data[i]) {
+ case '\t':
+ case '\r':
+ case '\n':
+ case '>':
+ case '<':
+ case '\'':
+ case '"':
+ case '&':
+ sprintf(p,"&#%d;",data[i]);
+ p+=strlen(p);
+ break;
+ default:
+ *p++=data[i];
+ }
+ }
+ *p++='\0';
+ return 1;
+ } else {
+ strncpy(buffer, data, len);
+ buffer[len]='\0';
+ return 1;
+ }
+}
+
+
+void
+process_osmheader(OSMPBF__Blob *blob, unsigned char *data)
+{
+ OSMPBF__HeaderBlock *header_block;
+ header_block=osmpbf__header_block__unpack(&protobuf_c_system_allocator, blob->raw_size, data);
+ osmpbf__header_block__free_unpacked(header_block, &protobuf_c_system_allocator);
+}
+
+void
+process_user(OSMPBF__PrimitiveBlock *primitive_block, int user_sid, int uid, int swap)
+{
+ char userbuff[1024];
+ get_string(userbuff, sizeof(userbuff), primitive_block, user_sid, 1);
+ if (userbuff[0] && uid != -1) {
+ if (swap)
+ printf(" uid=\"%d\" user=\"%s\"",uid,userbuff);
+ else
+ printf(" user=\"%s\" uid=\"%d\"",userbuff,uid);
+ }
+}
+
+void
+process_timestamp(long long timestamp)
+{
+ time_t ts;
+ struct tm *tm;
+ char tsbuff[1024];
+ ts=timestamp;
+ tm=gmtime(&ts);
+ strftime(tsbuff, sizeof(tsbuff), "%Y-%m-%dT%H:%M:%SZ", tm);
+ printf(" timestamp=\"%s\"",tsbuff);
+}
+
+void
+process_tag(OSMPBF__PrimitiveBlock *primitive_block, int key, int val)
+{
+ char keybuff[1024];
+ char valbuff[1024];
+#if 0
+ get_string(keybuff, sizeof(keybuff), primitive_block, key, 1);
+ get_string(valbuff, sizeof(valbuff), primitive_block, val, 1);
+ printf("\t\t<tag k=\"%s\" v=\"%s\" />\n",keybuff,valbuff);
+#else
+ get_string(keybuff, sizeof(keybuff), primitive_block, key, 0);
+ get_string(valbuff, sizeof(valbuff), primitive_block, val, 0);
+ osm_add_tag(keybuff, valbuff);
+#endif
+}
+
+
+void
+process_dense(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__DenseNodes *dense, FILE *out_nodes)
+{
+ int i,j=0,has_tags;
+ long long id=0,lat=0,lon=0,changeset=0,timestamp=0;
+ int version,user_sid=0,uid=0;
+
+ if (!dense)
+ return;
+
+ for (i = 0 ; i < dense->n_id ; i++) {
+ id+=dense->id[i];
+ lat+=dense->lat[i];
+ lon+=dense->lon[i];
+ version=dense->denseinfo->version[i];
+ changeset+=dense->denseinfo->changeset[i];
+ user_sid+=dense->denseinfo->user_sid[i];
+ uid+=dense->denseinfo->uid[i];
+ timestamp+=dense->denseinfo->timestamp[i];
+ has_tags=dense->keys_vals && dense->keys_vals[j];
+ osm_add_node(id, lat/latlon_scale,lon/latlon_scale);
+#if 0
+ printf("\t<node id=\"%Ld\" lat=\"%.7f\" lon=\"%.7f\" version=\"%d\" changeset=\"%Ld\"",id,lat/latlon_scale,lon/latlon_scale,version,changeset);
+ process_user(primitive_block, user_sid, uid, 0);
+ process_timestamp(timestamp);
+#endif
+ if (has_tags) {
+#if 0
+ printf(">\n");
+#endif
+ while (dense->keys_vals[j]) {
+ process_tag(primitive_block, dense->keys_vals[j], dense->keys_vals[j+1]);
+ j+=2;
+ }
+#if 0
+ printf("\t</node>\n");
+ } else
+ printf("/>\n");
+#else
+ }
+#endif
+ osm_end_node(out_nodes);
+ j++;
+ }
+}
+
+void
+process_info(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Info *info)
+{
+ printf(" version=\"%d\" changeset=\"%Ld\"",info->version,info->changeset);
+ process_user(primitive_block, info->user_sid, info->uid, 1);
+ process_timestamp(info->timestamp);
+}
+
+void
+process_way(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Way *way, FILE *out_ways)
+{
+ int i;
+ long long ref=0;
+
+ osm_add_way(way->id);
+#if 0
+ printf("\t<way id=\"%Ld\"",way->id);
+ process_info(primitive_block, way->info);
+ printf(">\n");
+#else
+#endif
+ for (i = 0 ; i < way->n_refs ; i++) {
+ ref+=way->refs[i];
+ osm_add_nd(ref);
+#if 0
+ printf("\t\t<nd ref=\"%Ld\"/>\n",ref);
+#else
+#endif
+ }
+ for (i = 0 ; i < way->n_keys ; i++)
+ process_tag(primitive_block, way->keys[i], way->vals[i]);
+#if 0
+ printf("\t</way>\n");
+#endif
+ osm_end_way(out_ways);
+}
+
+void
+process_relation(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Relation *relation, FILE *out_turn_restrictions, FILE *out_boundaries)
+{
+ int i;
+ long long ref=0;
+ char rolebuff[1024];
+
+#if 0
+ printf("\t<relation id=\"%Ld\"",relation->id);
+ process_info(primitive_block, relation->info);
+ printf(">\n");
+#endif
+ osm_add_relation(relation->id);
+ for (i = 0 ; i < relation->n_roles_sid ; i++) {
+#if 0
+ printf("\t\t<member type=\"");
+ switch (relation->types[i]) {
+ case 0:
+ printf("node");
+ break;
+ case 1:
+ printf("way");
+ break;
+ case 2:
+ printf("relation");
+ break;
+ default:
+ printf("unknown");
+ break;
+ }
+#endif
+ ref+=relation->memids[i];
+ get_string(rolebuff, sizeof(rolebuff), primitive_block, relation->roles_sid[i], 1);
+#if 0
+ printf("\" ref=\"%Ld\" role=\"%s\"/>\n",ref,rolebuff);
+#else
+ osm_add_member(relation->types[i]+1,ref,rolebuff);
+#endif
+ }
+ for (i = 0 ; i < relation->n_keys ; i++)
+ process_tag(primitive_block, relation->keys[i], relation->vals[i]);
+#if 0
+ printf("\t</relation>\n");
+#else
+ osm_end_relation(out_turn_restrictions, out_boundaries);
+#endif
+}
+
+void
+process_osmdata(OSMPBF__Blob *blob, unsigned char *data, FILE *out_nodes, FILE *out_ways, FILE *out_turn_restrictions, FILE *out_boundaries)
+{
+ int i,j;
+ OSMPBF__PrimitiveBlock *primitive_block;
+ primitive_block=osmpbf__primitive_block__unpack(&protobuf_c_system_allocator, blob->raw_size, data);
+ for (i = 0 ; i < primitive_block->n_primitivegroup ; i++) {
+ OSMPBF__PrimitiveGroup *primitive_group=primitive_block->primitivegroup[i];
+ process_dense(primitive_block, primitive_group->dense, out_nodes);
+ for (j = 0 ; j < primitive_group->n_ways ; j++)
+ process_way(primitive_block, primitive_group->ways[j], out_ways);
+ for (j = 0 ; j < primitive_group->n_relations ; j++)
+ process_relation(primitive_block, primitive_group->relations[j], out_turn_restrictions, out_boundaries);
+#if 0
+ printf("Group %p %d %d %d %d\n",primitive_group->dense,primitive_group->n_nodes,primitive_group->n_ways,primitive_group->n_relations,primitive_group->n_changesets);
+#endif
+ }
+ osmpbf__primitive_block__free_unpacked(primitive_block, &protobuf_c_system_allocator);
+}
+
+
+int
+map_collect_data_osm_protobuf(FILE *in, FILE *out_ways, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries)
+{
+ OSMPBF__BlobHeader *header;
+ OSMPBF__Blob *blob;
+ unsigned char *data;
+#if 0
+ printf("<?xml version='1.0' encoding='UTF-8'?>\n");
+ printf("<osm version=\"0.6\" generator=\"pbf2osm\">\n");
+#endif
+ while ((header=read_header(in))) {
+ blob=read_blob(header, in);
+ data=uncompress_blob(blob);
+ if (!strcmp(header->type,"OSMHeader")) {
+ process_osmheader(blob, data);
+ } else if (!strcmp(header->type,"OSMData")) {
+ process_osmdata(blob, data, out_nodes, out_ways, out_turn_restrictions, out_boundaries);
+ } else {
+ printf("unknown\n");
+ return 0;
+ }
+ free(data);
+ osmpbf__blob__free_unpacked(blob, &protobuf_c_system_allocator);
+ osmpbf__blob_header__free_unpacked(header, &protobuf_c_system_allocator);
+ }
+#if 0
+ printf("</osm>\n");
+#endif
+ return 1;
+}
--- /dev/null
+option java_package = "crosby.binary";
+package OSMPBF;
+
+/* OSM Binary file format
+
+This is the master schema file of the OSM binary file format. This
+file is designed to support limited random-access and future
+extendability.
+
+A binary OSM file consists of a sequence of FileBlocks (please see
+fileformat.proto). The first fileblock contains a serialized instance
+of HeaderBlock, followed by a sequence of PrimitiveBlock blocks that
+contain the primitives.
+
+Each primitiveblock is designed to be independently parsable. It
+contains a string table storing all strings in that block (keys and
+values in tags, roles in relations, usernames, etc.) as well as
+metadata containing the precision of coordinates or timestamps in that
+block.
+
+A primitiveblock contains a sequence of primitive groups, each
+containing primitives of the same type (nodes, densenodes, ways,
+relations). Coordinates are stored in signed 64-bit integers. Lat&lon
+are measured in units <granularity> nanodegrees. The default of
+granularity of 100 nanodegrees corresponds to about 1cm on the ground,
+and a full lat or lon fits into 32 bits.
+
+Converting an integer to a lattitude or longitude uses the formula:
+$OUT = IN * granularity / 10**9$. Many encoding schemes use delta
+coding when representing nodes and relations.
+
+*/
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+
+/* Contains the file header. */
+
+message HeaderBlock {
+ optional HeaderBBox bbox = 1;
+ /* Additional tags to aid in parsing this dataset */
+ repeated string required_features = 4;
+ repeated string optional_features = 5;
+
+ optional string writingprogram = 16;
+ optional string source = 17; // From the bbox field.
+}
+
+
+/** The bounding box field in the OSM header. BBOX, as used in the OSM
+header. Units are always in nanodegrees -- they do not obey
+granularity rules. */
+
+message HeaderBBox {
+ required sint64 left = 1;
+ required sint64 right = 2;
+ required sint64 top = 3;
+ required sint64 bottom = 4;
+}
+
+
+///////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////
+
+
+message PrimitiveBlock {
+ required StringTable stringtable = 1;
+ repeated PrimitiveGroup primitivegroup = 2;
+
+ // Granularity, units of nanodegrees, used to store coordinates in this block
+ optional int32 granularity = 17 [default=100];
+ // Offset value between the output coordinates coordinates and the granularity grid in unites of nanodegrees.
+ optional int64 lat_offset = 19 [default=0];
+ optional int64 lon_offset = 20 [default=0];
+
+// Granularity of dates, normally represented in units of milliseconds since the 1970 epoch.
+ optional int32 date_granularity = 18 [default=1000];
+
+
+ // Proposed extension:
+ //optional BBox bbox = XX;
+}
+
+// Group of OSMPrimitives. All primitives in a group must be the same type.
+message PrimitiveGroup {
+ repeated Node nodes = 1;
+ optional DenseNodes dense = 2;
+ repeated Way ways = 3;
+ repeated Relation relations = 4;
+ repeated ChangeSet changesets = 5;
+}
+
+
+/** String table, contains the common strings in each block.
+
+ Note that we reserve index '0' as a delimiter, so the entry at that
+ index in the table is ALWAYS blank and unused.
+
+ */
+message StringTable {
+ repeated bytes s = 1;
+}
+
+/* Optional metadata that may be included into each primitive. */
+message Info {
+ optional int32 version = 1 [default = -1];
+ optional int64 timestamp = 2;
+ optional int64 changeset = 3;
+ optional int32 uid = 4;
+ optional uint32 user_sid = 5; // String IDs
+}
+
+/** Optional metadata that may be included into each primitive. Special dense format used in DenseNodes. */
+message DenseInfo {
+ repeated int32 version = 1 [packed = true];
+ repeated sint64 timestamp = 2 [packed = true]; // DELTA coded
+ repeated sint64 changeset = 3 [packed = true]; // DELTA coded
+ repeated sint32 uid = 4 [packed = true]; // DELTA coded
+ repeated sint32 user_sid = 5 [packed = true]; // String IDs for usernames. DELTA coded
+}
+
+
+// THIS IS STUB DESIGN FOR CHANGESETS. NOT USED RIGHT NOW.
+// TODO: REMOVE THIS?
+message ChangeSet {
+ required int64 id = 1;
+//
+// // Parallel arrays.
+// repeated uint32 keys = 2 [packed = true]; // String IDs.
+// repeated uint32 vals = 3 [packed = true]; // String IDs.
+//
+// optional Info info = 4;
+
+// optional int64 created_at = 8;
+// optional int64 closetime_delta = 9;
+// optional bool open = 10;
+// optional HeaderBBox bbox = 11;
+}
+
+
+message Node {
+ required sint64 id = 1;
+ // Parallel arrays.
+ repeated uint32 keys = 2 [packed = true]; // String IDs.
+ repeated uint32 vals = 3 [packed = true]; // String IDs.
+
+ optional Info info = 4; // May be omitted in omitmeta
+
+ required sint64 lat = 8;
+ required sint64 lon = 9;
+}
+
+/* Used to densly represent a sequence of nodes that do not have any tags.
+
+We represent these nodes columnwise as five columns: ID's, lats, and
+lons, all delta coded. When metadata is not omitted,
+
+We encode keys & vals for all nodes as a single array of integers
+containing key-stringid and val-stringid, using a stringid of 0 as a
+delimiter between nodes.
+
+ ( (<keyid> <valid>)* '0' )*
+ */
+
+message DenseNodes {
+ repeated sint64 id = 1 [packed = true]; // DELTA coded
+
+ //repeated Info info = 4;
+ optional DenseInfo denseinfo = 5;
+
+ repeated sint64 lat = 8 [packed = true]; // DELTA coded
+ repeated sint64 lon = 9 [packed = true]; // DELTA coded
+
+ // Special packing of keys and vals into one array. May be empty if all nodes in this block are tagless.
+ repeated int32 keys_vals = 10 [packed = true];
+}
+
+
+message Way {
+ required int64 id = 1;
+ // Parallel arrays.
+ repeated uint32 keys = 2 [packed = true];
+ repeated uint32 vals = 3 [packed = true];
+
+ optional Info info = 4;
+
+ repeated sint64 refs = 8 [packed = true]; // DELTA coded
+}
+
+message Relation {
+ enum MemberType {
+ NODE = 0;
+ WAY = 1;
+ RELATION = 2;
+ }
+ required int64 id = 1;
+
+ // Parallel arrays.
+ repeated uint32 keys = 2 [packed = true];
+ repeated uint32 vals = 3 [packed = true];
+
+ optional Info info = 4;
+
+ // Parallel arrays
+ repeated int32 roles_sid = 8 [packed = true];
+ repeated sint64 memids = 9 [packed = true]; // DELTA encoded
+ repeated MemberType types = 10 [packed = true];
+}
+