#javascript #python #protocol-buffers #mapbox
Вопрос:
Я расшифровываю некоторые прото-буферы Mapbox. Смотрите спецификацию. В Python я могу сделать это довольно легко с помощью:
import mapbox_vector_tile
mapbox_vector_tile.decode(buffer)
И я получаю следующий JSON:
{
"default":{
"extent":4096,
"version":2,
"features":[
{
"geometry":{
"type":"Point",
"coordinates":[
1208,
2556
]
},
"properties":{
"original_address":"11919 Jamaica Ave, Jamaica, NY 11418, EE. UU."
},
"id":0,
"type":1
},
]
}
}
НО, если я сделаю то же самое в Javascript, со следующим кодом:
async function decodeMessage(buffer) {
const PROTO_FILE = await protobuf.load("vector_tile.proto");
const testMessage = PROTO_FILE.lookupType("vector_tile.Tile");
const err = testMessage.verify(buffer);
if (err) {
throw err;
}
const message = testMessage.decode(buffer);
return testMessage.toObject(message);
}
Будучи vector_tile.proto
файлом из спецификации 2.1
(или 2.0
, это не имеет значения). Я получаю следующий результат:
{
"layers": [
{
"name": "default",
"features": [
{
"tags": [
0,
0
],
"type": 1,
"geometry": [
9,
2416,
3080
]
},
],
"keys": [
"original_address"
],
"values": [
{
"stringValue": "Haags Kwartier 55, 2491 BM Den Haag, Netherlands"
}
],
"extent": 4096,
"version": 2
}
]
}
I do not understand why this difference in the format. I suppose the python package does some additional processing. Is that the case? Is there a way to get the same result on javascript?