Пример #1
0
static int file_read_header(avro_reader_t reader,
			    avro_schema_t * writers_schema, char *sync,
			    int synclen)
{
	int rval;
	avro_schema_t meta_schema;
	avro_schema_t meta_values_schema;
	avro_datum_t meta;
	char magic[4];
	avro_datum_t schema_bytes;
	char *p;
	int64_t len;
	avro_schema_error_t schema_error;

	check(rval, avro_read(reader, magic, sizeof(magic)));
	if (magic[0] != 'O' || magic[1] != 'b' || magic[2] != 'j'
	    || magic[3] != 1) {
		return EILSEQ;
	}
	meta_values_schema = avro_schema_bytes();
	meta_schema = avro_schema_map(meta_values_schema);
	rval = avro_read_data(reader, meta_schema, NULL, &meta);
	if (rval) {
		return EILSEQ;
	}
	check(rval, avro_map_get(meta, "avro.schema", &schema_bytes));
	avro_bytes_get(schema_bytes, &p, &len);
	check(rval,
	      avro_schema_from_json(p, len, writers_schema, &schema_error));
	avro_schema_decref(meta);
	return avro_read(reader, sync, synclen);
}
Пример #2
0
static int
avro_datum_value_grab_bytes(const avro_value_iface_t *iface,
			    const void *vself, avro_wrapped_buffer_t *dest)
{
	AVRO_UNUSED(iface);
	const avro_datum_t  self = (const avro_datum_t) vself;
	check_param(EINVAL, self, "datum instance");

	int  rval;
	char  *bytes;
	int64_t  sz;
	check(rval, avro_bytes_get(self, &bytes, &sz));

	/* nothing clever, just make a copy */
	return avro_wrapped_buffer_new_copy(dest, bytes, sz);
}
Пример #3
0
static int
avro_datum_value_get_bytes(const avro_value_iface_t *iface,
			   const void *vself, const void **buf, size_t *size)
{
	AVRO_UNUSED(iface);
	const avro_datum_t  self = (const avro_datum_t) vself;
	check_param(EINVAL, self, "datum instance");

	int  rval;
	char  *bytes;
	int64_t  sz;
	check(rval, avro_bytes_get(self, &bytes, &sz));
	if (buf != NULL) {
		*buf = (const void *) bytes;
	}
	if (size != NULL) {
		*size = sz;
	}
	return 0;
}