use of org.apache.geode.pdx.internal.PdxInputStream in project geode by apache.
the class InternalDataSerializer method readPdxInstance.
/**
* Reads a PdxInstance from dataBytes and returns it. If the first object read is not pdx encoded
* returns null.
*/
public static PdxInstance readPdxInstance(final byte[] dataBytes, InternalCache internalCache) {
try {
byte type = dataBytes[0];
if (type == PDX) {
PdxInputStream in = new PdxInputStream(dataBytes);
// throw away the type byte
in.readByte();
int len = in.readInt();
int typeId = in.readInt();
PdxType pdxType = internalCache.getPdxRegistry().getType(typeId);
if (pdxType == null) {
throw new IllegalStateException("Unknown pdx type=" + typeId);
}
return new PdxInstanceImpl(pdxType, in, len);
} else if (type == DSCODE.PDX_ENUM) {
PdxInputStream in = new PdxInputStream(dataBytes);
// throw away the type byte
in.readByte();
int dsId = in.readByte();
int tmp = readArrayLength(in);
int enumId = dsId << 24 | tmp & 0xFFFFFF;
TypeRegistry tr = internalCache.getPdxRegistry();
EnumInfo ei = tr.getEnumInfoById(enumId);
if (ei == null) {
throw new IllegalStateException("Unknown pdx enum id=" + enumId);
}
return ei.getPdxInstance(enumId);
} else if (type == DSCODE.PDX_INLINE_ENUM) {
PdxInputStream in = new PdxInputStream(dataBytes);
// throw away the type byte
in.readByte();
String className = DataSerializer.readString(in);
String enumName = DataSerializer.readString(in);
int enumOrdinal = InternalDataSerializer.readArrayLength(in);
return new PdxInstanceEnum(className, enumName, enumOrdinal);
}
} catch (IOException ignore) {
}
return null;
}
use of org.apache.geode.pdx.internal.PdxInputStream in project geode by apache.
the class BlobHelper method deserializeOffHeapBlob.
/**
* A blob is a serialized Object. This method returns the deserialized object. If a PdxInstance is
* returned then it will refer to Chunk's off-heap memory with an unretained reference.
*/
@Unretained
public static Object deserializeOffHeapBlob(StoredObject blob) throws IOException, ClassNotFoundException {
Object result;
final long start = startDeserialization();
// For both top level and nested pdxs we just want a reference to this off-heap blob.
// No copies.
// For non-pdx we want a stream that will read directly from the chunk.
PdxInputStream is = new PdxInputStream(blob);
result = DataSerializer.readObject(is);
endDeserialization(start, blob.getDataSize());
return result;
}
use of org.apache.geode.pdx.internal.PdxInputStream in project geode by apache.
the class BlobHelper method deserializeBlob.
/**
* A blob is a serialized Object. This method returns the deserialized object.
*/
public static Object deserializeBlob(byte[] blob, Version version, ByteArrayDataInput in) throws IOException, ClassNotFoundException {
Object result;
final long start = startDeserialization();
if (blob.length > 0 && blob[0] == DSCODE.PDX) {
// If the first byte of blob indicates a pdx then wrap
// blob in a PdxInputStream instead.
// This will prevent us from making a copy of the byte[]
// every time we deserialize a PdxInstance.
PdxInputStream is = new PdxInputStream(blob);
result = DataSerializer.readObject(is);
} else {
// just have the pdx bytes and not the outer objects bytes.
if (in == null) {
in = new ByteArrayDataInput();
}
in.initialize(blob, version);
result = DataSerializer.readObject(in);
}
endDeserialization(start, blob.length);
return result;
}
Aggregations