org.apache.calcite.avatica.remote

## Class ProtobufTranslationImpl

- java.lang.Object
- - org.apache.calcite.avatica.remote.ProtobufTranslationImpl

All Implemented Interfaces:
  ProtobufTranslation

    public class ProtobufTranslationImpl
    extends Object
    implements ProtobufTranslation

Implementation of `ProtobufTranslationImpl` that translates protobuf requests to POJO requests.

### Field Summary

Fields
`private static org.slf4j.Logger` `LOG`
`private static Map<Class<?>,com.google.protobuf.ByteString>` `MESSAGE_CLASSES`
`private static Map<String,RequestTranslator>` `REQUEST_PARSERS`
`private static Map<String,ResponseTranslator>` `RESPONSE_PARSERS`
`private ThreadLocal<UnsynchronizedBuffer>` `threadLocalBuffer`

### Constructor Summary

Constructors
Constructor and Description
`ProtobufTranslationImpl()`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`private static List<Class<?>>` `getAllMessageClasses()`
`(package private) com.google.protobuf.ByteString` `getClassNameBytes(Class<?> clz)`
`static RequestTranslator` `getParserForRequest(String className)` Fetches the concrete message's Parser implementation.
`static ResponseTranslator` `getParserForResponse(String className)` Fetches the concrete message's Parser implementation.
`Service.Request` `parseRequest(byte[] bytes)` Parses a serialized protocol buffer request into a `Service.Request`.
`Service.Response` `parseResponse(byte[] bytes)` Parses a serialized protocol buffer response into a `Service.Response`.
`(package private) void` `serializeMessage(OutputStream out, com.google.protobuf.Message msg)`
`byte[]` `serializeRequest(Service.Request request)` Serializes a `Service.Request` as a protocol buffer.
`byte[]` `serializeResponse(Service.Response response)` Serializes a `Service.Response` as a protocol buffer.
`private static com.google.protobuf.ByteString` `wrapClassName(Class<?> clz)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### LOG

    private static final org.slf4j.Logger LOG

#### REQUEST_PARSERS

    private static final Map<String,RequestTranslator> REQUEST_PARSERS

#### RESPONSE_PARSERS

    private static final Map<String,ResponseTranslator> RESPONSE_PARSERS

#### MESSAGE_CLASSES

    private static final Map<Class<?>,com.google.protobuf.ByteString> MESSAGE_CLASSES

#### threadLocalBuffer

    private final ThreadLocal<UnsynchronizedBuffer> threadLocalBuffer

### Constructor Detail

#### ProtobufTranslationImpl

    public ProtobufTranslationImpl()

### Method Detail

#### getAllMessageClasses

    private static List<Class<?>> getAllMessageClasses()

#### wrapClassName

    private static com.google.protobuf.ByteString wrapClassName(Class<?> clz)

#### getParserForRequest

    public static RequestTranslator getParserForRequest(String className)

Fetches the concrete message's Parser implementation.

Parameters:
  `className` - The protocol buffer class name
Returns:
  The Parser for the class
Throws:
  `IllegalArgumentException` - If the argument is null or if a Parser for the given class name is not found.

#### getParserForResponse

    public static ResponseTranslator getParserForResponse(String className)

Fetches the concrete message's Parser implementation.

Parameters:
  `className` - The protocol buffer class name
Returns:
  The Parser for the class
Throws:
  `IllegalArgumentException` - If the argument is null or if a Parser for the given class name is not found.

#### serializeResponse

    public byte[] serializeResponse(Service.Response response)
                             throws IOException

Description copied from interface: `ProtobufTranslation`
Serializes a `Service.Response` as a protocol buffer.

Specified by:
  `serializeResponse` in interface `ProtobufTranslation`
Parameters:
  `response` - The response to serialize
Throws:
  `IOException` - If there are errors during serialization

#### serializeRequest

    public byte[] serializeRequest(Service.Request request)
                            throws IOException

Description copied from interface: `ProtobufTranslation`
Serializes a `Service.Request` as a protocol buffer.

Specified by:
  `serializeRequest` in interface `ProtobufTranslation`
Parameters:
  `request` - The request to serialize
Throws:
  `IOException` - If there are errors during serialization

#### serializeMessage

    void serializeMessage(OutputStream out,
                          com.google.protobuf.Message msg)
                   throws IOException

Throws:
  `IOException`

#### getClassNameBytes

    com.google.protobuf.ByteString getClassNameBytes(Class<?> clz)

#### parseRequest

    public Service.Request parseRequest(byte[] bytes)
                                 throws IOException

Description copied from interface: `ProtobufTranslation`
Parses a serialized protocol buffer request into a `Service.Request`.

Specified by:
  `parseRequest` in interface `ProtobufTranslation`
Parameters:
  `bytes` - Serialized protocol buffer request from client
Returns:
  A Request object for the given bytes
Throws:
  `IOException` - If the protocol buffer cannot be deserialized

#### parseResponse

    public Service.Response parseResponse(byte[] bytes)
                                   throws IOException

Description copied from interface: `ProtobufTranslation`
Parses a serialized protocol buffer response into a `Service.Response`.

Specified by:
  `parseResponse` in interface `ProtobufTranslation`
Parameters:
  `bytes` - Serialized protocol buffer request from server
Returns:
  The Response object for the given bytes
Throws:
  `IOException` - If the protocol buffer cannot be deserialized