Esempio n. 1
0
 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));
             }
         }
     }
 }
Esempio n. 2
0
 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));
         }
     }
 }
Esempio n. 3
0
 protected override void AnalyzeDimensions(ObjectContainerBase container, object obj
                                           , ArrayInfo info)
 {
     int[] dim = ArrayReflector(container).Dimensions(obj);
     ((MultidimensionalArrayInfo)info).Dimensions(dim);
     info.ElementCount(ElementCount(dim));
 }
Esempio n. 4
0
        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);
                }
            }
        }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
        public virtual object NewInstance(IReflectClass componentType, ArrayInfo info)
        {
            // TODO: implement multidimensional arrays.
            var length = info.ElementCount();

            return(NewInstance(componentType, length));
        }
Esempio n. 7
0
        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);
            }
        }
Esempio n. 8
0
 private int ReducedCountForNullBitMap(ArrayInfo info, IReadBuffer context)
 {
     if (!HasNullBitmap(info))
     {
         return(0);
     }
     return(ReducedCountForNullBitMap(info.ElementCount(), ReadNullBitmap(context, info
                                                                          .ElementCount())));
 }
Esempio n. 9
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));
 }
Esempio n. 10
0
 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));
 }
Esempio n. 11
0
 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);
 }
Esempio n. 12
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);
 }
Esempio n. 13
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();
                }
            }
Esempio n. 14
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));
        }
Esempio n. 15
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);
 }
Esempio n. 16
0
 public virtual object NewInstance(IReflectClass componentType, ArrayInfo info)
 {
     // TODO: implement multidimensional arrays.
     var length = info.ElementCount();
     return NewInstance(componentType, length);
 }
Esempio n. 17
0
 protected virtual void WriteDimensions(IWriteContext context, ArrayInfo info)
 {
     context.WriteInt(info.ElementCount());
 }
Esempio n. 18
0
 protected virtual void ReadDimensions(ArrayInfo info, IReadBuffer buffer)
 {
     info.ElementCount(buffer.ReadInt());
 }
Esempio n. 19
0
 protected virtual void AnalyzeDimensions(ObjectContainerBase container, object obj
                                          , ArrayInfo info)
 {
     info.ElementCount(ArrayReflector(container).GetLength(obj));
 }