“无法解析输入"来自Google协议缓冲区protoc命令的``--decode_raw`` [英] "Failed to parse input" from Google protocol buffers protoc command for ``--decode_raw``

查看:1478
本文介绍了“无法解析输入"来自Google协议缓冲区protoc命令的``--decode_raw``的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 google protobuf文件,该文件来自来自Geofabrik的列支敦士登国家/地区摘录. protoc命令说它使用--decode_raw选项将原始标签/值写入stdout".但是我一直收到此错误:

I have a google protobuf file from OpenStreetMap, specifically I have the 1.4MB Liechtenstein country extract from Geofabrik. The protoc command says it "write the raw tag/values to stdout" with the --decode_raw option. However I keep getting this error:

$ cat liechtenstein-latest.osm.pbf | protoc --decode_raw
Failed to parse input.

我已经直接从Google编译并安装了protobuf库,版本为2.6.1.

I have compiled and installed the protobuf library direct from Google, version 2.6.1 which is the current one.

此文件是有效的,可读取pbf文件的各种OpenStreetMap工具( osm2pgsql 渗透)可以正常阅读.

This file is valid, various OpenStreetMap tools that read pbf files (osm2pgsql, osmosis) can read it fine.

可能是什么问题?如何使--decode_raw正常工作?我在做错什么吗?

What could be wrong? How can I get --decode_raw to work? Am I doing something wrong?

推荐答案

OpenStreetMap .osm.pbf格式不是是原始协议缓冲区.格式记录在这里:

The OpenStreetMap .osm.pbf format is not a raw protocol buffer. The format is documented here:

http://wiki.openstreetmap.org/wiki/PBF_Format

关键语录:

格式是以下重复序列:

The format is a repeating sequence of:

  • int4:BlobHeader消息的长度,以网络字节顺序
  • 序列化的BlobHeader消息
  • 序列化的Blob消息(大小在标题中给出)
  • int4: length of the BlobHeader message in network byte order
  • serialized BlobHeader message
  • serialized Blob message (size is given in the header)

因此,您需要先读取四个字节,将它们解释为整数(大端),然后读取那么多字节并将其解析为BlobHeader,这又将告诉您要读取和解析多少字节.作为Blob.

So you need to read four bytes first, interpret them as an integer (big-endian), then read that many bytes and parse as a BlobHeader, and that in turn will tell you how many bytes to read and parse as a Blob.

protoc工具不会自动执行此操作,因为它不知道此格式.可能有可用的OSM专用工具.

The protoc tool will not do this automatically since it doesn't know this format. Probably there is an OSM-specific tool out there that you can use.

这篇关于“无法解析输入"来自Google协议缓冲区protoc命令的``--decode_raw``的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