Skip to content

Commit

Permalink
upgrades protobufjs dependency (some browser tests still fail)
Browse files Browse the repository at this point in the history
  • Loading branch information
marook committed Oct 9, 2018
1 parent ff2040e commit a1530bf
Show file tree
Hide file tree
Showing 12 changed files with 15,313 additions and 761 deletions.
3 changes: 2 additions & 1 deletion README.dev
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ js modules for the proto files generated with (see scripts in package.json):

$ npm run buildProto


------------------------------------------------------------------------
Generating manyNodes.pbf test data

Expand All @@ -55,7 +56,7 @@ $ git commit -a
$ npm install
$ npm test
$ npm run browserify
$ xdg-open test/index.html
$ xdg-open test.html
$ npm publish
$ git tag <released version>
$ git push
Expand Down
4 changes: 2 additions & 2 deletions lib/browser/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
var Zlib = require('../../node_modules/zlibjs/bin/inflate.min.js').Zlib;

function inflateBlob(blob, callback){
var infl = new Zlib.Inflate(new Uint8Array(blob.zlib_data.toBuffer()), {
bufferSize: blob.raw_size
var infl = new Zlib.Inflate(new Uint8Array(blob.zlibData), {
bufferSize: blob.rawSize
});
return callback(null, infl.decompress());
}
Expand Down
2 changes: 1 addition & 1 deletion lib/nodejs/zlib.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var zlib = require('zlib');

function inflateBlob(blob, callback){
zlib.inflate(blob.zlib_data.toBuffer(), callback);
zlib.inflate(blob.zlibData, callback);
}

module.exports = {
Expand Down
56 changes: 29 additions & 27 deletions lib/pbfParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
* - [1] blob
*/

var blockFormat = require('./proto/osmformat.js');
var fileFormat = require('./proto/fileformat.js');
var protoBuf = require("protobufjs");
var proto = require('./proto');
var buf = require('./buffer.js');

var zlib, reader, arrayBufferReader, fileReader;
Expand Down Expand Up @@ -188,7 +186,7 @@ var BLOCK_VISITORS_BY_TYPE = {
var BLOB_HEADER_SIZE_SIZE = 4;

function readBlobHeaderContent(fd, position, size, callback){
return reader.readPBFElement(fd, position, size, fileFormat.BlobHeader.decode, callback);
return reader.readPBFElement(fd, position, size, proto.OSMPBF.BlobHeader.decode, callback);
}

function readFileBlock(fd, position, callback){
Expand Down Expand Up @@ -252,7 +250,7 @@ function getStringTableEntry(i){
} else {
s = this.s[i];

str = s.toUTF8();
str = s.toString('utf-8');
this.cache[i] = str;
}

Expand Down Expand Up @@ -284,7 +282,7 @@ function createNodesView(pb, pg){
return null;
}

keysVals = pg.dense.keys_vals;
keysVals = pg.dense.keysVals;
tags = {};
tagsList = [];

Expand Down Expand Up @@ -334,10 +332,10 @@ function createNodesView(pb, pg){

for(i = 0; i < length; ++i){
// TODO we should test wheather adding 64bit numbers works fine with high values
id += pg.dense.id[i].toNumber();
id += toNumber(pg.dense.id[i]);

lat += pg.dense.lat[i].toNumber();
lon += pg.dense.lon[i].toNumber();
lat += toNumber(pg.dense.lat[i]);
lon += toNumber(pg.dense.lon[i]);

deltaData = {
id: id,
Expand All @@ -347,15 +345,15 @@ function createNodesView(pb, pg){

if(pg.dense.denseinfo){
// TODO we should test wheather adding 64bit numbers works fine with high values
timestamp += pg.dense.denseinfo.timestamp[i].toNumber();
changeset += pg.dense.denseinfo.changeset[i].toNumber();
timestamp += toNumber(pg.dense.denseinfo.timestamp[i]);
changeset += toNumber(pg.dense.denseinfo.changeset[i]);

// TODO we should test wheather adding 64bit numbers works fine with high values
uid += pg.dense.denseinfo.uid[i];

userIndex += pg.dense.denseinfo.user_sid[i];
userIndex += pg.dense.denseinfo.userSid[i];

deltaData.timestamp = timestamp * pb.date_granularity;
deltaData.timestamp = timestamp * pb.dateGranularity;
deltaData.changeset = changeset;
deltaData.uid = uid;
deltaData.userIndex = userIndex;
Expand All @@ -376,8 +374,8 @@ function createNodesView(pb, pg){

node = {
id: '' + nodeDeltaData.id,
lat: (pb.lat_offset.toNumber() + (pb.granularity * nodeDeltaData.lat)) / 1000000000,
lon: (pb.lon_offset.toNumber() + (pb.granularity * nodeDeltaData.lon)) / 1000000000,
lat: (toNumber(pb.latOffset) + (pb.granularity * nodeDeltaData.lat)) / 1000000000,
lon: (toNumber(pb.lonOffset) + (pb.granularity * nodeDeltaData.lon)) / 1000000000,
tags: tagsList[i]
};

Expand Down Expand Up @@ -422,16 +420,16 @@ function addInfo(pb, result, info){
result.version = info.version;
}
if (info.timestamp) {
result.timestamp = info.timestamp.toNumber() * pb.date_granularity;
result.timestamp = toNumber(info.timestamp) * pb.dateGranularity;
}
if (info.changeset) {
result.changeset = info.changeset.toNumber();
result.changeset = toNumber(info.changeset);
}
if (info.uid) {
result.uid = '' + info.uid;
}
if (info.user_sid) {
result.user = pb.stringtable.getEntry(info.user_sid);
if (info.userSid) {
result.user = pb.stringtable.getEntry(info.userSid);
}
}
}
Expand All @@ -454,7 +452,7 @@ function createWaysView(pb, pg){

for(i = 0; i < way.refs.length; ++i){
// TODO we should test wheather adding 64bit numbers works fine with high values
lastRefId += way.refs[i].toNumber();
lastRefId += toNumber(way.refs[i]);

nodeIds.push('' + lastRefId);
}
Expand Down Expand Up @@ -492,18 +490,18 @@ function createRelationsView(pb, pg){
function createMembers(){
var members, memberObj, lastRefId, i, MemberType, type;

MemberType = blockFormat.Relation.MemberType;
MemberType = proto.OSMPBF.Relation.MemberType;
members = [];
lastRefId = 0;

for(i = 0; i < relation.memids.length; ++i){
memberObj = {};

// TODO we should test wheather adding 64bit numbers works fine with high values
lastRefId += relation.memids[i].toNumber();
lastRefId += toNumber(relation.memids[i]);
memberObj.ref = '' + lastRefId;

memberObj.role = pb.stringtable.getEntry(relation.roles_sid[i]);
memberObj.role = pb.stringtable.getEntry(relation.rolesSid[i]);

type = relation.types[i];
if (MemberType.NODE === type) {
Expand Down Expand Up @@ -537,6 +535,10 @@ function createRelationsView(pb, pg){
};
}

function toNumber(x){
return typeof(x) === 'number' ? x : x.toNumber();
}

function extendPrimitiveGroup(pb, pg){
pg.nodesView = createNodesView(pb, pg);
pg.waysView = createWaysView(pb, pg);
Expand All @@ -546,7 +548,7 @@ function extendPrimitiveGroup(pb, pg){
function decodePrimitiveBlock(buffer){
var data, i;

data = blockFormat.PrimitiveBlock.decode(buffer);
data = proto.OSMPBF.PrimitiveBlock.decode(buffer);

// extend stringtable
extendStringTable(data.stringtable);
Expand All @@ -560,7 +562,7 @@ function decodePrimitiveBlock(buffer){
}

var OSM_BLOB_DECODER_BY_TYPE = {
'OSMHeader': blockFormat.HeaderBlock.decode,
'OSMHeader': proto.OSMPBF.HeaderBlock.decode,
'OSMData': decodePrimitiveBlock
};

Expand Down Expand Up @@ -589,7 +591,7 @@ function createFileParser(fd, callback){
}

function readBlob(fileBlock, callback){
return reader.readPBFElement(fd, fileBlock.blobHeader.position, fileBlock.blobHeader.datasize, fileFormat.Blob.decode, callback);
return reader.readPBFElement(fd, fileBlock.blobHeader.position, fileBlock.blobHeader.datasize, proto.OSMPBF.Blob.decode, callback);
}

function readBlock(fileBlock, callback){
Expand All @@ -598,7 +600,7 @@ function createFileParser(fd, callback){
return callback(err);
}

if(blob.raw_size === 0){
if(blob.rawSize === 0){
return callback('Uncompressed pbfs are currently not supported.');
}

Expand Down
86 changes: 0 additions & 86 deletions lib/proto/fileformat.js

This file was deleted.

Loading

0 comments on commit a1530bf

Please sign in to comment.