Exemple #1
0
        /// <summary>
        /// Read a varying ILeaf which can be either a ILeaf type or a raw data marker
        /// </summary>
        /// <param name="dataSize"></param>
        /// <param name="leafType"></param>
        /// <returns>true if we found a ILeaf, false if we found raw data marker</returns>
        public ILeafContainer ReadVaryingType(out uint dataSize)
        {
            UInt16 leafValue = ReadUInt16();

            if (leafValue < (ushort)LeafType.LF_NUMERIC)
            {
                // $TODO: ILeafValue is not a ILeaf marker, but it's still a valid ushort
                // do we need to save this?
                dataSize = 0;
                return(null);
            }

            if (!Enum.IsDefined(typeof(LeafType), leafValue))
            {
                throw new InvalidDataException($"Unknown ILeaf type {leafValue} while computing ILeaf data size");
            }

            LeafType leafType = (LeafType)leafValue;

            dataSize = PrimitiveDataSizes[leafType];
            Seek(-2, SeekOrigin.Current);

            TypeDataReader rdr  = new TypeDataReader(ctx, this);
            ILeafContainer leaf = rdr.ReadTypeDirect(hasSize: false);

            //ILeafContainer leaf = new TypeDataReader(ctx, this).ReadTypeDirect(hasSize: false);

            // add leaf size
            this.Position += rdr.Position;

            return(leaf);
        }
Exemple #2
0
        private ILeafContainer ReadTypeOld(out long dataSize)
        {
            uint hash = ReadUInt32();

            // we have no length, so we just pass all memory (after the hash)
            SpanStream     memStream = new SpanStream(Memory.Slice((int)Position));
            TypeDataReader rdr       = new TypeDataReader(ctx, memStream);

            // without a length, and with a small amount of data, we can just read this directly
            ILeafContainer leaf = rdr.ReadTypeDirect(false);

            // hash + type data
            dataSize = Position + rdr.Position;

            Position += rdr.Position;
            return(leaf);
        }