RegisterRMRequestCodec extends AbstractIdentifyRequestCodec { @Override public <T> void decode(T t, ByteBuffer in) { RegisterRMRequest registerRMRequest = (RegisterRMRequest)t; if (in.remaining() < 2) { return; } short len = in.getShort(); if (len > 0) { if (in.remaining() < len) { return; } byte[] bs = new byte[len]; in.get(bs); registerRMRequest.setVersion(new String(bs, UTF8)); } else { return; } if (in.remaining() < 2) { return; } len = in.getShort(); if (len > 0) { if (in.remaining() < len) { return; } byte[] bs = new byte[len]; in.get(bs); registerRMRequest.setApplicationId(new String(bs, UTF8)); } if (in.remaining() < 2) { return; } len = in.getShort(); if (in.remaining() < len) { return; } byte[] bs = new byte[len]; in.get(bs); registerRMRequest.setTransactionServiceGroup(new String(bs, UTF8)); if (in.remaining() < 2) { return; } len = in.getShort(); if (len > 0) { if (in.remaining() < len) { return; } bs = new byte[len]; in.get(bs); registerRMRequest.setExtraData(new String(bs, UTF8)); } int iLen; if (in.remaining() < 4) { return; } iLen = in.getInt(); if (iLen > 0) { if (in.remaining() < iLen) { return; } bs = new byte[iLen]; in.get(bs); registerRMRequest.setResourceIds(new String(bs, UTF8)); } }  @Override Class<?> getMessageClassType(); @Override void decode(T t, ByteBuffer in);  }
@Test public void test_codec() { RegisterRMRequest registerRMRequest = new RegisterRMRequest(); registerRMRequest.setResourceIds("a1,a2"); registerRMRequest.setApplicationId("abc"); registerRMRequest.setExtraData("abc124"); registerRMRequest.setTransactionServiceGroup("def"); registerRMRequest.setVersion("1"); byte[] body = seataCodec.encode(registerRMRequest); RegisterRMRequest registerRMRequest2 = seataCodec.decode(body); assertThat(registerRMRequest2.getResourceIds()).isEqualTo(registerRMRequest.getResourceIds()); assertThat(registerRMRequest2.getExtraData()).isEqualTo(registerRMRequest.getExtraData()); assertThat(registerRMRequest2.getApplicationId()).isEqualTo(registerRMRequest.getApplicationId()); assertThat(registerRMRequest2.getVersion()).isEqualTo(registerRMRequest.getVersion()); assertThat(registerRMRequest2.getTransactionServiceGroup()).isEqualTo(registerRMRequest.getTransactionServiceGroup()); }