Esempio n. 1
0
        public override object Read(object value, ProtoReader source)
        {
            int       fieldNumber = source.FieldNumber;
            BasicList list        = new BasicList();

            if ((this.packedWireType != WireType.None) && (source.WireType == WireType.String))
            {
                SubItemToken token = ProtoReader.StartSubItem(source);
                while (ProtoReader.HasSubValue(this.packedWireType, source))
                {
                    list.Add(base.Tail.Read(null, source));
                }
                ProtoReader.EndSubItem(token, source);
            }
            else
            {
                do
                {
                    list.Add(base.Tail.Read(null, source));
                }while (source.TryReadFieldHeader(fieldNumber));
            }
            int   offset = this.AppendToCollection ? ((value == null) ? 0 : ((Array)value).Length) : 0;
            Array array  = Array.CreateInstance(this.itemType, (int)(offset + list.Count));

            if (offset != 0)
            {
                ((Array)value).CopyTo(array, 0);
            }
            list.CopyTo(array, offset);
            return(array);
        }
Esempio n. 2
0
        public override object Read(object value, ProtoReader source)
        {
            int       field     = source.FieldNumber;
            BasicList basicList = new BasicList();

            if (packedWireType != WireType.None && source.WireType == WireType.String)
            {
                SubItemToken token = ProtoReader.StartSubItem(source);
                while (ProtoReader.HasSubValue(packedWireType, source))
                {
                    basicList.Add(base.Tail.Read(null, source));
                }
                ProtoReader.EndSubItem(token, source);
            }
            else
            {
                do
                {
                    basicList.Add(base.Tail.Read(null, source));
                }while (source.TryReadFieldHeader(field));
            }
            int   num   = AppendToCollection ? ((value != null) ? ((Array)value).Length : 0) : 0;
            Array array = Array.CreateInstance(itemType, num + basicList.Count);

            if (num != 0)
            {
                ((Array)value).CopyTo(array, 0);
            }
            basicList.CopyTo(array, num);
            return(array);
        }
Esempio n. 3
0
        public override object Read(object value, ProtoReader source)
        {
            int       field = source.FieldNumber;
            BasicList list  = new BasicList();

            if (packedWireType != WireType.None && source.WireType == WireType.String)
            {
                SubItemToken token = ProtoReader.StartSubItem(source);
                while (ProtoReader.HasSubValue(packedWireType, source))
                {
                    list.Add(Tail.Read(null, source));
                }
                ProtoReader.EndSubItem(token, source);
            }
            else
            {
                do
                {
                    list.Add(Tail.Read(null, source));
                } while (source.TryReadFieldHeader(field));
            }
            int   oldLen = AppendToCollection ? ((value == null ? 0 : ((Array)value).Length)) : 0;
            Array result = Array.CreateInstance(itemType, oldLen + list.Count);

            if (oldLen != 0)
            {
                ((Array)value).CopyTo(result, 0);
            }
            list.CopyTo(result, oldLen);
            return(result);
        }
        public override object Read(object value, ProtoReader source)
        {
            int    field     = source.FieldNumber;
            object origValue = value;

            if (value == null)
            {
                value = ProtobufTypeHelper.CreateInstance(concreteType);
            }
            bool isList = IsList && !SuppressIList;

            if (packedWireType != WireType.None && source.WireType == WireType.String)
            {
                SubItemToken token = ProtoReader.StartSubItem(source);
                if (isList)
                {
                    IList list = (IList)value;
                    while (ProtoReader.HasSubValue(packedWireType, source))
                    {
                        list.Add(Tail.Read(null, source));
                    }
                }
                else
                {
                    object[] args = new object[1];
                    while (ProtoReader.HasSubValue(packedWireType, source))
                    {
                        args[0] = Tail.Read(null, source);
                        add.Invoke(value, args);
                    }
                }
                ProtoReader.EndSubItem(token, source);
            }
            else
            {
                if (isList)
                {
                    IList list = (IList)value;
                    do
                    {
                        object item = Tail.Read(null, source);
                        item = ProtobufTypeHelper.ConvertCLRInstance(item);
                        list.Add(item);
                    } while (source.TryReadFieldHeader(field));
                }
                else
                {
                    object[] args = new object[1];
                    do
                    {
                        args[0] = Tail.Read(null, source);
                        add.Invoke(value, args);
                    } while (source.TryReadFieldHeader(field));
                }
            }
            return(origValue == value ? null : value);
        }
