本文整理了Java中org.apache.kafka.connect.data.Struct.getBytes()
方法的一些代码示例,展示了Struct.getBytes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Struct.getBytes()
方法的具体详情如下:
包路径:org.apache.kafka.connect.data.Struct
类名称:Struct
方法名:getBytes
[英]Equivalent to calling #get(String) and casting the result to a byte[].
[中]相当于调用#get(String)并将结果转换为字节[]。
代码示例来源:origin: debezium/debezium
/**
* Decodes the encoded value - see {@link #fromLogical(Schema, BigDecimal)} for encoding format
*
* @param value the encoded value
* @return the decoded value
*/
public static SpecialValueDecimal toLogical(final Struct value) {
return new SpecialValueDecimal(new BigDecimal(new BigInteger(value.getBytes(VALUE_FIELD)), value.getInt32(SCALE_FIELD)));
}
}
代码示例来源:origin: debezium/debezium
private void assertGeomRecord(Struct value) {
Struct after = value.getStruct(Envelope.FieldName.AFTER);
Integer i = after.getInt32("id");
Testing.debug(after);
assertThat(i).isNotNull();
if (i == 1) {
// INSERT INTO dbz_507_geometry VALUES (1, ST_GeomFromText('POINT(1 1)', 4326), ST_GeomFromText('LINESTRING(0 0, 1 1)', 3187), ST_GeomFromText('POLYGON((0 0, 1 1, 1 0, 0 0))'), ST_GeomFromText('GEOMETRYCOLLECTION(POINT(1 1), LINESTRING(0 0, 1 1))', 4326));
assertThat(after.getStruct("geom").getInt32("srid")).isEqualTo(4326);
assertThat(DatatypeConverter.printHexBinary(after.getStruct("geom").getBytes("wkb"))).isEqualTo("0101000000000000000000F03F000000000000F03F");
assertThat(after.getStruct("linestring").getInt32("srid")).isEqualTo(3187);
assertThat(DatatypeConverter.printHexBinary(after.getStruct("linestring").getBytes("wkb"))).isEqualTo("01020000000200000000000000000000000000000000000000000000000000F03F000000000000F03F");
assertThat(after.getStruct("polygon").getInt32("srid")).isEqualTo(null);
assertThat(DatatypeConverter.printHexBinary(after.getStruct("polygon").getBytes("wkb"))).isEqualTo("0103000000010000000400000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000");
assertThat(after.getStruct("collection").getInt32("srid")).isEqualTo(4326);
assertThat(DatatypeConverter.printHexBinary(after.getStruct("collection").getBytes("wkb"))).isEqualTo("0107000000020000000101000000000000000000F03F000000000000F03F01020000000200000000000000000000000000000000000000000000000000F03F000000000000F03F");
} else if (i == 2) {
// INSERT INTO dbz_507_geometry VALUES (2, ST_GeomFromText('LINESTRING(0 0, 1 1)'), NULL, NULL, NULL);
assertThat(after.getStruct("geom").getInt32("srid")).isEqualTo(null);
assertThat(DatatypeConverter.printHexBinary(after.getStruct("geom").getBytes("wkb"))).isEqualTo("01020000000200000000000000000000000000000000000000000000000000F03F000000000000F03F");
assertThat(after.getStruct("linestring")).isNull();
assertThat(after.getStruct("polygon")).isNull();
assertThat(after.getStruct("collection")).isNull();
}
}
代码示例来源:origin: debezium/debezium
assertThat(c1).isEqualTo(Boolean.TRUE);
byte[] c2 = after.getBytes("c2");
assertThat(c2.length).isEqualTo(1);
assertThat(c2[0]).isEqualTo((byte) 2);
byte[] c3 = after.getBytes("c3");
assertThat(c3.length).isEqualTo(1);
assertThat(c3[0]).isEqualTo((byte) 64);
byte[] c4 = after.getBytes("c4");
assertThat(c4.length).isEqualTo(8); // bytes, little endian
assertThat(c4[0]).isEqualTo((byte) 219); // 11011011
代码示例来源:origin: io.debezium/debezium-core
/**
* Decodes the encoded value - see {@link #fromLogical(Schema, BigDecimal)} for encoding format
*
* @param value the encoded value
* @return the decoded value
*/
public static SpecialValueDecimal toLogical(final Struct value) {
return new SpecialValueDecimal(new BigDecimal(new BigInteger(value.getBytes(VALUE_FIELD)), value.getInt32(SCALE_FIELD)));
}
}
代码示例来源:origin: com.github.jcustenborder.kafka.connect/kafka-connect-transform-common
for (Field field : schema.fields()) {
if (this.config.fields.contains(field.name())) {
byte[] buffer = input.getBytes(field.name());
struct.put(field.name(), new String(buffer, this.config.charset));
} else {
代码示例来源:origin: io.debezium/debezium-connector-mysql
private void assertGeomRecord(Struct value) {
Struct after = value.getStruct(Envelope.FieldName.AFTER);
Integer i = after.getInt32("id");
Testing.debug(after);
assertThat(i).isNotNull();
if (i == 1) {
// INSERT INTO dbz_507_geometry VALUES (1, ST_GeomFromText('POINT(1 1)', 4326), ST_GeomFromText('LINESTRING(0 0, 1 1)', 3187), ST_GeomFromText('POLYGON((0 0, 1 1, 1 0, 0 0))'), ST_GeomFromText('GEOMETRYCOLLECTION(POINT(1 1), LINESTRING(0 0, 1 1))', 4326));
assertThat(after.getStruct("geom").getInt32("srid")).isEqualTo(4326);
assertThat(DatatypeConverter.printHexBinary(after.getStruct("geom").getBytes("wkb"))).isEqualTo("0101000000000000000000F03F000000000000F03F");
assertThat(after.getStruct("linestring").getInt32("srid")).isEqualTo(3187);
assertThat(DatatypeConverter.printHexBinary(after.getStruct("linestring").getBytes("wkb"))).isEqualTo("01020000000200000000000000000000000000000000000000000000000000F03F000000000000F03F");
assertThat(after.getStruct("polygon").getInt32("srid")).isEqualTo(null);
assertThat(DatatypeConverter.printHexBinary(after.getStruct("polygon").getBytes("wkb"))).isEqualTo("0103000000010000000400000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000");
assertThat(after.getStruct("collection").getInt32("srid")).isEqualTo(4326);
assertThat(DatatypeConverter.printHexBinary(after.getStruct("collection").getBytes("wkb"))).isEqualTo("0107000000020000000101000000000000000000F03F000000000000F03F01020000000200000000000000000000000000000000000000000000000000F03F000000000000F03F");
} else if (i == 2) {
// INSERT INTO dbz_507_geometry VALUES (2, ST_GeomFromText('LINESTRING(0 0, 1 1)'), NULL, NULL, NULL);
assertThat(after.getStruct("geom").getInt32("srid")).isEqualTo(null);
assertThat(DatatypeConverter.printHexBinary(after.getStruct("geom").getBytes("wkb"))).isEqualTo("01020000000200000000000000000000000000000000000000000000000000F03F000000000000F03F");
assertThat(after.getStruct("linestring")).isNull();
assertThat(after.getStruct("polygon")).isNull();
assertThat(after.getStruct("collection")).isNull();
}
}
代码示例来源:origin: io.debezium/debezium-connector-mysql
assertThat(c1).isEqualTo(Boolean.TRUE);
byte[] c2 = after.getBytes("c2");
assertThat(c2.length).isEqualTo(1);
assertThat(c2[0]).isEqualTo((byte) 2);
byte[] c3 = after.getBytes("c3");
assertThat(c3.length).isEqualTo(1);
assertThat(c3[0]).isEqualTo((byte) 64);
byte[] c4 = after.getBytes("c4");
assertThat(c4.length).isEqualTo(8); // bytes, little endian
assertThat(c4[0]).isEqualTo((byte) 219); // 11011011
内容来源于网络,如有侵权,请联系作者删除!