Search in sources :

Example 1 with TbSubscriptionUpdateTsValue

use of org.thingsboard.server.gen.transport.TransportProtos.TbSubscriptionUpdateTsValue in project thingsboard by thingsboard.

the class TbSubscriptionUtils method fromProto.

public static TelemetrySubscriptionUpdate fromProto(TbSubscriptionUpdateProto proto) {
    if (proto.getErrorCode() > 0) {
        return new TelemetrySubscriptionUpdate(proto.getSubscriptionId(), SubscriptionErrorCode.forCode(proto.getErrorCode()), proto.getErrorMsg());
    } else {
        Map<String, List<Object>> data = new TreeMap<>();
        proto.getDataList().forEach(v -> {
            List<Object> values = data.computeIfAbsent(v.getKey(), k -> new ArrayList<>());
            for (int i = 0; i < v.getTsValueCount(); i++) {
                Object[] value = new Object[2];
                TbSubscriptionUpdateTsValue tsValue = v.getTsValue(i);
                value[0] = tsValue.getTs();
                value[1] = tsValue.hasValue() ? tsValue.getValue() : null;
                values.add(value);
            }
        });
        return new TelemetrySubscriptionUpdate(proto.getSubscriptionId(), data);
    }
}
Also used : TelemetrySubscriptionUpdate(org.thingsboard.server.service.telemetry.sub.TelemetrySubscriptionUpdate) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) TbSubscriptionUpdateTsValue(org.thingsboard.server.gen.transport.TransportProtos.TbSubscriptionUpdateTsValue)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 TbSubscriptionUpdateTsValue (org.thingsboard.server.gen.transport.TransportProtos.TbSubscriptionUpdateTsValue)1 TelemetrySubscriptionUpdate (org.thingsboard.server.service.telemetry.sub.TelemetrySubscriptionUpdate)1