in kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/ColumnValueConvertUtils.java [65:145]
public static Message convertToProtobufMessage(final Object object) {
if (null == object) {
return Empty.getDefaultInstance();
}
if (object instanceof Integer) {
return Int32Value.of((int) object);
}
if (object instanceof Short) {
return Int32Value.of(((Short) object).intValue());
}
if (object instanceof Byte) {
return Int32Value.of(((Byte) object).intValue());
}
if (object instanceof Long) {
return Int64Value.of((long) object);
}
if (object instanceof BigInteger) {
return StringValue.of(object.toString());
}
if (object instanceof Float) {
return FloatValue.of((float) object);
}
if (object instanceof Double) {
return DoubleValue.of((double) object);
}
if (object instanceof BigDecimal) {
return StringValue.of(object.toString());
}
if (object instanceof String) {
return StringValue.of(object.toString());
}
if (object instanceof Boolean) {
return BoolValue.of((boolean) object);
}
if (object instanceof byte[]) {
return BytesValue.of(ByteString.copyFrom((byte[]) object));
}
if (object instanceof Time) {
Time time = (Time) object;
LocalTime localTime = LocalTime.of(time.getHours(), time.getMinutes(), time.getSeconds(), new Timestamp(time.getTime()).getNanos());
return Int64Value.of(localTime.toNanoOfDay());
}
if (object instanceof java.sql.Date) {
return Int64Value.of(((java.sql.Date) object).toLocalDate().toEpochDay());
}
if (object instanceof Date) {
return converToProtobufTimestamp((Date) object);
}
if (object instanceof LocalDateTime) {
return converToProtobufTimestamp(Timestamp.valueOf((LocalDateTime) object));
}
if (object instanceof LocalDate) {
return Int64Value.of(((LocalDate) object).toEpochDay());
}
if (object instanceof LocalTime) {
return Int64Value.of(((LocalTime) object).toNanoOfDay());
}
if (object instanceof OffsetDateTime) {
LocalDateTime localDateTime = ((OffsetDateTime) object).toLocalDateTime();
return converToProtobufTimestamp(Timestamp.valueOf(localDateTime));
}
if (object instanceof OffsetTime) {
return Int64Value.of(((OffsetTime) object).toLocalTime().toNanoOfDay());
}
if (object instanceof ZonedDateTime) {
return converToProtobufTimestamp(Timestamp.valueOf(((ZonedDateTime) object).toLocalDateTime()));
}
if (object instanceof Instant) {
Instant instant = (Instant) object;
return com.google.protobuf.Timestamp.newBuilder().setSeconds(instant.getEpochSecond()).setNanos(instant.getNano()).build();
}
if (object instanceof Clob) {
Clob clob = (Clob) object;
return StringValue.of(clob.getSubString(1L, (int) clob.length()));
}
if (object instanceof Blob) {
Blob blob = (Blob) object;
return BytesValue.of(ByteString.copyFrom(blob.getBytes(1L, (int) blob.length())));
}
return StringValue.newBuilder().setValue(object.toString()).build();
}