use of org.eclipse.californium.elements.RawData in project leshan by eclipse.
the class LockStepLwM2mClient method sendLwM2mRequest.
public void sendLwM2mRequest(UplinkRequest<? extends LwM2mResponse> lwm2mReq) {
// create CoAP request
CoapRequestBuilder coapRequestBuilder = new CoapRequestBuilder(destination);
lwm2mReq.accept(coapRequestBuilder);
Request coapReq = coapRequestBuilder.getRequest();
byte[] token = new byte[8];
r.nextBytes(token);
coapReq.setToken(token);
// serialize request
UdpDataSerializer serializer = new UdpDataSerializer();
RawData raw = serializer.serializeRequest(coapReq);
// send it
super.send(raw);
}
use of org.eclipse.californium.elements.RawData in project leshan by eclipse.
the class ObserveTest method sendNotification.
private void sendNotification(Connector connector, byte[] payload, Response firstCoapResponse, int contentFormat) {
// create observe response
Response response = new Response(org.eclipse.californium.core.coap.CoAP.ResponseCode.CONTENT);
response.setType(Type.NON);
response.setPayload(payload);
response.setMID(firstCoapResponse.getMID() + 1);
response.setToken(firstCoapResponse.getToken());
OptionSet options = new OptionSet().setContentFormat(contentFormat).setObserve(firstCoapResponse.getOptions().getObserve() + 1);
response.setOptions(options);
EndpointContext context = new AddressEndpointContext(helper.server.getUnsecuredAddress().getAddress(), helper.server.getUnsecuredAddress().getPort());
response.setDestinationContext(context);
// serialize response
UdpDataSerializer serializer = new UdpDataSerializer();
RawData data = serializer.serializeResponse(response);
// send it
connector.send(data);
}
use of org.eclipse.californium.elements.RawData 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