jklamer commented on a change in pull request #1602:
URL: https://github.com/apache/avro/pull/1602#discussion_r828731421
##########
File path: lang/rust/avro/src/encode.rs
##########
@@ -50,24 +51,25 @@ fn encode_int(i: i32, buffer: &mut Vec<u8>) {
/// **NOTE** This will not perform schema validation. The value is assumed to
/// be valid with regards to the schema. Schema are needed only to guide the
/// encoding for complex type values.
-pub fn encode_ref(value: &Value, schema: &Schema, buffer: &mut Vec<u8>) {
+pub fn encode_ref(
+ value: &Value,
+ schema: &Schema,
+ names: &HashMap<Name, &Schema>,
+ enclosing_namespace: &Namespace,
+ buffer: &mut Vec<u8>,
+) {
fn encode_ref0(
value: &Value,
schema: &Schema,
+ names: &HashMap<Name, &Schema>,
buffer: &mut Vec<u8>,
- schemas_by_name: &mut HashMap<Name, Schema>,
+ enclosing_namespace: &Namespace,
) {
- match &schema {
- Schema::Ref { ref name } => {
- let resolved = schemas_by_name.get(name).unwrap();
- return encode_ref0(value, resolved, buffer, &mut
schemas_by_name.clone());
- }
- Schema::Record { ref name, .. }
- | Schema::Enum { ref name, .. }
- | Schema::Fixed { ref name, .. } => {
- schemas_by_name.insert(name.clone(), schema.clone());
- }
- _ => (),
+ if let Schema::Ref { ref name } = schema {
+ let resolved = *names
+ .get(&name.fully_qualified_name(enclosing_namespace))
+ .unwrap();
Review comment:
Removed all panics from encode
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]