Exemple #1
0
static int test_bytes(void)
{
    char bytes[] = { 0xDE, 0xAD, 0xBE, 0xEF };
    avro_schema_t writer_schema = avro_schema_bytes();
    avro_datum_t datum;
    avro_datum_t expected_datum;

    datum = avro_givebytes(bytes, sizeof(bytes), NULL);
    write_read_check(writer_schema, datum, NULL, NULL, "bytes");
    test_json(datum, "\"\\u00de\\u00ad\\u00be\\u00ef\"");
    avro_datum_decref(datum);
    avro_schema_decref(writer_schema);

    datum = avro_givebytes(NULL, 0, NULL);
    avro_givebytes_set(datum, bytes, sizeof(bytes), NULL);
    expected_datum = avro_givebytes(bytes, sizeof(bytes), NULL);
    if (!avro_datum_equal(datum, expected_datum)) {
        fprintf(stderr,
                "Expected equal bytes instances.\n");
        exit(EXIT_FAILURE);
    }
    avro_datum_decref(datum);
    avro_datum_decref(expected_datum);

    // The following should bork if we don't copy the bytes value
    // correctly (since we'll try to free a static string).

    datum = avro_bytes("original", 8);
    avro_bytes_set(datum, "alsothis", 8);
    avro_datum_decref(datum);

    avro_schema_decref(writer_schema);
    return 0;
}
static int
avro_datum_value_set_bytes(const avro_value_iface_t *iface,
			   void *vself, void *buf, size_t size)
{
	AVRO_UNUSED(iface);
	avro_datum_t  self = (avro_datum_t) vself;
	check_param(EINVAL, self, "datum instance");
	return avro_bytes_set(self, (const char *) buf, size);
}