@ -118,36 +118,40 @@ class StoredNodeFactory<V> implements NodeFactory<V> {
private Node < V > decode ( final RLPInput nodeRLPs , final Supplier < String > errMessage ) {
final int nodesCount = nodeRLPs . enterList ( ) ;
try {
switch ( nodesCount ) {
case 1 :
return decodeNull ( nodeRLPs , errMessage ) ;
case 2 :
final Bytes encodedPath = nodeRLPs . readBytes ( ) ;
final Bytes path ;
try {
path = CompactEncoding . decode ( encodedPath ) ;
} catch ( final IllegalArgumentException ex ) {
throw new MerkleTrieException ( errMessage . get ( ) + ": invalid path " + encodedPath , ex ) ;
}
final int size = path . size ( ) ;
if ( size > 0 & & path . get ( size - 1 ) = = CompactEncoding . LEAF_TERMINATOR ) {
return decodeLeaf ( path , nodeRLPs , errMessage ) ;
} else {
return decodeExtension ( path , nodeRLPs , errMessage ) ;
}
case ( BranchNode . RADIX + 1 ) :
return decodeBranch ( nodeRLPs , errMessage ) ;
default :
throw new MerkleTrieException (
errMessage . get ( ) + format ( ": invalid list size %s" , nodesCount ) ) ;
}
} finally {
nodeRLPs . leaveList ( ) ;
switch ( nodesCount ) {
case 1 :
final NullNode < V > nullNode = decodeNull ( nodeRLPs , errMessage ) ;
nodeRLPs . leaveList ( ) ;
return nullNode ;
case 2 :
final Bytes encodedPath = nodeRLPs . readBytes ( ) ;
final Bytes path ;
try {
path = CompactEncoding . decode ( encodedPath ) ;
} catch ( final IllegalArgumentException ex ) {
throw new MerkleTrieException ( errMessage . get ( ) + ": invalid path " + encodedPath , ex ) ;
}
final int size = path . size ( ) ;
if ( size > 0 & & path . get ( size - 1 ) = = CompactEncoding . LEAF_TERMINATOR ) {
final LeafNode < V > leafNode = decodeLeaf ( path , nodeRLPs , errMessage ) ;
nodeRLPs . leaveList ( ) ;
return leafNode ;
} else {
final Node < V > extensionNode = decodeExtension ( path , nodeRLPs , errMessage ) ;
nodeRLPs . leaveList ( ) ;
return extensionNode ;
}
case ( BranchNode . RADIX + 1 ) :
final BranchNode < V > branchNode = decodeBranch ( nodeRLPs , errMessage ) ;
nodeRLPs . leaveList ( ) ;
return branchNode ;
default :
throw new MerkleTrieException (
errMessage . get ( ) + format ( ": invalid list size %s" , nodesCount ) ) ;
}
}