public BamlRecord ReadRecord() { BamlRecordType recordType = (BamlRecordType)_reader.ReadByte(); BamlRecord record = StaticBamlRecords.GetRecord(recordType); long startPosition = Position; int variableSize = 0; if (record.IsVariableSize) { variableSize = _reader.Read7BitEncodedInt(); } for (int i = 0; i < record.Fields.Length; i++) { record.Fields[i].Value = ReadField(record.Fields[i]); } // this deals with the rare case of undefined padding // at the end of a record. Only allowed for PropertyCustom if (record.IsVariableSize) { int processedSize = (int)(Position - startPosition); int extraPadding = variableSize - processedSize; Debug.Assert(extraPadding >= 0); if (extraPadding > 0) { Debug.Assert(recordType == BamlRecordType.PropertyCustom); byte[] bytes = _reader.ReadBytes(extraPadding); } } return(record); }
public IEnumerable <string> DefaultDumpRecord() { BamlRecord record; BamlRecordType recordType; int variableSize = 0; TextLineSections text; TextLineSections[] textList; recordType = ReadRecordType(out text); yield return(OutputTextLine(text, TextType.Record)); long startPosition = Position; // If we read a bad Record type, dump a few more bytes to help debug. if ((int)recordType >= (int)BamlRecordType.LastRecordType || null == StaticBamlRecords.GetRecord(recordType)) { byte[] bytes = _reader.ReadBytes(64); textList = CutIntoLines(startPosition, bytes, "", ""); foreach (string line in OutputTextLines(textList, TextType.Data)) { yield return(line); } // Go ahead and throw the nullRef/outofBounds exception below... } record = StaticBamlRecords.GetRecord(recordType); Debug.Assert(record != null); if (record.IsVariableSize) { variableSize = Read7bitEncodedInt("size", out text); yield return(OutputTextLine(text, TextType.Size)); } for (int i = 0; i < record.Fields.Length; i++) { object val = ReadField(record.Fields[i], out textList); record.Fields[i].Value = val; if (textList.Length == 1) { ImproveMeaning(record.Fields[i], textList); } TextType textType = TextType.Data; if (val is String) { textType = TextType.String; } foreach (string line in OutputTextLines(textList, textType)) { yield return(line); } } // this deals with the rare case of undefined padding // at the end of a record. Only allowed for PropertyCustom if (record.IsVariableSize) { int processedSize = (int)(Position - startPosition); int extraPadding = variableSize - processedSize; if (extraPadding < 0) { System.Diagnostics.Debugger.Break(); } if (extraPadding > 0) { long pos = Position; byte[] bytes = _reader.ReadBytes(extraPadding); string meaning = "?? custom"; if (recordType == BamlRecordType.PropertyCustom) { meaning = "Custom Data (variable size)"; } textList = CutIntoLines(pos, bytes, meaning, ""); foreach (string line in OutputTextLines(textList, TextType.Data)) { yield return(line); } } } ProcessRecord(record); }