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

org.infinispan.commons.marshall.ProtoStreamMarshaller Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev04
Show newest version
package org.infinispan.commons.marshall;

import org.infinispan.protostream.ProtobufUtil;
import org.infinispan.protostream.SerializationContext;
import org.infinispan.protostream.SerializationContextInitializer;
import org.infinispan.protostream.config.Configuration;

/**
 * Provides the starting point for implementing a {@link org.infinispan.commons.marshall.Marshaller} that uses Protobuf
 * encoding.
 *
 * @author [email protected]
 * @since 6.0
 */
public class ProtoStreamMarshaller extends ImmutableProtoStreamMarshaller {

   public ProtoStreamMarshaller() {
      this(newSerializationContext());
   }

   public ProtoStreamMarshaller(SerializationContext serializationContext) {
      super(serializationContext);
   }

   public void register(SerializationContextInitializer initializer) {
      initializer.registerSchema(getSerializationContext());
      initializer.registerMarshallers(getSerializationContext());
   }

   @Override
   public SerializationContext getSerializationContext() {
      return (SerializationContext) serializationContext;
   }

   /**
    * @return a new {@link SerializationContext} with {@link Configuration#wrapCollectionElements()} enabled.
    * @see Configuration.Builder#wrapCollectionElements(boolean)
    */
   public static SerializationContext newSerializationContext() {
      return ProtobufUtil.newSerializationContext(Configuration.builder().wrapCollectionElements(true).build());
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy