예제 #1
0
        private long SaveBitmapToFile(MGRB bmp)
        {
            long off = _lastBitmapOffset;
            var  dat = bmp.Serialize();
            var  hdr = new byte[_hdrlen];
            var  b   = fastBinaryJSON.BJSON.ToBJSON(dat, new fastBinaryJSON.BJSONParameters {
                UseExtensions = false
            });

            hdr[0] = (byte)'b';
            hdr[1] = (byte)'m';
            hdr[2] = 0; // uncompressed

            if (Global.CompressBitmapBytes)
            {
                hdr[2] = 1;
                b      = MiniLZO.Compress(b);
            }

            var s = Helper.GetBytes(b.Length, false);

            Buffer.BlockCopy(s, 0, hdr, 3, 4);

            _bitmapFileWrite.Write(hdr, 0, hdr.Length);
            _lastBitmapOffset += hdr.Length;

            _bitmapFileWrite.Write(b, 0, b.Length);
            _lastBitmapOffset += b.Length;

            return(off);
        }
예제 #2
0
        public long WriteData(T key, byte[] data)
        {
            StorageItem <T> meta = new StorageItem <T>();

            meta.key = key;

            if (data.Length > (int)Global.CompressDocumentOverKiloBytes * _KILOBYTE)
            {
                meta.isCompressed = 1;
                data = MiniLZO.Compress(data);
            }

            return(internalWriteData(meta, data, false));
        }
예제 #3
0
        public long WriteObject(T key, object obj)
        {
            StorageItem <T> meta = new StorageItem <T>();

            meta.key      = key;
            meta.typename = fastJSON.Reflection.Instance.GetTypeAssemblyName(obj.GetType());
            byte[] data;
            if (_saveFormat == SF_FORMAT.BSON)
            {
                data = fastBinaryJSON.BJSON.ToBJSON(obj);
            }
            else
            {
                data = Helper.GetBytes(fastJSON.JSON.ToJSON(obj));
            }
            if (data.Length > (int)Global.CompressDocumentOverKiloBytes * _KILOBYTE)
            {
                meta.isCompressed = 1;
                data = MiniLZO.Compress(data); //MiniLZO
            }
            return(internalWriteData(meta, data, false));
        }
예제 #4
0
        private void SaveNew(string key, byte[] keybytes, object obj)
        {
            byte[]          data;
            AllocationBlock ab = new AllocationBlock();

            ab.key    = key;
            ab.keylen = (byte)keybytes.Length;

            data            = fastBinaryJSON.BJSON.ToBJSON(obj);
            ab.isBinaryJSON = true;

            if (data.Length > (int)Global.CompressDocumentOverKiloBytes * _KILOBYTE)
            {
                ab.isCompressed = true;
                data            = MiniLZO.Compress(data);
            }
            ab.datalength = data.Length;

            int firstblock = internalSave(keybytes, data, ab);

            // save keys
            _keys.Set(key, firstblock);
        }