Skip to content

Commit

Permalink
AVRO-2773: [C] Add get_decimal and set_decimal
Browse files Browse the repository at this point in the history
This patch adds "api level" support for decimal objects: these functions allow
manipulating decimal objects at a higher-level than the underlying bytes and
fixed objects.

Signed-off-by: Sahil Kang <sahil.kang@asilaycomputing.com>
Signed-off-by: Sahil Kang <sahilkang@google.com>
  • Loading branch information
SahilKang committed May 8, 2024
1 parent c2d7509 commit 30da03a
Show file tree
Hide file tree
Showing 6 changed files with 307 additions and 17 deletions.
23 changes: 23 additions & 0 deletions lang/c/src/avro/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,24 @@ struct avro_value_iface {
int (*set_branch)(const avro_value_iface_t *iface,
void *self, int discriminant,
avro_value_t *branch);

/*
* Returns the unscaled value, along with the values to the left and
* right hand sides of the decimal point. Any of unscaled, lhs, and rhs
* may be NULL.
*/
int (*get_decimal)(const avro_value_iface_t *iface,
const void *self, int64_t *unscaled,
int64_t *lhs, uint64_t *rhs);

/*
* Sets the decimal value from either unscaled or lhs and rhs. If
* unscaled is non-NULL, lhs and rhs are ignored. Otherwise, lhs and
* rhs must be non-NULL.
*/
int (*set_decimal)(const avro_value_iface_t *iface,
void *self, const int64_t *unscaled,
const int64_t *lhs, const uint64_t *rhs);
};


Expand Down Expand Up @@ -494,5 +512,10 @@ avro_value_to_json(const avro_value_t *value,
#define avro_value_set_branch(value, discriminant, branch) \
avro_value_call(value, set_branch, EINVAL, discriminant, branch)

#define avro_value_get_decimal(value, unscaled, lhs, rhs) \
avro_value_call(value, get_decimal, EINVAL, unscaled, lhs, rhs)
#define avro_value_set_decimal(value, unscaled, lhs, rhs) \
avro_value_call(value, set_decimal, EINVAL, unscaled, lhs, rhs)

CLOSE_EXTERN
#endif
4 changes: 3 additions & 1 deletion lang/c/src/datum_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,5 +768,7 @@ avro_value_iface_t AVRO_DATUM_VALUE_CLASS =
/* compound setters */
avro_datum_value_append,
avro_datum_value_add,
avro_datum_value_set_branch
avro_datum_value_set_branch,
NULL, /* get_decimal */
NULL, /* set_decimal */
};

0 comments on commit 30da03a

Please sign in to comment.