package btools.mapcreator;

import btools.util.DiffCoderDataInputStream;
import btools.util.DiffCoderDataOutputStream;

/**
 * Container for node data on the preprocessor level
 *
 * @author ab
 */
public class NodeData extends MapCreatorBase
{
  public long nid;
  public int ilon;
  public int ilat;
  public byte[] description;
  public short selev = Short.MIN_VALUE;

  public NodeData( long id, double lon, double lat )
  {
    nid = id;
    ilat = (int)( ( lat + 90. )*1000000. + 0.5);
    ilon = (int)( ( lon + 180. )*1000000. + 0.5);
  }

  public NodeData( DiffCoderDataInputStream dis ) throws Exception
  {
    nid  = dis.readDiffed( 0 );
    ilon = (int)dis.readDiffed( 1 );
    ilat = (int)dis.readDiffed( 2 );
    int mode = dis.readByte();
    if ( ( mode & 1 ) != 0 ) { int dlen = dis.read(); description = new byte[dlen]; dis.readFully( description ); }
    if ( ( mode & 2 ) != 0 ) selev = dis.readShort();
  }

  public void writeTo( DiffCoderDataOutputStream dos ) throws Exception  
  {
    dos.writeDiffed( nid,  0 );
    dos.writeDiffed( ilon, 1 );
    dos.writeDiffed( ilat, 2 );
    int mode = (description == null ? 0 : 1) | (selev == Short.MIN_VALUE ? 0 : 2);
    dos.writeByte((byte) mode);
    if ((mode & 1) != 0) { dos.write(description.length); dos.write(description); }
    if ((mode & 2) != 0) dos.writeShort(selev);
  }
}

@@ -1133,24 +1133,507 @@
 ilat, 2 );%0D%0A
+    if (description != null && description.length %3E Byte.MAX_VALUE) %7B%0D%0A      System.err.printf(%22Node id (%25s): description length (%25d) is longer then maximum allowed (%25d). The description will NOT be written.%22, nid, description.length, Byte.MAX_VALUE);%0D%0A      System.out.printf(%22Node id (%25s): description length (%25d) is longer then maximum allowed (%25d). The description will NOT be written.%22, nid, description.length, Byte.MAX_VALUE);%0D%0A      dos.writeByte((byte) 0);%0D%0A    %7D else %7B%0D%0A  
     int mode
@@ -1700,24 +1700,26 @@
  ? 0 : 2);%0D%0A
+  
     dos.writ
@@ -1739,24 +1739,26 @@
 mode);%0D%0A    
+  
 if ((mode & 
@@ -1822,24 +1822,26 @@
 iption); %7D%0D%0A
+  
     if ((mod
@@ -1873,20 +1873,27 @@
 rt(selev);%0D%0A
+    %7D%0D%0A
   %7D%0D%0A%7D%0D%0A

Add warning if Node Description exceeds max allowed serialization length.