Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of Pof Internals
package com.benstopford.coherence.bootstrap.morecomplex;
import com.tangosol.io.ReadBuffer;
import com.tangosol.io.pof.*;
import com.tangosol.util.Binary;
import com.tangosol.util.ExternalizableHelper;
import java.io.IOException;
public class PofPrimerGist {
public static void main(String[] args) throws IOException {
SimplePofContext context = new SimplePofContext();
context.registerUserType(1042, PofObject.class, new PortableObjectSerializer(1042));
PofObject object = new PofObject("TheData");
//get the binary & stream
Binary binary = ExternalizableHelper.toBinary(object, context);
ReadBuffer.BufferInput stream = binary.getBufferInput();
System.out.printf("Header btye: %s\n" +
"ClassType is: %s\n" +
"ClassVersion is: %s\n" +
"FieldPofId is: %s\n" +
"Field data type is: %s\n" +
"Field length is: %s\n",
stream.readPackedInt(),
stream.readPackedInt(),
stream.readPackedInt(),
stream.readPackedInt(),
stream.readPackedInt(),
stream.readPackedInt()
);
System.out.printf("Field Value is: %s\n",
binary.toBinary(6, "TheData".length() + 1).getBufferInput().readSafeUTF()
);
}
public static class PofObject implements PortableObject {
private Object data;
PofObject(Object data) {
this.data = data;
}
public void readExternal(PofReader pofReader) throws IOException {
data = pofReader.readObject(1);
}
public void writeExternal(PofWriter pofWriter) throws IOException {
pofWriter.writeObject(1, data);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment