public static AvroProtocol Parse(string text) => AvroParser.ReadProtocol(text);
static int GenerateCode(string projectName, Options options) { var namespaceMapping = options.Namespace.Select(r => r.Split('.')).ToDictionary(k => k[0], v => v[1]); var codeGen = new CodeGen(namespaceMapping); var codeWriter = new CodeWriter(); var protocolHashes = new Dictionary <string, string>(); var typeHashes = new Dictionary <string, string>(); if (options.Schema) { Log("Parsing Schema File(s) ...", options.Quiet); foreach (var schemaFile in GetFiles(options.Path, ".avsc")) { Log($" '{schemaFile.FullName}' ...", options.Quiet); using (var reader = new StreamReader(schemaFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8)) { var text = reader.ReadToEnd(); var schema = AvroParser.ReadSchema(text, out var schemas); codeGen.AddSchemas(schemas); foreach (var s in schemas) { var hash = string.Join("", HASH_FUNC.ComputeHash(Encoding.UTF8.GetBytes(s.ToAvroCanonical())).Select(r => r.ToString("X2"))); if (typeHashes.TryGetValue(s.Name, out var existingHash)) { typeHashes.Add(s.Name, hash); } else if (hash != existingHash) { Log(" Hash mismatch:", options.Quiet); } Log($" T: '{s.FullName}'", options.Quiet); } } } } if (options.Protocol) { Log("Parsing Schema File(s) ...", options.Quiet); foreach (var protocolFile in GetFiles(options.Path, ".avpr")) { Log($" '{protocolFile.FullName}' ...", options.Quiet); using (var reader = new StreamReader(protocolFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8)) { var text = reader.ReadToEnd(); var protocol = AvroParser.ReadProtocol(text, out var schemas); codeGen.AddProtocol(protocol); Log($" P: '{protocol.FullName}'", options.Quiet); foreach (var s in schemas) { Log($" T: '{s.FullName}'", options.Quiet); } } } } codeWriter.WriteProject(options.OutDir, codeGen, projectName); return(0); }