org.apache.kafka.common.protocol.types
Class Struct

java.lang.Object
  extended by org.apache.kafka.common.protocol.types.Struct

public class Struct
extends java.lang.Object

A record that can be serialized and deserialized according to a pre-defined schema


Constructor Summary
Struct(Schema schema)
           
 
Method Summary
 void clear()
          Empty all the values from this record
 boolean equals(java.lang.Object obj)
           
 java.lang.Object get(Field field)
          Get the value for the field directly by the field index with no lookup needed (faster!)
 java.lang.Object get(java.lang.String name)
          Get the record value for the field with the given name by doing a hash table lookup (slower!)
 java.lang.Object[] getArray(Field field)
           
 java.lang.Object[] getArray(java.lang.String name)
           
 java.nio.ByteBuffer getBytes(Field field)
           
 java.nio.ByteBuffer getBytes(java.lang.String name)
           
 java.lang.Integer getInt(Field field)
           
 java.lang.Integer getInt(java.lang.String name)
           
 java.lang.Long getLong(Field field)
           
 java.lang.Long getLong(java.lang.String name)
           
 java.lang.Short getShort(Field field)
           
 java.lang.Short getShort(java.lang.String name)
           
 java.lang.String getString(Field field)
           
 java.lang.String getString(java.lang.String name)
           
 Struct getStruct(Field field)
           
 Struct getStruct(java.lang.String name)
           
 boolean hasField(java.lang.String name)
          Check if the struct contains a field.
 int hashCode()
           
 Struct instance(Field field)
          Create a struct for the schema of a container type (struct or array).
 Struct instance(java.lang.String field)
          Create a struct instance for the given field which must be a container type (struct or array)
 Schema schema()
          The schema for this struct.
 Struct set(Field field, java.lang.Object value)
          Set the given field to the specified value
 Struct set(java.lang.String name, java.lang.Object value)
          Set the field specified by the given name to the value
 int sizeOf()
          Get the serialized size of this object
 java.nio.ByteBuffer[] toBytes()
          Create a byte buffer containing the serialized form of the values in this struct.
 java.lang.String toString()
           
 void validate()
          Validate the contents of this struct against its schema
 void writeTo(java.nio.ByteBuffer buffer)
          Write this struct to a buffer
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Struct

public Struct(Schema schema)
Method Detail

schema

public Schema schema()
The schema for this struct.


get

public java.lang.Object get(Field field)
Get the value for the field directly by the field index with no lookup needed (faster!)

Parameters:
field - The field to look up
Returns:
The value for that field.

get

public java.lang.Object get(java.lang.String name)
Get the record value for the field with the given name by doing a hash table lookup (slower!)

Parameters:
name - The name of the field
Returns:
The value in the record

hasField

public boolean hasField(java.lang.String name)
Check if the struct contains a field.

Parameters:
name -
Returns:
Whether a field exists.

getStruct

public Struct getStruct(Field field)

getStruct

public Struct getStruct(java.lang.String name)

getShort

public java.lang.Short getShort(Field field)

getShort

public java.lang.Short getShort(java.lang.String name)

getInt

public java.lang.Integer getInt(Field field)

getInt

public java.lang.Integer getInt(java.lang.String name)

getLong

public java.lang.Long getLong(Field field)

getLong

public java.lang.Long getLong(java.lang.String name)

getBytes

public java.nio.ByteBuffer getBytes(Field field)

getBytes

public java.nio.ByteBuffer getBytes(java.lang.String name)

getArray

public java.lang.Object[] getArray(Field field)

getArray

public java.lang.Object[] getArray(java.lang.String name)

getString

public java.lang.String getString(Field field)

getString

public java.lang.String getString(java.lang.String name)

set

public Struct set(Field field,
                  java.lang.Object value)
Set the given field to the specified value

Parameters:
field - The field
value - The value

set

public Struct set(java.lang.String name,
                  java.lang.Object value)
Set the field specified by the given name to the value

Parameters:
name - The name of the field
value - The value to set

instance

public Struct instance(Field field)
Create a struct for the schema of a container type (struct or array). Note that for array type, this method assumes that the type is an array of schema and creates a struct of that schema. Arrays of other types can't be instantiated with this method.

Parameters:
field - The field to create an instance of
Returns:
The struct

instance

public Struct instance(java.lang.String field)
Create a struct instance for the given field which must be a container type (struct or array)

Parameters:
field - The name of the field to create (field must be a schema type)
Returns:
The struct

clear

public void clear()
Empty all the values from this record


sizeOf

public int sizeOf()
Get the serialized size of this object


writeTo

public void writeTo(java.nio.ByteBuffer buffer)
Write this struct to a buffer


validate

public void validate()
Validate the contents of this struct against its schema


toBytes

public java.nio.ByteBuffer[] toBytes()
Create a byte buffer containing the serialized form of the values in this struct. This method can choose to break the struct into multiple ByteBuffers if need be.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object