use of com.ms.silverking.cloud.dht.daemon.storage.convergence.LeafChecksumNode in project SilverKing by Morgan-Stanley.
the class ProtoChecksumTreeMessageGroup method serialize.
public static void serialize(ByteBuffer buffer, ChecksumNode node) {
if (node == null) {
// only supported for root of tree
writeNullRoot(buffer);
} else {
if (node instanceof NonLeafChecksumNode) {
List<? extends ChecksumNode> children;
writeNodeHeader(buffer, NodeType.NON_LEAF, node);
children = node.getChildren();
for (ChecksumNode child : children) {
serialize(buffer, child);
}
} else if (node instanceof LeafChecksumNode) {
writeNodeHeader(buffer, NodeType.LEAF, node);
writeKeyAndVersionChecksums(buffer, (LeafChecksumNode) node);
} else {
throw new RuntimeException("panic");
}
}
}
use of com.ms.silverking.cloud.dht.daemon.storage.convergence.LeafChecksumNode in project SilverKing by Morgan-Stanley.
the class ProtoChecksumTreeMessageGroup method deserialize.
public static ChecksumNode deserialize(ByteBuffer buffer) {
NodeType type;
RingRegion region;
int numChildren;
AbstractChecksumNode root;
type = NodeType.values()[buffer.get()];
if (type != NodeType.NULL) {
region = deserializeRegion(buffer);
numChildren = buffer.getInt();
} else {
region = null;
numChildren = 0;
}
switch(type) {
case NON_LEAF:
List<ChecksumNode> children;
children = new ArrayList<>(numChildren);
for (int i = 0; i < numChildren; i++) {
children.add(deserialize(buffer));
}
root = new NonLeafChecksumNode(region, children);
break;
case LEAF:
List<KeyAndVersionChecksum> keyAndVersionChecksums;
keyAndVersionChecksums = deserializeKeyAndVersionChecksums(buffer);
root = new LeafChecksumNode(region, keyAndVersionChecksums);
break;
case NULL:
root = null;
break;
default:
throw new RuntimeException("panic");
}
if (root != null) {
root.freezeIfNotFrozen();
}
return root;
}
Aggregations