|
|
|
@ -27,6 +27,7 @@ import com.google.protobuf.ByteString; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.SneakyThrows; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.thingsboard.common.util.TbStringPool; |
|
|
|
import org.thingsboard.server.common.data.AttributeScope; |
|
|
|
@ -63,6 +64,9 @@ import java.util.UUID; |
|
|
|
@Slf4j |
|
|
|
public class EdqsConverter { |
|
|
|
|
|
|
|
@Value("${queue.edqs.string_compression_length_threshold:512}") |
|
|
|
private int stringCompressionLengthThreshold; |
|
|
|
|
|
|
|
private final Map<ObjectType, Converter<? extends EdqsObject>> converters = new HashMap<>(); |
|
|
|
private final Converter<Entity> defaultConverter = new JsonConverter<>(Entity.class); |
|
|
|
|
|
|
|
@ -131,7 +135,7 @@ public class EdqsConverter { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public static DataPointProto toDataPointProto(long ts, KvEntry kvEntry) { |
|
|
|
public DataPointProto toDataPointProto(long ts, KvEntry kvEntry) { |
|
|
|
DataPointProto.Builder proto = DataPointProto.newBuilder(); |
|
|
|
proto.setTs(ts); |
|
|
|
switch (kvEntry.getDataType()) { |
|
|
|
@ -140,7 +144,7 @@ public class EdqsConverter { |
|
|
|
case DOUBLE -> proto.setDoubleV(kvEntry.getDoubleValue().get()); |
|
|
|
case STRING -> { |
|
|
|
String strValue = kvEntry.getStrValue().get(); |
|
|
|
if (strValue.length() < CompressedStringDataPoint.MIN_STR_SIZE_TO_COMPRESS) { |
|
|
|
if (strValue.length() < stringCompressionLengthThreshold) { |
|
|
|
proto.setStringV(strValue); |
|
|
|
} else { |
|
|
|
proto.setCompressedStringV(ByteString.copyFrom(compress(strValue))); |
|
|
|
@ -148,7 +152,7 @@ public class EdqsConverter { |
|
|
|
} |
|
|
|
case JSON -> { |
|
|
|
String jsonValue = kvEntry.getJsonValue().get(); |
|
|
|
if (jsonValue.length() < CompressedStringDataPoint.MIN_STR_SIZE_TO_COMPRESS) { |
|
|
|
if (jsonValue.length() < stringCompressionLengthThreshold) { |
|
|
|
proto.setJsonV(jsonValue); |
|
|
|
} else { |
|
|
|
proto.setCompressedJsonV(ByteString.copyFrom(compress(jsonValue))); |
|
|
|
@ -158,7 +162,7 @@ public class EdqsConverter { |
|
|
|
return proto.build(); |
|
|
|
} |
|
|
|
|
|
|
|
public static DataPoint fromDataPointProto(DataPointProto proto) { |
|
|
|
public DataPoint fromDataPointProto(DataPointProto proto) { |
|
|
|
long ts = proto.getTs(); |
|
|
|
if (proto.hasBoolV()) { |
|
|
|
return new BoolDataPoint(ts, proto.getBoolV()); |
|
|
|
|