protected virtual void WriteElements(IWriteContext context, object obj, ArrayInfo info) { if (HandleAsByteArray(obj)) { context.WriteBytes((byte[])obj); } else { // byte[] performance optimisation if (HasNullBitmap(info)) { BitMap4 nullItems = NullItemsMap(ArrayReflector(Container(context)), obj); WriteNullBitmap(context, nullItems); for (int i = 0; i < info.ElementCount(); i++) { if (!nullItems.IsTrue(i)) { context.WriteObject(_handler, ArrayReflector(Container(context)).Get(obj, i)); } } } else { for (int i = 0; i < info.ElementCount(); i++) { context.WriteObject(_handler, ArrayReflector(Container(context)).Get(obj, i)); } } } }
protected void ReadInto(IReadContext context, ArrayInfo info, object array) { if (array == null) { return; } if (HandleAsByteArray(array)) { context.ReadBytes((byte[])array); // byte[] performance optimisation return; } if (HasNullBitmap(info)) { BitMap4 nullBitMap = ReadNullBitmap(context, info.ElementCount()); for (int i = 0; i < info.ElementCount(); i++) { object obj = nullBitMap.IsTrue(i) ? null : context.ReadObject(_handler); ArrayReflector(Container(context)).Set(array, i, obj); } } else { for (int i = 0; i < info.ElementCount(); i++) { ArrayReflector(Container(context)).Set(array, i, context.ReadObject(_handler)); } } }
protected override void AnalyzeDimensions(ObjectContainerBase container, object obj , ArrayInfo info) { int[] dim = ArrayReflector(container).Dimensions(obj); ((MultidimensionalArrayInfo)info).Dimensions(dim); info.ElementCount(ElementCount(dim)); }
protected override void WriteElements(IWriteContext context, object obj, ArrayInfo info) { IEnumerator objects = AllElements(Container(context), obj); if (HasNullBitmap(info)) { BitMap4 nullBitMap = new BitMap4(info.ElementCount()); IReservedBuffer nullBitMapBuffer = context.Reserve(nullBitMap.MarshalledLength()); int currentElement = 0; while (objects.MoveNext()) { object current = objects.Current; if (current == null) { nullBitMap.SetTrue(currentElement); } else { context.WriteObject(DelegateTypeHandler(), current); } currentElement++; } nullBitMapBuffer.WriteBytes(nullBitMap.Bytes()); } else { while (objects.MoveNext()) { context.WriteObject(DelegateTypeHandler(), objects.Current); } } }
public void DefragmentSlot(IDefragmentContext context) { if (IsUntypedByteArray(context)) { return; } int classIdOffset = context.TargetBuffer().Offset(); ArrayInfo info = NewArrayInfo(); ReadInfo(context.Transaction(), context, info); DefragmentWriteMappedClassId(context, info, classIdOffset); int elementCount = info.ElementCount(); if (HasNullBitmap(info)) { BitMap4 bitMap = ReadNullBitmap(context, elementCount); elementCount -= ReducedCountForNullBitMap(elementCount, bitMap); } ITypeHandler4 correctTypeHandlerVersion = CorrectHandlerVersion(context, _handler , info); for (int i = 0; i < elementCount; i++) { context.Defragment(correctTypeHandlerVersion); } }
public virtual object NewInstance(IReflectClass componentType, ArrayInfo info) { // TODO: implement multidimensional arrays. var length = info.ElementCount(); return(NewInstance(componentType, length)); }
protected virtual void ReadInfo(Transaction trans, IReadBuffer buffer, ArrayInfo info) { var classID = buffer.ReadInt(); if (IsPreVersion0Format(classID)) { throw new UnsupportedOldFormatException(); } _versionHelper.ReadTypeInfo(trans, buffer, info, classID); ReflectClassFromElementsEntry(Container(trans), info, classID); ReadDimensions(info, buffer); if (Debug4.ExceedsMaximumArrayEntries(info.ElementCount(), _usePrimitiveClassReflector )) { info.ElementCount(0); } }
private int ReducedCountForNullBitMap(ArrayInfo info, IReadBuffer context) { if (!HasNullBitmap(info)) { return(0); } return(ReducedCountForNullBitMap(info.ElementCount(), ReadNullBitmap(context, info .ElementCount()))); }
public virtual object NewInstance(IReflectClass componentType, ArrayInfo info) { componentType = componentType.GetDelegate(); if (componentType is GenericClass) { var length = info.ElementCount(); return(new GenericArray(((GenericClass)componentType).ArrayClass(), length)); } return(_delegate.NewInstance(componentType, info)); }
private void ReadDimensions(ArrayInfo info, IReadBuffer buffer, int dimensionCount ) { int[] dim = new int[dimensionCount]; for (int i = 0; i < dim.Length; i++) { dim[i] = buffer.ReadInt(); } ((MultidimensionalArrayInfo)info).Dimensions(dim); info.ElementCount(ElementCount(dim)); }
protected override void ReadElements(IReadContext context, ArrayInfo info, object array) { if (array == null) { return; } object[] objects = new object[info.ElementCount()]; ReadInto(context, info, objects); ArrayReflector(Container(context)).Shape(objects, 0, array, ((MultidimensionalArrayInfo )info).Dimensions(), 0); }
public override object NewInstance(IReflectClass componentType, ArrayInfo info) { Type type = GetNetType(componentType); if (info.Nullable()) { type = NullableType(type); } MultidimensionalArrayInfo multiDimensionalInfo = info as MultidimensionalArrayInfo; if (multiDimensionalInfo == null) { return System.Array.CreateInstance(type, info.ElementCount()); } int[] dimensions = multiDimensionalInfo.Dimensions(); if (dimensions.Length == 1) { return UnfoldArrayCreation(type, dimensions, 0); } return UnfoldArrayCreation(GetArrayType(type, dimensions.Length - 1), dimensions, 0); }
public void Run() { if (context.Buffer() == null) { return; } if (_enclosing.IsUntypedByteArray(context)) { return; } _enclosing.ReadInfo(context.Transaction(), context, info); var elementCount = info.ElementCount(); elementCount -= _enclosing.ReducedCountForNullBitMap(info, context); for (var i = 0; i < elementCount; i++) { elementRunnable.Run(); } }
public override object NewInstance(IReflectClass componentType, ArrayInfo info) { Type type = GetNetType(componentType); if (info.Nullable()) { type = NullableType(type); } MultidimensionalArrayInfo multiDimensionalInfo = info as MultidimensionalArrayInfo; if (multiDimensionalInfo == null) { return(System.Array.CreateInstance(type, info.ElementCount())); } int[] dimensions = multiDimensionalInfo.Dimensions(); if (dimensions.Length == 1) { return(UnfoldArrayCreation(type, dimensions, 0)); } return(UnfoldArrayCreation(GetArrayType(type, dimensions.Length - 1), dimensions, 0)); }
public virtual object NewInstance(IReflectClass componentType, ArrayInfo info) { componentType = componentType.GetDelegate(); if (componentType is GenericClass) { var length = info.ElementCount(); return new GenericArray(((GenericClass) componentType).ArrayClass(), length); } return _delegate.NewInstance(componentType, info); }
public virtual object NewInstance(IReflectClass componentType, ArrayInfo info) { // TODO: implement multidimensional arrays. var length = info.ElementCount(); return NewInstance(componentType, length); }
protected virtual void WriteDimensions(IWriteContext context, ArrayInfo info) { context.WriteInt(info.ElementCount()); }
protected virtual void ReadDimensions(ArrayInfo info, IReadBuffer buffer) { info.ElementCount(buffer.ReadInt()); }
protected virtual void AnalyzeDimensions(ObjectContainerBase container, object obj , ArrayInfo info) { info.ElementCount(ArrayReflector(container).GetLength(obj)); }