Skip to content

Commit

Permalink
add method RLPOutputStream::writeList(Object...)
Browse files Browse the repository at this point in the history
  • Loading branch information
esaulpaugh committed Jul 23, 2024
1 parent ebc9a46 commit 3756dcb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public void writeSequence(Iterable<?> rawObjects) throws IOException {
writeOut(RLPEncoder.sequence(rawObjects));
}

public void writeList(Object... rawElements) throws IOException {
writeOut(RLPEncoder.list(rawElements));
}

public void writeList(Iterable<?> rawElements) throws IOException {
writeOut(RLPEncoder.list(rawElements));
}
Expand Down
19 changes: 8 additions & 11 deletions src/test/java/com/esaulpaugh/headlong/rlp/RLPStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ public class RLPStreamTest {

@Test
public void testRLPOutputStream() throws Throwable {
Object[] objects = new Object[] {
Strings.decode("0573490923738490"),
new HashSet<byte[]>(),
new Object[] { new byte[] { 0x77, 0x61 } }
};
TestUtils.assertThrown(NullPointerException.class, () -> {try(RLPOutputStream ros = new RLPOutputStream(null)){}});
try (Baos baos = new Baos(); RLPOutputStream ros = new RLPOutputStream(baos)) {
ros.write(0xc0);
Expand All @@ -78,16 +73,18 @@ public void testRLPOutputStream() throws Throwable {
byte[] bytes = baos.toByteArray();
assertEquals("81c0827f20010203c3040506", Strings.encode(bytes));
}
Object[] objects = new Object[] {
Strings.decode("0573490923738490"),
new HashSet<byte[]>(),
new Object[] { new byte[] { 0x77, 0x61 } }
};
try (Baos baos = new Baos(); RLPOutputStream ros = new RLPOutputStream(baos)) {
Notation notation = Notation.forObjects(objects);
ros.writeSequence(objects);
byte[] bytes = baos.toByteArray();
assertEquals(notation, Notation.forEncoding(bytes));
assertEquals(Notation.forObjects(objects), Notation.forEncoding(baos.toByteArray()));
}
try (Baos baos = new Baos(); RLPOutputStream ros = new RLPOutputStream(baos)) {
ros.writeList(Arrays.asList(objects));
byte[] bytes = baos.toByteArray();
assertEquals(Notation.forObjects(new Object[] { objects }), Notation.forEncoding(bytes));
ros.writeList(objects);
assertEquals(Notation.forObjects( (Object) objects), Notation.forEncoding(baos.toByteArray()));
assertEquals("ce880573490923738490c0c3827761", baos.toString());
assertEquals("ce880573490923738490c0c3827761", ros.toString());
}
Expand Down

0 comments on commit 3756dcb

Please sign in to comment.