示例#1
0
        public void TestIonWriterContractWriteValue()
        {
            IIonValue ionHashTests = loader.Load(file);

            byte[] expected = ExerciseWriter(IonReaderBuilder.Build(ionHashTests), false, (r, w) => { r.MoveNext(); w.WriteValue(r); });
            byte[] actual   = ExerciseWriter(IonReaderBuilder.Build(ionHashTests), true, (r, w) => { r.MoveNext(); w.WriteValue(r); });
            Assert.IsTrue(expected.Length > 10);
            Assert.IsTrue(actual.Length > 10);
            TestUtil.AssertEquals(expected, actual, "Byte arrays mismatch.");
        }
示例#2
0
        public void TestUnresolvedSid()
        {
            // unresolved SIDs (such as SID 10 here) should result in an exception
            IIonValue ionContainer = loader.Load("(0xd3 0x8a 0x21 0x01)");

            byte[] ionBinary = IonHashTest.ContainerToBytes(ionContainer.GetElementAt(0));

            IIonHashReader ihr = IonHashReaderBuilder
                                 .Standard()
                                 .WithHasherProvider(new IdentityIonHasherProvider())
                                 .WithReader(IonReaderBuilder.Build(ionBinary))
                                 .Build();

            ihr.MoveNext();
            Assert.ThrowsException <UnknownSymbolException>(() => ihr.MoveNext());
        }
示例#3
0
        public Entity(Stream stream, int id, int type, ISymbolTable symbolTable, 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.GetField(KfxSymbols.BcComprType).IntValue;

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

            var drmScheme = entityInfo.GetField(KfxSymbols.BcDrmScheme).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()))
                : ((IonDatagram)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)
        }