Map() public method

public Map ( long Offset, Stream Stream ) : MapStream
Offset long
Stream Stream
return MapStream
Ejemplo n.º 1
0
		public void TestRead()
		{
			var Stream1 = new ZeroStream(5, 0x11);
			var Stream2 = new ZeroStream(3, 0x22);
			var MapStream = new MapStream();
			byte[] Readed1, Readed2, Readed3, Readed4;

			MapStream.Map(3, Stream1);
			MapStream.Map(3 + 5, Stream2);

			MapStream.Position = 4;

			Readed1 = MapStream.ReadBytesUpTo(3);
			CollectionAssert.AreEqual(new byte[] { 0x11, 0x11, 0x11 }, Readed1);

			Readed2 = MapStream.ReadBytesUpTo(3);
			CollectionAssert.AreEqual(new byte[] { 0x11, 0x22, 0x22 }, Readed2);

			Readed3 = MapStream.ReadBytesUpTo(1);
			CollectionAssert.AreEqual(new byte[] { 0x22 }, Readed3);

			MapStream.Position = 3;
			Readed4 = MapStream.ReadBytesUpTo(8);
			CollectionAssert.AreEqual(new byte[] { 0x11, 0x11, 0x11, 0x11, 0x11, 0x22, 0x22, 0x22 }, Readed4);
		}
Ejemplo n.º 2
0
	/// <summary>
	/// 
	/// </summary>
	/// <param name="Stream"></param>
	/// <param name="Spaces"></param>
	/// <returns></returns>
	public static MapStream ConvertSpacesToMapStream(this Stream Stream, SpaceAssigner1D.Space[] Spaces)
	{
		var MapStream = new MapStream();

		foreach (var Space in Spaces)
		{
			MapStream.Map(Space.Min, Stream.SliceWithBounds(Space.Min, Space.Max));
		}

		return MapStream;
	}
Ejemplo n.º 3
0
		public void TestLongRead()
		{
			var Position = (long)5197762560L;
			var Array = new byte[] { 0x11, 0x12, 0x13, 0x14, 0x15 };
			var Stream1 = new MemoryStream(Array);
			var MapStream = new MapStream();

			MapStream.Map(Position, Stream1);

			var SerializedData = SerializerUtils.SerializeToMemoryStream(MapStream.Serialize).ToArray();

			var MapStream2 = MapStream.Unserialize(new MemoryStream(SerializedData));
			MapStream2.Position = Position;
			CollectionAssert.AreEqual(Array, MapStream2.ReadBytes(5));
		}
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="targetStream"></param>
        /// <returns></returns>
        public static MapStream Unserialize(Stream targetStream)
        {
            if (targetStream.ReadString(4) != "MAPS")
            {
                throw new InvalidDataException("Not a MapStream serialized stream");
            }

            var version   = targetStream.ReadVariableUlongBit8Extends();
            var mapStream = new MapStream();

            switch (version)
            {
            case 1:
                var entryCount = (int)targetStream.ReadVariableUlongBit8Extends();
                var entries    = new Tuple <ulong, ulong> [entryCount];
                for (var n = 0; n < entryCount; n++)
                {
                    //var EntryFileOffset = TargetStream.ReadVariableUlongBit8Extends();
                    var entryMapOffset = targetStream.ReadVariableUlongBit8Extends();
                    var entryLength    = targetStream.ReadVariableUlongBit8Extends();
                    entries[n] = new Tuple <ulong, ulong>(entryMapOffset, entryLength);
                }

                foreach (var entry in entries)
                {
                    var entryMapOffset = entry.Item1;
                    var entryLength    = entry.Item2;
                    var entryStream    = targetStream.ReadStream((long)entryLength);
                    mapStream.Map((long)entryMapOffset, entryStream);
                }

                break;

            default:
                throw new InvalidDataException("Unsupported MapStream serialized stream version " + version);
            }

            return(mapStream);
        }