riot icon indicating copy to clipboard operation
riot copied to clipboard

add parseHex and parseUuid spel functions to return byte arrays

Open jeremyplichta opened this issue 9 months ago • 2 comments

Added new spel functions parseHex and parseUuid

To complete before merge:

  • [x] test locally with local redis instance
  • [ ] add unit/integration tests

jeremyplichta avatar Mar 20 '25 03:03 jeremyplichta

Could we use jakarta.xml.bind.DataTypeConverter.parseHexBinary(String hex) for the hex parser?

Also we could probably simplify parseUuid with java.nio.ByteBuffer:

	public static String parseUuid(String uuid) {
		if (uuid == null) {
			return null;
		}
		UUID uuidObj = UUID.fromString(uuid);
		ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
		bb.putLong(uuidObj.getMostSignificantBits());
		bb.putLong(uuidObj.getLeastSignificantBits());
		return new String(bb.array());
	}

jruaux avatar Mar 20 '25 04:03 jruaux

Could we use jakarta.xml.bind.DataTypeConverter.parseHexBinary(String hex) for the hex parser?

Also we could probably simplify parseUuid with java.nio.ByteBuffer:

	public static String parseUuid(String uuid) {
		if (uuid == null) {
			return null;
		}
		UUID uuidObj = UUID.fromString(uuid);
		ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
		bb.putLong(uuidObj.getMostSignificantBits());
		bb.putLong(uuidObj.getLeastSignificantBits());
		return new String(bb.array());
	}

Thanks, those are good suggestions. I will make those when I have a chance as well as implement some tests for this to make sure that we are not having any character encode issues going from byte to string. I'll ping you on here for another review when I'm ready. Thanks!

jeremyplichta avatar Mar 21 '25 05:03 jeremyplichta