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.9.0
Show newest version
/**
 * Copyright 2013 Netflix, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.netflix.astyanax.serializers;

import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.AbstractType;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.MapType;

import java.nio.ByteBuffer;
import java.util.Map;

/**
 * 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 - 2025 Weber Informatics LLC | Privacy Policy