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

core.mddocs/

Core Framework

Essential classes and interfaces for Thrift object handling, serialization, processing, and configuration. This module provides the fundamental building blocks for all Thrift operations.

Capabilities

Serialization and Deserialization

Core utilities for converting Thrift objects to and from byte arrays or strings.

/**
 * Utility for serializing Thrift objects into byte arrays or strings
 */
public class TSerializer {
    /** Create serializer with default binary protocol */
    public TSerializer() throws TTransportException;
    
    /** Create serializer with specific protocol factory */
    public TSerializer(TProtocolFactory protocolFactory) throws TTransportException;
    
    /** Serialize a Thrift object to byte array */
    public byte[] serialize(TBase<?, ?> base) throws TException;
    
    /** Serialize a Thrift object to string representation */
    public String toString(TBase<?, ?> base) throws TException;
}

/**
 * Utility for deserializing Thrift objects from byte arrays or strings
 * with support for partial deserialization
 */
public class TDeserializer {
    /** Create deserializer with default binary protocol */
    public TDeserializer() throws TTransportException;
    
    /** Create deserializer with specific protocol factory */
    public TDeserializer(TProtocolFactory protocolFactory) throws TTransportException;
    
    /** Create deserializer for partial deserialization with field processor */
    public TDeserializer(Class<? extends TBase> thriftClass, Collection<String> fieldNames, 
                        ThriftFieldValueProcessor processor, TProtocolFactory protocolFactory) throws TTransportException;
    
    /** Deserialize byte array into existing Thrift object */
    public void deserialize(TBase base, byte[] bytes) throws TException;
    
    /** Deserialize byte array subset into existing Thrift object */
    public void deserialize(TBase base, byte[] bytes, int offset, int length) throws TException;
    
    /** Deserialize string with specified charset into existing Thrift object */
    public void deserialize(TBase base, String data, String charset) throws TException;
    
    /** Deserialize string from byte array using UTF-8 encoding */
    public void fromString(TBase base, String data) throws TException;
    
    // Partial deserialization methods using field path
    /** Partially deserialize object into existing Thrift struct using field path */
    public void partialDeserialize(TBase tb, byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException;
    
    /** Partially deserialize boolean field using field path */
    public Boolean partialDeserializeBool(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException;
    
    /** Partially deserialize byte field using field path */
    public Byte partialDeserializeByte(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException;
    
    /** Partially deserialize double field using field path */
    public Double partialDeserializeDouble(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException;
    
    /** Partially deserialize 16-bit integer field using field path */
    public Short partialDeserializeI16(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException;
    
    /** Partially deserialize 32-bit integer field using field path */
    public Integer partialDeserializeI32(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException;
    
    /** Partially deserialize 64-bit integer field using field path */
    public Long partialDeserializeI64(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException;
    
    /** Partially deserialize string field using field path */
    public String partialDeserializeString(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException;
    
    /** Partially deserialize binary field using field path */
    public ByteBuffer partialDeserializeByteArray(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException;
    
    /** Partially deserialize set field ID in union using field path */
    public Short partialDeserializeSetFieldIdInUnion(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException;
    
    /** Partially deserialize complete object from bytes */
    public Object partialDeserializeObject(byte[] bytes) throws TException;
    
    /** Partially deserialize complete object from bytes with offset and length */
    public Object partialDeserializeObject(byte[] bytes, int offset, int length) throws TException;
    
    /** Get metadata for partial deserialization */
    public ThriftMetadata.ThriftStruct getMetadata();
}

Usage Examples:

import org.apache.thrift.TSerializer;
import org.apache.thrift.TDeserializer;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TJSONProtocol;

// Basic serialization with binary protocol
TSerializer serializer = new TSerializer();
byte[] data = serializer.serialize(myThriftObject);

// Serialization with JSON protocol
TSerializer jsonSerializer = new TSerializer(new TJSONProtocol.Factory());
String jsonData = jsonSerializer.toString(myThriftObject);

// Basic deserialization
TDeserializer deserializer = new TDeserializer();
MyThriftClass obj = new MyThriftClass();
deserializer.deserialize(obj, data);

// Partial deserialization - extract only specific field using field enums
TDeserializer partialDeserializer = new TDeserializer();
String name = partialDeserializer.partialDeserializeString(data, MyThriftClass._Fields.NAME);
Integer age = partialDeserializer.partialDeserializeI32(data, MyThriftClass._Fields.AGE);

// Deserialize from JSON string
TDeserializer jsonDeserializer = new TDeserializer();
MyThriftClass objFromJson = new MyThriftClass();
jsonDeserializer.fromString(objFromJson, jsonString);

Base Interfaces

Core interfaces that all generated Thrift classes implement.

/**
 * Generic base interface for all generated Thrift objects
 * @param <T> The concrete type of the implementing class
 * @param <F> The field enum type for this class
 */
public interface TBase<T extends TBase<T, F>, F extends TFieldIdEnum> extends Serializable, Cloneable, Comparable<T> {
    /** Get field enum for the given field ID */
    public F fieldForId(int fieldId);
    
    /** Check if the specified field is set (has a value) */
    public boolean isSet(F field);
    
    /** Get the value of the specified field */
    public Object getFieldValue(F field);
    
    /** Set the value of the specified field */
    public void setFieldValue(F field, Object value);
    
    /** Create a deep copy of this object */
    public T deepCopy();
    
    /** Clear all fields (set them to null/default values) */
    public void clear();
}

/**
 * Interface for serializable Thrift objects
 */
public interface TSerializable {
    /** Read object data from protocol */
    public void read(TProtocol iprot) throws TException;
    
    /** Write object data to protocol */
    public void write(TProtocol oprot) throws TException;
}

/**
 * Interface for Thrift enum types
 */
public interface TEnum {
    /** Get the integer value of this enum */
    public int getValue();
}

/**
 * Interface for generated struct field enums
 */
public interface TFieldIdEnum {
    /** Get the Thrift field ID */
    public short getThriftFieldId();
    
    /** Get the field name */
    public String getFieldName();
}

Processing Framework

Interfaces and base classes for handling Thrift service requests.

/**
 * Interface for processing Thrift requests
 */
public interface TProcessor {
    /** Process a request from input protocol and write response to output protocol */
    public void process(TProtocol in, TProtocol out) throws TException;
}

/**
 * Factory for creating processor instances
 */
public interface TProcessorFactory {
    /** Create a new processor instance for the given transport */
    public TProcessor getProcessor(TTransport trans);
}

/**
 * Base implementation for synchronous processors
 */
public class TBaseProcessor implements TProcessor {
    /** Process request using registered process functions */
    public void process(TProtocol in, TProtocol out) throws TException;
    
    /** Register a process function for a method name */
    protected void registerProcessor(String methodName, ProcessFunction<?, ?> fn);
}

/**
 * Interface for asynchronous processing
 */
public interface TAsyncProcessor {
    /** Process async request with callback */
    public void process(AsyncProcessFunction<?, ?, ?> function, TProtocol iproto, TProtocol oproto, AsyncMethodCallback callback) throws TException;
}

/**
 * Base implementation for asynchronous processors
 */
public class TBaseAsyncProcessor implements TAsyncProcessor {
    /** Process async request using registered async process functions */
    public void process(AsyncProcessFunction<?, ?, ?> function, TProtocol iproto, TProtocol oproto, AsyncMethodCallback callback) throws TException;
    
    /** Register an async process function for a method name */
    protected void registerProcessor(String methodName, AsyncProcessFunction<?, ?, ?> fn);
}

Service Client Framework

Base classes for generated service clients.

/**
 * Base class for generated service clients
 */
public class TServiceClient {
    /** Create client with single protocol for both input and output */
    public TServiceClient(TProtocol prot);
    
    /** Create client with separate input and output protocols */
    public TServiceClient(TProtocol iprot, TProtocol oprot);
    
    /** Get the input protocol */
    protected TProtocol getInputProtocol();
    
    /** Get the output protocol */
    protected TProtocol getOutputProtocol();
}

/**
 * Factory for creating service client instances
 * @param <T> The service client type
 */
public class TServiceClientFactory<T extends TServiceClient> {
    /** Create client with single protocol */
    public T getClient(TProtocol prot);
    
    /** Create client with separate input/output protocols */
    public T getClient(TProtocol iprot, TProtocol oprot);
}

Configuration Management

Configuration settings and options for Thrift operations.

/**
 * Configuration settings for Thrift operations with size and recursion limits
 */
public class TConfiguration {
    /** Default maximum message size (100MB) */
    public static final int DEFAULT_MAX_MESSAGE_SIZE = 100 * 1024 * 1024;
    
    /** Default maximum frame size (~16MB) */
    public static final int DEFAULT_MAX_FRAME_SIZE = 16384000;
    
    /** Default recursion depth limit */
    public static final int DEFAULT_RECURSION_DEPTH = 64;
    
    /** Create configuration with default values */
    public TConfiguration();
    
    /** Create configuration with specified limits */
    public TConfiguration(int maxMessageSize, int maxFrameSize, int recursionLimit);
    
    /** Default configuration instance */
    public static final TConfiguration DEFAULT = new Builder().build();
    
    /** Get maximum message size */
    public int getMaxMessageSize();
    
    /** Get maximum frame size */
    public int getMaxFrameSize();
    
    /** Get recursion limit */
    public int getRecursionLimit();
    
    /** Create a builder for custom configuration */
    public static Builder custom();
    
    public static class Builder {
        /** Set maximum message size */
        public Builder setMaxMessageSize(int maxMessageSize);
        
        /** Set maximum frame size */
        public Builder setMaxFrameSize(int maxFrameSize);
        
        /** Set recursion limit */
        public Builder setRecursionLimit(int recursionLimit);
        
        /** Build the configuration */
        public TConfiguration build();
    }
}

Multiplexed Service Support

Support for running multiple services on a single transport.

/**
 * Processor that supports multiplexed services
 */
public class TMultiplexedProcessor implements TProcessor {
    /** Create multiplexed processor */
    public TMultiplexedProcessor();
    
    /** Register a processor for a service name */
    public void registerProcessor(String serviceName, TProcessor processor);
    
    /** Process request, routing to appropriate service processor */
    public void process(TProtocol in, TProtocol out) throws TException;
}

Union Support

Base class for Thrift union types.

/**
 * Abstract base class for generated union types
 * @param <T> The concrete type of the implementing union class
 * @param <F> The field enum type for this union
 */
public abstract class TUnion<T extends TUnion<T, F>, F extends TFieldIdEnum> implements TBase<T, F> {
    /** Default constructor */
    protected TUnion();
    
    /** Constructor with initial field and value */
    protected TUnion(F setField, Object value);
    
    /** Copy constructor */
    protected TUnion(TUnion<T, F> other);
    
    /** Check if any field is set */
    public boolean isSet();
    
    /** Get the currently set field */
    public F getSetField();
    
    /** Get the value of the currently set field */
    public Object getFieldValue();
    
    /** Set a field value (clears other fields) */
    public void setFieldValue(F field, Object value);
    
    /** Get the value of the specified field */
    public Object getFieldValue(F field);
    
    /** Clear all fields */
    public void clear();
    
    /** Create a deep copy */
    public T deepCopy();
}

Exception Handling

Core exception types for Thrift operations.

/**
 * Base exception class for all Thrift-related errors
 */
public class TException extends Exception {
    /** Create exception with no message */
    public TException();
    
    /** Create exception with message */
    public TException(String message);
    
    /** Create exception wrapping another throwable */
    public TException(Throwable cause);
    
    /** Create exception with message and cause */
    public TException(String message, Throwable cause);
}

/**
 * Application-level exception with specific error types
 */
public class TApplicationException extends TException {
    /** Unknown error */
    public static final int UNKNOWN = 0;
    /** Unknown method name */
    public static final int UNKNOWN_METHOD = 1;
    /** Invalid message type */
    public static final int INVALID_MESSAGE_TYPE = 2;
    /** Wrong method name in response */
    public static final int WRONG_METHOD_NAME = 3;
    /** Bad sequence ID in response */
    public static final int BAD_SEQUENCE_ID = 4;
    /** Missing result in response */
    public static final int MISSING_RESULT = 5;
    /** Internal server error */
    public static final int INTERNAL_ERROR = 6;
    /** Protocol error */
    public static final int PROTOCOL_ERROR = 7;
    /** Invalid data transform */
    public static final int INVALID_TRANSFORM = 8;
    /** Invalid protocol */
    public static final int INVALID_PROTOCOL = 9;
    /** Unsupported client type */
    public static final int UNSUPPORTED_CLIENT_TYPE = 10;
    
    /** Create exception with unknown type */
    public TApplicationException();
    
    /** Create exception with specific type */
    public TApplicationException(int type);
    
    /** Create exception with type and message */
    public TApplicationException(int type, String message);
    
    /** Create exception with message */
    public TApplicationException(String message);
    
    /** Get the exception type */
    public int getType();
    
    /** Read exception from protocol */
    public static TApplicationException readFrom(TProtocol iprot) throws TException;
    
    /** Write exception to protocol */
    public void write(TProtocol oprot) throws TException;
}

Utility Classes

Helper classes for common Thrift operations.

/**
 * Encoding and decoding utilities
 */
public final class EncodingUtils {
    /** Set bit in integer value */
    public static int setBit(int n, int pos, boolean value);
    
    /** Clear bit in integer value */
    public static int clearBit(int n, int pos);
    
    /** Test if bit is set in integer value */
    public static boolean testBit(int n, int pos);
    
    /** Encode integer as big-endian bytes */
    public static void encodeBigEndian(int val, byte[] buf, int offset);
    
    /** Decode big-endian bytes as integer */
    public static int decodeBigEndian(byte[] buf, int offset);
}

/**
 * Helper methods for TBase objects
 */
public final class TBaseHelper {
    /** Compare two objects (null-safe) */
    public static int compareTo(Object a, Object b);
    
    /** Convert object to string representation */
    public static String toString(Object o, StringBuilder sb);
    
    /** Copy binary data */
    public static ByteBuffer copyBinary(ByteBuffer orig);
    
    /** Compare binary data */
    public static int compareBinary(ByteBuffer a, ByteBuffer b);
    
    /** Deep copy a TBase object */
    public static <T extends TBase<T, F>, F extends TFieldIdEnum> T deepCopy(T orig);
}

/**
 * Helper methods for TEnum objects
 */
public final class TEnumHelper {
    /** Find enum value by integer value */
    public static <T extends TEnum> T findByValue(Class<T> enumClass, int value);
    
    /** Read enum value using standard scheme */
    public static <T extends TEnum> T standardSchemeReadValue(TProtocol iprot, Class<T> enumClass) throws TException;
    
    /** Write enum value using standard scheme */
    public static void standardSchemeWriteValue(TProtocol oprot, TEnum enumValue) throws TException;
}

/**
 * Optional value container
 */
public class Option<T> {
    /** Create empty option */
    public static <T> Option<T> fromNullable(T value);
    
    /** Check if value is present */
    public boolean has();
    
    /** Get the value (throws if not present) */
    public T get();
    
    /** Get the value or return alternative */
    public T or(T alternative);
}

Constants

/**
 * Field requirement type constants
 */
public final class TFieldRequirementType {
    public static final byte REQUIRED = 1;
    public static final byte OPTIONAL = 2;
    public static final byte DEFAULT = 3;
}

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