Skip to content

Latest commit

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

CBOR Java library

The Concise Binary Object Representation (CBOR) is a data format whose design goals include the possibility of extremely small code size, fairly small message size, and extensibility without the need for version negotiation

Read more in the documentation on ReadTheDocs.

Examples

decode integer

Stringinput = "1b000000e8d4a51000";
byte[] bytes = fromHex(input);
CBORDecoderdecoder = newCBORDecoder();
CBORObjectresult = decoder.decode(bytes);
assertTrue(result.valinstanceofLong);
assertEquals(1000000000000L, result.val);

decode bytes

Stringinput = "5818010203040102030401020304010203040102030401020304";
byte[] bytes = fromHex(input);
CBORDecoderdecoder = newCBORDecoder();
CBORObjectresult = decoder.decode(bytes);
assertTrue(result.valinstanceofbyte[]);
byte[] checkBytes = {0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04};
byte[] resultBytes = (byte[]) result.val;
for (inti = 0; i < resultBytes.length; i++) {
assertEquals(checkBytes[i], resultBytes[i]);
}

decode array

Stringinput = "83010203";
byte[] bytes = fromHex(input);
CBORDecoderdecoder = newCBORDecoder();
CBORObjectresult = decoder.decode(bytes);
assertTrue(result.valinstanceofArrayList);
ArrayListitems = (ArrayList) result.val;
assertEquals(1L, items.get(0));
assertEquals(2L, items.get(1));
assertEquals(3L, items.get(2));

Getting help

Please contact sfa.alptekin@gmail.com

About

Java implementation of CBOR. http://cbor.io/

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages