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

com.netflix.astyanax.serializers.ByteBufferSerializer 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 java.util.Map;

import org.apache.cassandra.db.marshal.BytesType;

/**
 * The BytesExtractor is a simple identity function. It supports the Extractor
 * interface and implements the fromBytes and toBytes as simple identity
 * functions. However, the from and to methods both return the results of
 * {@link ByteBuffer#duplicate()}
 * 
 * 
 * @author Ran Tavory
 * @author zznate
 */
public final class ByteBufferSerializer extends AbstractSerializer {

    private static ByteBufferSerializer instance = new ByteBufferSerializer();

    public static ByteBufferSerializer get() {
        return instance;
    }

    @Override
    public ByteBuffer fromByteBuffer(ByteBuffer bytes) {
        if (bytes == null) {
            return null;
        }
        return bytes.duplicate();
    }

    @Override
    public ByteBuffer toByteBuffer(ByteBuffer obj) {
        if (obj == null) {
            return null;
        }
        return obj.duplicate();
    }

    @Override
    public List toBytesList(List list) {
        return list;
    }

    @Override
    public List fromBytesList(List list) {
        return list;
    }

    @Override
    public  Map toBytesMap(Map map) {
        return map;
    }

    @Override
    public  Map fromBytesMap(Map map) {
        return map;
    }

    @Override
    public ByteBuffer fromString(String str) {
        return BytesType.instance.fromString(str);
    }

    @Override
    public String getString(ByteBuffer byteBuffer) {
        return BytesType.instance.getString(byteBuffer);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy