Esempio n. 1
0
        public void WriteObjectWithAnnotations(int annotationCount)
        {
            using (var writer = new ManagedBinaryWriter(_memoryStream, Symbols.EmptySymbolTablesArray))
            {
                writer.StepIn(IonType.Struct);

                writer.SetFieldName("FieldName");
                for (var i = 0; i < annotationCount; i++)
                {
                    writer.AddTypeAnnotation($"annot_{i}");
                }

                writer.WriteString("FieldValue");

                writer.StepOut();
                writer.Flush();
            }

            var reader = new UserBinaryReader(new MemoryStream(_memoryStream.GetWrittenBuffer()));

            reader.MoveNext();
            reader.StepIn();
            reader.MoveNext();
            //load the value
            reader.StringValue();
            var annotations = reader.GetTypeAnnotations().ToList();

            for (var i = 0; i < annotationCount; i++)
            {
                Assert.IsTrue(annotations.Any(s => s.Text == $"annot_{i}"));
            }
        }
Esempio n. 2
0
        public void WriteValuesWithAnnotation()
        {
            var ionValues    = new List <IIonValue>();
            var valueFactory = new ValueFactory();

            ionValues.Add(valueFactory.NewBool(true));
            ionValues.Add(valueFactory.NewString("string"));
            ionValues.Add(valueFactory.NewFloat(22.22f));
            ionValues.Add(valueFactory.NewDecimal(3.4m));
            ionValues.Add(valueFactory.NewInt(3));
            ionValues.Add(valueFactory.NewNull());
            ionValues.Add(valueFactory.NewSymbol("symbol"));
            ionValues.Add(valueFactory.NewTimestamp(new Timestamp(DateTime.Now)));
            var arrayOfbytes          = Enumerable.Repeat <byte>(1, 10).ToArray();
            ReadOnlySpan <byte> bytes = new ReadOnlySpan <byte>(arrayOfbytes);

            ionValues.Add(valueFactory.NewClob(bytes));
            ionValues.Add(valueFactory.NewBlob(bytes));

            foreach (var ionValue in ionValues)
            {
                ionValue.AddTypeAnnotation("annotation");
            }

            var ms     = new MemoryStream();
            var writer = IonBinaryWriterBuilder.Build(ms);

            using (writer)
            {
                foreach (var ionValue in ionValues)
                {
                    ionValue.WriteTo(writer);
                }
                writer.Finish();
            }

            var reader = new UserBinaryReader(new MemoryStream(ms.GetWrittenBuffer()));

            while (reader.MoveNext() != IonType.None)
            {
                var annotation = reader.GetTypeAnnotations();
                Assert.AreEqual("annotation", annotation[0]);
            }
        }