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

com.netflix.astyanax.Serializer Maven / Gradle / Ivy

There is a newer version: 3.10.2
Show newest version
/**
 *  DataSerializer.java
 *  dsmirnov Apr 4, 2011
 */
package com.netflix.astyanax;

import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.netflix.astyanax.serializers.ComparatorType;

/**
 * Serializes a type T from the given bytes, or vice a versa.
 * 
 * In cassandra column names and column values (and starting with 0.7.0 row
 * keys) are all byte[]. To allow type safe conversion in java and keep all
 * conversion code in one place we define the Extractor interface. Implementors
 * of the interface define type conversion according to their domains. A
 * predefined set of common extractors can be found in the extractors package,
 * for example {@link StringSerializer}.
 * 
 * @author Ran Tavory
 * 
 * @param 
 *            The type to which data extraction should work.
 */
public interface Serializer {

    /**
     * Extract bytes from the obj of type T
     * 
     * @param obj
     * @return
     */
    ByteBuffer toByteBuffer(T obj);

    byte[] toBytes(T obj);

    T fromBytes(byte[] bytes);

    /**
     * Extract an object of type T from the bytes.
     * 
     * @param bytes
     * @return
     */
    T fromByteBuffer(ByteBuffer byteBuffer);

    Set toBytesSet(List list);

    List fromBytesSet(Set list);

     Map toBytesMap(Map map);

     Map fromBytesMap(Map map);

    List toBytesList(List list);

    List toBytesList(Collection list);

    List toBytesList(Iterable list);
    
    List fromBytesList(List list);

    ComparatorType getComparatorType();

    /**
     * Return the byte buffer for the next value in sorted order for the
     * matching comparator type. This is used for paginating columns.
     * 
     * @param byteBuffer
     * @return
     */
    ByteBuffer getNext(ByteBuffer byteBuffer);

    /**
     * Create a ByteBuffer by first parsing the type out of a string
     * 
     * @param string
     * @return
     */
    ByteBuffer fromString(String string);

    String getString(ByteBuffer byteBuffer);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy