DynamicRecord readDynamicRecord() throws IOException { // id+type+in_use(byte)+nr_of_bytes(int)+next_block(long) long id = channel.getLong(); assert id >= 0 && id <= (1l << 36) - 1 : id + " is not a valid dynamic record id"; int type = channel.getInt(); byte inUseFlag = channel.get(); boolean inUse = (inUseFlag & Record.IN_USE.byteValue()) != 0; DynamicRecord record = new DynamicRecord(id); record.setInUse(inUse, type); if (inUse) { record.setStartRecord((inUseFlag & Record.FIRST_IN_CHAIN.byteValue()) != 0); int nrOfBytes = channel.getInt(); assert nrOfBytes >= 0 && nrOfBytes < ((1 << 24) - 1) : nrOfBytes + " is not valid for a number of bytes field of " + "a dynamic record"; long nextBlock = channel.getLong(); assert (nextBlock >= 0 && nextBlock <= (1l << 36 - 1)) || (nextBlock == Record.NO_NEXT_BLOCK.intValue()) : nextBlock + " is not valid for a next record field of " + "a dynamic record"; record.setNextBlock(nextBlock); byte data[] = new byte[nrOfBytes]; channel.get(data, nrOfBytes); record.setData(data); } return record; }
private Collection<DynamicRecord> serialize( SchemaRule rule, long id, boolean inUse, boolean created) { RecordSerializer serializer = new RecordSerializer(); serializer = serializer.append(rule); DynamicRecord record = new DynamicRecord(id); record.setData(serializer.serialize()); if (created) { record.setCreated(); } if (inUse) { record.setInUse(true); } return Arrays.asList(record); }