A Java implementation of Multicodec in Java.
static
codecs registry- no lookups for a codec when encoding
- direct
static
access to codecs
- built-in
Unsigned VarInt
support
/* encode an input as P-521 public key */
byte[] encoded = KeyCodec.P521_PUBLIC_KEY.encode(input);
/* encode an input as an identity */
byte[] encoded = MultihashCodec.IDENTITY.encode(input);
/* get decoder instance initialized with all supported codecs */
var decoder = MulticodecDecoder.getInstance();
/* get decoder initialized with codecs tagged as key and hash */
var decoder = MulticodecDecoder.getInstance(Tag.Key, Tag.Hash);
/* get decoder initialized with custom codec set */
var decoder = MulticodecDecoder.getInstance(codecs...);
/* decode */
byte[] decoded = decoder.decode(encoded);
/* or check if encoding is supported */
Optional<Multicodec> codec = decoder.getCodec(encoded);
if (codec.isPresent()) {
byte[] decoded = codec.get().decode(encoded);
}
/* or directy when only one codec is supported */
byte[] decoded = KeyCodec.P521_PUBLIC_KEY.decode(encoded);
/* check if byte array is encoded with a codec */
if (KeyCodec.P521_PUBLIC_KEY.isEncoded(encoded)) {
...
}
<dependency>
<groupId>com.apicatalog</groupId>
<artifactId>copper-multicodec</artifactId>
<version>0.1.1</version>
</dependency>
implementation("com.apicatalog:copper-multicodec:0.1.1")
All PR's welcome!
Fork and clone the project repository.
> cd copper-multicodec
> mvn clean package