/// <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); } }
internal override void DoAdd(IonContainer container, IonValue item) { var fieldName = $"Field{_serial++}"; var v = (IonStruct)container; v[fieldName] = item; }
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); }
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); }
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)); }
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);
protected override void DoAdd(IonContainer container, IonValue item) { var list = (IonList)container; list.Add(item); }
public ContainedValueException(IonValue value) : this(value.ToString()) { }
protected override void DoAdd(IonContainer container, IonValue item) { container.Add(item); }
internal override void DoAdd(IonContainer container, IonValue item) { container.Add(item); }
/// <summary> /// Implementations should add <paramref name="item"/> to <paramref name="container"/>. /// </summary> internal abstract void DoAdd(IonContainer container, IonValue item);