in lightning-core/src/main/java/org/apache/directmemory/lightning/internal/generator/BytecodeMarshallerGenerator.java [302:365]
private void createMarshallMethod( ClassWriter cw, String className, Class<?> type,
SerializationStrategy serializationStrategy,
List<PropertyDescriptor> propertyDescriptors )
{
MethodVisitor mv =
cw.visitMethod( ACC_PUBLIC, "marshall", MARSHALLER_MARSHALL_SIGNATURE, null, MARSHALLER_EXCEPTIONS );
// If element type is not reference capable or SerializationStrategy is
// not SizeOptimized just prevent generation of code
if ( serializationStrategy == SerializationStrategy.SizeOptimized && ClassUtil.isReferenceCapable( type ) )
{
// Load this to method stack
mv.visitVarInsn( ALOAD, 0 );
// Load value to method stack
mv.visitVarInsn( ALOAD, 1 );
// Load type to method stack
mv.visitVarInsn( ALOAD, 2 );
// Load dataOutput to method stack
mv.visitVarInsn( ALOAD, 3 );
// Load serializationContext to method stack
mv.visitVarInsn( ALOAD, 4 );
// Call super.isAlreadyMarshalled(...);
mv.visitMethodInsn( INVOKEVIRTUAL, SUPER_CLASS_INTERNAL_TYPE, "isAlreadyMarshalled",
MARSHALLER_IS_ALREADY_MARSHALLED_SIGNATURE );
// Label if value is not yet marshalled
Label notYetMarshalled = new Label();
// Test if already marshalled
mv.visitJumpInsn( IFEQ, notYetMarshalled );
// If marshalled - just return
mv.visitInsn( RETURN );
// Visit label - if not yet marshalled - marshall it
mv.visitLabel( notYetMarshalled );
}
for ( PropertyDescriptor propertyDescriptor : propertyDescriptors )
{
if ( propertyDescriptor.getType().isArray()
&& !propertyDescriptor.getType().getComponentType().isPrimitive() )
{
visitObjectArrayPropertyAccessorRead( mv, className, propertyDescriptor );
}
else
{
visitValuePropertyAccessorRead( mv, className, propertyDescriptor );
}
}
// Add Return instruction
mv.visitInsn( RETURN );
// End visiting
mv.visitMaxs( 9, 9 );
mv.visitEnd();
}