use of org.eclipse.californium.core.observe.Observation in project leshan by eclipse.
the class ObservationSerDes method deserialize.
public static Observation deserialize(byte[] data) {
JsonObject v = (JsonObject) Json.parse(new String(data));
EndpointContext endpointContext = EndpointContextSerDes.deserialize(v.get("peer").asObject());
byte[] req = Hex.decodeHex(v.getString("request", null).toCharArray());
RawData rawData = RawData.outbound(req, endpointContext, null, false);
Request request = (Request) parser.parseMessage(rawData);
request.setDestinationContext(endpointContext);
JsonValue ctxValue = v.get("context");
if (ctxValue != null) {
Map<String, String> context = new HashMap<>();
JsonObject ctxObject = (JsonObject) ctxValue;
for (String name : ctxObject.names()) {
context.put(name, ctxObject.getString(name, null));
}
request.setUserContext(context);
}
return new Observation(request, endpointContext);
}
Aggregations