Example usage for org.objectweb.asm MethodVisitor visitMethodInsn

List of usage examples for org.objectweb.asm MethodVisitor visitMethodInsn

Introduction

In this page you can find the example usage for org.objectweb.asm MethodVisitor visitMethodInsn.

Prototype

@Deprecated
public void visitMethodInsn(final int opcode, final String owner, final String name, final String descriptor) 

Source Link

Document

Visits a method instruction.

Usage

From source file:com.google.gwtorm.jdbc.AccessGen.java

License:Apache License

private void implementQuery(final QueryModel info) {
    final List<ColumnModel> pCols = info.getParameters();
    final boolean hasLimitParam = info.hasLimitParameter();
    final Type[] pTypes = new Type[pCols.size() + (hasLimitParam ? 1 : 0)];
    final int[] pVars = new int[pTypes.length];
    int nextVar = 1;
    for (int i = 0; i < pCols.size(); i++) {
        pTypes[i] = CodeGenSupport.toType(pCols.get(i));
        pVars[i] = nextVar;/* www .  j av a 2  s  .  co  m*/
        nextVar += pTypes[i].getSize();
    }
    if (hasLimitParam) {
        pTypes[pTypes.length - 1] = Type.INT_TYPE;
        pVars[pTypes.length - 1] = nextVar;
        nextVar += Type.INT_TYPE.getSize();
    }

    final int psvar = nextVar++;
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_FINAL, info.getName(),
            Type.getMethodDescriptor(Type.getType(com.google.gwtorm.server.ResultSet.class), pTypes), null,
            new String[] { Type.getType(OrmException.class).getInternalName() });
    mv.visitCode();

    mv.visitVarInsn(ALOAD, 0);
    mv.visitLdcInsn(info.getSelectSql(dialect, REL_ALIAS));
    mv.visitMethodInsn(INVOKEVIRTUAL, superTypeName, "prepareStatement", Type.getMethodDescriptor(
            Type.getType(PreparedStatement.class), new Type[] { Type.getType(String.class) }));
    mv.visitVarInsn(ASTORE, psvar);

    final int argIdx[] = new int[] { 0 };
    final CodeGenSupport cgs = new CodeGenSupport(mv) {
        @Override
        public void pushSqlHandle() {
            mv.visitVarInsn(ALOAD, psvar);
        }

        @Override
        public void pushFieldValue() {
            appendGetField(getFieldReference());
        }

        @Override
        protected void appendGetField(final ColumnModel c) {
            final int n = argIdx[0];
            if (c == pCols.get(n)) {
                loadVar(pTypes[n], pVars[n]);
            } else {
                super.appendGetField(c);
            }
        }
    };
    for (final ColumnModel c : pCols) {
        if (c.isNested()) {
            for (final ColumnModel n : c.getAllLeafColumns()) {
                cgs.setFieldReference(n);
                dialect.getSqlTypeInfo(n).generatePreparedStatementSet(cgs);
            }
        } else {
            cgs.setFieldReference(c);
            dialect.getSqlTypeInfo(c).generatePreparedStatementSet(cgs);
        }
        argIdx[0]++;
    }

    if (info.hasLimit()) {
        if (hasLimitParam || !dialect.selectHasLimit()) {
            mv.visitVarInsn(ALOAD, psvar);
            if (hasLimitParam) {
                mv.visitVarInsn(ILOAD, pVars[pTypes.length - 1]);
            } else {
                cgs.push(info.getStaticLimit());
            }
            mv.visitMethodInsn(INVOKEINTERFACE, Type.getType(PreparedStatement.class).getInternalName(),
                    "setMaxRows", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE }));
        }
    }

    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, psvar);
    mv.visitMethodInsn(INVOKEVIRTUAL, superTypeName, "queryList",
            Type.getMethodDescriptor(Type.getType(com.google.gwtorm.server.ResultSet.class),
                    new Type[] { Type.getType(PreparedStatement.class) }));
    mv.visitInsn(ARETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.nosql.AccessGen.java

License:Apache License

private void implementConstructor() {
    final String consName = "<init>";
    final String consDesc = Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { schemaType });
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, consName, consDesc, null, null);
    mv.visitCode();//from ww w . j av  a  2 s .c  om
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKESPECIAL, accessType.getInternalName(), consName, consDesc);
    mv.visitInsn(RETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.nosql.AccessGen.java

License:Apache License

private void implementKeyQuery(KeyModel key) {
    final Type keyType = CodeGenSupport.toType(key.getField());
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_FINAL, key.getName(),
            Type.getMethodDescriptor(entityType, new Type[] { keyType }), null,
            new String[] { Type.getType(OrmException.class).getInternalName() });
    mv.visitCode();//from   w w w .j  a v  a2  s  . co m

    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKESPECIAL, accessType.getInternalName(), "get",
            Type.getMethodDescriptor(object, new Type[] { ormKey }));
    mv.visitTypeInsn(CHECKCAST, entityType.getInternalName());

    mv.visitInsn(ARETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.nosql.AccessGen.java

License:Apache License

private void implementQuery(final QueryModel info) throws OrmException {
    final List<ColumnModel> pCols = info.getParameters();
    final boolean hasLimitParam = info.hasLimitParameter();
    final Type[] pTypes = new Type[pCols.size() + (hasLimitParam ? 1 : 0)];
    final int[] pVars = new int[pTypes.length];
    int nextVar = 1;
    for (int i = 0; i < pCols.size(); i++) {
        pTypes[i] = CodeGenSupport.toType(pCols.get(i));
        pVars[i] = nextVar;// w ww .ja  va2  s.co m
        nextVar += pTypes[i].getSize();
    }
    if (hasLimitParam) {
        pTypes[pTypes.length - 1] = Type.INT_TYPE;
        pVars[pTypes.length - 1] = nextVar;
        nextVar += Type.INT_TYPE.getSize();
    }

    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_FINAL, info.getName(),
            Type.getMethodDescriptor(resultSet, pTypes), null, new String[] { ormException.getInternalName() });
    mv.visitCode();

    final List<Tree> ops = compareOpsOnly(info.getParseTree());

    // Generate fromKey
    //
    final int fromBuf = nextVar++;
    mv.visitTypeInsn(NEW, indexKeyBuilder.getInternalName());
    mv.visitInsn(DUP);
    mv.visitMethodInsn(INVOKESPECIAL, indexKeyBuilder.getInternalName(), "<init>",
            Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}));
    mv.visitVarInsn(ASTORE, fromBuf);

    QueryCGS cgs = new QueryCGS(mv, pTypes, pCols, pVars, fromBuf);
    encodeFields(info, ops, mv, cgs, true /* fromKey */);

    // Generate toKey
    //
    final int toBuf = nextVar++;
    mv.visitTypeInsn(NEW, indexKeyBuilder.getInternalName());
    mv.visitInsn(DUP);
    mv.visitMethodInsn(INVOKESPECIAL, indexKeyBuilder.getInternalName(), "<init>",
            Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}));
    mv.visitVarInsn(ASTORE, toBuf);

    cgs = new QueryCGS(mv, pTypes, pCols, pVars, toBuf);
    encodeFields(info, ops, mv, cgs, false /* fromKey */);
    cgs.infinity();

    // Make the scan call
    //
    mv.visitVarInsn(ALOAD, 0);
    if (needsIndexFunction(info)) {
        mv.visitFieldInsn(GETSTATIC, implTypeName, "index_" + info.getName(), indexFunction.getDescriptor());
    }

    mv.visitVarInsn(ALOAD, fromBuf);
    mv.visitMethodInsn(INVOKEVIRTUAL, indexKeyBuilder.getInternalName(), "toByteArray",
            Type.getMethodDescriptor(byteArray, new Type[] {}));

    mv.visitVarInsn(ALOAD, toBuf);
    mv.visitMethodInsn(INVOKEVIRTUAL, indexKeyBuilder.getInternalName(), "toByteArray",
            Type.getMethodDescriptor(byteArray, new Type[] {}));

    // Set the limit on the number of results.
    //
    if (info.hasLimit()) {
        if (hasLimitParam) {
            mv.visitVarInsn(ILOAD, pVars[pTypes.length - 1]);
        } else {
            cgs.push(info.getStaticLimit());
        }
    } else {
        cgs.push(0);
    }

    // Only keep order if there is an order by clause present
    //
    cgs.push(info.hasOrderBy() ? 1 : 0);

    if (needsIndexFunction(info)) {
        mv.visitMethodInsn(INVOKEVIRTUAL, accessType.getInternalName(), "scanIndex",
                Type.getMethodDescriptor(resultSet,
                        new Type[] { indexFunction, byteArray, byteArray, Type.INT_TYPE, Type.BOOLEAN_TYPE }));
    } else {
        // No where and no order by clause? Use the primary key instead.
        //
        mv.visitMethodInsn(INVOKEVIRTUAL, accessType.getInternalName(), "scanPrimaryKey",
                Type.getMethodDescriptor(resultSet,
                        new Type[] { byteArray, byteArray, Type.INT_TYPE, Type.BOOLEAN_TYPE }));
    }

    mv.visitInsn(ARETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.nosql.IndexFunctionGen.java

License:Apache License

private void implementConstructor() {
    final String consName = "<init>";
    final String consDesc = Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {});
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, consName, consDesc, null, null);
    mv.visitCode();// ww w  .  ja v a2 s.c  o m

    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, superTypeName, consName, consDesc);

    mv.visitInsn(RETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.nosql.IndexFunctionGen.java

License:Apache License

private void checkConstants(Tree node, MethodVisitor mv, IncludeCGS cgs) throws OrmException {
    switch (node.getType()) {
    // These don't impact the constant evaluation
    case QueryParser.ORDER:
    case QueryParser.LIMIT:
        break;//  ww w  .  ja v  a  2 s.c  om

    case 0: // nil node used to join other nodes together
    case QueryParser.WHERE:
    case QueryParser.AND:
        for (int i = 0; i < node.getChildCount(); i++) {
            checkConstants(node.getChild(i), mv, cgs);
        }
        break;

    case QueryParser.LT:
    case QueryParser.LE:
    case QueryParser.GT:
    case QueryParser.GE:
    case QueryParser.EQ: {
        final Tree lhs = node.getChild(0);
        final Tree rhs = node.getChild(1);
        if (lhs.getType() != QueryParser.ID) {
            throw new OrmException("Unsupported query token");
        }

        cgs.setFieldReference(((QueryParser.Column) lhs).getField());
        switch (rhs.getType()) {
        case QueryParser.PLACEHOLDER:
            // Parameter evaluated at runtime
            break;

        case QueryParser.TRUE:
            cgs.pushFieldValue();
            mv.visitJumpInsn(IFEQ, cgs.no);
            break;

        case QueryParser.FALSE:
            cgs.pushFieldValue();
            mv.visitJumpInsn(IFNE, cgs.no);
            break;

        case QueryParser.CONSTANT_INTEGER:
            cgs.pushFieldValue();
            cgs.push(Integer.parseInt(rhs.getText()));
            mv.visitJumpInsn(IF_ICMPNE, cgs.no);
            break;

        case QueryParser.CONSTANT_STRING:
            if (cgs.getFieldReference().getPrimitiveType() == Character.TYPE) {
                cgs.push(dequote(rhs.getText()).charAt(0));
                cgs.pushFieldValue();
                mv.visitJumpInsn(IF_ICMPNE, cgs.no);
            } else {
                mv.visitLdcInsn(dequote(rhs.getText()));
                cgs.pushFieldValue();
                mv.visitMethodInsn(INVOKEVIRTUAL, string.getInternalName(), "equals",
                        Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] { object }));
                mv.visitJumpInsn(IFEQ, cgs.no);
            }
            break;
        }
        break;
    }

    default:
        throw new OrmException("Unsupported query token " + node.toStringTree());
    }
}

