persolijn

an efficient router for busses
Log | Files | Refs

HeaderBlock.java (1740B)


      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 // optional HeaderBBox bbox = 1;
     11 // repeated string required_features = 4;
     12 // repeated string optional_features = 5;
     13 // optional string writingprogram = 16; 
     14 // optional string source = 17; // From the bbox field.
     15 // optional int64 osmosis_replication_timestamp = 32;
     16 // optional int64 osmosis_replication_sequence_number = 33;
     17 // optional string osmosis_replication_base_url = 34;
     18 public class HeaderBlock implements Message<HeaderBlock> {
     19     public final List<String> requiredFeatures = new ArrayList<>();
     20     public final List<String> optionalFeatures = new ArrayList<>();
     21     public double[] bbox = null;
     22     public String writingProgram = null;
     23     public String source = null;
     24 
     25     @Override
     26     public String toString() {
     27         return String.format("required:\t%s\noptional:\t%s\nbound-box:\t%s", requiredFeatures, optionalFeatures,
     28                 List.of(bbox[0], bbox[1], bbox[2], bbox[3]));
     29     }
     30 
     31     @Override
     32     public HeaderBlock parse(Iterator<ProtobufReader> iter) {
     33         while (iter.hasNext()) {
     34             ProtobufReader message = iter.next();
     35             switch (message.tag()) {
     36                 case 1 -> bbox = message.message(new HeaderBBox());
     37                 case 4 -> requiredFeatures.add(message.string());
     38                 case 5 -> optionalFeatures.add(message.string());
     39                 case 16 -> writingProgram = message.string();
     40                 case 17 -> source = message.string();
     41                 case 32, 33, 34 -> message.skip();
     42                 default -> message.throwUnexpected();
     43             }
     44         }
     45         return this;
     46     }
     47 }