StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) getKnowledgeRuntime();
Marshaller marshaller = MarshallerFactory.newMarshaller( ksession.getKnowledgeBase(), new ObjectMarshallingStrategy[] { MarshallerFactory.newSerializeMarshallingStrategy() } );
ByteArrayOutputStream stream = new ByteArrayOutputStream();
marshaller.marshall( stream, (StatefulKnowledgeSession) getKnowledgeRuntime() );
stream.close();
byte[] bytes = stream.toByteArray();
out.writeInt( bytes.length );
out.write( bytes );