Implement simple binary inspector

This commit is contained in:
Victor Shcherb 2012-05-02 00:43:51 +02:00
parent dda06d8557
commit 8a8470e825
4 changed files with 105 additions and 13 deletions

View file

@ -16,8 +16,6 @@ using google::protobuf::io::FileInputStream;
using google::protobuf::internal::WireFormatLite;
//using namespace google::protobuf::internal;
static const int MAP_VERSION = 2;
static const int BASEMAP_ZOOM = 11;
std::map< std::string, BinaryMapFile* > openFiles;
@ -287,13 +285,16 @@ bool readMapIndex(CodedInputStream* input, MapIndex* mapIndex) {
// display google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)
bool initMapStructure(CodedInputStream* input, BinaryMapFile* file) {
uint32 tag;
uint32 version = -1;
uint32 versionConfirm = -2;
while ((tag = input->ReadTag()) != 0) {
switch (WireFormatLite::GetTagFieldNumber(tag)) {
// required uint32 version = 1;
case OsmAndStructure::kVersionFieldNumber: {
DO_((WireFormatLite::ReadPrimitive<uint32, WireFormatLite::TYPE_UINT32>(input, &version)));
DO_((WireFormatLite::ReadPrimitive<uint32, WireFormatLite::TYPE_UINT32>(input, &file->version)));
break;
}
case OsmAndStructure::kDateCreatedFieldNumber: {
DO_((WireFormatLite::ReadPrimitive<uint64, WireFormatLite::TYPE_UINT64>(input, &file->dateCreated)));
break;
}
case OsmAndStructure::kMapIndexFieldNumber: {
@ -323,11 +324,11 @@ bool initMapStructure(CodedInputStream* input, BinaryMapFile* file) {
}
}
}
if (version != versionConfirm) {
if (file->version != versionConfirm) {
osmand_log_print(LOG_ERROR, "Corrupted file. It should be ended as it starts with version");
return false;
}
if (version != MAP_VERSION) {
if (file->version != MAP_VERSION) {
osmand_log_print(LOG_ERROR, "Version of the file is not supported.");
return false;
}

View file

@ -16,6 +16,9 @@
#include "mapObjects.h"
#include "renderRules.h"
static const int MAP_VERSION = 2;
static const int BASEMAP_ZOOM = 11;
struct MapTreeBounds {
uint32 length;
@ -107,6 +110,8 @@ struct MapIndex {
struct BinaryMapFile {
std::string inputName;
uint32 version;
uint64 dateCreated;
std::vector<MapIndex> mapIndexes;
FILE* f;
bool basemap;

View file

@ -33,7 +33,7 @@ typedef uint32_t uint32;
typedef uint64_t uint64;
#endif
#ifdef HASH_MAP_GNU
#ifndef ANDROID
#define HMAP __gnu_cxx
namespace __gnu_cxx {

View file

@ -1,14 +1,100 @@
#include "binaryRead.h"
#include <stdio.h>
#include <time.h>
int main() {
BinaryMapFile* file = initBinaryMapFile("/home/victor/projects/OsmAnd/data/osm-gen/basemap_2.obf");
std::vector<MapIndex>::iterator it = file->mapIndexes.begin();
printf("File initialsed %d \n", file != NULL);
for(; it != file->mapIndexes.end(); it++) {
void println(const char * msg) {
printf("%s\n", msg);
}
void printUsage(std::string info) {
if(info.size() > 0) {
println(info.c_str());
}
println("Inspector is console utility for working with binary indexes of OsmAnd.");
println("It allows print info about file, extract parts and merge indexes.");
println("\nUsage for print info : inspector [-vaddress] [-vmap] [-vpoi] [-vtransport] [-zoom=Zoom] [-bbox=LeftLon,TopLat,RightLon,BottomLan] [file]");
println(" Prints information about [file] binary index of OsmAnd.");
println(" -v.. more verbouse output (like all cities and their streets or all map objects with tags/values and coordinates)");
}
class VerboseInfo {
public:
bool vaddress;
bool vtransport;
bool vpoi;
bool vmap;
double lattop, latbottom, lonleft, lonright;
int zoom;
VerboseInfo(int argc, char **params) {
lattop = 85;
latbottom = -85;
lonleft = -180;
lonright = 180;
zoom = 15;
for (int i = 1; i != argc; ++i) {
if (strcmp(params[i], "-vaddress") == 0) {
vaddress = true;
} else if (strcmp(params[i], "-vmap") == 0) {
vmap = true;
} else if (strcmp(params[i], "-vpoi") == 0) {
vpoi = true;
} else if (strcmp(params[i], "-vtransport") == 0) {
vtransport = true;
} else {
int z = 0;
if (sscanf(params[i], "-zoom=%d", &z) != EOF) {
zoom = z;
} else if (sscanf(params[i], "-bbox=%le,%le,%le,%le", &lonleft, &lattop, &lonright, &latbottom) != EOF) {
}
}
}
}
};
// public boolean contains(MapObject o){
// return lattop >= o.getLocation().getLatitude() && latbottom <= o.getLocation().getLatitude()
// && lonleft <= o.getLocation().getLongitude() && lonright >= o.getLocation().getLongitude();
//
// }
void printFileInformation(const char* fileName, VerboseInfo* info) {
BinaryMapFile* file = initBinaryMapFile(fileName);
std::vector<MapIndex>::iterator it = file->mapIndexes.begin();
time_t date = file->dateCreated/1000;
printf("Obf file.\n Version %d, basemap %d, date %s \n", file->version,
file->basemap, ctime(&date));
for (; it != file->mapIndexes.end(); it++) {
printf(" Name : %s \n", it.base()->name.c_str());
std::vector<MapRoot>::iterator rt = it.base()->levels.begin();
for(; rt != it.base()->levels.end(); rt++) {
for (; rt != it.base()->levels.end(); rt++) {
printf(" Level : %d - %d size %d\n", rt->minZoom, rt->maxZoom, rt->length);
}
}
}
int main(int argc, char **argv) {
if (argc <= 1) {
printUsage("");
return 1;
}
const char* f = argv[1];
if (f[0] == '-') {
// command
if (f[1]=='v') {
if (argc < 2) {
printUsage("Missing file parameter");
} else {
VerboseInfo* vinfo = new VerboseInfo(argc, argv);
printFileInformation(argv[argc -1], vinfo);
}
} else {
printUsage("Unknown command");
}
} else {
printFileInformation(f, NULL);
}
}