Exemplo n.º 1
0
  public static int getLength(ByteArray bytes, int index, int headerWord) {
    // FIXME: WE NEED TO SUPPORT CONSTRAINTS HERE TOO, so need to look at headerWord, and return
    // diff
    // size if it's a constraint (or even same size) e.g. for Boolean.
    boolean isConstraint = CompactAttrCodec.getAttrFunction(headerWord) == AttrFunction.constraint;
    switch (AttrDefinitionMgr.getAttrType(headerWord)) {
      case booleanValue:
        return isConstraint ? BooleanConstraintCodec.BOOLEAN_SIZE : BooleanCodec.BOOLEAN_SIZE;
      case enumExclusiveValue:
        return isConstraint ? bytes.getByte(index + LENGTH_OFFSET) : EnumCodec.EXCLUSIVE_ENUM_SIZE;
      case floatValue:
        return isConstraint ? bytes.getByte(index + LENGTH_OFFSET) : FloatCodec.FLOAT_SIZE;

      case floatRangePrefValue: // could have fixed size
        // FALLTHRU
      case enumMultiValue: // could have fixed size
        // FALLTHRU
      default: // all remainder have variable size
        int length = bytes.getByte(index + LENGTH_OFFSET);
        return length;
    }
  }
Exemplo n.º 2
0
 /**
  * Find the location of a given attribute within the given ByteArray.
  *
  * @return -1 if not found, index of start of attribute if found
  */
 public static int findAttrInBuf(ByteArray bytes, int attrId) {
   int i = 0;
   while (i < bytes.size()) {
     int headerWord = getHeaderWord(bytes, i);
     int length = getLength(bytes, i, headerWord);
     if (length
         == 0) { // shouldn't be needed, but was in past.  Would be good to remove this. FIXME For
       // now, just log
       LogFactory.getLogger(CompactAttrCodec.class).error("Got zero length. Wasn't expecting it");
       break;
     }
     int bufAttrId = getAttrId(headerWord);
     if (attrId == bufAttrId) {
       return i;
     }
     i += length;
   }
   return NOT_FOUND; // not found
 }
Exemplo n.º 3
0
 public static void setAttrId(ByteArray bytes, int index, int attrId) {
   assert (attrId < 65536);
   bytes.putShort(index + ATTR_ID_OFFSET, (short) (attrId | FN_ATTRIBUTE));
 }
Exemplo n.º 4
0
 public static int getHeaderWord(ByteArray bytes, int index) {
   int header = bytes.getShort(index + ATTR_ID_OFFSET);
   return header;
 }