private ILeafContainer ReadType(out long dataSize) { ushort length = ReadUInt16(); if (length == 0) { dataSize = sizeof(ushort); return(null); } dataSize = sizeof(ushort) + length; Position -= sizeof(ushort); #if false //$TODO { var leafDataBuf = ReadBytes((int)length + sizeof(ushort)); UInt32 leafHash = HasherV2.HashBufferV8(leafDataBuf, 0xFFFFFFFF); UInt32 hash = HasherV2.HashData(leafDataBuf, Header.Hash.NumHashBuckets); Position -= sizeof(ushort) + length; } #endif //OnLeafData?.Invoke(leafDataBuf); var typeSpan = Memory.Slice((int)Position, (int)dataSize); TypeDataReader rdr = new TypeDataReader(ctx, new SpanStream(typeSpan)); Position += dataSize; return(rdr.ReadTypeLazy()); }
/// <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); ILeafContainer leaf = new TypeDataReader(ctx, this).ReadTypeDirect(hasSize: false); //ILeafContainer leaf = new TypeDataReader(ctx, this).ReadTypeLazy(hasSize: false); return(leaf); }
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); }