From source file:com.google.gwtorm.nosql.IndexFunctionGen.java

License:Apache License

private static void encodeScalar(QueryModel.OrderBy f, final MethodVisitor mv, final EncodeCGS cgs)
        throws OrmException {
    String method = f.descending ? "desc" : "add";
    ColumnModel c = f.column;// w w w  .  j  av a  2  s.  com
    cgs.setFieldReference(c);

    switch (Type.getType(c.getPrimitiveType()).getSort()) {
    case Type.BOOLEAN:
    case Type.BYTE:
    case Type.SHORT:
    case Type.CHAR:
    case Type.INT:
        cgs.pushBuilder();
        cgs.pushFieldValue();
        mv.visitInsn(I2L);
        mv.visitMethodInsn(INVOKEVIRTUAL, indexKeyBuilder.getInternalName(), method,
                Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.LONG_TYPE }));
        break;

    case Type.LONG:
        cgs.pushBuilder();
        cgs.pushFieldValue();
        mv.visitMethodInsn(INVOKEVIRTUAL, indexKeyBuilder.getInternalName(), method,
                Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.LONG_TYPE }));
        break;

    case Type.ARRAY:
    case Type.OBJECT: {
        if (c.getPrimitiveType() == byte[].class) {
            cgs.pushBuilder();
            cgs.pushFieldValue();
            mv.visitMethodInsn(INVOKEVIRTUAL, indexKeyBuilder.getInternalName(), method,
                    Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(byte[].class) }));

        } else if (c.getPrimitiveType() == String.class) {
            cgs.pushBuilder();
            cgs.pushFieldValue();
            mv.visitMethodInsn(INVOKEVIRTUAL, indexKeyBuilder.getInternalName(), method,
                    Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { string }));

        } else if (c.getPrimitiveType() == java.sql.Timestamp.class
                || c.getPrimitiveType() == java.util.Date.class
                || c.getPrimitiveType() == java.sql.Date.class) {
            cgs.pushBuilder();
            cgs.pushFieldValue();
            String tsType = Type.getType(c.getPrimitiveType()).getInternalName();
            mv.visitMethodInsn(INVOKEVIRTUAL, tsType, "getTime",
                    Type.getMethodDescriptor(Type.LONG_TYPE, new Type[] {}));
            mv.visitMethodInsn(INVOKEVIRTUAL, indexKeyBuilder.getInternalName(), method,
                    Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.LONG_TYPE }));
        } else {
            throw new OrmException(
                    "Type " + c.getPrimitiveType() + " not supported for field " + c.getPathToFieldName());
        }
        break;
    }

    default:
        throw new OrmException(
                "Type " + c.getPrimitiveType() + " not supported for field " + c.getPathToFieldName());
    }
}

