ios使用 c语言数组赋值,ios – 使用C语言将arrary数据设置为Avro数组类型

我在Objective-C编程.我使用

Apache Avro进行数据序列化.

我的avro架构是这样的:

{

"name": "School",

"type":"record",

"fields":[

{

"name":"Employees",

"type":["null", {"type": "array",

"items":{

"name":"Teacher",

"type":"record",

"fields":[

{"name":"name", "type":"string"}

{"name":"age", "type":"int"}

]

}

}

],

"default":null

}

]

}

在我的Objective-C代码中,我有一个教师对象数组,每个教师对象包含name&的值.年龄.

我想使用Avro将教师数组数据写入文件,并显示上面的模式.我主要关注如何将数据写入上述模式中定义的Employees数组.

这是我的代码(我必须使用C样式代码来执行此操作,我遵循Avro C documentation):

// I don't show this function, it constructs the a `avro_value_t` based on the schema. No problem here.

avro_value_t school = [self constructSchoolValueForSchema];

// get "Employees" field

avro_value_t employees;

avro_value_get_by_name(school, "employees", &employees, 0);

int idx = 0;

for (Teacher *teacher in teacherArray) {

// get name and age

NSString *name = teacher.name;

int age = teacher.age;

// set value to avro data type.

// here 'unionField' is the field of 'Employees', it is a Avro union type which is either null or an array as defined in schema above

avro_value_t field, unionField;

avro_value_set_branch(&employees, 1, &unionField);

// based on documentation, I should use 'avro_value_append'

avro_value_append(&employees, name, idx);

// I get confused here!!!!

// in above line of code, I append 'name' to 'employees',

//which looks not correct,

// because the 'Employees' array is an array of 'Teacher', not arrary of 'name'

// What is the correct way to add teacher to 'employees' ?

idx ++;

}

我想问的问题实际上是在上面的代码注释中.

我正在关注Avro C文档,但是我迷失了如何将每位老师添加到员工中?在上面的代码中,我只将每个教师的名字添加到employees数组中.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值