https://github.com/simonit/gdx-cbor
CBOR adapters to use with libGDX
https://github.com/simonit/gdx-cbor
cbor libgdx serialization
Last synced: 5 months ago
JSON representation
CBOR adapters to use with libGDX
- Host: GitHub
- URL: https://github.com/simonit/gdx-cbor
- Owner: SimonIT
- License: apache-2.0
- Created: 2025-01-12T21:48:33.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-13T10:03:41.000Z (about 1 year ago)
- Last Synced: 2025-06-20T01:05:05.000Z (12 months ago)
- Topics: cbor, libgdx, serialization
- Language: Java
- Homepage:
- Size: 123 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gdx-cbor

[](https://github.com/SimonIT/gdx-cbor/actions/workflows/build-and-publish.yml)
[](https://javadoc.io/doc/dev.simonit/gdx-cbor)
`gdx-cbor` is a Java library for encoding and decoding [CBOR (Concise Binary Object Representation)](https://cbor.io) data, specifically designed to work with [libGDX](https://libgdx.com/).
It uses the [cbor-java](https://github.com/cbor-java/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](https://github.com/MrStahlfelge/gdx-websockets) using [gdx-websocket-cbor](https://github.com/SimonIT/gdx-cbor/tree/main/gdx-websocket-cbor)
## Installation
Add the dependency to your core project:
```groovy
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:
```groovy
dependencies {
implementation "dev.simonit:gdx-cbor:0.0.2:sources"
}
```
Then, add the following line to your GWT module (.gwt.xml) file:
```xml
```
## 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](https://libgdx.com/wiki/utils/reading-and-writing-json)
### Encoding Data
```java
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
```java
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
```java
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](LICENSE) file for more information.