c-rack / cbor-java

Java implementation of RFC 7049: Concise Binary Object Representation (CBOR)
http://cbor.io/
Apache License 2.0
118 stars 25 forks source link

co.nstant.in.cbor.CborException: Reserved additional information #43

Closed alihaider123456 closed 7 years ago

alihaider123456 commented 7 years ago

can any one tell how to avoid this exception

c-rack commented 7 years ago

@alihaider123456 Could you please provide the byte array you want to decode? Or, even better, send a PR with a failing unit test? Thanks!

alihaider123456 commented 7 years ago

actually i am working on coap client and resource directory and handle message format in resource directory. if i am not send payload then it will execute properly but when i send payload and retrieve on server side then exception will rise client code here try{ CborBuilder builder = new CborBuilder(); builder .addMap().put("name","Temperature Monitoring System") .put("description", "Sensor system monitoring area temperature") .end(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); CborEncoder encoder = new CborEncoder(baos); List value1 = builder.build();
encoder.encode(value1);

        /*<DataItem> dataItems = CborDecoder.decode(baos.toByteArray());
        Map map = new Map();
        map = (Map)dataItems.get(0);
        Collection<DataItem> keys = map.getKeys();
        for (Iterator<DataItem> iterator = keys.iterator(); iterator.hasNext();){
            DataItem name = (DataItem)iterator.next();
            System.out.println(name + "  "+map.get(name));
        }*/
        CoapClient client =  new CoapClient("coap://127.0.0.1:5683/rd?ep=node1");
        CoapResponse response = client.post(baos.toByteArray(), MediaTypeRegistry.APPLICATION_CBOR);
        if ( response != null ) {
            System.out.println("Resources: " +
                                   response.getResponseText());
            }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

on server side code here ByteArrayInputStream bais = new ByteArrayInputStream(payload.getBytes()); CborDecoder decoder = new CborDecoder(bais); List item = decoder.decode();

c-rack commented 7 years ago

Could you please provide the hexdump of the payload/byte array after encoding (client side) and before decoding (server side)? Are they the same?

alihaider123456 commented 7 years ago

server side byte -17-65-67100110971091011202984101109112101114971161171141013277111110105116111114105110103328312111511610110910710010111599114105112116105111110120418310111011511111432115121115116101109321091111101051161111141051101033297114101973211610110911210111497116117114101 -94100110971091011202984101109112101114971161171141013277111110105116111114105110103328312111511610110910710010111599114105112116105111110120418310111011511111432115121115116101109321091111101051161111141051101033297114101973211610110911210111497116117114101

alihaider123456 commented 7 years ago

server side before -94100110971091011202984101109112101114971161171141013277111110105116111114105110103328312111511610110910710010111599114105112116105111110120418310111011511111432115121115116101109321091111101051161111141051101033297114101973211610110911210111497116117114101

alihaider123456 commented 7 years ago

both are different

c-rack commented 7 years ago

Ok, then something during the transmission goes wrong. The "-94100..." part is identical on both sides, so I assume that the problem is related to the coap client/server, not with cbor-java.

alihaider123456 commented 7 years ago

i did wrong some code for getting payload. but now its working fine. thanks

c-rack commented 7 years ago

Ok, I'm closing this issue then.