Beispiel #1
0
        /// <summary>
        ///   将一个IntellectObject数组转换成byte数组的形式
        /// </summary>
        /// <param name="value">值</param>
        /// <exception cref="UnexpectedValueException">结果错误</exception>
        /// <exception cref="ArgumentNullException">参数不能为空</exception>
        public static byte[] BindIntellectObjectArray(IntellectObject[] value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            MemoryAllotter.Instance.Initialize();
            IMemorySegmentProxy proxy = MemorySegmentProxyFactory.Create();

            proxy.WriteUInt32((uint)value.Length);
            for (int i = 0; i < value.Length; i++)
            {
                IntellectObject elementObj = value[i];
                if (elementObj == null)
                {
                    proxy.WriteUInt16(0);
                }
                else
                {
                    MemoryPosition currentPostion = proxy.GetPosition();
                    proxy.Skip(2U);
                    int length = IntellectObjectEngine.ToBytes(elementObj, proxy);
                    proxy.WriteBackUInt16(currentPostion, (ushort)length);
                }
            }
            return(proxy.GetBytes());
        }