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

com.netflix.astyanax.serializers.MapSerializer 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.Map;

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

import com.netflix.astyanax.serializers.AbstractSerializer;

/**
 * Serializer implementation for generic maps.
 * 
 * @author vermes
 * 
 * @param 
 *            key type
 * @param 
 *            value type
 */
public class MapSerializer extends AbstractSerializer> {

    private final MapType myMap;

    /**
     * @param key
     * @param value
     */
    public MapSerializer(AbstractType key, AbstractType value) {
        myMap = MapType.getInstance(key, value);
    }

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy