public static Entry CreateEntry(CalithaBinReader reader) { Entry entry = null; byte entryType = reader.ReadByte(); switch (entryType) { case 69: // 'E' entry = new EmptyEntry(); break; case 98: // 'b' entry = new ByteEntry(reader); break; case 66: // 'B' entry = new BooleanEntry(reader); break; case 73: // 'I' entry = new IntegerEntry(reader); break; case 83: // 'S' entry = new StringEntry(reader); break; default: //Unknown throw new CGTStructureException("Unknown entry type"); } return entry; }
/// <summary> /// Reads a CGT and creates all the objects needed to create /// a tokenizer and parser at a later time. /// </summary> /// <param name="stream">The CGT stream.</param> private void ReadFile(Stream stream) { try { Reset(); this.stream = stream; CalithaBinReader reader = new CalithaBinReader(stream); string header = ""; try { header = reader.ReadUnicodeString(); if (! header.StartsWith("GOLD")) throw new CGTStructureException("File header is invalid"); } catch (EndOfStreamException e) { throw new CGTStructureException("File header is invalid",e); } RecordCollection records = new RecordCollection(); while (!(stream.Position == stream.Length)) { records.Add(ReadRecord(reader)); } structure = new CGTStructure(header,records); content = new CGTContent(structure); dfaStates = CreateDFAStates(content); parserStates = CreateParserStates(content); } finally { stream.Close(); } }
private Record ReadRecord(CalithaBinReader reader) { Record record = new Record(); byte entriesHeader = reader.ReadByte(); if (entriesHeader != 77) // 'M' { throw new CGTStructureException("Invalid entries header at byte "+(stream.Position-1)); } ushort entriesCount = reader.ReadUInt16(); for (int i=0;i<entriesCount;i++) { record.Entries.Add(ReadEntry(reader)); } return record; }
private Entry ReadEntry(CalithaBinReader reader) { Entry entry = EntryFactory.CreateEntry(reader); if (entry == null) throw new CGTStructureException("Invalid entry type at byte "+(stream.Position-1)); return entry; }
public ByteEntry(CalithaBinReader reader) { value = reader.ReadByte(); }
public StringEntry(CalithaBinReader reader) { value = reader.ReadUnicodeString(); }
public IntegerEntry(CalithaBinReader reader) { value = reader.ReadInt16(); }
public BooleanEntry(CalithaBinReader reader) { value = reader.ReadBoolean(); }