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 BitMap4 ReadBitMap(int bitCount) { BitMap4 value = _source.ReadBitMap(bitCount); _target.IncrementOffset(value.MarshalledLength()); return(value); }
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)); } } } }
public override void Write(Transaction trans, ClassMetadata clazz, ClassAspect aspect , ByteArrayBuffer writer) { writer.WriteShortString(trans, aspect.GetName()); if (!(aspect is FieldMetadata)) { return; } var field = (FieldMetadata)aspect; field.Alive(); if (field.IsVirtual()) { return; } var handler = field.GetHandler(); if (handler is StandardReferenceTypeHandler) { // TODO: ensure there is a test case, to make this happen if (((StandardReferenceTypeHandler)handler).ClassMetadata().GetID() == 0) { trans.Container().NeedsUpdate(clazz); } } writer.WriteInt(field.FieldTypeID()); var bitmap = new BitMap4(3); bitmap.Set(0, field.IsPrimitive()); bitmap.Set(1, Handlers4.HandlesArray(handler)); bitmap.Set(2, Handlers4.HandlesMultidimensionalArray(handler)); // keep the order writer.WriteByte(bitmap.GetByte(0)); }
public virtual BitMap4 ReadBitMap(int bitCount) { BitMap4 map = new BitMap4(_current._buffer, _current._offset, bitCount); _current.Seek(_current.Offset() + map.MarshalledLength()); return(map); }
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)); } } }
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 BitMap4 ReadBitMap(int bitCount) { BitMap4 map = new BitMap4(_buffer, _offset, bitCount); _offset += map.MarshalledLength(); return(map); }
public virtual void ReadTypeInfo(Transaction trans, IReadBuffer buffer, ArrayInfo info, int classID) { BitMap4 typeInfoBitmap = new BitMap4(buffer.ReadByte()); info.Primitive(typeInfoBitmap.IsTrue(0)); info.Nullable(typeInfoBitmap.IsTrue(1)); }
public virtual void WriteTypeInfo(IWriteContext context, ArrayInfo info) { BitMap4 typeInfoBitmap = new BitMap4(2); typeInfoBitmap.Set(0, info.Primitive()); typeInfoBitmap.Set(1, info.Nullable()); context.WriteByte(typeInfoBitmap.GetByte(0)); }
private void TBit(BitMap4 map, int bit) { map.SetTrue(bit); Assert.IsTrue(map.IsTrue(bit)); map.SetFalse(bit); Assert.IsFalse(map.IsTrue(bit)); map.SetTrue(bit); Assert.IsTrue(map.IsTrue(bit)); }
private int ReducedCountForNullBitMap(int count, BitMap4 bitMap) { int nullCount = 0; for (int i = 0; i < count; i++) { if (bitMap.IsTrue(i)) { nullCount++; } } return(nullCount); }
protected virtual BitMap4 NullItemsMap(IReflectArray reflector, object array) { int arrayLength = reflector.GetLength(array); BitMap4 nullBitMap = new BitMap4(arrayLength); for (int i = 0; i < arrayLength; i++) { if (reflector.Get(array, i) == null) { nullBitMap.Set(i, true); } } return(nullBitMap); }
public MarshallingContext(Db4objects.Db4o.Internal.Transaction trans, ObjectReference @ref, IUpdateDepth updateDepth, bool isNew) { // YapClass ID // Marshaller Version // number of fields _transaction = trans; _reference = @ref; _nullBitMap = new BitMap4(AspectCount()); _updateDepth = ClassMetadata().AdjustUpdateDepth(trans, updateDepth); _isNew = isNew; _writeBuffer = new MarshallingBuffer(); _currentBuffer = _writeBuffer; }
public RawFieldSpec(AspectType aspectType, string name, int fieldTypeID, byte attribs ) { _type = aspectType; _name = name; _fieldTypeID = fieldTypeID; var bitmap = new BitMap4(attribs); _isPrimitive = bitmap.IsTrue(0); _isArray = bitmap.IsTrue(1); _isNArray = bitmap.IsTrue(2); _isVirtual = false; _indexID = 0; }
public virtual void Test() { byte[] buffer = new byte[100]; for (int i = 0; i < 17; i++) { BitMap4 map = new BitMap4(i); map.WriteTo(buffer, 11); BitMap4 reReadMap = new BitMap4(buffer, 11, i); for (int j = 0; j < i; j++) { TBit(map, j); TBit(reReadMap, j); } } }
public virtual void Test() { var buffer = new byte[100]; for (var i = 0; i < 17; i++) { var map = new BitMap4(i); map.WriteTo(buffer, 11); var reReadMap = new BitMap4(buffer, 11, i); for (var j = 0; j < i; j++) { TBit(map, j); TBit(reReadMap, j); } } }
private void WriteNullBitmap(IWriteBuffer context, BitMap4 bitMap) { context.WriteBytes(bitMap.Bytes()); }
public ObjectHeaderAttributes(ByteArrayBuffer reader) { _fieldCount = reader.ReadInt(); _nullBitMap = reader.ReadBitMap(_fieldCount); }
public void WriteBitMap(BitMap4 nullBitMap) { nullBitMap.WriteTo(_buffer, _offset); _offset += nullBitMap.MarshalledLength(); }