int calculateParamTransportSize(Object value) {
        if (value == null) {
            return 0;
        }
        // Layout for primitives: |type flag(1)|value|
        // size = original size + type flag (1)
        if (value instanceof Integer || int.class.isInstance(value)) {
            return 5;
        } else if (value instanceof String) {
            // Layout for string: |type flag(1)|length(4)|string content|
            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 {
            // Ignore unexpected type.
            return 0;
        }
    }
@Test
    public void testCalculateParamTransportSize() {
        ParamFlowRequestDataWriter writer = new ParamFlowRequestDataWriter();
        // POJO (non-primitive type) should not be regarded as a valid parameter.
        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));
    }