Ejemplo n.º 1
0
            protected override TSelf OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
            {
                for (int i = s_pipes.Count - 1; i >= 0; i--)
                {
                    bytes = s_pipes[i].Outflow(bytes);
                }

                var obj     = new TSelf();
                var q       = new Queue <DelegateCarried>(_carrieds);
                var d       = pool.Deconstruct(bytes);
                var carried = default(DelegateCarried);
                var value   = default(object);

                while (q.Count > 1)
                {
                    carried = q.Dequeue();
                    value   = d.Detach(carried.Type);
                    carried.SetValue(obj, value);
                }

                carried = q.Dequeue();
                value   = d.Detach(carried.Type, out length);
                carried.SetValue(obj, value);

                return(obj);
            }
Ejemplo n.º 2
0
        protected override Array OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
        {
            var d       = pool.Deconstruct(bytes);
            var element = d.Detach <Type>();
            var count   = d.Detach <int>(out length);
            var array   = Array.CreateInstance(element, count);

            if (count == 0)
            {
                goto Leave;
            }
            if (count != 1)
            {
                for (int i = 0; i < count - 1; i++)
                {
                    var current = d.Detach(element);
                    array.SetValue(current, i);
                }
            }
            var last = d.Detach(element, out length);

            array.SetValue(last, count - 1);

Leave:
            return(array);
        }
Ejemplo n.º 3
0
        protected override object OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
        {
            var d     = pool.Deconstruct(bytes);
            var type  = d.Detach <Type>();
            var value = d.Detach(type, out length);

            return(value);
        }
Ejemplo n.º 4
0
        protected override IPEndPoint OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
        {
            var d    = pool.Deconstruct(bytes);
            var addr = d.Detach <IPAddress>();
            var p    = d.Detach <int>(out length);

            return(new IPEndPoint(addr, p));
        }
Ejemplo n.º 5
0
        protected override Enum OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
        {
            var d           = pool.Deconstruct(bytes);
            var enumType    = d.Detach <Type>();
            var underlyType = Enum.GetUnderlyingType(enumType);
            var value       = d.Detach(underlyType, out length);

            return((Enum)Enum.ToObject(enumType, value));
        }
Ejemplo n.º 6
0
        protected override Test OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
        {
            var d   = pool.Deconstruct(bytes);
            var obj = new Test();

            obj.Data1 = d.Detach <int>();
            obj.Data2 = d.Detach <string>(out length);
            return(obj);
        }
Ejemplo n.º 7
0
        protected override IList OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
        {
            var d    = pool.Deconstruct(bytes);
            var flag = d.Detach <byte>();

            if (flag == 2)
            {
                var generic = d.Detach <Type>();
                var typeDef = d.Detach <Type>();
                var count   = d.Detach <int>(out length);

                var listType = typeDef.MakeGenericType(generic);
                var list     = (IList)Activator.CreateInstance(listType);
                if (count == 0)
                {
                    goto Leave;
                }

                if (count != 1)
                {
                    for (int i = 0; i < count - 1; i++)
                    {
                        list.Add(d.Detach(generic));
                    }
                }

                list.Add(d.Detach(generic, out length));
Leave:
                return(list);
            }
            else if (flag == 1)
            {
                var listType = d.Detach <Type>();
                var count    = d.Detach <int>(out length);

                var list = (IList)Activator.CreateInstance(listType);

                if (count == 0)
                {
                    goto Leave;
                }

                if (count != 1)
                {
                    for (int i = 0; i < count - 1; i++)
                    {
                        list.Add(d.Detach <object>());
                    }
                }

                list.Add(d.Detach <object>(out length));
Leave:
                return(list);
            }

            throw new NotSupportedException();
        }
Ejemplo n.º 8
0
        protected override Regex OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
        {
            var d           = pool.Deconstruct(bytes);
            var options     = (RegexOptions)d.Detach <short>();
            var timeSpan    = d.Detach <TimeSpan>();
            var regex       = d.Detach <string>(out length);
            var regexObject = new Regex(regex, options, timeSpan);

            return(regexObject);
        }
