CBOR for Java

Java implementation of RFC 7049: Concise Binary Object Representation (CBOR)

License

License

Categories

Categories

Ant Build Tools
GroupId

GroupId

co.nstant.in
ArtifactId

ArtifactId

cbor
Last Version

Last Version

0.9
Release Date

Release Date

Type

Type

jar
Description

Description

CBOR for Java
Java implementation of RFC 7049: Concise Binary Object Representation (CBOR)
Project URL

Project URL

https://github.com/c-rack/cbor-java
Source Code Management

Source Code Management

https://github.com/c-rack/cbor-java

Download cbor

How to add to project

<!-- https://jarcasting.com/artifacts/co.nstant.in/cbor/ -->
<dependency>
    <groupId>co.nstant.in</groupId>
    <artifactId>cbor</artifactId>
    <version>0.9</version>
</dependency>
// https://jarcasting.com/artifacts/co.nstant.in/cbor/
implementation 'co.nstant.in:cbor:0.9'
// https://jarcasting.com/artifacts/co.nstant.in/cbor/
implementation ("co.nstant.in:cbor:0.9")
'co.nstant.in:cbor:jar:0.9'
<dependency org="co.nstant.in" name="cbor" rev="0.9">
  <artifact name="cbor" type="jar" />
</dependency>
@Grapes(
@Grab(group='co.nstant.in', module='cbor', version='0.9')
)
libraryDependencies += "co.nstant.in" % "cbor" % "0.9"
[co.nstant.in/cbor "0.9"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.13

Project Modules

There are no modules declared in this project.

cbor-java

A Java 7 implementation of RFC 7049: Concise Binary Object Representation (CBOR)

Build Status Coverage Status Coverity Scan Build Status Code Quality: Java Total Alerts

Features

  • Encodes and decodes all examples described in RFC 7049
  • Provides a fluent interface builder for CBOR messages
  • Supports semantic tags
  • Supports 64-bit integer values
  • Passes all CPD, PMD and FindBugs tests

Documentation

Maven Dependency

Add this to the dependencies section of your pom.xml file:

<dependency>
    <groupId>co.nstant.in</groupId>
    <artifactId>cbor</artifactId>
    <version>0.9</version>
</dependency>

Usage

Encoding Example

ByteArrayOutputStream baos = new ByteArrayOutputStream();
new CborEncoder(baos).encode(new CborBuilder()
    .add("text")                // add string
    .add(1234)                  // add integer
    .add(new byte[] { 0x10 })   // add byte array
    .addArray()                 // add array
        .add(1)
        .add("text")
        .end()
    .build());
byte[] encodedBytes = baos.toByteArray();

Decoding Example

ByteArrayInputStream bais = new ByteArrayInputStream(encodedBytes);
List<DataItem> dataItems = new CborDecoder(bais).decode();
for(DataItem dataItem : dataItems) {
    // process data item
}

Streaming Decoding Example

ByteArrayInputStream bais = new ByteArrayInputStream(encodedBytes);
new CborDecoder(bais).decode(new DataItemListener() {

    @Override
    public void onDataItem(DataItem dataItem) {
        // process data item
    }

});

Preserving order of map entries

By default, maps are encoded in canonical format. If you want to preserve the order of map entries, use the encoder in non-canonical mode:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
new CborEncoder(baos).nonCanonical().encode(new CborBuilder()
    .addMap()
        .put(1, "v1")
        .put(0, "v2")
        .end()
    .build());
byte[] encodedBytes = baos.toByteArray();

Contribution Process

This project uses the C4 process for all code changes.

License

Copyright 2013-2019 Constantin Rack

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
0.9
0.8
0.7
0.5
0.4.1
0.4
0.3