Skip to content

Commit

Permalink
Convert byte[] -> bytes32 and fail on unknown classes instead of sile…
Browse files Browse the repository at this point in the history
…ntly encode to byte[0]

(cherry picked from commit 5c02de2)
  • Loading branch information
Nashatyrev committed Feb 6, 2017
1 parent 2b1d49b commit 441119d
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,14 @@ public byte[] encode(Object value) {
byte[] bytes = ((String) value).getBytes(StandardCharsets.UTF_8);
System.arraycopy(bytes, 0, ret, 0, bytes.length);
return ret;
} else if (value instanceof byte[]) {
byte[] bytes = (byte[]) value;
byte[] ret = new byte[32];
System.arraycopy(bytes, 0, ret, 32 - bytes.length, bytes.length);
return ret;
}

return new byte[0];
throw new RuntimeException("Can't encode java type " + value.getClass() + " to bytes32");
}

@Override
Expand Down

0 comments on commit 441119d

Please sign in to comment.