/* (non-Javadoc)
  * @see org.directmemory.utils.Serializer#deserialize(byte[], java.lang.Class)
  */
 @SuppressWarnings("unchecked")
 public Object deserialize(byte[] source, @SuppressWarnings("rawtypes") Class clazz)
     throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
   final Object object = clazz.newInstance();
   @SuppressWarnings("rawtypes")
   final Schema schema = RuntimeSchema.getSchema(clazz);
   ProtostuffIOUtil.mergeFrom(source, object, schema);
   return object;
 }
예제 #2
0
  public <T> void run(final Action<T> handler, final Factory<T> factory, final Class<T> typeClass) {
    final Schema<T> schema = RuntimeSchema.getSchema(typeClass);

    while (true) {
      final byte[] message = subscriber.recv(0);
      T event = factory.build();
      ProtobufIOUtil.mergeFrom(message, event, schema);
      handler.invoke(event);
    }
  }
  /* (non-Javadoc)
   * @see org.directmemory.utils.Serializer#serialize(java.lang.Object, java.lang.Class)
   */
  @SuppressWarnings("unchecked")
  public byte[] serialize(Object obj, @SuppressWarnings("rawtypes") Class clazz)
      throws IOException {
    @SuppressWarnings("rawtypes")
    Schema schema = RuntimeSchema.getSchema(clazz);
    final LinkedBuffer buffer = LinkedBuffer.allocate(serBufferSize);
    byte[] protostuff = null;

    try {
      protostuff = ProtostuffIOUtil.toByteArray(obj, schema, buffer);
    } finally {
      buffer.clear();
    }
    return protostuff;
  }