From source file:com.google.gwtorm.protobuf.CodecGen.java

License:Apache License

private static void sizeofScalar(final MethodVisitor mv, final SizeofCGS cgs, final JavaColumnModel f)
        throws OrmException {
    cgs.setFieldReference(f);/*from  w w w .j a  va2  s . c  o  m*/

    switch (Type.getType(f.getPrimitiveType()).getSort()) {
    case Type.BOOLEAN:
        cgs.push(f.getColumnID());
        cgs.pushFieldValue();
        cgs.inc("computeBoolSize", Type.INT_TYPE, Type.BOOLEAN_TYPE);
        break;

    case Type.CHAR:
        cgs.push(f.getColumnID());
        cgs.pushFieldValue();
        cgs.inc("computeUInt32Size", Type.INT_TYPE, Type.INT_TYPE);
        break;

    case Type.BYTE:
    case Type.SHORT:
    case Type.INT:
        cgs.push(f.getColumnID());
        cgs.pushFieldValue();
        cgs.inc("computeSInt32Size", Type.INT_TYPE, Type.INT_TYPE);
        break;

    case Type.FLOAT:
        cgs.push(f.getColumnID());
        cgs.pushFieldValue();
        cgs.inc("computeFloatSize", Type.INT_TYPE, Type.FLOAT_TYPE);
        break;

    case Type.DOUBLE:
        cgs.push(f.getColumnID());
        cgs.pushFieldValue();
        cgs.inc("computeDoubleSize", Type.INT_TYPE, Type.DOUBLE_TYPE);
        break;

    case Type.LONG:
        cgs.push(f.getColumnID());
        cgs.pushFieldValue();
        cgs.inc("computeSInt64", Type.INT_TYPE, Type.LONG_TYPE);
        break;

    case Type.ARRAY:
    case Type.OBJECT: {
        final Label end = new Label();
        cgs.pushFieldValue();
        mv.visitJumpInsn(IFNULL, end);

        if (f.getPrimitiveType() == byte[].class) {
            cgs.push(f.getColumnID());
            cgs.inc("computeTagSize", Type.INT_TYPE);

            cgs.pushFieldValue();
            mv.visitInsn(ARRAYLENGTH);
            cgs.inc("computeRawVarint32Size", Type.INT_TYPE);

            cgs.pushFieldValue();
            mv.visitInsn(ARRAYLENGTH);
            cgs.inc();

        } else if (f.getPrimitiveType() == String.class) {
            cgs.push(f.getColumnID());
            cgs.pushFieldValue();
            cgs.inc("computeStringSize", Type.INT_TYPE, string);

        } else if (f.getPrimitiveType() == java.sql.Timestamp.class
                || f.getPrimitiveType() == java.util.Date.class
                || f.getPrimitiveType() == java.sql.Date.class) {
            cgs.push(f.getColumnID());
            String tsType = Type.getType(f.getPrimitiveType()).getInternalName();
            mv.visitMethodInsn(INVOKEVIRTUAL, tsType, "getTime",
                    Type.getMethodDescriptor(Type.LONG_TYPE, new Type[] {}));
            cgs.inc("computeFixed64Size", Type.INT_TYPE, Type.LONG_TYPE);

        } else {
            throw new OrmException(
                    "Type " + f.getPrimitiveType() + " not supported for field " + f.getPathToFieldName());
        }
        mv.visitLabel(end);
        break;
    }

    default:
        throw new OrmException(
                "Type " + f.getPrimitiveType() + " not supported for field " + f.getPathToFieldName());
    }
}

