@Test public void testCalculateParamTransportSize() { ParamFlowRequestDataWriter writer = new ParamFlowRequestDataWriter(); assertEquals(0, writer.calculateParamTransportSize(new SomePojo().setParam1("abc"))); assertEquals(4 + 1, writer.calculateParamTransportSize(1)); assertEquals(1 + 1, writer.calculateParamTransportSize((byte) 1)); assertEquals(1 + 1, writer.calculateParamTransportSize(false)); assertEquals(8 + 1, writer.calculateParamTransportSize(2L)); assertEquals(8 + 1, writer.calculateParamTransportSize(4.0d)); final String paramStr = "Sentinel"; assertEquals(1 + 4 + paramStr.getBytes().length, writer.calculateParamTransportSize(paramStr)); }
int calculateParamTransportSize(Object value) { if (value == null) { return 0; } if (value instanceof Integer || int.class.isInstance(value)) { return 5; } else if (value instanceof String) { String tmpValue = (String)value; byte[] tmpChars = tmpValue.getBytes(); return 1 + 4 + tmpChars.length; } else if (boolean.class.isInstance(value) || value instanceof Boolean) { return 2; } else if (long.class.isInstance(value) || value instanceof Long) { return 9; } else if (double.class.isInstance(value) || value instanceof Double) { return 9; } else if (float.class.isInstance(value) || value instanceof Float) { return 5; } else if (byte.class.isInstance(value) || value instanceof Byte) { return 2; } else if (short.class.isInstance(value) || value instanceof Short) { return 3; } else { return 0; } }
ParamFlowRequestDataWriter implements EntityWriter<ParamFlowRequestData, ByteBuf> { int calculateParamTransportSize(Object value) { if (value == null) { return 0; } if (value instanceof Integer || int.class.isInstance(value)) { return 5; } else if (value instanceof String) { String tmpValue = (String)value; byte[] tmpChars = tmpValue.getBytes(); return 1 + 4 + tmpChars.length; } else if (boolean.class.isInstance(value) || value instanceof Boolean) { return 2; } else if (long.class.isInstance(value) || value instanceof Long) { return 9; } else if (double.class.isInstance(value) || value instanceof Double) { return 9; } else if (float.class.isInstance(value) || value instanceof Float) { return 5; } else if (byte.class.isInstance(value) || value instanceof Byte) { return 2; } else if (short.class.isInstance(value) || value instanceof Short) { return 3; } else { return 0; } } }
ParamFlowRequestDataWriter implements EntityWriter<ParamFlowRequestData, ByteBuf> { int calculateParamTransportSize(Object value) { if (value == null) { return 0; } if (value instanceof Integer || int.class.isInstance(value)) { return 5; } else if (value instanceof String) { String tmpValue = (String)value; byte[] tmpChars = tmpValue.getBytes(); return 1 + 4 + tmpChars.length; } else if (boolean.class.isInstance(value) || value instanceof Boolean) { return 2; } else if (long.class.isInstance(value) || value instanceof Long) { return 9; } else if (double.class.isInstance(value) || value instanceof Double) { return 9; } else if (float.class.isInstance(value) || value instanceof Float) { return 5; } else if (byte.class.isInstance(value) || value instanceof Byte) { return 2; } else if (short.class.isInstance(value) || value instanceof Short) { return 3; } else { return 0; } } ParamFlowRequestDataWriter();  ParamFlowRequestDataWriter(int maxParamByteSize); }
ParamFlowRequestDataWriter implements EntityWriter<ParamFlowRequestData, ByteBuf> { int calculateParamTransportSize(Object value) { if (value == null) { return 0; } if (value instanceof Integer || int.class.isInstance(value)) { return 5; } else if (value instanceof String) { String tmpValue = (String)value; byte[] tmpChars = tmpValue.getBytes(); return 1 + 4 + tmpChars.length; } else if (boolean.class.isInstance(value) || value instanceof Boolean) { return 2; } else if (long.class.isInstance(value) || value instanceof Long) { return 9; } else if (double.class.isInstance(value) || value instanceof Double) { return 9; } else if (float.class.isInstance(value) || value instanceof Float) { return 5; } else if (byte.class.isInstance(value) || value instanceof Byte) { return 2; } else if (short.class.isInstance(value) || value instanceof Short) { return 3; } else { return 0; } } ParamFlowRequestDataWriter();  ParamFlowRequestDataWriter(int maxParamByteSize); @Override void writeTo(ParamFlowRequestData entity, ByteBuf target); }
ParamFlowRequestDataWriter implements EntityWriter<ParamFlowRequestData, ByteBuf> { int calculateParamTransportSize(Object value) { if (value == null) { return 0; } if (value instanceof Integer || int.class.isInstance(value)) { return 5; } else if (value instanceof String) { String tmpValue = (String)value; byte[] tmpChars = tmpValue.getBytes(); return 1 + 4 + tmpChars.length; } else if (boolean.class.isInstance(value) || value instanceof Boolean) { return 2; } else if (long.class.isInstance(value) || value instanceof Long) { return 9; } else if (double.class.isInstance(value) || value instanceof Double) { return 9; } else if (float.class.isInstance(value) || value instanceof Float) { return 5; } else if (byte.class.isInstance(value) || value instanceof Byte) { return 2; } else if (short.class.isInstance(value) || value instanceof Short) { return 3; } else { return 0; } } ParamFlowRequestDataWriter();  ParamFlowRequestDataWriter(int maxParamByteSize); @Override void writeTo(ParamFlowRequestData entity, ByteBuf target);  }