use of tech.pegasys.teku.infrastructure.ssz.tree.SszNodeTemplate in project teku by ConsenSys.
the class AbstractSszCollectionSchema method sszDeserializeSupernode.
private DeserializedData sszDeserializeSupernode(SszReader reader, int supernodeDepth) {
SszNodeTemplate template = elementSszSupernodeTemplate.get();
int sszSize = reader.getAvailableBytes();
if (sszSize % template.getSszLength() != 0) {
throw new SszDeserializeException("Ssz length is not multiple of element length");
}
int elementsCount = sszSize / template.getSszLength();
int chunkSize = (1 << supernodeDepth) * template.getSszLength();
int bytesRemain = sszSize;
List<SszSuperNode> sszNodes = new ArrayList<>(bytesRemain / chunkSize + 1);
while (bytesRemain > 0) {
int toRead = min(bytesRemain, chunkSize);
bytesRemain -= toRead;
Bytes bytes = reader.read(toRead);
SszSuperNode node = new SszSuperNode(supernodeDepth, template, bytes);
sszNodes.add(node);
}
TreeNode tree = TreeUtil.createTree(sszNodes, new SszSuperNode(supernodeDepth, template, Bytes.EMPTY), treeDepth() - supernodeDepth);
return new DeserializedData(tree, elementsCount);
}
Aggregations