Ejemplo n.º 9
0
        protected override DataSet OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
        {
            var d           = pool.Deconstruct(bytes);
            var dataSetName = d.Detach <string>();
            var dataSet     = new DataSet(dataSetName);
            var tables      = d.Detach <DataTable[]>(out length);

            dataSet.Tables.AddRange(tables);
            return(dataSet);
        }
Ejemplo n.º 10
0
        public void CustomizeTypeTest()
        {
            var raw = new Test {
                Data1 = 123456, Data2 = "Test-String"
            };

            byte[] c = p.Construct().Attach(raw);

            var wrapped = p.Deconstruct(c).Detach <Test>(out var len);

            raw.Should().BeEquivalentTo(wrapped);
            c.Length.Should().Be(len);
        }
Ejemplo n.º 11
0
        protected override DataTable OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
        {
            var d          = pool.Deconstruct(bytes);
            var tableName  = d.Detach <string>();
            var @namespace = d.Detach <string>();
            var table      = new DataTable(tableName, @namespace);

            var columns = d.Detach <DataColumn[]>();

            foreach (var col in columns)
            {
                table.Columns.Add(col);
            }

            var rowCount = d.Detach <int>(out length);
            var colCount = columns.Length;

            if (rowCount == 0)
            {
                goto Leave;
            }

            if (rowCount != 1)
            {
                for (int rowIndex = 0; rowIndex < rowCount - 1; rowIndex++)
                {
                    var row = table.NewRow();
                    foreach (var col in columns)
                    {
                        row[col] = d.Detach(col.DataType);
                    }
                    table.Rows.Add(row);
                }
            }

            var lastRow = table.NewRow();

            for (int columnIndex = 0; columnIndex < columns.Length - 1; columnIndex++)
            {
                var column = columns[columnIndex];
                lastRow[column] = d.Detach(column.DataType);
            }
            var lastColumn = columns[columns.Length - 1];

            lastRow[lastColumn] = d.Detach(lastColumn.DataType, out length);
            table.Rows.Add(lastRow);

Leave:
            table.AcceptChanges();
            return(table);
        }
Ejemplo n.º 12
0
        protected override Type OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
        {
            var d    = pool.Deconstruct(bytes);
            var code = d.Detach <int>(out length);

            if (TypeMap.TryGet(code, out var typeString))
            {
                return(Type.GetType(typeString));
            }
            if (code == 0x7FFFFFFF)
            {
                return(Type.GetType(d.Detach <string>(out length)));
            }

            throw new InvalidCastException("Dislocation, unregistered type or not type not matched.");
        }
Ejemplo n.º 13
0
        protected override ITuple OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
        {
            var d            = pool.Deconstruct(bytes);
            var maxStackSize = d.Detach <int>();
            var values       = new Stack <object>(maxStackSize);

            for (int i = 0; i < maxStackSize - 1; i++)
            {
                var current = d.Detach <object>();
                values.Push(current);
            }
            var last = d.Detach <object>(out length);

            values.Push(last);

            return(CreateByArgs(values, maxStackSize));
        }
Ejemplo n.º 14
0
        private void EquivalentToClass <T>(T data)
        {
            byte[] c = p.Construct().Attach(data);

            var d       = p.Deconstruct(c);
            var wrapped = d.Detach <T>(out var len);

            data?.Should().BeEquivalentTo(wrapped);
            c.Length.Should().Be(len);

            BuildCtx(wrapped, len);
        }
Ejemplo n.º 15
0
        protected override BigInteger OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
        {
            var d     = pool.Deconstruct(bytes);
            var len   = d.Detach <int>(out length);
            var array = new byte[len];

            if (len == 0)
            {
                goto Leave;
            }
            if (len != 1)
            {
                for (int i = 0; i < len - 1; i++)
                {
                    array[i] = d.Detach <byte>();
                }
            }
            array[len - 1] = d.Detach <byte>(out length);

Leave:
            return(new BigInteger(array));
        }
