Ejemplo n.º 1
0
static int
avro_datum_value_set_float(const avro_value_iface_t *iface,
			   void *vself, float val)
{
	AVRO_UNUSED(iface);
	avro_datum_t  self = (avro_datum_t) vself;
	check_param(EINVAL, self, "datum instance");
	return avro_float_set(self, val);
}
Ejemplo n.º 2
0
static int json_t_to_avro_value_helper(
		const avro_schema_t schema, const json_t *json, avro_datum_t datum)
{
	switch (schema->type) {
		case AVRO_BOOLEAN:
			check_param(EINVAL, json_is_boolean(json), "JSON boolean");
			if (avro_boolean_set(datum, json_is_true(json))) return EINVAL;
			return 0;
		case AVRO_DOUBLE:
			check_param(EINVAL, json_is_real(json), "JSON float");
			if (avro_double_set(datum, json_real_value(json))) return EINVAL;
			return 0;
		case AVRO_FLOAT:
			check_param(EINVAL, json_is_real(json), "JSON float");
			if (avro_float_set(datum, json_real_value(json))) return EINVAL;
			return 0;
		case AVRO_INT32:
			check_param(EINVAL, json_is_integer(json), "JSON integer");
			if (avro_int32_set(datum, json_integer_value(json))) return EINVAL;
			return 0;
		case AVRO_INT64:
			check_param(EINVAL, json_is_integer(json), "JSON integer");
			if (avro_int64_set(datum, json_integer_value(json))) return EINVAL;
			return 0;
		case AVRO_NULL:
			check_param(EINVAL, json_is_null(json), "JSON null");
			return 0;
		case AVRO_STRING: {
			check_param(EINVAL, json_is_string(json), "JSON string");
			if (avro_string_set(datum, json_string_value(json))) return EINVAL;
			return 0;
		}
		case AVRO_BYTES:
		case AVRO_ARRAY:
		case AVRO_ENUM:
		case AVRO_FIXED:
		case AVRO_MAP:
		case AVRO_RECORD:
		case AVRO_UNION:
		default:
			// TODO
			avro_set_error("json_t_to_avro_value: unimplemented type");
			return EINVAL;
	}
}