public long WriteObject(T key, object obj) { StorageItem <T> meta = new StorageItem <T>(); meta.key = key; //meta.typename = fastJSON.Reflection.Instance.GetTypeAssemblyName(obj.GetType());//fastJSON meta.typename = Reflection.Instance.GetTypeAssemblyName(obj.GetType()); byte[] data; if (_saveFormat == SF_FORMAT.BSON) { //data = fastBinaryJSON.BJSON.ToBJSON(obj);//fastBinaryJSON data = _bson.SerializeObject(obj); } else { //data = Helper.GetBytes(fastJSON.JSON.ToJSON(obj));//fastJSON data = Helper.GetBytes(_json.SerializeObject(obj)); } //超过压缩最大值界限就开启压缩 if (data.Length > (int)Global.CompressDocumentOverKiloBytes * _KILOBYTE) { meta.isCompressed = 1; data = MiniLZO.Compress(data); //MiniLZO } return(internalWriteData(meta, data, false)); }
//public long WriteReplicationObject(T key, object obj) //{ // StorageItem<T> meta = new StorageItem<T>(); // meta.key = key; // meta.isReplicated = true; // meta.typename = fastJSON.Reflection.Instance.GetTypeAssemblyName(obj.GetType());//fastJSON // byte[] data; // if (_saveFormat == SF_FORMAT.BSON) // data = fastBinaryJSON.BJSON.ToBJSON(obj);//fastBinaryJSON // else // data = Helper.GetBytes(fastJSON.JSON.ToJSON(obj));//fastJSON // if (data.Length > (int)Global.CompressDocumentOverKiloBytes * _KILOBYTE) // { // meta.isCompressed = 1; // data = MiniLZO.Compress(data); // } // return internalWriteData(meta, data, false); //} 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)); }
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);//fastBinaryJSON data = _bson.SerializeObject(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); }