Ejemplo n.º 16
0
        protected override DataColumn OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
        {
            var d             = pool.Deconstruct(bytes);
            var columnName    = d.Detach <string>();
            var dataType      = d.Detach <Type>();
            var expr          = d.Detach <string>();
            var columnMapping = (MappingType)d.Detach <byte>();
            var column        = new DataColumn(columnName, dataType, expr, columnMapping)
            {
                AllowDBNull       = d.Detach <bool>(),
                AutoIncrement     = d.Detach <bool>(),
                AutoIncrementSeed = d.Detach <long>(),
                AutoIncrementStep = d.Detach <long>(),
                Caption           = d.Detach <string>(),
                DateTimeMode      = (DataSetDateTime)d.Detach <byte>(),
                MaxLength         = d.Detach <int>(),
                Namespace         = d.Detach <string>(),
                ReadOnly          = d.Detach <bool>(),
                Unique            = d.Detach <bool>(out length)
            };

            return(column);
        }
Ejemplo n.º 17
0
 protected override StringBuilder OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool) => new StringBuilder(pool.Deconstruct(bytes).Detach <string>(out length));
Ejemplo n.º 18
0
 protected override UIntPtr OnConvertFromBytes(byte[] bytes, IMarshalingProvider pool) => new UIntPtr(pool.Deconstruct(bytes).Detach <uint>());
Ejemplo n.º 19
0
 protected override TEnum OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
 {
     return((TEnum)pool.Deconstruct(bytes).Detach(_underlyingType, out length));
 }
Ejemplo n.º 20
0
 protected override CultureInfo OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
 {
     return(new CultureInfo(pool.Deconstruct(bytes).Detach <int>(out length)));
 }
Ejemplo n.º 21
0
        protected override IDictionary OnConvertFromBytes(byte[] bytes, out int length, IMarshalingProvider pool)
        {
            var d    = pool.Deconstruct(bytes);
            var flag = d.Detach <byte>();

            if (flag == 2)
            {
                var count     = d.Detach <int>();
                var keyType   = d.Detach <Type>();
                var valueType = d.Detach <Type>(out length);
                var dictType  = typeof(Dictionary <,>).MakeGenericType(keyType, valueType);
                var dict      = Activator.CreateInstance(dictType) as IDictionary;
                if (count == 0)
                {
                    goto Leave;
                }

                if (count != 1)
                {
                    for (int i = 0; i < count - 1; i++)
                    {
                        var currentKey   = d.Detach(keyType);
                        var currentValue = d.Detach(valueType);
                        dict.Add(currentKey, currentValue);
                    }
                }

                var lastKey   = d.Detach(keyType);
                var lastValue = d.Detach(valueType, out length);
                dict.Add(lastKey, lastValue);

Leave:
                return(dict);
            }
            else if (flag == 1)
            {
                var count    = d.Detach <int>();
                var dictType = d.Detach <Type>(out length);
                var dict     = Activator.CreateInstance(dictType) as IDictionary;
                if (count == 0)
                {
                    goto Leave;
                }

                if (count != 1)
                {
                    for (int i = 0; i < count - 1; i++)
                    {
                        var currentKey   = d.Detach <object>();
                        var currentValue = d.Detach <object>();
                        dict.Add(currentKey, currentValue);
                    }
                }

                var lastKey   = d.Detach <object>();
                var lastValue = d.Detach <object>(out length);
                dict.Add(lastKey, lastValue);

Leave:
                return(dict);
            }
            throw new NotSupportedException();
        }
Ejemplo n.º 22
0
 protected override DateTime OnConvertFromBytes(byte[] bytes, IMarshalingProvider pool)
 {
     return(new DateTime(pool.Deconstruct(bytes).Detach <long>()));
 }