private IAWArray UnrollArray(ArrayList arr) { IAWArray iSFSArray = AWArray.NewInstance(); IEnumerator enumerator = arr.GetEnumerator(); try { while (enumerator.MoveNext()) { object current = enumerator.Current; AWDataWrapper sFSDataWrapper = this.WrapField(current); if (sFSDataWrapper == null) { throw new AWCodecError("Cannot serialize field of array: " + current + " -- unsupported type!"); } iSFSArray.Add(sFSDataWrapper); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } return(iSFSArray); }
public ByteArray Array2Binary(IAWArray array) { ByteArray byteArray = new ByteArray(); byteArray.WriteByte(Convert.ToByte(17)); byteArray.WriteShort(Convert.ToInt16(array.Size())); return(this.Arr2bin(array, byteArray)); }
private ByteArray Arr2bin(IAWArray array, ByteArray buffer) { for (int i = 0; i < array.Size(); i++) { AWDataWrapper wrappedElementAt = array.GetWrappedElementAt(i); buffer = this.EncodeObject(buffer, wrappedElementAt.Type, wrappedElementAt.Data); } return(buffer); }
private ArrayList RebuildArray(IAWArray sfsArr) { ArrayList arrayList = new ArrayList(); for (int i = 0; i < sfsArr.Size(); i++) { arrayList.Add(this.UnwrapField(sfsArr.GetWrappedElementAt(i))); } return(arrayList); }
private void ConvertSFSObject(IAWArray fieldList, object csObj, Type objType) { for (int i = 0; i < fieldList.Size(); i++) { IAWObject sFSObject = fieldList.GetAWObject(i); string utfString = sFSObject.GetUtfString(DefaultAWDataSerializer.FIELD_NAME_KEY); AWDataWrapper data = sFSObject.GetData(DefaultAWDataSerializer.FIELD_VALUE_KEY); object value = this.UnwrapField(data); FieldInfo field = objType.GetField(utfString, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { field.SetValue(csObj, value); } } }
private void ConvertCsObj(object csObj, IAWObject sfsObj) { Type type = csObj.GetType(); string fullName = type.FullName; if (!(csObj is SerializableAWType)) { throw new AWCodecError(string.Concat(new object[] { "Cannot serialize object: ", csObj, ", type: ", fullName, " -- It doesn't implement the SerializableAWType interface" })); } IAWArray iSFSArray = AWArray.NewInstance(); sfsObj.PutUtfString(DefaultAWDataSerializer.CLASS_MARKER_KEY, fullName); sfsObj.PutSFSArray(DefaultAWDataSerializer.CLASS_FIELDS_KEY, iSFSArray); FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); FieldInfo[] array = fields; for (int i = 0; i < array.Length; i++) { FieldInfo fieldInfo = array[i]; string name = fieldInfo.Name; object value = fieldInfo.GetValue(csObj); IAWObject iSFSObject = AWObject.NewInstance(); AWDataWrapper sFSDataWrapper = this.WrapField(value); if (sFSDataWrapper == null) { throw new AWCodecError(string.Concat(new object[] { "Cannot serialize field of object: ", csObj, ", field: ", name, ", type: ", fieldInfo.GetType().Name, " -- unsupported type!" })); } iSFSObject.PutUtfString(DefaultAWDataSerializer.FIELD_NAME_KEY, name); iSFSObject.Put(DefaultAWDataSerializer.FIELD_VALUE_KEY, sFSDataWrapper); iSFSArray.AddSFSObject(iSFSObject); } }
private IAWArray DecodeSFSArray(ByteArray buffer) { IAWArray iSFSArray = AWArray.NewInstance(); AWDataType sFSDataType = (AWDataType)Convert.ToInt32(buffer.ReadByte()); if (sFSDataType != AWDataType.SFS_ARRAY) { throw new AWCodecError(string.Concat(new object[] { "Invalid AWDataType. Expected: ", AWDataType.SFS_ARRAY, ", found: ", sFSDataType })); } int num = (int)buffer.ReadShort(); if (num < 0) { throw new AWCodecError("Can't decode AWArray. Size is negative: " + num); } try { for (int i = 0; i < num; i++) { AWDataWrapper sFSDataWrapper = this.DecodeObject(buffer); if (sFSDataWrapper == null) { throw new AWCodecError("Could not decode AWArray item at index: " + i); } iSFSArray.Add(sFSDataWrapper); } } catch (AWCodecError sFSCodecError) { throw sFSCodecError; } return(iSFSArray); }
public void AddSFSArray(IAWArray val) { this.AddObject(val, AWDataType.SFS_ARRAY); }
public void PutSFSArray(string key, IAWArray val) { this.dataHolder[key] = new AWDataWrapper(AWDataType.SFS_ARRAY, val); }