static int
array_equal(struct avro_array_datum_t *a, struct avro_array_datum_t *b)
{
	if (!avro_schema_equal(a->schema, b->schema)) {
		return 0;
	}

	long i;

	if (a->els->num_entries != b->els->num_entries) {
		return 0;
	}
	for (i = 0; i < a->els->num_entries; i++) {
		union {
			st_data_t data;
			avro_datum_t datum;
		} ael, bel;
		st_lookup(a->els, i, &ael.data);
		st_lookup(b->els, i, &bel.data);
		if (!avro_datum_equal(ael.datum, bel.datum)) {
			return 0;
		}
	}
	return 1;
}
static int fixed_equal(struct avro_fixed_datum_t *a,
		       struct avro_fixed_datum_t *b)
{
	if (!avro_schema_equal(a->schema, b->schema)) {
		return 0;
	}

	return a->size == b->size && memcmp(a->bytes, b->bytes, a->size) == 0;
}
static int union_equal(struct avro_union_datum_t *a,
		       struct avro_union_datum_t *b)
{
	if (!avro_schema_equal(a->schema, b->schema)) {
		return 0;
	}

	return a->discriminant == b->discriminant && avro_datum_equal(a->value, b->value);
}
Exemple #4
0
int
avro_value_cmp(avro_value_t *val1, avro_value_t *val2)
{
	avro_schema_t  schema1 = avro_value_get_schema(val1);
	avro_schema_t  schema2 = avro_value_get_schema(val2);
	if (!avro_schema_equal(schema1, schema2)) {
		return 0;
	}

	return avro_value_cmp_fast(val1, val2);
}
Exemple #5
0
int
avro_value_copy(avro_value_t *dest, const avro_value_t *src)
{
	avro_schema_t  dest_schema = avro_value_get_schema(dest);
	avro_schema_t  src_schema = avro_value_get_schema(src);
	if (!avro_schema_equal(dest_schema, src_schema)) {
		avro_set_error("Schemas don't match");
		return EINVAL;
	}

	return avro_value_copy_fast(dest, src);
}
static int map_equal(struct avro_map_datum_t *a, struct avro_map_datum_t *b)
{
	if (!avro_schema_equal(a->schema, b->schema)) {
		return 0;
	}

	struct st_equal_args args = { 1, b->map };
	if (a->map->num_entries != b->map->num_entries) {
		return 0;
	}
	st_foreach(a->map, st_equal_foreach, (st_data_t) & args);
	return args.rval;
}
static int record_equal(struct avro_record_datum_t *a,
			struct avro_record_datum_t *b)
{
	if (!avro_schema_equal(a->schema, b->schema)) {
		return 0;
	}

	struct st_equal_args args = { 1, b->fields_byname };
	if (a->fields_byname->num_entries != b->fields_byname->num_entries) {
		return 0;
	}
	st_foreach(a->fields_byname, st_equal_foreach, (st_data_t) & args);
	return args.rval;
}
Exemple #8
0
static int
schema_record_equal(struct avro_record_schema_t *a,
		    struct avro_record_schema_t *b)
{
	long i;
	if (strcmp(a->name, b->name)) {
		/*
		 * They have different names 
		 */
		return 0;
	}
	if (nullstrcmp(a->space, b->space)) {
		return 0;
	}
	if (a->fields->num_entries != b->fields->num_entries) {
		/* They have different numbers of fields */
		return 0;
	}
	for (i = 0; i < a->fields->num_entries; i++) {
		union {
			st_data_t data;
			struct avro_record_field_t *f;
		} fa, fb;
		st_lookup(a->fields, i, &fa.data);
		if (!st_lookup(b->fields, i, &fb.data)) {
			return 0;
		}
		if (strcmp(fa.f->name, fb.f->name)) {
			/*
			 * They have fields with different names 
			 */
			return 0;
		}
		if (!avro_schema_equal(fa.f->type, fb.f->type)) {
			/*
			 * They have fields with different schemas 
			 */
			return 0;
		}
	}
	return 1;
}
Exemple #9
0
static int
schema_union_equal(struct avro_union_schema_t *a, struct avro_union_schema_t *b)
{
	long i;
	for (i = 0; i < a->branches->num_entries; i++) {
		union {
			st_data_t data;
			avro_schema_t schema;
		} ab, bb;
		st_lookup(a->branches, i, &ab.data);
		if (!st_lookup(b->branches, i, &bb.data)) {
			return 0;
		}
		if (!avro_schema_equal(ab.schema, bb.schema)) {
			/*
			 * They don't have the same schema types 
			 */
			return 0;
		}
	}
	return 1;
}
avro_schema_t r_kv_get_schema(kv_store_t *kvstore,
                             const char *space,
                             const char *name) {
    int nsch, i;
    avro_schema_t *schemas = NULL, schema = NULL;

    if (!kvstore || !name) {
        return NULL;
    }

    schema = avro_schema_record(name, space);
    nsch = kv_avro_get_current_schemas(kvstore, &schemas);
    PRINTF("r_kv_get_schema, name = %s, space = %s, nsch = %d\n", name, space, nsch);
    for (i = 0; i < nsch; i++) {
        avro_schema_t sch = schemas[i];
        if (avro_typeof(sch) == AVRO_RECORD &&
            avro_schema_equal(schema, sch)) {
            avro_schema_decref(schema);
            return sch;
        }
    }
    avro_schema_decref(schema);
    return NULL;
}
Exemple #11
0
int process_file(const char *in_filename, const char *out_filename)
{
	avro_file_reader_t  reader;
	avro_file_writer_t  writer;

	if (in_filename == NULL) {
		if (avro_file_reader_fp(stdin, "<stdin>", 0, &reader)) {
			fprintf(stderr, "Error opening <stdin>:\n  %s\n",
				avro_strerror());
			return 1;
		}
	} else {
		if (avro_file_reader(in_filename, &reader)) {
			fprintf(stderr, "Error opening %s:\n  %s\n",
				in_filename, avro_strerror());
			return 1;
		}
	}

	avro_schema_t  wschema;
	wschema = avro_file_reader_get_writer_schema(reader);

	/* Check that the reader schema is the same as the writer schema */
	{
		avro_schema_t oschema;
		avro_file_reader_t oreader;

		if (avro_file_reader(out_filename, &oreader)) {
			fprintf(stderr, "Error opening %s:\n   %s\n",
					out_filename, avro_strerror());
			avro_file_reader_close(reader);
			return 1;
		}

		oschema = avro_file_reader_get_writer_schema(oreader);

		if (avro_schema_equal(oschema, wschema) == 0) {
			fprintf(stderr, "Error: reader and writer schema are not equal.\n");
			avro_file_reader_close(oreader);
			avro_file_reader_close(reader);
			return 1;
		}

		avro_file_reader_close(oreader);
		avro_schema_decref(oschema);
	}

	if (avro_file_writer_open(out_filename, &writer)) {
		fprintf(stderr, "Error opening %s:\n   %s\n",
				out_filename, avro_strerror());
		avro_file_reader_close(reader);
		return 1;
	}

	avro_value_iface_t  *iface;
	avro_value_t  value;

	iface = avro_generic_class_from_schema(wschema);
	avro_generic_value_new(iface, &value);

	while (avro_file_reader_read_value(reader, &value) == 0) {
		if (avro_file_writer_append_value(writer, &value)) {
			fprintf(stderr, "Error writing to %s:\n  %s\n",
				out_filename, avro_strerror());
			return 1;
		}
		avro_value_reset(&value);
	}

	avro_file_reader_close(reader);
	avro_file_writer_close(writer);
	avro_value_decref(&value);
	avro_value_iface_decref(iface);
	avro_schema_decref(wschema);

	return 0;
}
static int enum_equal(struct avro_enum_datum_t *a, struct avro_enum_datum_t *b)
{
	return avro_schema_equal(a->schema, b->schema) && a->value == b->value;
}
Exemple #13
0
static int
schema_array_equal(struct avro_array_schema_t *a, struct avro_array_schema_t *b)
{
	return avro_schema_equal(a->items, b->items);
}
Exemple #14
0
static int
schema_map_equal(struct avro_map_schema_t *a, struct avro_map_schema_t *b)
{
	return avro_schema_equal(a->values, b->values);
}