PostgreSQLUnspecifiedBinaryProtocolValue implements PostgreSQLBinaryProtocolValue { @Override public Object read(final PostgreSQLPacketPayload payload) { payload.getByteBuf().readerIndex(payload.getByteBuf().readerIndex() - 4); byte[] bytes = new byte[payload.readInt4()]; payload.getByteBuf().readBytes(bytes); String result = new String(bytes); return new PostgreSQLTypeUnspecifiedSQLParameter(result); }  @Override int getColumnLength(final Object value); @Override Object read(final PostgreSQLPacketPayload payload); @Override void write(final PostgreSQLPacketPayload payload, final Object value);  }
@Test public void assertRead() { String timestampStr = "2020-08-23 15:57:03+08"; int expectedLength = 4 + timestampStr.length(); ByteBuf byteBuf = ByteBufTestUtils.createByteBuf(expectedLength); byteBuf.writeInt(timestampStr.length()); byteBuf.writeCharSequence(timestampStr, StandardCharsets.ISO_8859_1); byteBuf.readInt(); PostgreSQLPacketPayload payload = new PostgreSQLPacketPayload(byteBuf); Object result = new PostgreSQLUnspecifiedBinaryProtocolValue().read(payload); assertNotNull(result); assertTrue(result instanceof PostgreSQLTypeUnspecifiedSQLParameter); assertThat(result.toString(), is(timestampStr)); assertThat(byteBuf.readerIndex(), is(expectedLength)); }