Closed alihaider123456 closed 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!
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
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
Could you please provide the hexdump of the payload/byte array after encoding (client side) and before decoding (server side)? Are they the same?
server side byte -17-65-67100110971091011202984101109112101114971161171141013277111110105116111114105110103328312111511610110910710010111599114105112116105111110120418310111011511111432115121115116101109321091111101051161111141051101033297114101973211610110911210111497116117114101 -94100110971091011202984101109112101114971161171141013277111110105116111114105110103328312111511610110910710010111599114105112116105111110120418310111011511111432115121115116101109321091111101051161111141051101033297114101973211610110911210111497116117114101
server side before -94100110971091011202984101109112101114971161171141013277111110105116111114105110103328312111511610110910710010111599114105112116105111110120418310111011511111432115121115116101109321091111101051161111141051101033297114101973211610110911210111497116117114101
both are different
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.
i did wrong some code for getting payload. but now its working fine. thanks
Ok, I'm closing this issue then.
can any one tell how to avoid this exception