persolijn

an efficient router for busses
Log | Files | Refs

PrimitiveBlock.java (1555B)


      1 package osm.message;
      2 
      3 import java.util.ArrayList;
      4 import java.util.Iterator;
      5 import java.util.List;
      6 
      7 import protobuf.Message;
      8 import protobuf.ProtobufReader;
      9 
     10 // required StringTable stringtable = 1;
     11 // repeated PrimitiveGroup primitivegroup = 2;
     12 // optional int32 granularity = 17 [default=100]; 
     13 // optional int64 lat_offset = 19 [default=0];
     14 // optional int64 lon_offset = 20 [default=0]; 
     15 // optional int32 date_granularity = 18 [default=1000]; 
     16 public class PrimitiveBlock implements Message<List<Entity>> {
     17     public static final double NANO = 1e-9;
     18 
     19     public List<String> stringtable = null;
     20 
     21     public List<byte[]> groupBuffers = new ArrayList<>();
     22 
     23     public double granularity = NANO * 100;
     24     public double latitudeOffset = 0;
     25     public double longitudeOffset = 0;
     26 
     27     @Override
     28     public List<Entity> parse(Iterator<ProtobufReader> iter) {
     29         List<Entity> groups = new ArrayList<>();
     30 
     31         while (iter.hasNext()) {
     32             ProtobufReader message = iter.next();
     33             switch (message.tag()) {
     34                 case 1 -> stringtable = message.message(new StringTable());
     35                 case 2 -> message.delayed(new PrimitiveGroup(this), groups::addAll);
     36                 case 17 -> granularity = NANO * message.varint32();
     37                 case 18 -> message.skip();
     38                 case 19 -> latitudeOffset = NANO * message.varint64();
     39                 case 20 -> longitudeOffset = NANO * message.varint64();
     40                 default -> message.throwUnexpected();
     41             }
     42         }
     43 
     44         return groups;
     45     }
     46 }