Esempio n. 5
0
        public override object Read(object value, ProtoReader source)
        {
            int    fieldNumber = source.FieldNumber;
            object obj         = value;

            if (value == null)
            {
                value = Activator.CreateInstance(this.concreteType);
            }
            bool flag = (!this.IsList ? false : !this.SuppressIList);

            if (this.packedWireType != WireType.None && source.WireType == WireType.String)
            {
                SubItemToken subItemToken = ProtoReader.StartSubItem(source);
                if (!flag)
                {
                    object[] objArray = new object[1];
                    while (ProtoReader.HasSubValue(this.packedWireType, source))
                    {
                        objArray[0] = this.Tail.Read(null, source);
                        [email protected](value, objArray);
                    }
                }
                else
                {
                    IList lists = (IList)value;
                    while (ProtoReader.HasSubValue(this.packedWireType, source))
                    {
                        lists.Add(this.Tail.Read(null, source));
                    }
                }
                ProtoReader.EndSubItem(subItemToken, source);
            }
            else if (!flag)
            {
                object[] objArray1 = new object[1];
                do
                {
                    objArray1[0] = this.Tail.Read(null, source);
                    [email protected](value, objArray1);
                }while (source.TryReadFieldHeader(fieldNumber));
            }
            else
            {
                IList lists1 = (IList)value;
                do
                {
                    lists1.Add(this.Tail.Read(null, source));
                }while (source.TryReadFieldHeader(fieldNumber));
            }
            if (obj != value)
            {
                return(value);
            }
            return(null);
        }
Esempio n. 6
0
        public override object Read(object value, ProtoReader source)
        {
            int    field = source.FieldNumber;
            object obj   = value;

            if (value == null)
            {
                value = Activator.CreateInstance(concreteType);
            }
            bool flag = IsList && !SuppressIList;

            if (packedWireType != WireType.None && source.WireType == WireType.String)
            {
                SubItemToken token = ProtoReader.StartSubItem(source);
                if (flag)
                {
                    IList list = (IList)value;
                    while (ProtoReader.HasSubValue(packedWireType, source))
                    {
                        list.Add(base.Tail.Read(null, source));
                    }
                }
                else
                {
                    object[] array = new object[1];
                    while (ProtoReader.HasSubValue(packedWireType, source))
                    {
                        array[0] = base.Tail.Read(null, source);
                        add.Invoke(value, array);
                    }
                }
                ProtoReader.EndSubItem(token, source);
            }
            else if (flag)
            {
                IList list2 = (IList)value;
                do
                {
                    list2.Add(base.Tail.Read(null, source));
                }while (source.TryReadFieldHeader(field));
            }
            else
            {
                object[] array2 = new object[1];
                do
                {
                    array2[0] = base.Tail.Read(null, source);
                    add.Invoke(value, array2);
                }while (source.TryReadFieldHeader(field));
            }
            if (obj != value)
            {
                return(value);
            }
            return(null);
        }
Esempio n. 7
0
        public override object Read(object value, ProtoReader source)
        {
            int    fieldNumber = source.FieldNumber;
            object obj2        = value;

            if (value == null)
            {
                value = Activator.CreateInstance(this.concreteType);
            }
            bool flag = this.IsList && !this.SuppressIList;

            if ((this.packedWireType != WireType.None) && (source.WireType == WireType.String))
            {
                SubItemToken token = ProtoReader.StartSubItem(source);
                if (flag)
                {
                    IList list = (IList)value;
                    while (ProtoReader.HasSubValue(this.packedWireType, source))
                    {
                        list.Add(base.Tail.Read(null, source));
                    }
                }
                else
                {
                    object[] parameters = new object[1];
                    while (ProtoReader.HasSubValue(this.packedWireType, source))
                    {
                        parameters[0] = base.Tail.Read(null, source);
                        this.add.Invoke(value, parameters);
                    }
                }
                ProtoReader.EndSubItem(token, source);
            }
            else if (flag)
            {
                IList list2 = (IList)value;
                do
                {
                    list2.Add(base.Tail.Read(null, source));
                }while (source.TryReadFieldHeader(fieldNumber));
            }
            else
            {
                object[] objArray2 = new object[1];
                do
                {
                    objArray2[0] = base.Tail.Read(null, source);
                    this.add.Invoke(value, objArray2);
                }while (source.TryReadFieldHeader(fieldNumber));
            }
            if (obj2 != value)
            {
                return(value);
            }
            return(null);
        }
