Skip to content

Commit 1895a18

Browse files
committed
Extra blob->hex conversions utilities
1 parent e0f835e commit 1895a18

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

convex-core/src/main/java/convex/core/data/ABlobLike.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ public final String toHexString(int hexLength) {
135135
public String toHexString() {
136136
return toHexString(Utils.checkedInt(hexLength()));
137137
}
138+
139+
/**
140+
* Converts this data object to a lowercase hex string representation
141+
* @return Hex String representation
142+
*/
143+
public AString toCVMHexString() {
144+
BlobBuilder bb=new BlobBuilder();
145+
long hl=hexLength();
146+
appendHex(bb,hl);
147+
return bb.getCVMString();
148+
}
138149

139150
/**
140151
* Append hex string up to the given length in hex digits (a multiple of two)

convex-core/src/test/java/convex/core/data/BlobsTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ public void testHexEquals() {
9999
assertTrue(Blob.fromHex("0123").hexEquals(Blob.fromHex("4567"), 4, 0));
100100
}
101101

102+
@Test
103+
public void testHexString() {
104+
assertEquals("0123",Blob.fromHex("0123").toCVMHexString().toString());
105+
}
106+
102107
@Test
103108
public void testHexMatchLength() {
104109
assertEquals(4,Blob.fromHex("0123").hexMatch(Blob.fromHex("0123"), 0, 4));

0 commit comments

Comments
 (0)