All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.query.remote.client.BaseProtoStreamMarshaller Maven / Gradle / Ivy

There is a newer version: 9.1.7.Final
Show newest version
package org.infinispan.query.remote.client;

import org.infinispan.commons.io.ByteBuffer;
import org.infinispan.commons.io.ByteBufferImpl;
import org.infinispan.commons.marshall.AbstractMarshaller;
import org.infinispan.protostream.ProtobufUtil;
import org.infinispan.protostream.SerializationContext;

import java.io.IOException;

/**
 * @author [email protected]
 * @since 6.0
 */
public abstract class BaseProtoStreamMarshaller extends AbstractMarshaller {

   protected BaseProtoStreamMarshaller() {
   }

   protected abstract SerializationContext getSerializationContext();

   @Override
   public Object objectFromByteBuffer(byte[] buf, int offset, int length) throws IOException, ClassNotFoundException {
      return ProtobufUtil.fromWrappedByteArray(getSerializationContext(), buf, offset, length);
   }

   @Override
   public boolean isMarshallable(Object o) {
      // Protostream can handle all of these type as well
      if (o instanceof String || o instanceof Long || o instanceof Integer || o instanceof Double || o instanceof Float
            || o instanceof Boolean || o instanceof byte[]) {    //todo [anistor] java.util.Date ?
         return true;
      }
      return getSerializationContext().canMarshall(o.getClass());
   }

   @Override
   protected ByteBuffer objectToBuffer(Object o, int estimatedSize) throws IOException, InterruptedException {
      byte[] bytes = ProtobufUtil.toWrappedByteArray(getSerializationContext(), o);
      return new ByteBufferImpl(bytes, 0, bytes.length);
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy