Beispiel #1
0
        /// <summary>
        /// 设置远程对象
        /// </summary>
        /// <param name="value"></param>
        /// <param name="blockIndex">磁盘块编号</param>
        /// <param name="bufferSize">序列化缓冲区大小</param>
        /// <returns></returns>
        public unsafe bool Set(valueType value, int blockIndex, SubBuffer.Size bufferSize = SubBuffer.Size.Kilobyte4)
        {
            if (value == null)
            {
                SetNull();
                return(true);
            }
            Server.TcpInternalClient client = ClientPool.Get(blockIndex);
            if (client != null)
            {
                BinarySerialize.Serializer serializer = BinarySerialize.Serializer.YieldPool.Default.Pop() ?? new BinarySerialize.Serializer();
                SubBuffer.PoolBufferFull   buffer     = default(SubBuffer.PoolBufferFull);
                SubBuffer.Pool.GetPool(bufferSize).Get(ref buffer);
                try
                {
                    fixed(byte *bufferFixed = buffer.Buffer)
                    {
                        byte *start = bufferFixed + buffer.StartIndex;

                        serializer.SerializeNotNull(value, start, buffer.PoolBuffer.Pool.Size, ClientConfig.BinarySerializeConfig);
                        AutoCSer.Net.TcpServer.ReturnValue <ulong> index;
                        int size = serializer.Stream.ByteSize;

                        if (serializer.Stream.Data.Data == start)
                        {
                            index = client.append(new AppendBuffer {
                                Buffer = new SubArray <byte> {
                                    Array = buffer.Buffer, Start = buffer.StartIndex, Length = size
                                }, Index = size == Size ? Index : 0, BlockIndex = (ushort)blockIndex
                            });
                        }
                        else
                        {
                            index = client.append(new AppendBuffer {
                                Buffer = new SubArray <byte> {
                                    Array = serializer.Stream.GetArray(), Length = size
                                }, Index = size == Size ? Index : 0, BlockIndex = (ushort)blockIndex
                            });
                        }
                        if (index.Type == Net.TcpServer.ReturnType.Success && index.Value != 0)
                        {
                            Index = index.Value;
                            Size  = size;
                            value = Value;
                            state = MemberState.Remote;
                            return(true);
                        }
                    }
                }
                finally
                {
                    buffer.Free();
                    serializer.Free();
                }
            }
            return(false);
        }
Beispiel #2
0
 /// <summary>
 /// 设置远程对象
 /// </summary>
 /// <param name="value"></param>
 /// <param name="blockIndex">磁盘块编号</param>
 /// <param name="bufferSize">序列化缓冲区大小</param>
 /// <returns></returns>
 public unsafe bool Set(valueType value, int blockIndex, AutoCSer.Memory.BufferSize bufferSize = AutoCSer.Memory.BufferSize.Kilobyte4)
 {
     if (value == null)
     {
         SetNull();
         return(true);
     }
     Server.TcpInternalClient client = ClientPool.Get(blockIndex);
     if (client != null)
     {
         BinarySerializer         serializer = BinarySerializer.YieldPool.Default.Pop() ?? new BinarySerializer();
         SubBuffer.PoolBufferFull buffer     = default(SubBuffer.PoolBufferFull);
         SubBuffer.Pool.GetPool(bufferSize).Get(ref buffer);
         try
         {
             int          size;
             AppendBuffer appendBuffer = getAppendBuffer(ref value, serializer, ref buffer, out size);
             appendBuffer.BlockIndex = (ushort)blockIndex;
             AutoCSer.Net.TcpServer.ReturnValue <ulong> index = client.append(appendBuffer);
             if (index.Type == Net.TcpServer.ReturnType.Success && index.Value != 0)
             {
                 Index = index.Value;
                 Size  = size;
                 value = Value;
                 state = MemberState.Remote;
                 return(true);
             }
         }
         finally
         {
             buffer.Free();
             serializer.Free();
         }
     }
     return(false);
 }