package eu.toolchain.serializer;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.util.BitSet;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.Optional;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.UUID;
/**
* Serialization Framework.
*
* This type is the entry-point to everything regarding serialization.
*
*
Fixed vs. Variable Width Serializers
*
* A fixed-width {@link Serializer} always marshalls the value into the same number of bytes.
*
* A variable-width {@link Serializer} encodes the value using a varying number of bytes, typically
* to reduce the size for more frequent numerals.
*
* @author udoprog
*/
public interface SerializerFramework {
/**
* A fixed-length {@link Serializer} for {@link String}s.
*/
public Serializer string();
/**
* A fixed-length {@link Serializer} for {@link Byte}s.
*/
public Serializer fixedByte();
/**
* A fixed-length {@link Serializer} for {@link Boolean}s.
*/
public Serializer fixedBoolean();
/**
* A fixed-length {@link Serializer} for {@link Short}s.
*/
public Serializer fixedShort();
/**
* A fixed-length {@code Serializer} for {@link Integer}s.
*/
public Serializer fixedInteger();
/**
* A fixed-length {@link Serializer} for {@link Long}s.
*/
public Serializer fixedLong();
/**
* A fixed-length {@link Serializer} for {@link Float}s.
*/
public Serializer fixedFloat();
/**
* A fixed-length {@link Serializer} for {@link Double}s.
*/
public Serializer fixedDouble();
/**
* A fixed-length {@link Serializer} for {@link Character}s.
*/
public Serializer fixedCharacter();
/**
* A variable-length {@link Serializer} for {@link Integer}s.
*/
public Serializer variableInteger();
/**
* A variable-length {@link Serializer} for {@link Long}s.
*/
public Serializer variableLong();
/* deprecated */
/**
* @see #fixedBoolean()
*/
@Deprecated
public Serializer bool();
/**
* @see #fixedShort()
*/
@Deprecated
public Serializer shortNumber();
/**
* @see #fixedInteger()
*/
@Deprecated
public Serializer integer();
/**
* @see #fixedLong()
*/
@Deprecated
public Serializer longNumber();
/**
* @see #fixedFloat()
*/
@Deprecated
public Serializer floatNumber();
/**
* @see #fixedDouble()
*/
@Deprecated
public Serializer doubleNumber();
/**
* @see #variableInteger()
*/
@Deprecated
public Serializer varint();
/**
* @see #variableLong()
*/
@Deprecated
public Serializer varlong();
/* more fancy things */
/**
* Build a {@code Serializer} that can serialize null values.
*/
public Serializer nullable(Serializer serializer);
/**
* Same as {@link #prefix(byte[], Serializer)}, but using a 32 bit integer as a prefix.
*/
public Serializer prefix(int prefix, Serializer serializer);
/**
* Build a {@code Serializer} that adds the specified prefix when serializing.
*
* If this prefix is missing when reading, a runtime exception will be thrown.
*
* @param prefix The prefix to use.
* @param serializer The {@code Serializer} to prefix.
* @return A new {@code Serializer} with the prefix operation.
*/
public Serializer prefix(byte[] prefix, Serializer serializer);
/**
* Create a length-prefixed serialized that buffers up data, and guarantees that the underlying
* child-serializer gets the specified amount.
*
* @param serializer The {@code Serializer} to length prefix.
* @param policy A policy governing how long a child message is allowed to be.
* @return A new {@code Serializer} with the length prefix operation.
*/
public Serializer lengthPrefixed(Serializer serializer, LengthPolicy policy);
/**
* This will use a the default length policy that is configured in the framework.
*
* @see #lengthPrefixed(Serializer, LengthPolicy)
*/
public Serializer lengthPrefixed(Serializer serializer);
/**
* Build a {@code Serializer} that can serialize a list.
*
* How the list is encoded is implementation specific.
*
* @param Type of the list items.
* @param serializer The {@code Serializer} to use for each list item.
* @return A new list {@code Serializer}.
*/
public Serializer> list(Serializer serializer);
/**
* Build a {@code Serializer} that can serialize a map.
*
* How the map is encoded is implementation specific.
*
* @param Type of map keys.
* @param Type of map values.
* @param key The {@code Serializer} to use for map keys.
* @param value The {@code Serializer} to use for map values.
* @return A new map {@code Serializer}.
*/
public Serializer