Exemplo n.º 1
0
        public void RespectPrettyTextSerializationFormat()
        {
            var serializer =
                new IonSerializer(new IonSerializationOptions {
                Format = IonSerializationFormat.PRETTY_TEXT
            });
            MemoryStream testStream = (MemoryStream)serializer.Serialize(TestObjects.John);
            string       testString = System.Text.Encoding.UTF8.GetString(testStream.ToArray());

            IIonValue    ionValue             = IonLoader.Default.Load(TestObjects.JohnIonText).GetElementAt(0);
            StringWriter expectedStringWriter = new StringWriter();

            using (var writer =
                       IonTextWriterBuilder.Build(expectedStringWriter, new IonTextOptions {
                PrettyPrint = true
            }))
            {
                ionValue.WriteTo(writer);
                writer.Finish();
            }

            string expectedString = expectedStringWriter.ToString();

            Assert.AreEqual(expectedString, testString);
        }
Exemplo n.º 2
0
            internal override IIonReader GetIonReader(IIonValue ionValue)
            {
                MemoryStream ms     = new MemoryStream();
                IIonWriter   writer = IonBinaryWriterBuilder.Build(ms);

                ionValue.WriteTo(writer);
                writer.Flush();
                return(IonReaderBuilder.Build(ms.ToArray()));
            }
        public static ValueHolder CreateValueHolder(IIonValue ionValue)
        {
            MemoryStream stream = new MemoryStream();

            using (var writer = IonBinaryWriterBuilder.Build(stream))
            {
                ionValue.WriteTo(writer);
                writer.Finish();
            }

            var valueHolder = new ValueHolder
            {
                IonBinary = new MemoryStream(stream.GetWrittenBuffer())
            };

            return(valueHolder);
        }
Exemplo n.º 4
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);
         }
     }
 }
Exemplo n.º 5
0
        public void RespectBinarySerializationFormat()
        {
            var serializer = new IonSerializer(new IonSerializationOptions {
                Format = IonSerializationFormat.BINARY
            });
            MemoryStream testStream = (MemoryStream)serializer.Serialize(TestObjects.John);

            IIonValue    ionValue       = IonLoader.Default.Load(TestObjects.JohnIonText).GetElementAt(0);
            MemoryStream expectedStream = new MemoryStream();

            using (var writer = IonBinaryWriterBuilder.Build(expectedStream))
            {
                ionValue.WriteTo(writer);
                writer.Finish();
            }

            Assert.IsTrue(expectedStream.ToArray().SequenceEqual(testStream.ToArray()));
        }
Exemplo 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);
        }