From source file:com.google.gwtorm.protobuf.CodecGen.java

License:Apache License

private static void encodeMessage(final JavaColumnModel[] myFields, final MethodVisitor mv, final EncodeCGS cgs)
        throws OrmException {
    final int oldVar = cgs.codedOutputStreamVar;
    cgs.codedOutputStreamVar = cgs.newLocal();

    final int strVar = cgs.newLocal();
    mv.visitMethodInsn(INVOKESTATIC, byteString.getInternalName(), "newOutput",
            Type.getMethodDescriptor(byteStringOutput, new Type[] {}));
    mv.visitVarInsn(ASTORE, strVar);//ww w .  ja v a  2 s.  c  om

    mv.visitVarInsn(ALOAD, strVar);
    mv.visitMethodInsn(INVOKESTATIC, codedOutputStream.getInternalName(), "newInstance",
            Type.getMethodDescriptor(codedOutputStream, new Type[] { Type.getType(OutputStream.class) }));
    mv.visitVarInsn(ASTORE, cgs.codedOutputStreamVar);

    for (final JavaColumnModel f : myFields) {
        if (f.isNested()) {
            final Label end = new Label();
            cgs.setFieldReference(f);
            cgs.pushFieldValue();
            mv.visitJumpInsn(IFNULL, end);

            final int v = cgs.newLocal();
            encodeMessage(sort(f.getNestedColumns()), mv, cgs);
            mv.visitVarInsn(ASTORE, v);

            mv.visitVarInsn(ALOAD, v);
            mv.visitMethodInsn(INVOKEVIRTUAL, byteString.getInternalName(), "size",
                    Type.getMethodDescriptor(Type.INT_TYPE, new Type[] {}));
            mv.visitJumpInsn(IFEQ, end);

            cgs.pushCodedOutputStream();
            cgs.push(f.getColumnID());
            mv.visitVarInsn(ALOAD, v);
            cgs.write("writeBytes", byteString);

            cgs.freeLocal(v);
            mv.visitLabel(end);
        } else {
            encodeScalar(mv, cgs, f);
        }
    }

    cgs.pushCodedOutputStream();
    mv.visitMethodInsn(INVOKEVIRTUAL, codedOutputStream.getInternalName(), "flush",
            Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}));

    cgs.freeLocal(cgs.codedOutputStreamVar);
    cgs.codedOutputStreamVar = oldVar;

    mv.visitVarInsn(ALOAD, strVar);
    mv.visitMethodInsn(INVOKEVIRTUAL, byteStringOutput.getInternalName(), "toByteString",
            Type.getMethodDescriptor(byteString, new Type[] {}));
    cgs.freeLocal(strVar);
}

