Пример #1
0
        public override AContainer <BinaryStream> CreateContainer(int size = 0)
        {
            var memStream = new MemoryStream(size);
            var binStream = new BinaryStream(memStream, true);
            var container = new BinaryContainer(binStream, _serializers);

            return(container);
        }
        public BinaryContainer GetContainerFromData(byte[] data, bool writable)
        {
            if (!BinaryStream.IsValidData(data))
            {
                return(null);
            }
            var memStream = CreateMemoryStream(data, writable);
            var binStream = new BinaryStream(memStream, writable);

            if (!binStream.CheckIsValidStream()) // just in case but can be removed
            {
                return(null);
            }
            var container = new BinaryContainer(binStream, _serializers);

            return(container);
        }
Пример #3
0
        public override AContainer <BinaryStream> LoadContainer(string name, bool writable, bool errorIfNotExist = true)
        {
            // all saved in memory containers are considered as writable
            AContainer <BinaryStream> container = null;

            if (_containerPositions.TryGetValue(name, out PosLen containerPosLen))
            {
                _storage.Seek(containerPosLen.Position, SeekOrigin.Begin);
                var data = new byte[containerPosLen.Length];
                _storage.Read(data, 0, data.Length);
                var memStream = CreateMemoryStream(data, writable);
                var binStream = new BinaryStream(memStream, writable);
                container = new BinaryContainer(binStream, _serializers);
            }
            else if (errorIfNotExist)
            {
                SerializationLogger.LogError($"Container '{name}' does not exist in {this.PrettyTypeName()}");
            }
            return(container);
        }
Пример #4
0
        public override AContainer <BinaryStream> LoadContainer(string name, bool writable = false, bool errorIfNotExist = true)
        {
            // all files are considered as writable
            string filePath = GetFilePath(name);

            if (!File.Exists(filePath))
            {
                if (errorIfNotExist)
                {
                    SerializationLogger.LogError($"File '{filePath}' does not exist");
                }
                return(null);
            }
            var data      = File.ReadAllBytes(filePath);
            var memStream = CreateMemoryStream(data, writable);
            var binStream = new BinaryStream(memStream, writable);
            var container = new BinaryContainer(binStream, _serializers);

            return(container);
        }