An encoder and decoder implementation in Java for Azam Codec, a lexicographically sortable multi-section base16 encoding of byte array. Zero external dependencies.
MIT License Copyright (c) 2023 Azamshul Azizy
This library is published to Maven Central; you can add it as Maven/Gradle/etc dependency as needed. Refer Maven Central for latest published version and snippets on adding dependency to your project.
// Decode to ints
int[] ints = AzamCodec.azamDecodeInts("xytxvyyfh5wgg1"); // -559038737, 21, 49153
// Decode to big endian bytes
byte[][] bytes = AzamCodec.azamDecodeBytes("xytxvyyfh5wgg1"); // 0xdeadbeef, 0x15, 0xc001// Encode from ints
String encodedInts = AzamCodec.azamEncodeInts(new int[]{ -559038737, 21, 49153 }); // "xytxvyyfh5wgg1"
// Encode from bytes
String encodedBytes = AzamCodec.azamEncodeBytes(new byte[][]{ //
new byte[] { 0xde, 0xad, 0xbe, 0xef }, //
new byte[] { 0x15 }, //
new byte[] { 0xc0, 0x01 } //
}); // "xytxvyyfh5wgg1"Azam Codec is designed to be a sortable identifier representation, so using it to represent multi sectioned identifier is the best example.
public class RecordId {
int tenantId;
int objectId;
int recordId;
public RecordId(String id) throws ParseException {
int[] sections = AzamCodec.azamDecodeInts(id);
this.tenantId = sections[0];
this.objectId = sections[1];
this.recordId = sections[2];
}
public String toString() {
return AzamCodec.azamEncodeInts(new int[] { this.tenantId, this.objectId, this.recordId });
}
}Standard Java development method applies. Please make sure that code is correctly formatted and tests are passing before sending a PR.
mvn formatter:format xml-format:xml-formatmvn verifymvn -P benchmark package
java -jar target/benchmark.jar AzamCodecBench