MySQLDecimalBinlogProtocolValue implements MySQLBinlogProtocolValue { @Override public Serializable read(final MySQLBinlogColumnDef columnDef, final MySQLPacketPayload payload) { DecimalMetaData decimalMetaData = new DecimalMetaData(columnDef.getColumnMeta()); return toDecimal(decimalMetaData, payload.readStringFixByBytes(decimalMetaData.getTotalByteLength())); }  @Override Serializable read(final MySQLBinlogColumnDef columnDef, final MySQLPacketPayload payload);  }
@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")); }
@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")); }
@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")); }