Esempio n. 8
0
        // Token: 0x06003575 RID: 13685 RVA: 0x001348B0 File Offset: 0x00132CB0
        public override object Read(object value, ProtoReader source)
        {
            object obj         = builderFactory.Invoke(null, null);
            int    fieldNumber = source.FieldNumber;

            object[] array = new object[1];
            if (base.AppendToCollection && value != null && ((IList)value).Count != 0)
            {
                if (addRange != null)
                {
                    array[0] = value;
                    addRange.Invoke(obj, array);
                }
                else
                {
                    IEnumerator enumerator = ((IList)value).GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            object obj2 = enumerator.Current;
                            array[0] = obj2;
                            add.Invoke(obj, array);
                        }
                    }
                    finally
                    {
                        IDisposable disposable;
                        if ((disposable = (enumerator as IDisposable)) != null)
                        {
                            disposable.Dispose();
                        }
                    }
                }
            }
            if (packedWireType != WireType.None && source.WireType == WireType.String)
            {
                SubItemToken token = ProtoReader.StartSubItem(source);
                while (ProtoReader.HasSubValue(packedWireType, source))
                {
                    array[0] = Tail.Read(null, source);
                    add.Invoke(obj, array);
                }
                ProtoReader.EndSubItem(token, source);
            }
            else
            {
                do
                {
                    array[0] = Tail.Read(null, source);
                    add.Invoke(obj, array);
                }while (source.TryReadFieldHeader(fieldNumber));
            }
            return(finish.Invoke(obj, null));
        }
Esempio n. 9
0
        public override object Read(object value, ProtoReader source)
        {
            int field = source.FieldNumber;

            if (value == null)
            {
                value = Activator.CreateInstance(concreteType);
            }

            if (packedWireType != WireType.None && source.WireType == WireType.String)
            {
                SubItemToken token = ProtoReader.StartSubItem(source);
                if (isList)
                {
                    IList list = (IList)value;
                    while (ProtoReader.HasSubValue(packedWireType, source))
                    {
                        list.Add(Tail.Read(null, source));
                    }
                }
                else
                {
                    object[] args = new object[1];
                    while (ProtoReader.HasSubValue(packedWireType, source))
                    {
                        args[0] = Tail.Read(null, source);
                        add.Invoke(value, args);
                    }
                }
                ProtoReader.EndSubItem(token, source);
            }
            else
            {
                if (isList)
                {
                    IList list = (IList)value;
                    do
                    {
                        list.Add(Tail.Read(null, source));
                    } while (source.TryReadFieldHeader(field));
                }
                else
                {
                    object[] args = new object[1];
                    do
                    {
                        args[0] = Tail.Read(null, source);
                        add.Invoke(value, args);
                    } while (source.TryReadFieldHeader(field));
                }
            }
            return(value);
        }
Esempio n. 10
0
        public override object Read(ProtoReader source, ref ProtoReader.State state, object value)
        {
            object builderInstance = builderFactory.Invoke(null, null);
            int    field           = source.FieldNumber;

            object[] args = new object[1];
            if (AppendToCollection && value != null && (isEmpty != null ? !(bool)isEmpty.GetValue(value, null) : (int)length.GetValue(value, null) != 0))
            {
                if (addRange != null)
                {
                    args[0] = value;
                    addRange.Invoke(builderInstance, args);
                }
                else
                {
                    foreach (object item in (ICollection)value)
                    {
                        args[0] = item;
                        add.Invoke(builderInstance, args);
                    }
                }
            }

            if (packedWireType != WireType.None && source.WireType == WireType.String)
            {
                SubItemToken token = ProtoReader.StartSubItem(source, ref state);
                while (ProtoReader.HasSubValue(packedWireType, source))
                {
                    args[0] = Tail.Read(source, ref state, null);
                    add.Invoke(builderInstance, args);
                }
                ProtoReader.EndSubItem(token, source, ref state);
            }
            else
            {
                do
                {
                    args[0] = Tail.Read(source, ref state, null);
                    add.Invoke(builderInstance, args);
                } while (source.TryReadFieldHeader(ref state, field));
            }

            return(finish.Invoke(builderInstance, null));
        }
