private IMPArray DecodeMPArray(ByteArray buffer) { IMPArray array = MPArray.NewInstance(); MPDataType type = (MPDataType)Convert.ToInt32(buffer.ReadByte()); if (type != MPDataType.MP_ARRAY) { throw new Exception(string.Concat("Invalid MPDataType. Expected: ", MPDataType.MP_ARRAY, ", found: ", type)); } int num = buffer.ReadShort(); if (num < 0) { throw new Exception("Can't decode MPArray. Size is negative: " + num); } for (int i = 0; i < num; i++) { MPDataWrapper val = DecodeObject(buffer); if (val == null) { throw new Exception("Could not decode SFSArray item at index: " + i); } array.Add(val); } return(array); }
private void ConvertCsObj(object csObj, IMPObject mpObj) { Type type = csObj.GetType(); string fullName = type.FullName; if (!(mpObj is Serializable)) { throw new Exception(string.Concat("Cannot serialize object: ", csObj, ", type: ", fullName, " -- It doesn't implement the SerializableSFSType interface")); } IMPArray val = MPArray.NewInstance(); mpObj.PutUtfString(CLASS_MARKER_KEY, fullName); mpObj.PutMPArray(CLASS_FIELDS_KEY, val); foreach (FieldInfo info in type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)) { string name = info.Name; object obj2 = info.GetValue(csObj); IMPObject obj3 = MPObject.NewInstance(); MPDataWrapper wrapper = WrapField(obj2); if (wrapper != null) { obj3.PutUtfString(FIELD_NAME_KEY, name); obj3.Put(FIELD_VALUE_KEY, wrapper); val.AddMPObject(obj3); } else { throw new Exception(string.Concat("Cannot serialize field of object: ", csObj, ", field: ", name, ", type: ", info.GetType().Name, " -- unsupported type!")); } } }
internal ByteArray Array2Binary(IMPArray array) { ByteArray buffer = new ByteArray(); buffer.WriteByte(Convert.ToByte(MPDataType.MP_ARRAY)); buffer.WriteShort(Convert.ToInt16(array.Size())); return(Arr2bin(array, buffer)); }
private ByteArray Arr2bin(IMPArray array, ByteArray buffer) { for (int i = 0; i < array.Size(); i++) { MPDataWrapper wrappedElementAt = array.GetWrappedElementAt(i); buffer = EncodeObject(buffer, wrappedElementAt.Type, wrappedElementAt.Data); } return(buffer); }
/// <summary> /// /// </summary> /// <param name="mpa"></param> /// <returns></returns> public static MPUser FromSFSArray(IMPArray mpa) { MPUser user = new MPUser(mpa.GetInt(0), mpa.GetUtfString(1)) { PrivilegeId = mpa.GetShort(2) }; return(user); }
private ArrayList RebuildArray(IMPArray mpArr) { ArrayList list = new ArrayList(); for (int i = 0; i < mpArr.Size(); i++) { list.Add(UnwrapField(mpArr.GetWrappedElementAt(i))); } return(list); }
private IMPArray UnrollCollection(ICollection collection) { IMPArray array = MPArray.NewInstance(); foreach (object item in collection) { array.Add(WrapField(item)); } return(array); }
private IMPArray UnrollArray(object[] arr) { IMPArray array = MPArray.NewInstance(); foreach (object item in arr) { array.Add(WrapField(item)); } return(array); }
private void ConvertMPObject(IMPArray fieldList, object csObj, Type objType) { for (int i = 0; i < fieldList.Size(); i++) { IMPObject sFSObject = fieldList.GetMPObject(i); string utfString = sFSObject.GetUtfString(FIELD_NAME_KEY); MPDataWrapper data = sFSObject.GetData(FIELD_VALUE_KEY); object obj3 = UnwrapField(data); FieldInfo field = objType.GetField(utfString, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (field == null) { throw new Exception(string.Format("The deserialized class ({0}) doesn't contain the field: {1}", objType.FullName, utfString)); } field.SetValue(csObj, obj3); } }
/// <summary> /// /// </summary> /// <param name="assets"></param> /// <param name="asset"></param> /// <param name="rootDir"></param> /// <param name="type"></param> /// <param name="depens"></param> private static AssetInfo AddBuilderAsset(Dictionary <BuilderGuiType, Dictionary <string, AssetInfo> > assets, string assetRoot, Object asset, string rootDir, BuilderGuiType type, IMPArray depens) { string path = AssetDatabase.GetAssetPath(asset); string rootPath = path.Substring(assetRoot.Length); string dir = rootPath.LastIndexOf("/") != -1 ? rootPath.Substring(0, rootPath.LastIndexOf("/")) : null; if (dir == null) { dir = rootDir; } else { dir = rootDir + "/" + dir; } string fileName = asset.name; AssetInfo assetInfo = new AssetInfo() { asset = asset, dir = dir, fileName = fileName }; Dictionary <string, AssetInfo> items = null; if (!assets.ContainsKey(type)) { items = new Dictionary <string, AssetInfo>(); assets.Add(type, items); } else { items = assets[type]; } if (!items.ContainsKey(assetInfo.fileName)) { items.Add(assetInfo.fileName, assetInfo); } if (depens != null) { depens.AddUtfString(dir + "/" + fileName); } return(assetInfo); }
public void PutMPArray(string key, IMPArray val) { dataHolder[key] = new MPDataWrapper(MPDataType.MP_ARRAY, val); }
public void AddMPArray(IMPArray val) { AddObject(val, MPDataType.MP_ARRAY); }