@Test public void codeC() throws Exception { UserInfo info = new UserInfo(20, "wuhulala"); byte[] b = jdkCodeC(info); System.out.println("jdk serializable length is : " + b.length); printSeparator(); System.out.println("custom serializable length is : " + info.codeC().length); }
public byte[] codeC(){ ByteBuffer buffer = ByteBuffer.allocate(1024); byte[] value = this.userName.getBytes(); buffer.putInt(value.length); buffer.put(value); buffer.putInt(this.userId); buffer.flip(); byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; }
UserInfo implements Serializable { public byte[] codeC(){ ByteBuffer buffer = ByteBuffer.allocate(1024); byte[] value = this.userName.getBytes(); buffer.putInt(value.length); buffer.put(value); buffer.putInt(this.userId); buffer.flip(); byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; } }
UserInfo implements Serializable { public byte[] codeC(){ ByteBuffer buffer = ByteBuffer.allocate(1024); byte[] value = this.userName.getBytes(); buffer.putInt(value.length); buffer.put(value); buffer.putInt(this.userId); buffer.flip(); byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; } UserInfo();  UserInfo(int userId, String userName); }
UserInfo implements Serializable { public byte[] codeC(){ ByteBuffer buffer = ByteBuffer.allocate(1024); byte[] value = this.userName.getBytes(); buffer.putInt(value.length); buffer.put(value); buffer.putInt(this.userId); buffer.flip(); byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; } UserInfo();  UserInfo(int userId, String userName); String getUserName(); void setUserName(String userName); int getUserId(); void setUserId(int userId); byte[] codeC(); }
UserInfo implements Serializable { public byte[] codeC(){ ByteBuffer buffer = ByteBuffer.allocate(1024); byte[] value = this.userName.getBytes(); buffer.putInt(value.length); buffer.put(value); buffer.putInt(this.userId); buffer.flip(); byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; } UserInfo();  UserInfo(int userId, String userName); String getUserName(); void setUserName(String userName); int getUserId(); void setUserId(int userId); byte[] codeC();  }