Esempio n. 11
0
        MetaType TryRead(MetaType metaType, ProtoReader source, int recursionLevel)
        {
            SubType[] subTypes = metaType.GetSubtypes();
            int       fieldNumber;
            SubType   subType;

            if (recursionLevel == 0)
            {
                if (source.WireType != WireType.String)
                {
                    fieldNumber = source.ReadInt32() - 1;
                    subType     = subTypes.FirstOrDefault(st => st.FieldNumber == fieldNumber);
                    return(subType?.DerivedType ?? metaType); // versioning
                }
            }
            SubItemToken?token = null;

            if (recursionLevel == 0)
            {
                token = ProtoReader.StartSubItem(source);
            }

            try
            {
                if (!ProtoReader.HasSubValue(WireType.Variant, source))
                {
                    return(metaType);
                }

                fieldNumber = source.ReadInt32() - 1;
                subType     = subTypes.FirstOrDefault(st => st.FieldNumber == fieldNumber);
                return(subType != null // versioning
                            ? TryRead(subType.DerivedType, source, recursionLevel + 1)
                            : metaType);
            }
            finally
            {
                if (token != null)
                {
                    ProtoReader.EndSubItem(token.Value, true, source);
                }
            }
        }
        public override object Read(object value, ProtoReader source)
        {
            object obj         = this.builderFactory.Invoke(null, null);
            int    fieldNumber = source.FieldNumber;

            object[] objArray = new object[1];
            if (base.AppendToCollection && value != null && ((IList)value).Count != 0)
            {
                if (this.addRange == null)
                {
                    foreach (object obj1 in (IList)value)
                    {
                        objArray[0] = obj1;
                        [email protected](obj, objArray);
                    }
                }
                else
                {
                    objArray[0] = value;
                    this.addRange.Invoke(obj, objArray);
                }
            }
            if (this.packedWireType == WireType.None || source.WireType != WireType.String)
            {
                do
                {
                    objArray[0] = this.Tail.Read(null, source);
                    [email protected](obj, objArray);
                }while (source.TryReadFieldHeader(fieldNumber));
            }
            else
            {
                SubItemToken subItemToken = ProtoReader.StartSubItem(source);
                while (ProtoReader.HasSubValue(this.packedWireType, source))
                {
                    objArray[0] = this.Tail.Read(null, source);
                    [email protected](obj, objArray);
                }
                ProtoReader.EndSubItem(subItemToken, source);
            }
            return(this.finish.Invoke(obj, null));
        }
        public override object Read(object value, ProtoReader source)
        {
            object obj         = builderFactory.Invoke(null, null);
            int    fieldNumber = source.FieldNumber;

            object[] array = new object[1];
            if (base.AppendToCollection && value != null && ((IList)value).Count != 0)
            {
                if (addRange != null)
                {
                    array[0] = value;
                    addRange.Invoke(obj, array);
                }
                else
                {
                    foreach (object item in (IList)value)
                    {
                        object obj2 = array[0] = item;
                        add.Invoke(obj, array);
                    }
                }
            }
            if (packedWireType != WireType.None && source.WireType == WireType.String)
            {
                SubItemToken token = ProtoReader.StartSubItem(source);
                while (ProtoReader.HasSubValue(packedWireType, source))
                {
                    array[0] = Tail.Read(null, source);
                    add.Invoke(obj, array);
                }
                ProtoReader.EndSubItem(token, source);
            }
            else
            {
                do
                {
                    array[0] = Tail.Read(null, source);
                    add.Invoke(obj, array);
                }while (source.TryReadFieldHeader(fieldNumber));
            }
            return(finish.Invoke(obj, null));
        }
