protected int generateTightMarshal1Body()

in activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/marshallers/AmqCppMarshallingClassesGenerator.java [227:300]


    protected int generateTightMarshal1Body(PrintWriter out) {
        int baseSize = 0;

        for ( JProperty property : getProperties() ) {
            JAnnotation annotation = property.getAnnotation("openwire:property");
            JAnnotationValue version = annotation.getValue("version");
            JAnnotationValue size = annotation.getValue("size");
            JClass propertyType = property.getType();
            String type = propertyType.getSimpleName();
            String getter = "info->" + property.getGetter().getSimpleName() + "()";
            String indent = "        ";

            if( version.asInt() > 1 ) {
                indent = indent + "    ";
                out.println("        if (wireVersion >= " + version.asInt() + ") {");
            }

            if (type.equals("boolean")) {
                out.println(indent + "bs->writeBoolean(" + getter + ");");
            }
            else if (type.equals("byte")) {
                baseSize += 1;
            }
            else if (type.equals("char")) {
                baseSize += 2;
            }
            else if (type.equals("short")) {
                baseSize += 2;
            }
            else if (type.equals("int")) {
                baseSize += 4;
            }
            else if (type.equals("long")) {
                out.println(indent + "rc += tightMarshalLong1(wireFormat, " + getter + ", bs);");
            }
            else if (type.equals("String")) {
                out.print("");
                out.println(indent + "rc += tightMarshalString1(" + getter + ", bs);" );
            }
            else if (type.equals("byte[]") || type.equals("ByteSequence")) {
                if (size == null) {
                    out.println(indent + "bs->writeBoolean(" + getter + ".size() != 0);" );
                    out.println(indent + "rc += " + getter + ".size() == 0 ? 0 : (int)" + getter + ".size() + 4;");
                }
                else {
                    baseSize += size.asInt();
                }
            }
            else if (propertyType.isArrayType()) {
                if (size != null) {
                    out.println(indent + "rc += tightMarshalObjectArrayConstSize1(wireFormat, " + getter + ", bs, " + size.asInt() + ");");
                }
                else {
                    out.println(indent + "rc += tightMarshalObjectArray1(wireFormat, " + getter + ", bs);");
                }
            }
            else if (isThrowable(propertyType)) {
                out.println(indent + "rc += tightMarshalBrokerError1(wireFormat, " + getter + ".get(), bs);");
            }
            else {
                if (isCachedProperty(property)) {
                    out.println(indent + "rc += tightMarshalCachedObject1(wireFormat, " + getter + ".get(), bs);");
                }
                else {
                    out.println(indent + "rc += tightMarshalNestedObject1(wireFormat, " + getter + ".get(), bs);");
                }
            }

            if( version.asInt() > 1 ) {
                out.println("        }");
            }
        }
        return baseSize;
    }