java - Protocol message contained an invalid tag (zero) -


I'm working with Pibif files open road map

I node relationships

The code looks like

When I try to parse the node, I get the message

The code looks like this

  Package myCode; Import java.io.file; Import java.io.FileInputStream; Import java.io.IOException; Import java.util.list; Import protobb code. OSMPBF; Import protpbufCode.OsmPbf.Node; Import protobb code. OSMPBF Group group; Public class ReadingPBF {public static void print (PrimitiveGroup node) {node (m: node.getNodesList ()) {System.out.print ( "Person ID:" + m.getId () + ""); System.out.print ("Lat:" + m.getLat () + ""); System.out.print ("Long:" + m.getLon () + ""); Println (""); }} Public static void (String args []) {try {PrimitiveGroup newNode = PrimitiveGroup.parseFrom (New FileInputStream (new file ("isle.pbf")); Print (newNode); } Grip (IOException E) {// TODO Auto-Generated Catch Block e.printStackTrace (); Println (e.getMessage ()); Println (e.getCause ()); }}}  

OsmPbf is a Java class that was created using Protofab compiler.

And who gets printed out.

  com.google.protobuf.InvalidProtocolBufferException: There is an invalid tag (zero) in the protocol message. On Com.google.protobuf.InvalidProtocolBufferException.invalidTag (invalidProtocolBufferException.java:89) on com.google.protobuf.CodedInputStream.readTag (CodedInputStream.java158) on protpbufCode.OsmPbf $ PrimitiveGroup. & Lt; Init & gt; (OsmPbf.java: 5230) Protibbford.asppff $ $ Primitive Group. And lieutenant; Init & gt; Protocol code on (OSMPBF.Java TS 219) OSMPBF $ Primitive Group $ 1 Protobufodem (OSMPBFJava / 329) Protapbook Code OSMPBF $ Primitive Group $ 1 Prseprtiylfom (Osmpibifkjawa: 1) com.google.protobuf.AbstractParser.parsePartialFrom (AbstractParser.java:192) com.google.protobuf.AbstractParser.parseFrom (AbstractParser.java:209) on com.google.protobuf.AbstractParser.parseFrom (on the AbstractParser.java: 215) on com.google.protobuf.AbstractParser.parseFrom (AbstractParser.java:49) protpbufCode.OsmPbf $ PrimitiveGroup.parseFrom (OsmPbf.java:5627) on myCode.ReadingPBF.main (ReadingPBF. Java: 33) Protocol message contains an invalid tag (zero) empty  

OpenStreetMap. Pbf files are not simple proto-buddies, see the document here:

Under the "File Format" section, As see it:

is a repeating sequence of format:

  • int4: BlobHeader message length in order to network byte
  • serial BlobHeader Message
  • The serial blob message (given in the heading size)

That is, the first protocol was started with the message before the 4-byte integer file it occurs. Since this integer is probably less than 2 ^ 24, the first byte will definitely be zero, which tells how you are seeing exceptions.

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

Personally I recommend looking for a PBF decoder library that already handles it for you. There should be something out there


Comments