Esempio n. 1
0
  /* (non-Javadoc)
   * @see com.lexst.db.head.Field#resolve(byte[], int)
   */
  @Override
  public int resolve(byte[] b, int offset) {
    int off = offset;

    dataType = b[off];
    off += 1;
    columnId = Numeric.toShort(b, off, 2);
    off += 2;

    byte sz = b[off];
    off += 1;
    byte[] nm = new byte[sz];
    System.arraycopy(b, off, nm, 0, sz);
    name = new String(nm, 0, nm.length);
    off += sz;

    indexType = b[off];
    off += 1;

    allowNull = (b[off] == 1 ? true : false);
    off += 1;

    function = b[off];
    off += 1;
    value = Numeric.toLong(b, off, 8);
    off += 8;

    return off - offset;
  }
Esempio n. 2
0
  /* (non-Javadoc)
   * @see com.lexst.db.head.Field#build()
   */
  @Override
  public byte[] build() {
    ByteArrayOutputStream buf = new ByteArrayOutputStream(128);
    buf.write(dataType); // data type
    byte[] b = Numeric.toBytes(columnId);
    buf.write(b, 0, b.length); // column id

    byte[] bs = name.getBytes();
    byte sz = (byte) (bs.length & 0xFF);
    buf.write(sz); // name size

    buf.write(bs, 0, bs.length); // name bytes

    buf.write(indexType); // index type
    byte tag = (byte) (allowNull ? 1 : 0);
    buf.write(tag); // allow null

    buf.write(function); // function type
    b = Numeric.toBytes(value);
    buf.write(b, 0, b.length); // default value

    return buf.toByteArray();
  }