Esempio n. 14
0
        public override object Read(object value, ProtoReader source)
        {
            int       num;
            int       fieldNumber = source.FieldNumber;
            BasicList basicLists  = new BasicList();

            if (this.packedWireType == WireType.None || source.WireType != WireType.String)
            {
                do
                {
                    basicLists.Add(this.Tail.Read(null, source));
                }while (source.TryReadFieldHeader(fieldNumber));
            }
            else
            {
                SubItemToken subItemToken = ProtoReader.StartSubItem(source);
                while (ProtoReader.HasSubValue(this.packedWireType, source))
                {
                    basicLists.Add(this.Tail.Read(null, source));
                }
                ProtoReader.EndSubItem(subItemToken, source);
            }
            if (this.AppendToCollection)
            {
                num = (value == null ? 0 : ((Array)value).Length);
            }
            else
            {
                num = 0;
            }
            int   num1   = num;
            Array arrays = Array.CreateInstance(this.itemType, num1 + basicLists.Count);

            if (num1 != 0)
            {
                ((Array)value).CopyTo(arrays, 0);
            }
            basicLists.CopyTo(arrays, num1);
            return(arrays);
        }
Esempio n. 15
0
 public override object Read(object value, ProtoReader source)
 {
     try
     {
         int    field     = source.FieldNumber;
         object origValue = value;
         if (value == null)
         {
             value = Activator.CreateInstance(concreteType);
         }
         bool isList = IsList && !SuppressIList;
         if (packedWireType != WireType.None && source.WireType == WireType.String)
         {
             SubItemToken token = ProtoReader.StartSubItem(source);
             if (isList)
             {
                 IList list = (IList)value;
                 while (ProtoReader.HasSubValue(packedWireType, source))
                 {
                     list.Add(Tail.Read(null, source));
                 }
             }
             else
             {
                 object[] args = new object[1];
                 while (ProtoReader.HasSubValue(packedWireType, source))
                 {
                     args[0] = Tail.Read(null, source);
                     add.Invoke(value, args);
                 }
             }
             ProtoReader.EndSubItem(token, source);
         }
         else
         {
             if (isList)
             {
                 IList list = (IList)value;
                 do
                 {
                     list.Add(Tail.Read(null, source));
                 } while (source.TryReadFieldHeader(field));
             }
             else
             {
                 object[] args = new object[1];
                 do
                 {
                     args[0] = Tail.Read(null, source);
                     add.Invoke(value, args);
                 } while (source.TryReadFieldHeader(field));
             }
         }
         return(origValue == value ? null : value);
     } catch (TargetInvocationException tie)
     {
         if (tie.InnerException != null)
         {
             throw tie.InnerException;
         }
         throw;
     }
 }
    private static IEnumerable <Channel> ReadChannels(string path)
    {
        using (var file = File.OpenRead(path))
            using (var reader = new ProtoReader(file, null, null))
            {
                while (reader.ReadFieldHeader() > 0)
                {
                    switch (reader.FieldNumber)
                    {
                    case 1:
                        Console.WriteLine("Recording name: {0}", reader.ReadString());
                        break;

                    case 2:     // each "2" instance represents a different "Channel" or a channel switch
                        var          channelToken = ProtoReader.StartSubItem(reader);
                        int          floatCount   = 0;
                        List <float> list         = new List <float>();
                        Channel      channel      = new Channel {
                            Points = list
                        };
                        while (reader.ReadFieldHeader() > 0)
                        {
                            switch (reader.FieldNumber)
                            {
                            case 1:
                                channel.Name = reader.ReadString();
                                break;

                            case 2:
                                switch (reader.WireType)
                                {
                                case WireType.String:             // packed array - multiple floats
                                    var dataToken = ProtoReader.StartSubItem(reader);
                                    while (ProtoReader.HasSubValue(WireType.Fixed32, reader))
                                    {
                                        list.Add(reader.ReadSingle());
                                        floatCount++;
                                    }
                                    ProtoReader.EndSubItem(dataToken, reader);
                                    break;

                                case WireType.Fixed32:        // simple float
                                    list.Add(reader.ReadSingle());
                                    floatCount++;             // got 1
                                    break;

                                default:
                                    Console.WriteLine("Unexpected data wire-type: {0}", reader.WireType);
                                    break;
                                }
                                break;

                            default:
                                Console.WriteLine("Unexpected field in channel: {0}/{1}", reader.FieldNumber, reader.WireType);
                                reader.SkipField();
                                break;
                            }
                        }
                        ProtoReader.EndSubItem(channelToken, reader);
                        yield return(channel);

                        break;

                    default:
                        Console.WriteLine("Unexpected field in recording: {0}/{1}", reader.FieldNumber, reader.WireType);
                        reader.SkipField();
                        break;
                    }
                }
            }
    }
