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

com.netflix.astyanax.serializers.ListSerializer Maven / Gradle / Ivy

There is a newer version: 3.10.2
Show newest version
package com.netflix.astyanax.serializers;

import java.nio.ByteBuffer;
import java.util.List;

import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.ListType;

import com.netflix.astyanax.serializers.AbstractSerializer;

/**
 * Serializer implementation for generic lists.
 * 
 * @author vermes
 * 
 * @param 
 *            element type
 */
public class ListSerializer extends AbstractSerializer> {

    private final ListType myList;

    /**
     * @param elements
     */
    public ListSerializer(AbstractType elements) {
        myList = ListType.getInstance(elements);
    }

    @Override
    public List fromByteBuffer(ByteBuffer arg0) {
        if (arg0 ==  null) return null;
        ByteBuffer dup = arg0.duplicate();
        return myList.compose(dup);
    }

    @Override
    public ByteBuffer toByteBuffer(List arg0) {
        return arg0 == null ? null : myList.decompose(arg0);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy