CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apache-thrift--libthrift

Apache Thrift Java Library - A lightweight, language-independent software stack for point-to-point RPC implementation providing clean abstractions and implementations for data transport, data serialization, and application level processing

Pending
Overview
Eval results
Files

protocols.mddocs/

Protocol Implementations

Data serialization protocols for different use cases and requirements. Protocols define how Thrift data structures are encoded and decoded for transmission over the wire or storage.

Capabilities

Protocol Base Classes

Core protocol interfaces and abstract classes that all protocol implementations extend.

/**
 * Abstract base class for all protocol implementations
 */
public abstract class TProtocol {
    /** Create protocol with transport */
    public TProtocol(TTransport trans);
    
    /** Get the underlying transport */
    public TTransport getTransport();
    
    // Message-level operations
    /** Begin writing a message */
    public abstract void writeMessageBegin(TMessage message) throws TException;
    
    /** End writing a message */
    public abstract void writeMessageEnd() throws TException;
    
    /** Begin reading a message */
    public abstract TMessage readMessageBegin() throws TException;
    
    /** End reading a message */
    public abstract void readMessageEnd() throws TException;
    
    // Struct-level operations
    /** Begin writing a struct */
    public abstract void writeStructBegin(TStruct struct) throws TException;
    
    /** End writing a struct */
    public abstract void writeStructEnd() throws TException;
    
    /** Begin reading a struct */
    public abstract TStruct readStructBegin() throws TException;
    
    /** End reading a struct */
    public abstract void readStructEnd() throws TException;
    
    // Field-level operations
    /** Begin writing a field */
    public abstract void writeFieldBegin(TField field) throws TException;
    
    /** End writing a field */
    public abstract void writeFieldEnd() throws TException;
    
    /** Write field stop marker */
    public abstract void writeFieldStop() throws TException;
    
    /** Begin reading a field */
    public abstract TField readFieldBegin() throws TException;
    
    /** End reading a field */
    public abstract void readFieldEnd() throws TException;
    
    // Container operations - Maps
    /** Begin writing a map */
    public abstract void writeMapBegin(TMap map) throws TException;
    
    /** End writing a map */
    public abstract void writeMapEnd() throws TException;
    
    /** Begin reading a map */
    public abstract TMap readMapBegin() throws TException;
    
    /** End reading a map */
    public abstract void readMapEnd() throws TException;
    
    // Container operations - Lists
    /** Begin writing a list */
    public abstract void writeListBegin(TList list) throws TException;
    
    /** End writing a list */
    public abstract void writeListEnd() throws TException;
    
    /** Begin reading a list */
    public abstract TList readListBegin() throws TException;
    
    /** End reading a list */
    public abstract void readListEnd() throws TException;
    
    // Container operations - Sets
    /** Begin writing a set */
    public abstract void writeSetBegin(TSet set) throws TException;
    
    /** End writing a set */
    public abstract void writeSetEnd() throws TException;
    
    /** Begin reading a set */
    public abstract TSet readSetBegin() throws TException;
    
    /** End reading a set */
    public abstract void readSetEnd() throws TException;
    
    // Primitive type operations
    /** Write boolean value */
    public abstract void writeBool(boolean b) throws TException;
    
    /** Read boolean value */
    public abstract boolean readBool() throws TException;
    
    /** Write byte value */
    public abstract void writeByte(byte b) throws TException;
    
    /** Read byte value */
    public abstract byte readByte() throws TException;
    
    /** Write 16-bit integer */
    public abstract void writeI16(short i16) throws TException;
    
    /** Read 16-bit integer */
    public abstract short readI16() throws TException;
    
    /** Write 32-bit integer */
    public abstract void writeI32(int i32) throws TException;
    
    /** Read 32-bit integer */
    public abstract int readI32() throws TException;
    
    /** Write 64-bit integer */
    public abstract void writeI64(long i64) throws TException;
    
    /** Read 64-bit integer */
    public abstract long readI64() throws TException;
    
    /** Write double value */
    public abstract void writeDouble(double dub) throws TException;
    
    /** Read double value */
    public abstract double readDouble() throws TException;
    
    /** Write string value */
    public abstract void writeString(String str) throws TException;
    
    /** Read string value */
    public abstract String readString() throws TException;
    
    /** Write binary data */
    public abstract void writeBinary(ByteBuffer bin) throws TException;
    
    /** Read binary data */
    public abstract ByteBuffer readBinary() throws TException;
    
    // Utility methods
    /** Skip field of specified type */
    public void skip(byte fieldType) throws TException;
    
    /** Reset protocol state */
    public void reset();
    
    /** Get minimum serialized size for type */
    public int getMinSerializedSize(byte type) throws TException;
}

/**
 * Factory interface for creating protocol instances
 */
public interface TProtocolFactory {
    /** Create protocol instance for the given transport */
    public TProtocol getProtocol(TTransport trans);
}

Binary Protocol

Efficient binary protocol implementation for high-performance scenarios.

/**
 * Binary protocol implementation with optional strict mode
 */
public class TBinaryProtocol extends TProtocol {
    /** Version information for protocol compatibility */
    public static final long VERSION_MASK = 0xffff0000;
    public static final int VERSION_1 = 0x80010000;
    
    /** Create binary protocol with transport and default settings */
    public TBinaryProtocol(TTransport trans);
    
    /** Create binary protocol with strict read/write settings */
    public TBinaryProtocol(TTransport trans, boolean strictRead, boolean strictWrite);
    
    /** Create binary protocol with size limits and strict settings */
    public TBinaryProtocol(TTransport trans, long stringLengthLimit, long containerLengthLimit, 
                          boolean strictRead, boolean strictWrite);
    
    /** Factory for creating binary protocol instances */
    public static class Factory implements TProtocolFactory {
        /** Create factory with default settings */
        public Factory();
        
        /** Create factory with strict read/write settings */
        public Factory(boolean strictRead, boolean strictWrite);
        
        /** Create factory with size limits and strict settings */
        public Factory(long stringLengthLimit, long containerLengthLimit, 
                      boolean strictRead, boolean strictWrite);
        
        public TProtocol getProtocol(TTransport trans);
    }
}

Usage Examples:

import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.transport.TSocket;

// Create binary protocol with default settings
TSocket transport = new TSocket("localhost", 9090);
TBinaryProtocol protocol = new TBinaryProtocol(transport);

// Create binary protocol with strict mode enabled
TBinaryProtocol strictProtocol = new TBinaryProtocol(transport, true, true);

// Use factory for creating protocols
TBinaryProtocol.Factory factory = new TBinaryProtocol.Factory();
TBinaryProtocol protocolFromFactory = (TBinaryProtocol) factory.getProtocol(transport);

// Factory with strict mode and size limits
TBinaryProtocol.Factory strictFactory = new TBinaryProtocol.Factory(1024 * 1024, 1024, true, true);

Compact Protocol

Space-efficient protocol with variable-length encoding for reduced bandwidth usage.

/**
 * Compact binary protocol with variable-length encoding
 */
public class TCompactProtocol extends TProtocol {
    /** Protocol identifier and version */
    public static final byte VERSION = 1;
    public static final byte VERSION_MASK = 0x1f;
    public static final byte TYPE_MASK = (byte) 0xE0;
    public static final int TYPE_SHIFT_AMOUNT = 5;
    
    /** Create compact protocol with transport */
    public TCompactProtocol(TTransport transport);
    
    /** Create compact protocol with size limits */
    public TCompactProtocol(TTransport transport, long stringLengthLimit, long containerLengthLimit);
    
    /** Factory for creating compact protocol instances */
    public static class Factory implements TProtocolFactory {
        /** Create factory with default settings */
        public Factory();
        
        /** Create factory with size limits */
        public Factory(long stringLengthLimit, long containerLengthLimit);
        
        public TProtocol getProtocol(TTransport trans);
    }
}

Usage Examples:

import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.transport.TSocket;

// Create compact protocol
TSocket transport = new TSocket("localhost", 9090);
TCompactProtocol protocol = new TCompactProtocol(transport);

// Use factory
TCompactProtocol.Factory factory = new TCompactProtocol.Factory();
TCompactProtocol compactProtocol = (TCompactProtocol) factory.getProtocol(transport);

// Factory with size limits
TCompactProtocol.Factory limitedFactory = new TCompactProtocol.Factory(1024 * 1024, 1024);

JSON Protocol

Human-readable JSON protocol for debugging and web services.

/**
 * JSON protocol implementation for human-readable output
 */
public class TJSONProtocol extends TProtocol {
    /** Create JSON protocol with transport */
    public TJSONProtocol(TTransport trans);
    
    /** Create JSON protocol with configuration */
    public TJSONProtocol(TTransport trans, TConfiguration config);
    
    /** Factory for creating JSON protocol instances */
    public static class Factory implements TProtocolFactory {
        /** Create factory with default settings */
        public Factory();
        
        public TProtocol getProtocol(TTransport trans);
    }
}

/**
 * Simple JSON protocol (write-only) for one-way serialization
 */
public class TSimpleJSONProtocol extends TProtocol {
    /** Create simple JSON protocol with transport */
    public TSimpleJSONProtocol(TTransport trans);
    
    /** Factory for creating simple JSON protocol instances */
    public static class Factory implements TProtocolFactory {
        /** Create factory */
        public Factory();
        
        public TProtocol getProtocol(TTransport trans);
    }
}

Usage Examples:

import org.apache.thrift.protocol.TJSONProtocol;
import org.apache.thrift.protocol.TSimpleJSONProtocol;
import org.apache.thrift.transport.TMemoryBuffer;

// Create JSON protocol for bidirectional serialization
TMemoryBuffer buffer = new TMemoryBuffer(1024);
TJSONProtocol jsonProtocol = new TJSONProtocol(buffer);

// Create simple JSON protocol for write-only serialization
TSimpleJSONProtocol simpleJsonProtocol = new TSimpleJSONProtocol(buffer);

// Use factories
TJSONProtocol.Factory jsonFactory = new TJSONProtocol.Factory();
TSimpleJSONProtocol.Factory simpleFactory = new TSimpleJSONProtocol.Factory();

Tuple Protocol

Memory-efficient protocol for use with tuple schemes.

/**
 * Tuple protocol for efficient serialization with tuple schemes
 */
public class TTupleProtocol extends TProtocol {
    /** Create tuple protocol with transport */
    public TTupleProtocol(TTransport transport);
}

Multiplexed Protocol

Protocol decorator that adds service name information for multiplexed services.

/**
 * Protocol decorator for multiplexed services
 */
public class TMultiplexedProtocol extends TProtocolDecorator {
    /** Service name separator */
    public static final String SEPARATOR = ":";
    
    /** Create multiplexed protocol with base protocol and service name */
    public TMultiplexedProtocol(TProtocol protocol, String serviceName);
    
    /** Write message begin with service name prefix */
    public void writeMessageBegin(TMessage tMessage) throws TException;
}

Usage Examples:

import org.apache.thrift.protocol.TMultiplexedProtocol;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.transport.TSocket;

// Create multiplexed protocol for specific service
TSocket transport = new TSocket("localhost", 9090);
TBinaryProtocol baseProtocol = new TBinaryProtocol(transport);
TMultiplexedProtocol multiplexedProtocol = new TMultiplexedProtocol(baseProtocol, "MyService");

// Use with generated client
MyService.Client client = new MyService.Client(multiplexedProtocol);

Protocol Data Structures

Data structures used by protocols to represent Thrift elements.

/**
 * Represents a Thrift message
 */
public class TMessage {
    /** Message name */
    public final String name;
    /** Message type (call, reply, exception, oneway) */
    public final byte type;
    /** Sequence ID for request/response correlation */
    public final int seqid;
    
    /** Create message */
    public TMessage(String name, byte type, int seqid);
    
    /** Create empty message */
    public TMessage();
    
    public String toString();
    public boolean equals(Object other);
    public int hashCode();
}

/**
 * Represents a Thrift struct
 */
public class TStruct {
    /** Struct name */
    public final String name;
    
    /** Create struct */
    public TStruct(String name);
    
    /** Create empty struct */
    public TStruct();
}

/**
 * Represents a Thrift field
 */
public class TField {
    /** Field name */
    public final String name;
    /** Field type */
    public final byte type;
    /** Field ID */
    public final short id;
    
    /** Create field */
    public TField(String name, byte type, short id);
    
    /** Create empty field */
    public TField();
    
    public String toString();
    public boolean equals(Object other);
    public int hashCode();
}

/**
 * Represents a Thrift map
 */
public class TMap {
    /** Key type */
    public final byte keyType;
    /** Value type */
    public final byte valueType;
    /** Map size */
    public final int size;
    
    /** Create map */
    public TMap(byte keyType, byte valueType, int size);
    
    /** Create empty map */
    public TMap();
    
    public String toString();
    public boolean equals(Object other);
    public int hashCode();
}

/**
 * Represents a Thrift list
 */
public class TList {
    /** Element type */
    public final byte elemType;
    /** List size */
    public final int size;
    
    /** Create list */
    public TList(byte elemType, int size);
    
    /** Create empty list */
    public TList();
    
    public String toString();
    public boolean equals(Object other);
    public int hashCode();
}

/**
 * Represents a Thrift set
 */
public class TSet {
    /** Element type */
    public final byte elemType;
    /** Set size */
    public final int size;
    
    /** Create set */
    public TSet(byte elemType, int size);
    
    /** Create empty set */
    public TSet();
    
    public String toString();
    public boolean equals(Object other);
    public int hashCode();
}

Protocol Constants

Constants used across protocol implementations.

/**
 * Thrift data type constants
 */
public final class TType {
    public static final byte STOP = 0;
    public static final byte VOID = 1;
    public static final byte BOOL = 2;
    public static final byte BYTE = 3;
    public static final byte I08 = 3;  // Same as BYTE
    public static final byte DOUBLE = 4;
    public static final byte I16 = 6;
    public static final byte I32 = 8;
    public static final byte I64 = 10;
    public static final byte STRING = 11;
    public static final byte UTF7 = 11;  // Same as STRING
    public static final byte STRUCT = 12;
    public static final byte MAP = 13;
    public static final byte SET = 14;
    public static final byte LIST = 15;
    public static final byte UTF8 = 16;
    public static final byte UTF16 = 17;
    public static final byte UUID = 18;
}

/**
 * Message type constants
 */
public final class TMessageType {
    public static final byte CALL = 1;     // Request message
    public static final byte REPLY = 2;    // Response message
    public static final byte EXCEPTION = 3; // Exception response
    public static final byte ONEWAY = 4;   // One-way call (no response expected)
}

Protocol Exceptions

Specific exception types for protocol-related errors.

/**
 * Exception for protocol-specific errors
 */
public class TProtocolException extends TException {
    public static final int UNKNOWN = 0;
    public static final int INVALID_DATA = 1;
    public static final int NEGATIVE_SIZE = 2;
    public static final int SIZE_LIMIT = 3;
    public static final int BAD_VERSION = 4;
    public static final int NOT_IMPLEMENTED = 5;
    public static final int DEPTH_LIMIT = 6;
    
    /** Create exception with unknown type */
    public TProtocolException();
    
    /** Create exception with specific type */
    public TProtocolException(int type);
    
    /** Create exception with type and message */
    public TProtocolException(int type, String message);
    
    /** Create exception with message */
    public TProtocolException(String message);
    
    /** Get the exception type */
    public int getType();
}

Protocol Utilities

Utility classes for protocol operations.

/**
 * Utility methods for protocol operations
 */
public class TProtocolUtil {
    /** Skip field of specified type in protocol */
    public static void skip(TProtocol prot, byte type) throws TException;
    
    /** Convert protocol data to string representation */
    public static String toString(TProtocol protocol, String indent) throws TException;
}

/**
 * Base class for protocol decorators
 */
public abstract class TProtocolDecorator extends TProtocol {
    /** The wrapped protocol */
    protected final TProtocol protocol;
    
    /** Create decorator wrapping another protocol */
    public TProtocolDecorator(TProtocol protocol);
    
    /** Get the wrapped protocol */
    public TProtocol getProtocol();
}

Install with Tessl CLI

npx tessl i tessl/maven-org-apache-thrift--libthrift

docs

async.md

core.md

index.md

metadata.md

protocols.md

schemes.md

servers.md

transports.md

utilities.md

tile.json