Ejemplo n.º 1
0
        public virtual void TestLinkOffset()
        {
            int linkOffset           = 7;
            MarshallingBuffer buffer = new MarshallingBuffer();

            buffer.WriteInt(Data1);
            buffer.WriteByte(Data2);
            MarshallingBuffer child = buffer.AddChild();

            child.WriteInt(Data3);
            child.WriteInt(Data4);
            MarshallingBuffer grandChild = child.AddChild();

            grandChild.WriteInt(Data5);
            buffer.MergeChildren(null, 0, linkOffset);
            ByteArrayBuffer content        = InspectContent(buffer);
            ByteArrayBuffer extendedBuffer = new ByteArrayBuffer(content.Length() + linkOffset
                                                                 );

            content.CopyTo(extendedBuffer, 0, linkOffset, content.Length());
            extendedBuffer.Seek(linkOffset);
            Assert.AreEqual(Data1, extendedBuffer.ReadInt());
            Assert.AreEqual(Data2, extendedBuffer.ReadByte());
            int address = extendedBuffer.ReadInt();

            extendedBuffer.Seek(address);
            Assert.AreEqual(Data3, extendedBuffer.ReadInt());
            Assert.AreEqual(Data4, extendedBuffer.ReadInt());
            address = extendedBuffer.ReadInt();
            extendedBuffer.Seek(address);
            Assert.AreEqual(Data5, extendedBuffer.ReadInt());
        }
Ejemplo n.º 2
0
 private void DeleteUpThrough(int location)
 {
     // int start = location + 1;  // start at the first byte after the location
     byte[] newBuffer = Arrays.CopyOfRange(buffer.ToByteArray(), location, buffer.Length
                                               ());
     buffer.Clear();
     buffer.Append(newBuffer, 0, newBuffer.Length);
 }
Ejemplo n.º 3
0
        public virtual Msg GetWriter(Transaction trans, ByteArrayBuffer bytes)
        {
            MsgD msg = GetWriterForLength(trans, bytes.Length());

            msg._payLoad.Append(bytes._buffer);
            return(msg);
        }
Ejemplo n.º 4
0
 private void AppendPayLoad(StatefulBuffer target, Pointer4 pointer, ByteArrayBuffer
                            payLoad)
 {
     target.WriteInt(payLoad.Length());
     target.WriteInt(pointer.Id());
     target.WriteInt(pointer.Address());
     target.Append(payLoad._buffer);
 }
Ejemplo n.º 5
0
        public MsgD GetWriterForBuffer(Transaction trans
                                       , ByteArrayBuffer buffer)
        {
            var writer = GetWriterForLength(trans, buffer
                                            .Length());

            writer.WriteBytes(buffer._buffer);
            return(writer);
        }
Ejemplo n.º 6
0
        private static byte[] BytesToSendFor(string message)
        {
            var io = new LatinStringIO();
            var marshalledStringLength = io.Length(message);
            var buffer = new ByteArrayBuffer(marshalledStringLength + Const4.IntLength);

            buffer.WriteInt(marshalledStringLength);

            io.WriteLengthAndString(buffer, message);
            buffer.Seek(0);
            return(buffer.ReadBytes(buffer.Length()));
        }
Ejemplo n.º 7
0
        public Msg ReplyFromServer()
        {
            ByteArrayBuffer bytes              = GetByteLoad();
            int             classMetadataID    = bytes.ReadInt();
            int             prefetchDepth      = bytes.ReadInt();
            int             prefetchCount      = bytes.ReadInt();
            bool            triggerQueryEvents = bytes.ReadInt() == 1;
            ByteArrayBuffer payload            = MarshallIDsFor(classMetadataID, prefetchDepth, prefetchCount
                                                                , triggerQueryEvents);
            MsgD message = Msg.IdList.GetWriterForLength(Transaction(), payload.Length());

            message.PayLoad().WriteBytes(payload._buffer);
            return(message);
        }
Ejemplo n.º 8
0
        internal MsgD GetWriter(Transaction trans, Pointer4 pointer, ByteArrayBuffer buffer
                                , int[] prependInts)
        {
            int lengthNeeded = buffer.Length() + LengthForFirst;

            if (prependInts != null)
            {
                lengthNeeded += (prependInts.Length * Const4.IntLength);
            }
            MsgD message = GetWriterForLength(trans, lengthNeeded);

            if (prependInts != null)
            {
                for (int i = 0; i < prependInts.Length; i++)
                {
                    message._payLoad.WriteInt(prependInts[i]);
                }
            }
            AppendPayLoad(message._payLoad, pointer, buffer);
            return(message);
        }
Ejemplo n.º 9
0
 private int CopyDependentSlot(IDefragmentContext context, int sourceId)
 {
     try
     {
         ByteArrayBuffer sourceBuffer      = context.SourceBufferById(sourceId);
         Slot            targetPayloadSlot = context.AllocateTargetSlot(sourceBuffer.Length());
         int             targetId          = context.Services().TargetNewId();
         context.Services().MapIDs(sourceId, targetId, false);
         context.Services().Mapping().MapId(targetId, targetPayloadSlot);
         DefragmentContextImpl payloadContext = new DefragmentContextImpl(sourceBuffer, (DefragmentContextImpl
                                                                                         )context);
         int           clazzId                 = payloadContext.CopyIDReturnOriginalID();
         ITypeHandler4 payloadHandler          = payloadContext.TypeHandlerForId(clazzId);
         ITypeHandler4 versionedPayloadHandler = HandlerRegistry.CorrectHandlerVersion(payloadContext
                                                                                       , payloadHandler);
         versionedPayloadHandler.Defragment(payloadContext);
         payloadContext.WriteToTarget(targetPayloadSlot.Address());
         return(targetId);
     }
     catch (IOException ioexc)
     {
         throw new Db4oIOException(ioexc);
     }
 }
Ejemplo n.º 10
0
        private MsgD BuildQueryResultMessage(int queryResultId, IIntIterator4 ids, int maxCount
                                             , ObjectExchangeConfiguration config)
        {
            ByteArrayBuffer payload = ObjectExchangeStrategyFactory.ForConfig(config).Marshall
                                          ((LocalTransaction)Transaction(), ids, maxCount);
            MsgD message = QueryResult.GetWriterForLength(Transaction(), Const4.IntLength + payload
                                                          .Length());
            StatefulBuffer writer = message.PayLoad();

            writer.WriteInt(queryResultId);
            writer.WriteBytes(payload._buffer);
            return(message);
        }
Ejemplo n.º 11
0
 private void Write(IBin storage, ByteArrayBuffer buffer)
 {
     storage.Write(0, buffer._buffer, buffer.Length());
 }
Ejemplo n.º 12
0
 private void Read(IBin storage, ByteArrayBuffer buffer)
 {
     storage.Read(0, buffer._buffer, buffer.Length());
 }
Ejemplo n.º 13
0
 private void Write(IBin storage, ByteArrayBuffer buffer)
 {
     storage.Write(0, buffer._buffer, buffer.Length());
 }
Ejemplo n.º 14
0
 /// <exception cref="System.IO.IOException"></exception>
 private static void WriteBytes(ByteArrayBuffer b, OutputStream @out)
 {
     @out.Write(b.Buffer(), 0, b.Length());
 }
Ejemplo n.º 15
0
 /// <exception cref="System.IO.IOException"></exception>
 private static void WriteBytes(ByteArrayBuffer b, OutputStream @out)
 {
     @out.Write(b.Buffer(), 0, b.Length());
 }
Ejemplo n.º 16
0
 public Db4objects.Db4o.CS.Internal.Messages.MsgD GetWriterForBuffer(Transaction trans
                                                                     , ByteArrayBuffer buffer)
 {
     Db4objects.Db4o.CS.Internal.Messages.MsgD writer = GetWriterForLength(trans, buffer
                                                                           .Length());
     writer.WriteBytes(buffer._buffer);
     return(writer);
 }
Ejemplo n.º 17
0
 private void Read(IBin storage, ByteArrayBuffer buffer)
 {
     storage.Read(0, buffer._buffer, buffer.Length());
 }