Esempio n. 1
0
        public SymbolTableReader(ISymbolTable symbolTable)
        {
            _symbolTable = symbolTable ?? throw new ArgumentNullException(nameof(symbolTable));

            lock (_symbolTable)
            {
                _maxId = _symbolTable.MaxId;
                _localSymbolsEnumerator = _symbolTable.GetDeclaredSymbolNames().GetEnumerator();
            }

            if (!_symbolTable.IsLocal)
            {
                SetFlag(HAS_NAME, true);
                SetFlag(HAS_VERSION, true);
            }

            //what is this???
            if (_maxId > 0)
            {
                // FIXME: is this ever true?
                SetFlag(HAS_MAX_ID, true);
            }

            _importedTables = _symbolTable.GetImportedTables().ToArray();
            if (_importedTables != null && _importedTables.Length > 0)
            {
                SetFlag(HAS_IMPORT_LIST, true);
            }

            if (_symbolTable.GetImportedMaxId() < _maxId)
            {
                SetFlag(HAS_SYMBOL_LIST, true);
            }
        }
Esempio n. 2
0
        public SymbolTableReader(ISymbolTable symbolTable)
        {
            this.symbolTable = symbolTable ?? throw new ArgumentNullException(nameof(symbolTable));

            lock (this.symbolTable)
            {
                this.maxId = this.symbolTable.MaxId;
                this.localSymbolsEnumerator = this.symbolTable.GetDeclaredSymbolNames().GetEnumerator();
            }

            if (!this.symbolTable.IsLocal)
            {
                this.SetFlag(HAS_NAME, true);
                this.SetFlag(HAS_VERSION, true);
            }

            if (this.maxId > 0)
            {
                this.SetFlag(HAS_MAX_ID, true);
            }

            this.importedTables = symbolTable.GetImportedTables().ToArray();
            if (this.importedTables != null && this.importedTables.Length > 0)
            {
                this.SetFlag(HAS_IMPORT_LIST, true);
            }

            if (this.symbolTable.GetImportedMaxId() < this.maxId)
            {
                this.SetFlag(HAS_SYMBOL_LIST, true);
            }
        }
Esempio n. 3
0
        public SymbolTableReader(ISymbolTable symbolTable)
        {
            this.symbolTable = symbolTable ?? throw new ArgumentNullException(nameof(symbolTable));

            lock (this.symbolTable)
            {
                this.maxId = this.symbolTable.MaxId;
                this.localSymbolsEnumerator = this.symbolTable.GetDeclaredSymbolNames().GetEnumerator();
            }

            if (!this.symbolTable.IsLocal)
            {
                this.SetFlag(HasNameFlag, true);
                this.SetFlag(HasVersionFlag, true);
            }

            if (this.maxId > 0)
            {
                this.SetFlag(HasMaxIdFlag, true);
            }

            this.importedTables = symbolTable.GetImportedTables().ToArray();
            if (this.importedTables != null && this.importedTables.Length > 0)
            {
                this.SetFlag(HasImportListFlag, true);
            }

            if (this.symbolTable.GetImportedMaxId() < this.maxId)
            {
                this.SetFlag(HasSymbolListFlag, true);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Returns a catalog that contains all shared symbol tables that the reader has read so far.
        /// </summary>
        /// <param name="readerTable">The reader's local symbol table. Typically obtained by calling <see cref="IIonReader.GetSymbolTable"/>.</param>
        /// <remarks>
        /// Normally when a text or binary Ion data with shared symbol tables is read, the materialized object (such as
        /// a .Net POCO object or an <see cref="IonDotnet.Tree.IonDatagram"/> does not have the reference to these tables.
        /// As such, systems that want to reuse those shared tables should extract them after reading through all the values.
        /// This method provides a shortcut to do get a catalog that contains those tables.
        /// </remarks>
        public static ICatalog GetReaderCatalog(ISymbolTable readerTable)
        {
            var catalog = new SimpleCatalog();

            foreach (var importedTable in readerTable.GetImportedTables())
            {
                Debug.Assert(importedTable.IsShared);
                if (importedTable.IsSystem || importedTable.IsSubstitute)
                {
                    continue;
                }

                catalog.PutTable(importedTable);
            }

            return(catalog);
        }
Esempio n. 5
0
 private static void RoundTrip_AssertBinary(IIonValue datagram, ISymbolTable readerTable)
 {
     using (var ms = new MemoryStream())
     {
         using (var writer = IonBinaryWriterBuilder.Build(ms, readerTable.GetImportedTables()))
         {
             datagram.WriteTo(writer);
             writer.Finish();
             var bin       = ms.ToArray();
             var catalog   = Symbols.GetReaderCatalog(readerTable);
             var datagram2 = IonLoader.WithReaderOptions(new ReaderOptions {
                 Catalog = catalog, Format = ReaderFormat.Binary
             }).Load(bin);
             AssertDatagramEquivalent(datagram, datagram2);
         }
     }
 }
Esempio n. 6
0
        private static void RoundTrip_AssertText(IIonValue datagram, ISymbolTable readerTable)
        {
            var sw     = new StringWriter();
            var writer = IonTextWriterBuilder.Build(sw, new IonTextOptions {
                PrettyPrint = true
            }, readerTable.GetImportedTables());

            datagram.WriteTo(writer);
            writer.Finish();
            var text = sw.ToString();

            Console.WriteLine(text);
            var catalog   = Symbols.GetReaderCatalog(readerTable);
            var datagram2 = IonLoader.WithReaderOptions(new ReaderOptions {
                Catalog = catalog
            }).Load(text);

            AssertDatagramEquivalent(datagram, datagram2);
        }