commit | a453a8ff1408bcb5d034ea84bcfc09d441937b9d | [log] [tgz] |
---|---|---|
author | Constantin Rack <constantin@rack.li> | Sat Jul 26 12:35:33 2014 +0200 |
committer | Constantin Rack <constantin@rack.li> | Sat Jul 26 12:35:33 2014 +0200 |
tree | 33b611a9b7648f919c50a14251a9108a578853d1 | |
parent | 0d6623c6199897e61f09ee8615872fec4210a79e [diff] |
Add unit tests
A Java 7 implementation of RFC 7049: Concise Binary Object Representation (CBOR)
Add this to the dependencies section of your pom.xml file:
<dependency> <groupId>co.nstant.in</groupId> <artifactId>cbor</artifactId> <version>0.4</version> </dependency>
ByteArrayOutputStream baos = new ByteArrayOutputStream(); CborEncoder encoder = new CborEncoder(baos); encoder.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();
ByteArrayInputStream bais = new ByteArrayInputStream(encodedBytes); CborDecoder decoder = new CborDecoder(bais); List<DataItem> dataItems = decoder.decode(); for(DataItem dataItem : dataItems) { // process data item }
ByteArrayInputStream bais = new ByteArrayInputStream(encodedBytes); CborDecoder decoder = new CborDecoder(bais); decoder.decode(new DataItemListener() { @Override public void onDataItem(DataItem dataItem) { // process data item } });
Copyright 2013-2014 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.