private void writeTightMarshal1()

in openwire-generator/src/main/java/org/apache/activemq/openwire/generator/builtin/UniversalMarshallerGenerator.java [265:351]


    private void writeTightMarshal1(PrintWriter out, OpenWireTypeDescriptor openWireType) {
        out.println("    /**");
        out.println("     * Write the booleans that this object uses to a BooleanStream");
        out.println("     *");
        out.println("     * @param wireFormat the OpenWireFormat instance to use");
        out.println("     * @param source the object to marshal");
        out.println("     * @param bs the boolean stream where the type's booleans are written");
        out.println("     *");
        out.println("     * @throws IOException if an error occurs while writing the data");
        out.println("     */");
        out.println("    public int tightMarshal1(OpenWireFormat wireFormat, Object source, BooleanStream bs) throws IOException {");

        if (openWireType.hasProperties()) {
            out.println("        " + openWireType.getTypeName() + " info = (" + openWireType.getTypeName() + ") source;");
            if (isOpenWireVersionNeeded(openWireType)) {
                out.println("        int version = wireFormat.getVersion();");
            }
        }

        if (openWireType.isMarshalAware()) {
            out.println("");
            out.println("        info.beforeMarshall(wireFormat);");
        }

        out.println("");
        out.println("        int rc = super.tightMarshal1(wireFormat, source, bs);");

        int baseSize = 0;
        for (final OpenWirePropertyDescriptor property : openWireType.getProperties()) {
            final int size = property.getSize();
            final String typeName = property.getTypeName();
            final String getter = "info." + property.getGetterName() + "()";

            String indent = "        ";
            if (property.getVersion() > 1) {
                indent = indent + "    ";
                out.println("        if (version >= " + property.getVersion() + ") {");
            }

            if (typeName.equals("boolean")) {
                out.println(indent + "bs.writeBoolean(" + getter + ");");
            } else if (typeName.equals("byte")) {
                baseSize += 1;
            } else if (typeName.equals("char")) {
                baseSize += 2;
            } else if (typeName.equals("short")) {
                baseSize += 2;
            } else if (typeName.equals("int")) {
                baseSize += 4;
            } else if (typeName.equals("long")) {
                out.println(indent + "rc += tightMarshalLong1(wireFormat, " + getter + ", bs);");
            } else if (typeName.equals("String")) {
                out.println(indent + "rc += tightMarshalString1(" + getter + ", bs);");
            } else if (typeName.equals("byte[]")) {
                if (size > 0) {
                    out.println(indent + "rc += tightMarshalConstByteArray1(" + getter + ", bs, " + size + ");");
                } else {
                    out.println(indent + "rc += tightMarshalByteArray1(" + getter + ", bs);");
                }
            } else if (typeName.equals("Buffer")) {
                out.println(indent + "rc += tightMarshalByteSequence1(" + getter + ", bs);");
            } else if (property.isArray()) {
                if (size > 0) {
                    out.println(indent + "rc += tightMarshalObjectArrayConstSize1(wireFormat, " + getter + ", bs, " + size + ");");
                } else {
                    out.println(indent + "rc += tightMarshalObjectArray1(wireFormat, " + getter + ", bs);");
                }
            } else if (property.isThrowable()) {
                out.println(indent + "rc += tightMarshalThrowable1(wireFormat, " + getter + ", bs);");
            } else {
                if (property.isCached()) {
                    out.println(indent + "rc += tightMarshalCachedObject1(wireFormat, (DataStructure)" + getter + ", bs);");
                } else {
                    out.println(indent + "rc += tightMarshalNestedObject1(wireFormat, (DataStructure)" + getter + ", bs);");
                }
            }

            if (property.getVersion() > 1) {
                out.println("        }");
            }
        }

        out.println("");
        out.println("        return rc + " + baseSize + ";");
        out.println("    }");
        out.println("");
    }