// throw new CASRuntimeException(CASRuntimeException.DESERIALIZING_COMPRESSED_BINARY_UNSUPPORTED);
// Only works for cases where the type systems match, and delta is false.
try {
(new BinaryCasSerDes6(this)).deserializeAfterVersion(dis, delta, AllowPreexistingFS.allow);
} catch (ResourceInitializationException e) {
throw new CASRuntimeException(CASRuntimeException.DESERIALIZING_COMPRESSED_BINARY_UNSUPPORTED, null, e);
}
return SerialFormat.COMPRESSED_FILTERED;
}
}
// main fsheap
final int fsheapsz = readInt(dis, swap);
int startPos = 0;
if (!delta) {
this.getHeap().reinitSizeOnly(fsheapsz);
} else {
startPos = this.getHeap().getNextId();
this.getHeap().grow(fsheapsz);
}
for (int i = startPos; i < fsheapsz+startPos; i++) {
this.getHeap().heap[i] = readInt(dis, swap);
}
// string heap
int stringheapsz = readInt(dis, swap);
final StringHeapDeserializationHelper shdh = new StringHeapDeserializationHelper();
shdh.charHeap = new char[stringheapsz];
for (int i = 0; i < stringheapsz; i++) {
shdh.charHeap[i] = (char) readShort(dis, swap);
}
shdh.charHeapPos = stringheapsz;
// word alignment
if (stringheapsz % 2 != 0) {
dis.readChar();
}
// string ref heap
int refheapsz = readInt(dis, swap);
refheapsz--;
refheapsz = refheapsz / 2;
refheapsz = refheapsz * 3;
// read back into references consisting to three ints
// --stringheap offset,length, stringlist offset
shdh.refHeap = new int[StringHeapDeserializationHelper.FIRST_CELL_REF + refheapsz];
dis.readInt(); // 0
for (int i = shdh.refHeapPos; i < shdh.refHeap.length; i += StringHeapDeserializationHelper.REF_HEAP_CELL_SIZE) {
shdh.refHeap[i + StringHeapDeserializationHelper.CHAR_HEAP_POINTER_OFFSET] = readInt(dis, swap);
shdh.refHeap[i + StringHeapDeserializationHelper.CHAR_HEAP_STRLEN_OFFSET] = readInt(dis, swap);
shdh.refHeap[i + StringHeapDeserializationHelper.STRING_LIST_ADDR_OFFSET] = 0;
}
shdh.refHeapPos = refheapsz + StringHeapDeserializationHelper.FIRST_CELL_REF;
this.getStringHeap().reinit(shdh, delta);
//if delta, handle modified fs heap cells
if (delta) {
int fsmodssz = readInt(dis, swap);
for (int i = 0; i < fsmodssz; i++) {
this.getHeap().heap[readInt(dis, swap)] = readInt(dis, swap);
}
}
// indexed FSs
int fsindexsz = readInt(dis, swap);
int[] fsindexes = new int[fsindexsz];
for (int i = 0; i < fsindexsz; i++) {
fsindexes[i] = readInt(dis, swap);
}
// build the index
if (delta) {
reinitDeltaIndexedFSs(fsindexes);
} else {
reinitIndexedFSs(fsindexes);
}
// byte heap
int heapsz = readInt(dis, swap);
if (!delta) {
this.getByteHeap().heap = new byte[Math.max(16, heapsz)]; // must be > 0
dis.readFully(this.getByteHeap().heap, 0, heapsz);
this.getByteHeap().heapPos = heapsz;
} else {
for (int i=0; i < heapsz; i++) {
this.getByteHeap().addByte(dis.readByte());
}
}
// word alignment
int align = (4 - (heapsz % 4)) % 4;
BinaryCasSerDes6.skipBytes(dis, align);
// short heap
heapsz = readInt(dis, swap);
if (!delta) {
this.getShortHeap().heap = new short[Math.max(16, heapsz)]; // must be > 0
for (int i = 0; i < heapsz; i++) {
this.getShortHeap().heap[i] = readShort(dis, swap);
}
this.getShortHeap().heapPos = heapsz;
} else {
for (int i = 0; i < heapsz; i++) {
this.getShortHeap().addShort(readShort(dis, swap));
}
}
// word alignment
if (heapsz % 2 != 0) {
dis.readShort();
}
// long heap
heapsz = readInt(dis, swap);
if (!delta) {
this.getLongHeap().heap = new long[Math.max(16, heapsz)]; // must be > 0
for (int i = 0; i < heapsz; i++) {
this.getLongHeap().heap[i] = readLong(dis, swap);
}
this.getLongHeap().heapPos = heapsz;
} else {
for (int i = 0; i < heapsz; i++) {
this.getLongHeap().addLong(readLong(dis, swap));
}
}
if (delta) {
//modified Byte Heap
heapsz = readInt(dis, swap);
if (heapsz > 0) {
int[] heapAddrs = new int[heapsz];
for (int i = 0; i < heapsz; i++) {
heapAddrs[i] = readInt(dis, swap);
}
for (int i = 0; i < heapsz; i++) {
this.getByteHeap().heap[heapAddrs[i]] = dis.readByte();
}
}
// word alignment
align = (4 - (heapsz % 4)) % 4;
BinaryCasSerDes6.skipBytes(dis, align);
//modified Short Heap
heapsz = readInt(dis, swap);
if (heapsz > 0) {
int[] heapAddrs = new int[heapsz];
for (int i = 0; i < heapsz; i++) {
heapAddrs[i] = readInt(dis, swap);
}
for (int i = 0; i < heapsz; i++) {
this.getShortHeap().heap[heapAddrs[i]] = readShort(dis, swap);
}
}
// word alignment
if (heapsz % 2 != 0) {
dis.readShort();
}
//modified Long Heap
heapsz = readInt(dis, swap);
if (heapsz > 0) {
int[] heapAddrs = new int[heapsz];
for (int i = 0; i < heapsz; i++) {
heapAddrs[i] = readInt(dis, swap);
}
for (int i = 0; i < heapsz; i++) {
this.getLongHeap().heap[heapAddrs[i]] = readLong(dis, swap);
}
}
} // of delta - modified processing
} catch (IOException e) {
String msg = e.getMessage();
if (msg == null) {
msg = e.toString();
}
CASRuntimeException exception = new CASRuntimeException(
CASRuntimeException.BLOB_DESERIALIZATION, new String[] { msg });
throw exception;
}
return SerialFormat.BINARY;
}