Esempio n. 17
0
        public void Read(TryReadMetaDelegate readNextMeta, Action prepareInstance, Action <object> add, ProtoReader source)
        {
            WireType packedWireType = _packedWireTypeForRead;
            bool     packed         = (!_protoCompatibility || packedWireType != WireType.None) && source.WireType == WireType.String;
            int      fieldNumber    = source.FieldNumber;

            bool subItemNeeded = packed || !_protoCompatibility;

            SubItemToken token = subItemNeeded ? ProtoReader.StartSubItem(source) : new SubItemToken();

            if (_protoCompatibility)
            {
                // this is not an error that we don't wait for the first item
                // if field is present there is at least one element

                prepareInstance?.Invoke();

                if (packed)
                {
                    while (ProtoReader.HasSubValue(packedWireType, source))
                    {
                        ReadElementContent(add, source);
                    }
                }
                else
                {
                    do
                    {
                        ReadElementContent(add, source);
                    } while (source.TryReadFieldHeader(fieldNumber));
                }
            }
            else
            {
                bool loop;

                do
                {
                    loop = false;

                    if (readNextMeta?.Invoke() ?? false)
                    {
                        loop = true;
                    }
                    else if (!source.TryReadFieldHeader(FieldItem))
                    {
                        if (source.ReadFieldHeader() == 0)
                        {
                            break;                                // empty
                        }
                        source.SkipField();
                        loop = true;
                    }
                } while (loop);

                prepareInstance?.Invoke();

                if (source.FieldNumber == FieldItem)
                {
                    if (packed)
                    {
                        packedWireType = source.WireType;
                        do
                        {
                            ReadElementContent(add, source);
                        } while (ProtoReader.HasSubValue(packedWireType, source));
                    }
                    else
                    {
                        do
                        {
                            ReadElementContent(add, source);
                        } while (source.TryReadFieldHeader(FieldItem));
                    }
                }
            }

            if (subItemNeeded)
            {
                ProtoReader.EndSubItem(token, source);
            }
        }
Esempio n. 18
0
        // Token: 0x0600359A RID: 13722 RVA: 0x00134344 File Offset: 0x00132744
        public override object Read(object value, ProtoReader source)
        {
            object result;

            try
            {
                int    field = source.FieldNumber;
                object obj   = value;
                if (value == null)
                {
                    value = Activator.CreateInstance(concreteType);
                }
                bool flag = IsList && !SuppressIList;
                if (packedWireType != WireType.None && source.WireType == WireType.String)
                {
                    SubItemToken token = ProtoReader.StartSubItem(source);
                    if (flag)
                    {
                        IList list = (IList)value;
                        while (ProtoReader.HasSubValue(packedWireType, source))
                        {
                            list.Add(Tail.Read(null, source));
                        }
                    }
                    else
                    {
                        object[] array = new object[1];
                        while (ProtoReader.HasSubValue(packedWireType, source))
                        {
                            array[0] = Tail.Read(null, source);
                            add.Invoke(value, array);
                        }
                    }
                    ProtoReader.EndSubItem(token, source);
                }
                else if (flag)
                {
                    IList list2 = (IList)value;
                    do
                    {
                        list2.Add(Tail.Read(null, source));
                    }while (source.TryReadFieldHeader(field));
                }
                else
                {
                    object[] array2 = new object[1];
                    do
                    {
                        array2[0] = Tail.Read(null, source);
                        add.Invoke(value, array2);
                    }while (source.TryReadFieldHeader(field));
                }
                result = ((obj != value) ? value : null);
            }
            catch (TargetInvocationException ex)
            {
                if (ex.InnerException != null)
                {
                    throw ex.InnerException;
                }
                throw;
            }
            return(result);
        }