Protocol message contained an invalid tag (zero)

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

Protocol message contained an invalid tag (zero)



I'm working with pbf files from the open street maps



I want to parse node, relations, and ways.



when I try to parse nodes I get that message.



The code looks like


package myCode;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;

import protpbufCode.OsmPbf;
import protpbufCode.OsmPbf.Node;
import protpbufCode.OsmPbf.PrimitiveGroup;


public class ReadingPBF


public static void print(PrimitiveGroup node)

for (Node m: node.getNodesList())

System.out.print("Person ID: " + m.getId() + " ");
System.out.print(" Lat: " + m.getLat()+ " ");
System.out.print(" Long: "+ m.getLon()+ " ");
System.out.println("");





public static void main (String args)

try

PrimitiveGroup newNode = PrimitiveGroup.parseFrom(new FileInputStream(new File("isle.pbf")));
print(newNode);

catch (IOException e)

// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(e.getMessage());
System.out.println(e.getCause());








the OsmPbf is java class that created using the protobuf compiler.



and that what gets printed.


com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
at com.google.protobuf.InvalidProtocolBufferException.invalidTag(InvalidProtocolBufferException.java:89)
at com.google.protobuf.CodedInputStream.readTag(CodedInputStream.java:158)
at protpbufCode.OsmPbf$PrimitiveGroup.<init>(OsmPbf.java:5230)
at protpbufCode.OsmPbf$PrimitiveGroup.<init>(OsmPbf.java:5219)
at protpbufCode.OsmPbf$PrimitiveGroup$1.parsePartialFrom(OsmPbf.java:5329)
at protpbufCode.OsmPbf$PrimitiveGroup$1.parsePartialFrom(OsmPbf.java:1)
at com.google.protobuf.AbstractParser.parsePartialFrom(AbstractParser.java:192)
at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:209)
at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:215)
at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:49)
at protpbufCode.OsmPbf$PrimitiveGroup.parseFrom(OsmPbf.java:5627)
at myCode.ReadingPBF.main(ReadingPBF.java:33)


Protocol message contained an invalid tag (zero).

null





Did you check if the PBF file is broken? Can it be read with other tools, like osmosis?
– scai
Oct 28 '14 at 8:01





yes i checked , it is not broken.
– Moe
Oct 28 '14 at 13:23




1 Answer
1



OpenStreetMap .pbf files are not simple protobufs. See the documentation here:



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



Under the section "File format", you'll see this:



The format is a repeating sequence of:



That is, the file starts out with a 4-byte integer before the first protobuf message. Since this integer is probably smaller than 2^24, the first byte will of course be zero, which explains the exact exception you are seeing.



You will need to read this 4-byte value manually, then make sure to read only that many bytes and parse them as a BlobHeader, and so on.


BlobHeader



Personally I'd recommend looking for a PBF decoder library that already handles this for you. There must be a few out there.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

Executable numpy error

Trying to Print Gridster Items to PDF without overlapping contents

Mass disable jenkins jobs