2017-07-14 23:56:23 +00:00
|
|
|
#ifndef SERIAL_HPP
|
|
|
|
#define SERIAL_HPP
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <vector>
|
2017-08-23 18:43:48 +00:00
|
|
|
#include <sys/stat.h>
|
2017-07-14 23:56:23 +00:00
|
|
|
#include "geometry.hpp"
|
2017-08-24 23:30:01 +00:00
|
|
|
#include "mbtiles.hpp"
|
2017-09-01 18:51:12 +00:00
|
|
|
#include "jsonpull/jsonpull.h"
|
2017-07-14 23:56:23 +00:00
|
|
|
|
2016-04-27 21:19:10 +00:00
|
|
|
size_t fwrite_check(const void *ptr, size_t size, size_t nitems, FILE *stream, const char *fname);
|
|
|
|
|
|
|
|
void serialize_int(FILE *out, int n, long long *fpos, const char *fname);
|
|
|
|
void serialize_long_long(FILE *out, long long n, long long *fpos, const char *fname);
|
2016-07-15 22:00:40 +00:00
|
|
|
void serialize_ulong_long(FILE *out, unsigned long long n, long long *fpos, const char *fname);
|
2016-04-27 21:19:10 +00:00
|
|
|
void serialize_byte(FILE *out, signed char n, long long *fpos, const char *fname);
|
|
|
|
void serialize_uint(FILE *out, unsigned n, long long *fpos, const char *fname);
|
|
|
|
void serialize_string(FILE *out, const char *s, long long *fpos, const char *fname);
|
|
|
|
|
|
|
|
void deserialize_int(char **f, int *n);
|
|
|
|
void deserialize_long_long(char **f, long long *n);
|
2016-07-15 22:00:40 +00:00
|
|
|
void deserialize_ulong_long(char **f, unsigned long long *n);
|
2016-04-27 21:19:10 +00:00
|
|
|
void deserialize_uint(char **f, unsigned *n);
|
|
|
|
void deserialize_byte(char **f, signed char *n);
|
|
|
|
|
|
|
|
int deserialize_int_io(FILE *f, int *n, long long *geompos);
|
|
|
|
int deserialize_long_long_io(FILE *f, long long *n, long long *geompos);
|
2016-07-15 22:00:40 +00:00
|
|
|
int deserialize_ulong_long_io(FILE *f, unsigned long long *n, long long *geompos);
|
2016-04-27 21:19:10 +00:00
|
|
|
int deserialize_uint_io(FILE *f, unsigned *n, long long *geompos);
|
|
|
|
int deserialize_byte_io(FILE *f, signed char *n, long long *geompos);
|
2016-08-08 22:36:49 +00:00
|
|
|
|
2016-12-09 23:35:57 +00:00
|
|
|
struct serial_val {
|
2017-11-07 23:20:17 +00:00
|
|
|
int type = 0;
|
|
|
|
std::string s = "";
|
2016-12-09 23:35:57 +00:00
|
|
|
};
|
|
|
|
|
2016-08-08 22:36:49 +00:00
|
|
|
struct serial_feature {
|
2017-11-07 23:20:17 +00:00
|
|
|
long long layer = 0;
|
|
|
|
int segment = 0;
|
|
|
|
long long seq = 0;
|
2016-08-08 22:36:49 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
signed char t = 0;
|
|
|
|
signed char feature_minzoom = 0;
|
2016-08-08 22:36:49 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
bool has_id = false;
|
|
|
|
unsigned long long id = 0;
|
2016-08-08 22:36:49 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
bool has_tippecanoe_minzoom = false;
|
|
|
|
int tippecanoe_minzoom = 0;
|
2016-08-08 22:36:49 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
bool has_tippecanoe_maxzoom = false;
|
|
|
|
int tippecanoe_maxzoom = 0;
|
2016-08-08 22:36:49 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
drawvec geometry = drawvec();
|
|
|
|
unsigned long long index = 0;
|
|
|
|
long long extent = 0;
|
2016-08-08 22:36:49 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
size_t m = 0;
|
|
|
|
std::vector<long long> keys = std::vector<long long>();
|
|
|
|
std::vector<long long> values = std::vector<long long>();
|
|
|
|
long long metapos = 0;
|
2016-12-09 00:28:57 +00:00
|
|
|
|
|
|
|
// XXX This isn't serialized. Should it be here?
|
2017-11-07 23:20:17 +00:00
|
|
|
long long bbox[4] = {0, 0, 0, 0};
|
|
|
|
std::vector<std::string> full_keys = std::vector<std::string>();
|
|
|
|
std::vector<serial_val> full_values = std::vector<serial_val>();
|
|
|
|
std::string layername = "";
|
2016-08-08 22:36:49 +00:00
|
|
|
};
|
|
|
|
|
2016-10-10 22:31:09 +00:00
|
|
|
void serialize_feature(FILE *geomfile, serial_feature *sf, long long *geompos, const char *fname, long long wx, long long wy, bool include_minzoom);
|
2016-12-09 00:28:57 +00:00
|
|
|
serial_feature deserialize_feature(FILE *geoms, long long *geompos_in, char *metabase, long long *meta_off, unsigned z, unsigned tx, unsigned ty, unsigned *initial_x, unsigned *initial_y);
|
2017-07-14 23:56:23 +00:00
|
|
|
|
2017-08-23 18:43:48 +00:00
|
|
|
struct reader {
|
2017-11-07 23:20:17 +00:00
|
|
|
int metafd = -1;
|
|
|
|
int poolfd = -1;
|
|
|
|
int treefd = -1;
|
|
|
|
int geomfd = -1;
|
|
|
|
int indexfd = -1;
|
2017-08-23 18:43:48 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
FILE *metafile = NULL;
|
|
|
|
struct memfile *poolfile = NULL;
|
|
|
|
struct memfile *treefile = NULL;
|
|
|
|
FILE *geomfile = NULL;
|
|
|
|
FILE *indexfile = NULL;
|
2017-08-23 18:43:48 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
long long metapos = 0;
|
|
|
|
long long geompos = 0;
|
|
|
|
long long indexpos = 0;
|
2017-08-23 18:43:48 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
long long file_bbox[4] = {0, 0, 0, 0};
|
2017-08-23 18:43:48 +00:00
|
|
|
|
|
|
|
struct stat geomst;
|
|
|
|
struct stat metast;
|
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
char *geom_map = NULL;
|
2017-08-23 18:43:48 +00:00
|
|
|
};
|
|
|
|
|
2017-08-23 01:10:52 +00:00
|
|
|
struct serialization_state {
|
2017-11-07 23:20:17 +00:00
|
|
|
const char *fname = NULL; // source file name
|
|
|
|
int line = 0; // user-oriented location within source for error reports
|
2017-08-23 01:10:52 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
volatile long long *layer_seq = NULL; // sequence within current layer
|
|
|
|
volatile long long *progress_seq = NULL; // overall sequence for progress indicator
|
2017-08-23 01:10:52 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
std::vector<struct reader> *readers = NULL; // array of data for each input thread
|
|
|
|
int segment = 0; // the current input thread
|
2017-08-23 01:10:52 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
unsigned *initial_x = NULL; // relative offset of all geometries
|
|
|
|
unsigned *initial_y = NULL;
|
|
|
|
int *initialized = NULL;
|
2017-08-23 01:10:52 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
double *dist_sum = NULL; // running tally for calculation of resolution within features
|
|
|
|
size_t *dist_count = NULL;
|
|
|
|
bool want_dist = false;
|
2017-08-24 22:46:35 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
int maxzoom = 0;
|
|
|
|
int basezoom = 0;
|
2017-08-25 00:10:15 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
bool filters = false;
|
|
|
|
bool uses_gamma = false;
|
2017-08-24 23:30:01 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
std::map<std::string, layermap_entry> *layermap = NULL;
|
2017-08-25 00:10:15 +00:00
|
|
|
|
2017-11-07 23:20:17 +00:00
|
|
|
std::map<std::string, int> const *attribute_types = NULL;
|
|
|
|
std::set<std::string> *exclude = NULL;
|
|
|
|
std::set<std::string> *include = NULL;
|
|
|
|
int exclude_all = 0;
|
|
|
|
json_object *filter = NULL;
|
2017-08-23 01:10:52 +00:00
|
|
|
};
|
|
|
|
|
2017-08-25 22:46:32 +00:00
|
|
|
int serialize_feature(struct serialization_state *sst, serial_feature &sf);
|
2017-08-28 18:10:57 +00:00
|
|
|
void coerce_value(std::string const &key, int &vt, std::string &val, std::map<std::string, int> const *attribute_types);
|
2017-08-25 22:46:32 +00:00
|
|
|
|
2017-07-14 23:56:23 +00:00
|
|
|
#endif
|