Avro C++

Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
avro::GenericDatum Class Reference

Generic datum which can hold any Avro type. More...

`#include <GenericDatum.hh>`

## Public Member Functions
Type | type () const
| The avro data type this datum holds.
LogicalType | logicalType () const
| The avro logical type that augments the main data type this datum holds.
template<typename T >
const T & | value () const
| Returns the value held by this datum. More...
template<typename T >
T & | value ()
| Returns the reference to the value held by this datum, which can be used to change the contents. More...
bool | isUnion () const
| Returns true if and only if this datum is a union.
size_t | unionBranch () const
| Returns the index of the current branch, if this is a union. More...
void | selectBranch (size_t branch)
| Selects a new branch in the union if this is a union. More...
| GenericDatum ()
| Makes a new AVRO_NULL datum.
| GenericDatum (bool v)
| Makes a new AVRO_BOOL datum whose value is of type bool. More...
| GenericDatum (int32_t v)
| Makes a new AVRO_INT datum whose value is of type int32_t. More...
| GenericDatum (int64_t v)
| Makes a new AVRO_LONG datum whose value is of type int64_t. More...
| GenericDatum (float v)
| Makes a new AVRO_FLOAT datum whose value is of type float. More...
| GenericDatum (double v)
| Makes a new AVRO_DOUBLE datum whose value is of type double. More...
| GenericDatum (const std::string &v)
| Makes a new AVRO_STRING datum whose value is of type std::string. More...
| GenericDatum (const std::vector< uint8_t > &v)
| Makes a new AVRO_BYTES datum whose value is of type std::vector<uint8_t>. More...
| GenericDatum (const NodePtr &schema)
| Constructs a datum corresponding to the given avro type. More...
template<typename T >
| GenericDatum (const NodePtr &schema, const T &v)
| Constructs a datum corresponding to the given avro type and set the value. More...
| GenericDatum (const ValidSchema &schema)
| Constructs a datum corresponding to the given avro type. More...

## Protected Member Functions
| GenericDatum (Type t)
| GenericDatum (Type t, LogicalType logicalType)
template<typename T >
| GenericDatum (Type t, LogicalType logicalType, const T &v)
void | init (const NodePtr &schema)

## Protected Attributes
Type | type_
LogicalType | logicalType_
boost::any | value_

## Detailed Description

Generic datum which can hold any Avro type.

The datum has a type and a value. The type is one of the Avro data types. The C++ type for value corresponds to the Avro type.

- An Avro `null` corresponds to no C++ type. It is illegal to to try to access values for `null`.
- Avro `boolean` maps to C++ `bool`
- Avro `int` maps to C++ `int32_t`.
- Avro `long` maps to C++ `int64_t`.
- Avro `float` maps to C++ `float`.
- Avro `double` maps to C++ `double`.
- Avro `string` maps to C++ `std::string`.
- Avro `bytes` maps to C++ `std::vector<uint_t>`.
- Avro `fixed` maps to C++ class `GenericFixed`.
- Avro `enum` maps to C++ class `GenericEnum`.
- Avro `array` maps to C++ class `GenericArray`.
- Avro `map` maps to C++ class `GenericMap`.
- There is no C++ type corresponding to Avro `union`. The object should have the C++ type corresponding to one of the constituent types of the union.

## Constructor & Destructor Documentation

## ◆ GenericDatum() [1/10]

avro::GenericDatum::GenericDatum | ( | bool | v | ) |
| inline

Makes a new AVRO_BOOL datum whose value is of type bool.

We don't make this explicit constructor because we want to allow automatic conversion

## ◆ GenericDatum() [2/10]

avro::GenericDatum::GenericDatum | ( | int32_t | v | ) |
| inline

Makes a new AVRO_INT datum whose value is of type int32_t.

We don't make this explicit constructor because we want to allow automatic conversion

## ◆ GenericDatum() [3/10]

avro::GenericDatum::GenericDatum | ( | int64_t | v | ) |
| inline

Makes a new AVRO_LONG datum whose value is of type int64_t.

We don't make this explicit constructor because we want to allow automatic conversion

## ◆ GenericDatum() [4/10]

avro::GenericDatum::GenericDatum | ( | float | v | ) |
| inline

Makes a new AVRO_FLOAT datum whose value is of type float.

We don't make this explicit constructor because we want to allow automatic conversion

## ◆ GenericDatum() [5/10]

avro::GenericDatum::GenericDatum | ( | double | v | ) |
| inline

Makes a new AVRO_DOUBLE datum whose value is of type double.

We don't make this explicit constructor because we want to allow automatic conversion

## ◆ GenericDatum() [6/10]

avro::GenericDatum::GenericDatum | ( | const std::string & | v | ) |
| inline

Makes a new AVRO_STRING datum whose value is of type std::string.

We don't make this explicit constructor because we want to allow automatic conversion

## ◆ GenericDatum() [7/10]

avro::GenericDatum::GenericDatum | ( | const std::vector< uint8_t > & | v | ) |
| inline

Makes a new AVRO_BYTES datum whose value is of type std::vector<uint8_t>.

We don't make this explicit constructor because we want to allow automatic conversion

## ◆ GenericDatum() [8/10]

avro::GenericDatum::GenericDatum | ( | const NodePtr & | schema | ) |

Constructs a datum corresponding to the given avro type.

The value will the appropriate default corresponding to the data type.

Parameters

  schema | The schema that defines the avro type. We don't make this explicit constructor because we want to allow automatic conversion

## ◆ GenericDatum() [9/10]

template<typename T >

avro::GenericDatum::GenericDatum | ( | const NodePtr & | schema,
|  | const T & | v
| ) |  |
| inline

Constructs a datum corresponding to the given avro type and set the value.

Parameters

  schema | The schema that defines the avro type.
  v | The value for this type.

## ◆ GenericDatum() [10/10]

avro::GenericDatum::GenericDatum | ( | const ValidSchema & | schema | ) |
| explicit

Constructs a datum corresponding to the given avro type.

The value will the appropriate default corresponding to the data type.

Parameters

  schema | The schema that defines the avro type.

## Member Function Documentation

## ◆ selectBranch()

void avro::GenericDatum::selectBranch | ( | size_t | branch | ) |
| inline

Selects a new branch in the union if this is a union.

See also
  isUnion().

## ◆ unionBranch()

size_t avro::GenericDatum::unionBranch | ( |  | ) | const
| inline

Returns the index of the current branch, if this is a union.

See also
  isUnion().

## ◆ value() [1/2]

template<typename T >

T & avro::GenericDatum::value

Returns the reference to the value held by this datum, which can be used to change the contents.

Please note that only value can be changed, the data type of the value held cannot be changed.

T The type for the value. This must correspond to the avro type returned by type().

References avro::AVRO_UNION.

## ◆ value() [2/2]

template<typename T >

const T & avro::GenericDatum::value

Returns the value held by this datum.

T The type for the value. This must correspond to the avro type returned by type().

References avro::AVRO_UNION.

The documentation for this class was generated from the following file:

- api/GenericDatum.hh