public class GroupDef extends Annotated
{
  public NsName getName () { return m_Name; }
  public void setName (NsName v) { m_Name = v; }
  public long getId () { return m_Id; }
  public boolean hasId () { return has_Id; }
  public void clearId () { has_Id = false; }
  public void setId (long v) { m_Id = v; has_Id = true; }
  public FieldDef [] getFields () { return m_Fields; }
  public void setFields (FieldDef [] v) { m_Fields = v; }
  public NsName getSuper () { return m_Super; }
  public boolean hasSuper () { return m_Super != null; }
  public void clearSuper () { m_Super = null; }
  public void setSuper (NsName v) { m_Super = v; }
  
  private boolean has_Id;
  
  private NsName m_Name;
  private long m_Id;
  private FieldDef [] m_Fields;
  private NsName m_Super;
} public class Define extends Annotated
{
  public NsName getName () { return m_Name; }
  public void setName (NsName v) { m_Name = v; }
  public int getId () { return m_Id; }
  public boolean hasId () { return has_Id; }
  public void clearId () { has_Id = false; }
  public void setId (int v) { m_Id = v; has_Id = true; }
  public TypeDef getType () { return m_Type; }
  public void setType (TypeDef v) { m_Type = v; }
  
  private boolean has_Id;
  
  private NsName m_Name;
  private int m_Id;
  private TypeDef m_Type;
} public class FieldDef extends Annotated
{
  public java.lang.String getName () { return m_Name; }
  public void setName (java.lang.String v) { m_Name = v; }
  public int getId () { return m_Id; }
  public boolean hasId () { return has_Id; }
  public void clearId () { has_Id = false; }
  public void setId (int v) { m_Id = v; has_Id = true; }
  public TypeDef getType () { return m_Type; }
  public void setType (TypeDef v) { m_Type = v; }
  public boolean getOptional () { return m_Optional; }
  public void setOptional (boolean v) { m_Optional = v; }
  
  private boolean has_Id;
  
  private java.lang.String m_Name;
  private int m_Id;
  private TypeDef m_Type;
  private boolean m_Optional;
} public class TypeDef extends Annotated
{
  
} public class Sequence extends TypeDef
{
  public TypeDef getType () { return m_Type; }
  public void setType (TypeDef v) { m_Type = v; }
  
  private TypeDef m_Type;
} public class Ref extends TypeDef
{
  public NsName getType () { return m_Type; }
  public void setType (NsName v) { m_Type = v; }
  
  private NsName m_Type;
} public class DynRef extends TypeDef
{
  public NsName getType () { return m_Type; }
  public void setType (NsName v) { m_Type = v; }
  
  private NsName m_Type;
} public class Bool extends TypeDef
{
  
} public class I8 extends TypeDef
{
  
} public class U8 extends TypeDef
{
  
} public class I16 extends TypeDef
{
  
} public class U16 extends TypeDef
{
  
} public class I32 extends TypeDef
{
  
} public class U32 extends TypeDef
{
  
} public class I64 extends TypeDef
{
  
} public class U64 extends TypeDef
{
  
} public class F64 extends TypeDef
{
  
} public class Decimal extends TypeDef
{
  
} public class FixedDec extends TypeDef
{
  public byte getScale () { return m_Scale; }
  public void setScale (byte v) { m_Scale = v; }
  
  private byte m_Scale;
} public class Binary extends TypeDef
{
  public byte getMaxSize () { return m_MaxSize; }
  public boolean hasMaxSize () { return has_MaxSize; }
  public void clearMaxSize () { has_MaxSize = false; }
  public void setMaxSize (byte v) { m_MaxSize = v; has_MaxSize = true; }
  
  private boolean has_MaxSize;
  
  private byte m_MaxSize;
} public class Fixed extends TypeDef
{
  public int getSize () { return m_Size; }
  public void setSize (int v) { m_Size = v; }
  
  private int m_Size;
} public class Symbol extends Annotated
{
  public java.lang.String getName () { return m_Name; }
  public void setName (java.lang.String v) { m_Name = v; }
  public int getValue () { return m_Value; }
  public void setValue (int v) { m_Value = v; }
  
  private java.lang.String m_Name;
  private int m_Value;
} public class NanoTime extends TypeDef
{
  
} public class MilliTime extends TypeDef
{
  
} public class TimeOfDayMilli extends TypeDef
{
  
} public class TimeOfDayNano extends TypeDef
{
  
} public class SchemaAnnotation
{
  public Annotation [] getAnnotations () { return m_Annotations; }
  public void setAnnotations (Annotation [] v) { m_Annotations = v; }
  public java.lang.String getNs () { return m_Ns; }
  public boolean hasNs () { return m_Ns != null; }
  public void clearNs () { m_Ns = null; }
  public void setNs (java.lang.String v) { m_Ns = v; }
  
  private Annotation [] m_Annotations;
  private java.lang.String m_Ns;
} public class Enum extends TypeDef
{
  public Symbol [] getSymbols () { return m_Symbols; }
  public void setSymbols (Symbol [] v) { m_Symbols = v; }
  
  private Symbol [] m_Symbols;
}
import com.pantor.blink.msg.blink.GroupDef;
import com.pantor.blink.msg.blink.Define;
import com.pantor.blink.msg.blink.FieldDef;
import com.pantor.blink.msg.blink.TypeDef;
import com.pantor.blink.msg.blink.Sequence;
import com.pantor.blink.msg.blink.Ref;
import com.pantor.blink.msg.blink.DynRef;
import com.pantor.blink.msg.blink.Bool;
import com.pantor.blink.msg.blink.I8;
import com.pantor.blink.msg.blink.U8;
import com.pantor.blink.msg.blink.I16;
import com.pantor.blink.msg.blink.U16;
import com.pantor.blink.msg.blink.I32;
import com.pantor.blink.msg.blink.U32;
import com.pantor.blink.msg.blink.I64;
import com.pantor.blink.msg.blink.U64;
import com.pantor.blink.msg.blink.F64;
import com.pantor.blink.msg.blink.Decimal;
import com.pantor.blink.msg.blink.FixedDec;
import com.pantor.blink.msg.blink.Binary;
import com.pantor.blink.msg.blink.Fixed;
import com.pantor.blink.msg.blink.Symbol;
import com.pantor.blink.msg.blink.NanoTime;
import com.pantor.blink.msg.blink.MilliTime;
import com.pantor.blink.msg.blink.TimeOfDayMilli;
import com.pantor.blink.msg.blink.TimeOfDayNano;
import com.pantor.blink.msg.blink.SchemaAnnotation;
import com.pantor.blink.msg.blink.Enum;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.List;
         def.setSuper (makeName (g.getSuperGroup ().getName ()));

      List<Schema.Field> fromFields = g.getFields ();
      FieldDef [] toFields = new FieldDef [fromFields.size ()];
      def.setFields (toFields);
      int pos = 0;
      for (Schema.Field f : fromFields)
         toFields [pos ++] = build (f);

      return def;
   }

   public Define build (Schema.Define d) throws BlinkException
   {
      Define def = new Define ();
      setAnnotations (d, def);
      def.setName (makeName (d.getName ()));

      if (d.getId () != null)
         def.setId (Integer.parseInt (d.getId ()));

      def.setType (build (d.getType ()));
      
      return def;
   }

   private FieldDef build (Schema.Field f) throws BlinkException
   {
      FieldDef def = new FieldDef ();
      setAnnotations (f, def);

      if (f.getId () != null)
         def.setId (Integer.parseInt (f.getId ()));

      def.setName (f.getName ());
      def.setType (build (f.getType ()));
      def.setOptional (f.isOptional ());
      return def;
   }

   private TypeDef build (Schema.Type t) throws BlinkException
   {
      switch (t.getCode ())
      {
       case I8: return build (new I8 (), t);
       case U8: return build (new U8 (), t);
       case I16: return build (new I16 (), t);
       case U16: return build (new U16 (), t);
       case I32: return build (new I32 (), t);
       case U32: return build (new U32 (), t);
       case I64: return build (new I64 (), t);
       case U64: return build (new U64 (), t);
       case F64: return build (new F64 (), t);
       case Decimal: return build (new Decimal (), t);
       case Date: return build (new com.pantor.blink.msg.blink.Date (), t);
       case TimeOfDayMilli: return build (new TimeOfDayMilli (), t);
       case TimeOfDayNano: return build (new TimeOfDayNano (), t);
       case Nanotime: return build (new NanoTime (), t);
       case Millitime: return build (new MilliTime (), t);
       case Bool: return build (new Bool (), t);
       case Object: return build (
          new com.pantor.blink.msg.blink.Object (), t);

       case FixedDec:
         {
            FixedDec def = new FixedDec ();
            def.setScale ((byte)((Schema.FixedDecType)t).getScale ());
            return build (def, t);
         }
         
       case String:
         {
            com.pantor.blink.msg.blink.String def =
               new com.pantor.blink.msg.blink.String ();
            Schema.StrType st = (Schema.StrType)t;
            if (st.hasMaxSize ())
               def.setMaxSize ((byte)((int)st.getMaxSize ()));
            return build (def, t);
         }
            
       case Binary:
         {
            Binary def = new Binary ();
            Schema.StrType st = (Schema.StrType)t;
            if (st.hasMaxSize ())
               def.setMaxSize ((byte)((int)st.getMaxSize ()));
            return build (def, t);
         }
            
       case Fixed:
         {
            Fixed def = new Fixed ();
            def.setSize (((Schema.FixedType)t).getSize ());
            return build (def, t);
         }
         
       case Ref:
         {
            Schema.Ref rt = t.toRef ();
            Schema.DefBase d = schema.find (rt.getName (), rt.getDefaultNs ());
            if (d != null)
            {
               if (rt.isDynamic ())
               {
                  DynRef def = new DynRef ();
                  def.setType (makeName (d.getName ()));
                  return build (def, t);
               }
               else
               {
                  Ref def = new Ref ();
                  def.setType (makeName (d.getName ()));
                  return build (def, t);
               }
            }
            else
               throw new BlinkException (
                  "No such blink definition: " + rt.getName ());
         }
         
       case Enum: