मैं ऑब्जेक्टिव-सी में प्रोग्रामिंग कर रहा हूँ के साथ एवरो सरणी प्रकार के arrary डेटा निर्धारित किया है। मैं डेटा क्रमिकरण के लिए Apache 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
}
]
}
मेरी ऑब्जेक्टिव-सी कोड में, मैं Teacher
ऑब्जेक्ट की श्रृंखला है, प्रत्येक शिक्षक वस्तु name
& age
का मान है।
मैं स्कीमा ऊपर दिखा साथ एवरो का उपयोग कर फाइल करने के लिए शिक्षक सरणी डेटा लिखने के लिए चाहते हैं। मैं मुख्य रूप से चिंता करता हूं कि ऊपर दिए गए स्कीमा में परिभाषित Employees
सरणी में डेटा कैसे लिखना है।
यहाँ मेरी कोड है (मैं यह करने के लिए सी शैली कोड का उपयोग करने के लिए है, मैं पालन 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 ++;
}
सवाल मैं पूछना चाहता हूँ इसके बाद के संस्करण कोड टिप्पणी में वास्तव में है।
मैं उस एवरो प्रलेखन का पालन कर रहा हूं, लेकिन मैं हार गया हूं कि मैं प्रत्येक teacher
को employees
में कैसे जोड़ सकता हूं? मेरे उपरोक्त कोड में, मैंने केवल प्रत्येक शिक्षक के name
को employees
सरणी में जोड़ा।