public void PushObject(object obj, string keyName = null) { if (mIsTxtMode) { mContext = StringSerialize.Serialize(obj); } else { if (string.IsNullOrEmpty(keyName)) { keyName = obj.GetType().Name; } BytesPack pack = null; if (mIsBinary) { pack = BytesSerialize.Serialize(obj); } else { string temps = StringSerialize.Serialize(obj); pack = new BytesPack(); pack.CreateReadBytes(System.Text.Encoding.UTF8.GetBytes(temps)); } mDataPacks[keyName] = pack; } }
private void _ReadFile() { if (mIsTxtMode) { if (mIsBinary) { mBytes = File.ReadAllBytes(mFilePath); } else { mContext = File.ReadAllText(mFilePath, System.Text.Encoding.Default); } } else { FileStream fs = new FileStream(mFilePath, FileMode.Open, FileAccess.Read); fs.Seek(0, SeekOrigin.Begin); var pack = new BytesPack(); byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); pack.CreateReadBytes(bytes); _ReadPack(pack); } }
private void _DrawObject(object obj, List <string> tags) { BytesPack pack = new BytesPack(); Serialize(obj, pack); pack.BeginSeek(); mTags = tags; Deserialize(pack, obj.GetType(), obj); }
public void SetBytes(byte[] bytes) { if (mIsBinary && mIsTxtMode) { mBytes = bytes; } else { var pack = new BytesPack(); pack.CreateReadBytes(bytes); _ReadPack(pack); } }
private object _GetObject(object obj, System.Type type, string keyName) { if (mIsTxtMode) { if (obj == null) { return(StringSerialize.Deserialize(mContext, type)); } else { StringSerialize.Deserialize(mContext, obj); } } else { if (string.IsNullOrEmpty(keyName)) { keyName = type.Name; } BytesPack pack = null; if (mDataPacks.TryGetValue(keyName, out pack)) { if (mIsBinary) { if (obj == null) { return(BytesSerialize.Deserialize(pack, type)); } else { BytesSerialize.Deserialize(pack, obj); } } else { string str = System.Text.Encoding.UTF8.GetString(pack.GetStream()); if (obj == null) { return(StringSerialize.Deserialize(str, type)); } else { StringSerialize.Deserialize(str, obj); } } } } return(null); }
private void _ReadPack(BytesPack pack) { mIsBinary = pack.PopBool(""); mIsEncrypt = pack.PopBool(""); while (!pack.IsOver()) { string fileName = pack.PopString(""); BytesPack pb = new BytesPack(); byte[] bytes = pack.PopBytes(); if (mIsEncrypt) { FUniversalFunction.EncryptBytes(bytes, 0); } pb.CreateReadBytes(bytes); mDataPacks[fileName] = pb; } }
public void SetPack(BytesPack pack) { _ReadPack(pack); }