From source file:com.google.gwtorm.protobuf.CodecGen.java

License:Apache License

private static void encodeScalar(final MethodVisitor mv, final EncodeCGS cgs, final JavaColumnModel f)
        throws OrmException {
    cgs.setFieldReference(f);//w w  w.j a  va2  s  . c om

    switch (Type.getType(f.getPrimitiveType()).getSort()) {
    case Type.BOOLEAN:
        cgs.pushCodedOutputStream();
        cgs.push(f.getColumnID());
        cgs.pushFieldValue();
        cgs.write("writeBool", Type.BOOLEAN_TYPE);
        break;

    case Type.CHAR:
        cgs.pushCodedOutputStream();
        cgs.push(f.getColumnID());
        cgs.pushFieldValue();
        cgs.write("writeUInt32", Type.INT_TYPE);
        break;

    case Type.BYTE:
    case Type.SHORT:
    case Type.INT:
        cgs.pushCodedOutputStream();
        cgs.push(f.getColumnID());
        cgs.pushFieldValue();
        cgs.write("writeSInt32", Type.INT_TYPE);
        break;

    case Type.FLOAT:
        cgs.pushCodedOutputStream();
        cgs.push(f.getColumnID());
        cgs.pushFieldValue();
        cgs.write("writeFloat", Type.FLOAT_TYPE);
        break;

    case Type.DOUBLE:
        cgs.pushCodedOutputStream();
        cgs.push(f.getColumnID());
        cgs.pushFieldValue();
        cgs.write("writeDouble", Type.DOUBLE_TYPE);
        break;

    case Type.LONG:
        cgs.pushCodedOutputStream();
        cgs.push(f.getColumnID());
        cgs.pushFieldValue();
        cgs.write("writeSInt64", Type.LONG_TYPE);
        break;

    case Type.ARRAY:
    case Type.OBJECT: {
        final Label end = new Label();
        cgs.pushFieldValue();
        mv.visitJumpInsn(IFNULL, end);

        if (f.getPrimitiveType() == byte[].class) {
            cgs.pushCodedOutputStream();
            cgs.push(f.getColumnID());
            cgs.push(WireFormat.FieldType.BYTES.getWireType());
            mv.visitMethodInsn(INVOKEVIRTUAL, codedOutputStream.getInternalName(), "writeTag",
                    Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE }));

            cgs.pushCodedOutputStream();
            cgs.pushFieldValue();
            mv.visitInsn(ARRAYLENGTH);
            mv.visitMethodInsn(INVOKEVIRTUAL, codedOutputStream.getInternalName(), "writeRawVarint32",
                    Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE }));

            cgs.pushCodedOutputStream();
            cgs.pushFieldValue();
            mv.visitMethodInsn(INVOKEVIRTUAL, codedOutputStream.getInternalName(), "writeRawBytes",
                    Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(byte[].class) }));

        } else {
            cgs.pushCodedOutputStream();
            cgs.push(f.getColumnID());
            cgs.pushFieldValue();

            if (f.getPrimitiveType() == String.class) {
                cgs.write("writeString", string);

            } else if (f.getPrimitiveType() == java.sql.Timestamp.class
                    || f.getPrimitiveType() == java.util.Date.class
                    || f.getPrimitiveType() == java.sql.Date.class) {
                String tsType = Type.getType(f.getPrimitiveType()).getInternalName();
                mv.visitMethodInsn(INVOKEVIRTUAL, tsType, "getTime",
                        Type.getMethodDescriptor(Type.LONG_TYPE, new Type[] {}));
                cgs.write("writeFixed64", Type.LONG_TYPE);

            } else {
                throw new OrmException(
                        "Type " + f.getPrimitiveType() + " not supported for field " + f.getPathToFieldName());
            }
        }
        mv.visitLabel(end);
        break;
    }

    default:
        throw new OrmException(
                "Type " + f.getPrimitiveType() + " not supported for field " + f.getPathToFieldName());
    }
}