Example #1
0
        /// <summary>
        /// Append an Ion value to this datagram.
        /// </summary>
        private void AppendValue(IonValue value)
        {
            if (_annotations.Count > 0)
            {
                value.ClearAnnotations();
                foreach (var annotation in _annotations)
                {
                    value.AddTypeAnnotation(annotation);
                }

                _annotations.Clear();
            }

            if (IsInStruct)
            {
                var field = AssumeFieldNameSymbol();
                ClearFieldName();
                if (field == default)
                {
                    throw new InvalidOperationException("Field name is missing");
                }

                var structContainer = _currentContainer as IonStruct;
                Debug.Assert(structContainer != null);
                structContainer.Add(field, value);
            }
            else
            {
                _currentContainer.Add(value);
            }
        }
Example #2
0
        internal override void DoAdd(IonContainer container, IonValue item)
        {
            var fieldName = $"Field{_serial++}";
            var v         = (IonStruct)container;

            v[fieldName] = item;
        }
Example #3
0
        public Entity(Stream stream, int id, int type, ISymbolTable symbolTable, IonDotnet.Systems.IonLoader loader)
        {
            using var reader = new BinaryReader(stream, Encoding.UTF8, true);
            Signature        = Encoding.ASCII.GetString(reader.ReadBytes(4));
            if (Signature != EntitySignature)
            {
                throw new Exception("Invalid signature");
            }

            Version = reader.ReadUInt16();
            if (!_allowedVersions.Contains(Version))
            {
                throw new Exception($"Version not supported ({Version})");
            }

            Length = reader.ReadUInt32();
            if (Length < MinHeaderLength)
            {
                throw new Exception("Header too short");
            }

            // Duplicated in KfxContainer
            // 10 = number of bytes read so far
            var containerInfoData = new MemoryStream(stream.ReadBytes((int)Length - 10));
            var entityInfo        = loader.LoadSingle <IonStruct>(containerInfoData);

            if (entityInfo == null)
            {
                throw new Exception("Bad container or something");
            }

            var compressionType = entityInfo.GetById <IonInt>(410).IntValue;

            if (compressionType != KfxContainer.DefaultCompressionType)
            {
                throw new Exception($"Unexpected bcComprType ({compressionType})");
            }

            var drmScheme = entityInfo.GetById <IonInt>(411).IntValue;

            if (drmScheme != KfxContainer.DefaultDrmScheme)
            {
                throw new Exception($"Unexpected bcDRMScheme ({drmScheme})");
            }

            FragmentId   = symbolTable.FindKnownSymbol(id);
            FragmentType = symbolTable.FindKnownSymbol(type);

            Value = RawFragmentTypes.Contains(FragmentType)
                ? new IonBlob(new ReadOnlySpan <byte>(stream.ReadToEnd()))
                : loader.Load(stream.ReadToEnd()).Single();

            // Skipping annotation handling for now

            //if ftype == fid and ftype in ROOT_FRAGMENT_TYPES and not self.pure:

            //fid = "$348"

            //return YJFragment(fid = fid if fid != "$348" else None, ftype = ftype, value = self.value)
        }
        public void Copy_NotSupported()
        {
            var v = (IonContainer)MakeMutableValue();

            DoAdd(v, MakeMutableValue());
            var arr = new IonValue[1];

            v.CopyTo(arr, 0);
        }
Example #5
0
        private static IonValue[] GetIonValues(IIonValue value)
        {
            if (value is null)
            {
                return(new IonValue[0]);
            }

            IonValue[] ionValues = new IonValue[value.Count];
            int        counter   = 0;

            foreach (var ionValue in value)
            {
                ionValues[counter++] = (IonValue)ionValue;
            }

            return(ionValues);
        }
Example #6
0
        public void IndexOf(int idx, int count)
        {
            Debug.Assert(count > idx);
            var      v = (IonSequence)MakeMutableValue();
            IonValue r = null;

            for (var i = 0; i < count; i++)
            {
                var c = (IonValue)MakeMutableValue();
                if (i == idx)
                {
                    r = c;
                }

                DoAdd(v, c);
            }

            Assert.AreEqual(idx, v.IndexOf(r));
        }
Example #7
0
        public void Remove(int idx, int count)
        {
            Debug.Assert(count > idx);
            var      v = (IonContainer)MakeMutableValue();
            IonValue r = null;

            for (var i = 0; i < count; i++)
            {
                var c = (IonValue)MakeMutableValue();
                if (i == idx)
                {
                    r = c;
                }

                DoAdd(v, c);
            }

            Assert.IsTrue(v.Contains(r));
            v.Remove(r);
            Assert.AreEqual(count - 1, v.Count);
        }
 /// <summary>
 /// Implementations should add <paramref name="item"/> to <paramref name="container"/>.
 /// </summary>
 protected abstract void DoAdd(IonContainer container, IonValue item);
Example #9
0
        protected override void DoAdd(IonContainer container, IonValue item)
        {
            var list = (IonList)container;

            list.Add(item);
        }
Example #10
0
 public ContainedValueException(IonValue value) : this(value.ToString())
 {
 }
Example #11
0
 protected override void DoAdd(IonContainer container, IonValue item)
 {
     container.Add(item);
 }
Example #12
0
 internal override void DoAdd(IonContainer container, IonValue item)
 {
     container.Add(item);
 }
Example #13
0
 /// <summary>
 /// Implementations should add <paramref name="item"/> to <paramref name="container"/>.
 /// </summary>
 internal abstract void DoAdd(IonContainer container, IonValue item);