Beispiel #1
0
        public SubrecordMemoryFrame ReadSubrecordMemoryFrame(IBinaryReadStream stream, RecordType targetType, bool readSafe = false)
        {
            var meta = GetSubrecord(stream);

            if (meta.RecordType != targetType)
            {
                throw new ArgumentException($"Unexpected header type: {meta.RecordType}");
            }
            return(new SubrecordMemoryFrame(meta, stream.ReadMemory(meta.TotalLength, readSafe: readSafe)));
        }
Beispiel #2
0
 public bool TryReadSubrecordMemoryFrame(IBinaryReadStream stream, RecordType targetType, out SubrecordMemoryFrame frame, bool readSafe = false)
 {
     if (!TryGetSubrecord(stream, targetType, out var meta))
     {
         frame = default;
         return(false);
     }
     frame = new SubrecordMemoryFrame(meta, stream.ReadMemory(meta.TotalLength, readSafe: readSafe));
     return(true);
 }
Beispiel #3
0
 public bool TryReadGroupMemoryFrame(IBinaryReadStream stream, out GroupMemoryFrame frame, bool checkIsGroup = true, bool readSafe = true)
 {
     if (!TryGetGroup(stream, out var meta, checkIsGroup: checkIsGroup))
     {
         frame = default;
         return(false);
     }
     frame = new GroupMemoryFrame(meta, stream.ReadMemory(checked ((int)meta.TotalLength), readSafe));
     return(true);
 }
Beispiel #4
0
 public static ReadOnlyMemorySlice <byte> LockExtractMemory(IBinaryReadStream stream, long min, long max)
 {
     lock (stream)
     {
         stream.Position = min;
         var size = checked ((int)(max - min));
         if (stream.IsPersistantBacking)
         {
             return(stream.ReadMemory(size));
         }
         else
         {
             byte[] data = new byte[size];
             stream.Read(data);
             return(data);
         }
     }
 }
Beispiel #5
0
        public SubrecordMemoryFrame ReadSubrecordMemoryFrame(IBinaryReadStream stream, bool readSafe = false)
        {
            var meta = GetSubrecord(stream);

            return(new SubrecordMemoryFrame(meta, stream.ReadMemory(meta.TotalLength, readSafe: readSafe)));
        }
Beispiel #6
0
        public MajorRecordMemoryFrame ReadMajorRecordMemoryFrame(IBinaryReadStream stream, bool readSafe = false)
        {
            var meta = GetMajorRecord(stream);

            return(new MajorRecordMemoryFrame(meta, stream.ReadMemory(checked ((int)meta.TotalLength), readSafe: readSafe)));
        }
Beispiel #7
0
        public GroupMemoryFrame ReadGroupMemoryFrame(IBinaryReadStream stream, bool readSafe = true)
        {
            var meta = GetGroup(stream);

            return(new GroupMemoryFrame(meta, stream.ReadMemory(checked ((int)meta.TotalLength), readSafe)));
        }
Beispiel #8
0
 /// <summary>
 /// Reads a ZString from the binary stream
 /// </summary>
 /// <param name="stream">Stream to read from</param>
 /// <param name="length">Length of the zstring</param>
 /// <returns>ZString of desired length</returns>
 public static string ReadZString(this IBinaryReadStream stream, int length)
 {
     return(BinaryStringUtility.ToZString(stream.ReadMemory(length)));
 }
Beispiel #9
0
 public VariableHeader ReadVariableMeta(IBinaryReadStream stream) => new VariableHeader(this, stream.ReadMemory(this.HeaderLength));