pub struct Schema {
pub fields: Vec<Field>,
pub lrecl_fixed: Option<u32>,
pub tail_odo: Option<TailODO>,
pub fingerprint: String,
}Expand description
A parsed COBOL copybook schema
Fields§
§fields: Vec<Field>Root fields in the schema
lrecl_fixed: Option<u32>Fixed record length (LRECL) if applicable
tail_odo: Option<TailODO>Tail ODO information if present
fingerprint: StringSchema fingerprint for provenance tracking
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn from_fields(fields: Vec<Field>) -> Self
pub fn from_fields(fields: Vec<Field>) -> Self
Create a schema from a list of fields
Sourcepub fn calculate_fingerprint(&mut self)
pub fn calculate_fingerprint(&mut self)
Calculate the schema fingerprint using SHA-256
Sourcepub fn create_canonical_json(&self) -> String
pub fn create_canonical_json(&self) -> String
Create canonical JSON representation for fingerprinting
Sourcepub fn find_field(&self, path: &str) -> Option<&Field>
pub fn find_field(&self, path: &str) -> Option<&Field>
Find a field by path
Looks up a field by its fully-qualified dotted path (e.g., "REC.ID").
Searches recursively through all nested groups.
§Examples
use copybook_core::parse_copybook;
let schema = parse_copybook("01 REC.\n 05 ID PIC 9(5).\n 05 NAME PIC X(20).").unwrap();
let field = schema.find_field("REC.ID").unwrap();
assert_eq!(field.name, "ID");
assert_eq!(field.len, 5);
assert!(schema.find_field("NONEXISTENT").is_none());Sourcepub fn find_field_or_alias(&self, name_or_path: &str) -> Option<&Field>
pub fn find_field_or_alias(&self, name_or_path: &str) -> Option<&Field>
Find a field by path or RENAMES alias name
This method first tries to find a field by its path using standard lookup. If not found, it searches for a level-66 RENAMES field whose name matches the query and returns that alias field.
§Examples
let schema: Schema = // ... parsed schema with RENAMES
// Direct field lookup
if let Some(field) = schema.find_field_or_alias("CUSTOMER-INFO") {
println!("Found field: {}", field.name);
}
// Alias lookup - finds level-66 field
if let Some(alias) = schema.find_field_or_alias("CUSTOMER-DETAILS") {
if alias.level == 66 {
println!("Found RENAMES alias: {}", alias.name);
}
}Sourcepub fn resolve_alias_to_target(&self, name_or_path: &str) -> Option<&Field>
pub fn resolve_alias_to_target(&self, name_or_path: &str) -> Option<&Field>
Resolve a RENAMES alias to its first target field
If the query matches a level-66 RENAMES alias, this method returns the first storage-bearing field covered by that alias (from resolved_renames.members). Otherwise, it performs standard field lookup.
This is useful for codec integration where you want to decode/encode data using an alias name but need the actual storage field.
§Examples
let schema: Schema = // ... parsed schema with RENAMES
// Resolve alias to target field
if let Some(target) = schema.resolve_alias_to_target("CUSTOMER-DETAILS") {
// target will be CUSTOMER-INFO (or its first member)
println!("Alias resolves to: {}", target.name);
}Sourcepub fn find_redefining_fields<'a>(&'a self, target_path: &str) -> Vec<&'a Field>
pub fn find_redefining_fields<'a>(&'a self, target_path: &str) -> Vec<&'a Field>
Find all fields that redefine the field at the given path
Returns a list of fields whose redefines_of points to target_path.
§Examples
use copybook_core::parse_copybook;
let schema = parse_copybook(
"01 REC.\n 05 AMT-NUM PIC 9(5)V99.\n 05 AMT-TXT REDEFINES AMT-NUM PIC X(7)."
).unwrap();
let redefs = schema.find_redefining_fields("AMT-NUM");
assert_eq!(redefs.len(), 1);
assert_eq!(redefs[0].name, "AMT-TXT");Sourcepub fn all_fields(&self) -> Vec<&Field>
pub fn all_fields(&self) -> Vec<&Field>
Get all fields in a flat list (pre-order traversal)
Returns every field in the schema, including nested children, as a flat vector in pre-order (depth-first) traversal order.
§Examples
use copybook_core::parse_copybook;
let schema = parse_copybook("01 REC.\n 05 ID PIC 9(5).\n 05 NAME PIC X(20).").unwrap();
let all = schema.all_fields();
assert_eq!(all.len(), 3); // REC group + 2 leaf fields
assert_eq!(all[0].name, "REC");
assert_eq!(all[1].name, "ID");
assert_eq!(all[2].name, "NAME");