gdx-cbor
is a Java library for encoding and decoding CBOR (Concise Binary Object Representation) data, specifically designed to work with libGDX.
It uses the cbor-java library under the hood to encode and decode CBOR data.
“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.”
- Encode and decode CBOR data
- Seamless integration with libGDX
- Supports various data types including strings, numbers, arrays, and maps
- Easy integration with gdx-websockets using gdx-websocket-cbor
Add the dependency to your core project:
dependencies {
implementation "dev.simonit:gdx-cbor:0.0.2"
}
To use gdx-cbor
with GWT, you need to include the sources in your gwt project:
dependencies {
implementation "dev.simonit:gdx-cbor:0.0.2:sources"
}
Then, add the following line to your GWT module (.gwt.xml) file:
<inherits name="dev.simonit.gdx-cbor"/>
Because gdx-cbor
is designed to work with libGDX, you can use the Json
class to encode and decode CBOR data. The CborReader
and CborWriter
classes are used to read and write CBOR data, respectively. More about libGDX Serializing and Deserializing
import dev.simonit.gdx.cbor.Cbor;
public void encodeData(Object data) {
Cbor cbor = new Cbor();
byte[] encodedData = cbor.toCbor(data);
}
(all other cbor.toJson()
methods also produce CBOR data!)
import dev.simonit.gdx.cbor.Cbor;
public void decodeData(byte[] data) {
Cbor cbor = new Cbor();
Object obj = cbor.fromCbor(Object.class, data);
}
(all other cbor.fromJson()
methods also read CBOR data!)
import dev.simonit.gdx.cbor.CborReader;
import dev.simonit.gdx.cbor.CborValue;
public void readCborData(byte[] data) {
CborValue root = new CborReader().parse(data);
}
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
This project is licensed under the Apache License 2.0. See the LICENSE file for more information.