Skip to content

SimonIT/gdx-cbor

Repository files navigation

gdx-cbor

Maven Central Version Build and publish javadoc

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.”

Features

  • 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

Installation

Add the dependency to your core project:

dependencies {
    implementation "dev.simonit:gdx-cbor:0.0.2"
}

GWT

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"/>

Usage

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

Encoding Data

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!)

Decoding 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!)

Reading to DOM

import dev.simonit.gdx.cbor.CborReader;
import dev.simonit.gdx.cbor.CborValue;

public void readCborData(byte[] data) {
	CborValue root = new CborReader().parse(data);
}

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the Apache License 2.0. See the LICENSE file for more information.