Example #1
0
int avro_schema_to_json(const avro_schema_t schema, avro_writer_t out)
{
	check_param(EINVAL, is_avro_schema(schema), "schema");
	check_param(EINVAL, out, "writer");

	int rval;

	if (is_avro_primitive(schema)) {
		check(rval, avro_write_str(out, "{\"type\":\""));
	}

	switch (avro_typeof(schema)) {
	case AVRO_STRING:
		check(rval, avro_write_str(out, "string"));
		break;
	case AVRO_BYTES:
		check(rval, avro_write_str(out, "bytes"));
		break;
	case AVRO_INT32:
		check(rval, avro_write_str(out, "int"));
		break;
	case AVRO_INT64:
		check(rval, avro_write_str(out, "long"));
		break;
	case AVRO_FLOAT:
		check(rval, avro_write_str(out, "float"));
		break;
	case AVRO_DOUBLE:
		check(rval, avro_write_str(out, "double"));
		break;
	case AVRO_BOOLEAN:
		check(rval, avro_write_str(out, "boolean"));
		break;
	case AVRO_NULL:
		check(rval, avro_write_str(out, "null"));
		break;
	case AVRO_RECORD:
		return write_record(out, avro_schema_to_record(schema));
	case AVRO_ENUM:
		return write_enum(out, avro_schema_to_enum(schema));
	case AVRO_FIXED:
		return write_fixed(out, avro_schema_to_fixed(schema));
	case AVRO_MAP:
		return write_map(out, avro_schema_to_map(schema));
	case AVRO_ARRAY:
		return write_array(out, avro_schema_to_array(schema));
	case AVRO_UNION:
		return write_union(out, avro_schema_to_union(schema));
	case AVRO_LINK:
		return write_link(out, avro_schema_to_link(schema));
	}

	if (is_avro_primitive(schema)) {
		return avro_write_str(out, "\"}");
	}
	avro_set_error("Unknown schema type");
	return EINVAL;
}
Example #2
0
File: dlink.c Project: tcbabu/kglib
int Dwrite(Dlink *L,FILE *fp,int write_link(FILE *f,void *buf)) {
 int count,i;
 D_l *tmp;
 tmp = L->st;
 if(tmp==NULL) return 1;
 while(tmp !=NULL) {
  if(write_link(fp,tmp->bf) <=0 ) {
    return -1;
  }
  tmp  = tmp->nx;
 }
 return 1;
}