Java Code Examples for io.netty.buffer.ByteBufUtil#decodeHexDump()

The following examples show how to use io.netty.buffer.ByteBufUtil#decodeHexDump() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DebugUtils.java    From jetlinks-community with Apache License 2.0 5 votes vote down vote up
static byte[] stringToBytes(String text){
    byte[] payload;
    if (StringUtils.isEmpty(text)) {
        payload = new byte[0];
    } else {
        if (text.startsWith("0x")) {
            payload = ByteBufUtil.decodeHexDump(text, 2, text.length()-2);
        } else {
            payload = text.getBytes();
        }
    }
    return payload;
}
 
Example 2
Source File: MySQLCommandPacketDecoderTest.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
private ByteBuf mockHandshakePacket() {
    String handshakePacket = "000a352e372e32312d6c6f6700090000004a592a1f725a0d0900fff7210200ff8115000000000000000000001a437b30323a4d2b514b5870006d"
        + "7973716c5f6e61746976655f70617373776f72640000000002000000";
    byte[] handshakePacketBytes = ByteBufUtil.decodeHexDump(handshakePacket);
    ByteBuf result = Unpooled.buffer(handshakePacketBytes.length);
    result.writeBytes(handshakePacketBytes);
    return result;
}
 
Example 3
Source File: MySQLDecimalBinlogProtocolValueTest.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
@Test
public void assertDecodePositiveNewDecimal() {
    byte[] newDecimalBytes = ByteBufUtil.decodeHexDump("810DFB38D204D2");
    when(payload.readStringFixByBytes(newDecimalBytes.length)).thenReturn(newDecimalBytes);
    BigDecimal actual = (BigDecimal) new MySQLDecimalBinlogProtocolValue().read(columnDef, payload);
    assertThat(actual.toString(), is("1234567890.1234"));
}
 
Example 4
Source File: MySQLDecimalBinlogProtocolValueTest.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
@Test
public void assertDecodeNegativeNewDecimal() {
    byte[] newDecimalBytes = ByteBufUtil.decodeHexDump("7EF204C72DFB2D");
    when(payload.readStringFixByBytes(newDecimalBytes.length)).thenReturn(newDecimalBytes);
    BigDecimal actual = (BigDecimal) new MySQLDecimalBinlogProtocolValue().read(columnDef, payload);
    assertThat(actual.toString(), is("-1234567890.1234"));
}
 
Example 5
Source File: MySQLDecimalBinlogProtocolValueTest.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
@Test
public void assertDecodeNegativeNewDecimalWithLargeNumber() {
    columnDef = new MySQLBinlogColumnDef(MySQLColumnType.MYSQL_TYPE_NEWDECIMAL);
    columnDef.setColumnMeta(32 << 8 | 6);
    byte[] newDecimalBytes = ByteBufUtil.decodeHexDump("7DFEFDB5CC2741EFDEBE4154FD52E7");
    when(payload.readStringFixByBytes(newDecimalBytes.length)).thenReturn(newDecimalBytes);
    BigDecimal actual = (BigDecimal) new MySQLDecimalBinlogProtocolValue().read(columnDef, payload);
    assertThat(actual.toString(), is("-33620554869842448557956779.175384"));
}
 
Example 6
Source File: HexBenchmark.java    From turbo-rpc with Apache License 2.0 4 votes vote down vote up
@Benchmark
@BenchmarkMode({ Mode.Throughput })
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public byte[] fromHexByNetty() {
	return ByteBufUtil.decodeHexDump(hex);
}
 
Example 7
Source File: RequestId.java    From redisson with Apache License 2.0 4 votes vote down vote up
public RequestId(String id) {
    this(ByteBufUtil.decodeHexDump(id));
}