Example #1
0
        internal FieldDescriptor(FieldDescriptorProto proto, FileDescriptor file,
                                 MessageDescriptor parent, int index, string propertyName)
            : base(file, file.ComputeFullName(parent, proto.Name), index)
        {
            Proto = proto;
            if (proto.Type != 0)
            {
                fieldType = GetFieldTypeFromProtoType(proto.Type);
            }

            if (FieldNumber <= 0)
            {
                throw new DescriptorValidationException(this, "Field numbers must be positive integers.");
            }
            ContainingType = parent;
            // OneofIndex "defaults" to -1 due to a hack in FieldDescriptor.OnConstruction.
            if (proto.OneofIndex != -1)
            {
                if (proto.OneofIndex < 0 || proto.OneofIndex >= parent.Proto.OneofDecl.Count)
                {
                    throw new DescriptorValidationException(this,
                                                            $"FieldDescriptorProto.oneof_index is out of range for type {parent.Name}");
                }
                ContainingOneof = parent.Oneofs[proto.OneofIndex];
            }

            file.DescriptorPool.AddSymbol(this);
            // We can't create the accessor until we've cross-linked, unfortunately, as we
            // may not know whether the type of the field is a map or not. Remember the property name
            // for later.
            // We could trust the generated code and check whether the type of the property is
            // a MapField, but that feels a tad nasty.
            this.propertyName = propertyName;
            JsonName          = Proto.JsonName == "" ? JsonFormatter.ToCamelCase(Proto.Name) : Proto.JsonName;
        }
Example #2
0
        internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, GeneratedClrTypeInfo generatedCodeInfo)
            : base(file, file.ComputeFullName(parent, proto.Name), typeIndex)
        {
            Proto          = proto;
            Parser         = generatedCodeInfo?.Parser;
            ClrType        = generatedCodeInfo?.ClrType;
            ContainingType = parent;

            // If generatedCodeInfo is null, we just won't generate an accessor for any fields.
            Oneofs = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.OneofDecl,
                (oneof, index) =>
                new OneofDescriptor(oneof, file, this, index, generatedCodeInfo?.OneofNames[index]));

            NestedTypes = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.NestedType,
                (type, index) =>
                new MessageDescriptor(type, file, this, index, generatedCodeInfo?.NestedTypes[index]));

            EnumTypes = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.EnumType,
                (type, index) =>
                new EnumDescriptor(type, file, this, index, generatedCodeInfo?.NestedEnums[index]));

            fieldsInDeclarationOrder = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.Field,
                (field, index) =>
                new FieldDescriptor(field, file, this, index, generatedCodeInfo?.PropertyNames[index]));
            fieldsInNumberOrder = new ReadOnlyCollection <FieldDescriptor>(fieldsInDeclarationOrder.OrderBy(field => field.FieldNumber).ToArray());
            // TODO: Use field => field.Proto.JsonName when we're confident it's appropriate. (And then use it in the formatter, too.)
            jsonFieldMap = CreateJsonFieldMap(fieldsInNumberOrder);
            file.DescriptorPool.AddSymbol(this);
            Fields = new FieldCollection(this);
        }
Example #3
0
        internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, GeneratedCodeInfo generatedCodeInfo)
            : base(file, file.ComputeFullName(parent, proto.Name), typeIndex)
        {
            this.proto    = proto;
            generatedType = generatedCodeInfo == null ? null : generatedCodeInfo.ClrType;

            containingType = parent;

            oneofs = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.OneofDecl,
                (oneof, index) =>
                new OneofDescriptor(oneof, file, this, index, generatedCodeInfo == null ? null : generatedCodeInfo.OneofNames[index]));

            nestedTypes = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.NestedType,
                (type, index) =>
                new MessageDescriptor(type, file, this, index, generatedCodeInfo == null ? null : generatedCodeInfo.NestedTypes[index]));

            enumTypes = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.EnumType,
                (type, index) =>
                new EnumDescriptor(type, file, this, index, generatedCodeInfo == null ? null : generatedCodeInfo.NestedEnums[index]));

            fieldsInDeclarationOrder = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.Field,
                (field, index) =>
                new FieldDescriptor(field, file, this, index, generatedCodeInfo == null ? null : generatedCodeInfo.PropertyNames[index]));
            fieldsInNumberOrder = new ReadOnlyCollection <FieldDescriptor>(fieldsInDeclarationOrder.OrderBy(field => field.FieldNumber).ToArray());
            // TODO: Use field => field.Proto.JsonName when we're confident it's appropriate. (And then use it in the formatter, too.)
            jsonFieldMap = new Dictionary <string, FieldDescriptor>(fieldsInNumberOrder.ToDictionary(field => JsonFormatter.ToCamelCase(field.Name)));
            file.DescriptorPool.AddSymbol(this);
            fields = new FieldCollection(this);
        }
Example #4
0
        internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, GeneratedCodeInfo generatedCodeInfo)
            : base(file, file.ComputeFullName(parent, proto.Name), typeIndex)
        {
            this.proto    = proto;
            generatedType = generatedCodeInfo == null ? null : generatedCodeInfo.ClrType;

            containingType = parent;

            oneofs = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.OneofDecl,
                (oneof, index) =>
                new OneofDescriptor(oneof, file, this, index, generatedCodeInfo == null ? null : generatedCodeInfo.OneofNames[index]));

            nestedTypes = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.NestedType,
                (type, index) =>
                new MessageDescriptor(type, file, this, index, generatedCodeInfo == null ? null : generatedCodeInfo.NestedTypes[index]));

            enumTypes = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.EnumType,
                (type, index) =>
                new EnumDescriptor(type, file, this, index, generatedCodeInfo == null ? null : generatedCodeInfo.NestedEnums[index]));

            fieldsInDeclarationOrder = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.Field,
                (field, index) =>
                new FieldDescriptor(field, file, this, index, generatedCodeInfo == null ? null : generatedCodeInfo.PropertyNames[index]));
            fieldsInNumberOrder = new ReadOnlyCollection <FieldDescriptor>(fieldsInDeclarationOrder.OrderBy(field => field.FieldNumber).ToArray());
            file.DescriptorPool.AddSymbol(this);
            fields = new FieldCollection(this);
        }
Example #5
0
        internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, string clrName)
            : base(file, file.ComputeFullName(parent, proto.Name), index)
        {
            this.proto     = proto;
            containingType = parent;

            file.DescriptorPool.AddSymbol(this);
            accessor = CreateAccessor(clrName);
        }
        internal ServiceDescriptor(ServiceDescriptorProto proto, FileDescriptor file, int index)
            : base(file, file.ComputeFullName(null, proto.Name), index)
        {
            this.proto = proto;
            methods    = DescriptorUtil.ConvertAndMakeReadOnly(proto.Method,
                                                               (method, i) => new MethodDescriptor(method, file, this, i));

            file.DescriptorPool.AddSymbol(this);
        }
        internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, GeneratedClrTypeInfo generatedCodeInfo)
            : base(file, file.ComputeFullName(parent, proto.Name), typeIndex)
        {
            Proto          = proto;
            Parser         = generatedCodeInfo?.Parser;
            ClrType        = generatedCodeInfo?.ClrType;
            ContainingType = parent;

            // If generatedCodeInfo is null, we just won't generate an accessor for any fields.
            Oneofs = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.OneofDecl,
                (oneof, index) =>
                new OneofDescriptor(oneof, file, this, index, generatedCodeInfo?.OneofNames[index]));

            int syntheticOneofCount = 0;

            foreach (var oneof in Oneofs)
            {
                if (oneof.IsSynthetic)
                {
                    syntheticOneofCount++;
                }
                else if (syntheticOneofCount != 0)
                {
                    throw new ArgumentException("All synthetic oneofs should come after real oneofs");
                }
            }
            RealOneofCount = Oneofs.Count - syntheticOneofCount;

            NestedTypes = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.NestedType,
                (type, index) =>
                new MessageDescriptor(type, file, this, index, generatedCodeInfo?.NestedTypes[index]));

            EnumTypes = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.EnumType,
                (type, index) =>
                new EnumDescriptor(type, file, this, index, generatedCodeInfo?.NestedEnums[index]));

            Extensions = new ExtensionCollection(this, generatedCodeInfo?.Extensions);

            fieldsInDeclarationOrder = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.Field,
                (field, index) =>
                new FieldDescriptor(field, file, this, index, generatedCodeInfo?.PropertyNames[index], null));
            fieldsInNumberOrder = new ReadOnlyCollection <FieldDescriptor>(fieldsInDeclarationOrder.OrderBy(field => field.FieldNumber).ToArray());
            // TODO: Use field => field.Proto.JsonName when we're confident it's appropriate. (And then use it in the formatter, too.)
            jsonFieldMap = CreateJsonFieldMap(fieldsInNumberOrder);
            file.DescriptorPool.AddSymbol(this);
            Fields = new FieldCollection(this);
        }
Example #8
0
        internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, GeneratedClrTypeInfo generatedCodeInfo)
            : base(file, file.ComputeFullName(parent, proto.Name), typeIndex)
        {
            Proto = proto;
            if (generatedCodeInfo != null)
            {
                this.Parser = generatedCodeInfo.Parser;
            }
            if (generatedCodeInfo != null)
            {
                this.ClrType = generatedCodeInfo.ClrType;
            }
            ContainingType = parent;

            // Note use of generatedCodeInfo. rather than generatedCodeInfo?. here... we don't expect
            // to see any nested oneofs, types or enums in "not actually generated" code... we do
            // expect fields though (for map entry messages).
            Oneofs = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.OneofDecl,
                (oneof, index) =>
                new OneofDescriptor(oneof, file, this, index, generatedCodeInfo.OneofNames[index]));

            NestedTypes = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.NestedType,
                (type, index) =>
                new MessageDescriptor(type, file, this, index, generatedCodeInfo.NestedTypes[index]));

            EnumTypes = DescriptorUtil.ConvertAndMakeReadOnly(
                proto.EnumType,
                (type, index) =>
                new EnumDescriptor(type, file, this, index, generatedCodeInfo.NestedEnums[index]));

            fieldsInDeclarationOrder = DescriptorUtil.ConvertAndMakeReadOnly <FieldDescriptorProto, FieldDescriptor>(
                proto.Field,
                (field, index) =>
            {
                string prop = null;
                if (generatedCodeInfo != null)
                {
                    prop = generatedCodeInfo.PropertyNames[index];
                }
                return(new FieldDescriptor(field, file, this, index, prop));
            });

            fieldsInNumberOrder = new ReadOnlyCollection <FieldDescriptor>(fieldsInDeclarationOrder.OrderBy(field => field.FieldNumber).ToArray());
            // TODO: Use field => field.Proto.JsonName when we're confident it's appropriate. (And then use it in the formatter, too.)
            jsonFieldMap = CreateJsonFieldMap(fieldsInNumberOrder);
            file.DescriptorPool.AddSymbol(this);
            Fields = new FieldCollection(this);
        }
Example #9
0
        internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, string clrName)
            : base(file, file.ComputeFullName(parent, proto.Name), index)
        {
            this.Proto     = proto;
            containingType = parent;
            file.DescriptorPool.AddSymbol(this);

            // It's useful to determine whether or not this is a synthetic oneof before cross-linking. That means
            // diving into the proto directly rather than using FieldDescriptor, but that's okay.
            var firstFieldInOneof = parent.Proto.Field.FirstOrDefault(fieldProto => fieldProto.HasOneofIndex && fieldProto.OneofIndex == index);

            IsSynthetic = firstFieldInOneof?.Proto3Optional ?? false;

            accessor = CreateAccessor(clrName);
        }
Example #10
0
        internal EnumDescriptor(EnumDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, Type clrType)
            : base(file, file.ComputeFullName(parent, proto.Name), index)
        {
            this.proto     = proto;
            this.clrType   = clrType;
            containingType = parent;

            if (proto.Value.Count == 0)
            {
                // We cannot allow enums with no values because this would mean there
                // would be no valid default value for fields of this type.
                throw new DescriptorValidationException(this, "Enums must contain at least one value.");
            }

            values = DescriptorUtil.ConvertAndMakeReadOnly(proto.Value,
                                                           (value, i) => new EnumValueDescriptor(value, file, this, i));

            File.DescriptorPool.AddSymbol(this);
        }
Example #11
0
        internal EnumDescriptor(EnumDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, Type clrType) : base(file, file.ComputeFullName(parent, proto.Name), index)
        {
            EnumDescriptor __4__this;

            while (true)
            {
IL_E8:
                uint arg_BC_0 = 4109983820u;
                while (true)
                {
                    uint num;
                    switch ((num = (arg_BC_0 ^ 3766774863u)) % 8u)
                    {
                    case 0u:
                        goto IL_E8;

                    case 1u:
                        this.clrType = clrType;
                        arg_BC_0     = (num * 1684544113u ^ 3373526018u);
                        continue;

                    case 3u:
                        __4__this = this;
                        arg_BC_0  = (num * 2337484923u ^ 1148379752u);
                        continue;

                    case 4u:
                        this.containingType = parent;
                        arg_BC_0            = (num * 1220569408u ^ 3140952130u);
                        continue;

                    case 5u:
                        arg_BC_0 = (((proto.Value.Count == 0) ? 1596062239u : 198363322u) ^ num * 3295210363u);
                        continue;

                    case 6u:
                        this.proto = proto;
                        arg_BC_0   = (num * 3344172837u ^ 841144240u);
                        continue;

                    case 7u:
                        goto IL_EF;
                    }
                    goto Block_2;
                }
            }
Block_2:
            goto IL_100;
IL_EF:
            throw new DescriptorValidationException(this, Module.smethod_34 <string>(1600269481u));
IL_100:
            this.values = DescriptorUtil.ConvertAndMakeReadOnly <EnumValueDescriptorProto, EnumValueDescriptor>(proto.Value, (EnumValueDescriptorProto value, int i) => new EnumValueDescriptor(value, file, __4__this, i));
            base.File.DescriptorPool.AddSymbol(this);
        }
Example #12
0
        internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, GeneratedCodeInfo generatedCodeInfo) : base(file, file.ComputeFullName(parent, proto.Name), typeIndex)
        {
            MessageDescriptor __4__this;

            while (true)
            {
IL_247:
                uint arg_20A_0 = 4043199534u;
                while (true)
                {
                    uint num;
                    switch ((num = (arg_20A_0 ^ 3788346645u)) % 12u)
                    {
                    case 0u:
                        this.< ContainingType > k__BackingField = parent;
                        arg_20A_0 = (num * 1002898729u ^ 1601684763u);
                        continue;

                    case 1u:
                    {
                        GeneratedCodeInfo expr_1D9 = generatedCodeInfo;
                        this.< Parser > k__BackingField = ((expr_1D9 != null) ? expr_1D9.Parser : null);
                        arg_20A_0 = 2694476678u;
                        continue;
                    }

                    case 2u:
                        file.DescriptorPool.AddSymbol(this);
                        this.Fieldsk__BackingField = new MessageDescriptor.FieldCollection(this);
                        arg_20A_0 = (num * 174268781u ^ 339015310u);
                        continue;

                    case 3u:
                        goto IL_247;

                    case 4u:
                        this.< NestedTypes > k__BackingField = DescriptorUtil.ConvertAndMakeReadOnly <DescriptorProto, MessageDescriptor>(proto.NestedType, (DescriptorProto type, int index) => new MessageDescriptor(type, file, __4__this, index, generatedCodeInfo.NestedTypes[index]));
                        arg_20A_0 = (num * 1204710165u ^ 359963217u);
                        continue;

                    case 5u:
                    {
                        IEnumerable <FieldDescriptor>  arg_161_0 = this.fieldsInNumberOrder;
                        Func <FieldDescriptor, string> arg_161_1;
                        if ((arg_161_1 = MessageDescriptor.__c.__9__4_5) == null)
                        {
                            arg_161_1 = (MessageDescriptor.__c.__9__4_5 = new Func <FieldDescriptor, string>(MessageDescriptor.__c.__9.<.ctor > b__4_5));
                        }
                        this.jsonFieldMap = new ReadOnlyDictionary <string, FieldDescriptor>(arg_161_0.ToDictionary(arg_161_1));
                        arg_20A_0         = 3491112463u;
                        continue;
                    }

                    case 6u:
                    {
                        this.fieldsInDeclarationOrder = DescriptorUtil.ConvertAndMakeReadOnly <FieldDescriptorProto, FieldDescriptor>(proto.Field, delegate(FieldDescriptorProto field, int index)
                            {
                                FileDescriptor arg_26_1    = file;
                                MessageDescriptor arg_26_2 = __4__this;
                                GeneratedCodeInfo expr_14  = generatedCodeInfo;
                                return(new FieldDescriptor(field, arg_26_1, arg_26_2, index, (expr_14 != null) ? expr_14.PropertyNames[index] : null));
                            });
                        IEnumerable <FieldDescriptor> arg_11D_0 = this.fieldsInDeclarationOrder;
                        Func <FieldDescriptor, int>   arg_11D_1;
                        if ((arg_11D_1 = MessageDescriptor.__c.__9__4_4) == null)
                        {
                            arg_11D_1 = (MessageDescriptor.__c.__9__4_4 = new Func <FieldDescriptor, int>(MessageDescriptor.__c.__9.<.ctor > b__4_4));
                        }
                        this.fieldsInNumberOrder = new ReadOnlyCollection <FieldDescriptor>(arg_11D_0.OrderBy(arg_11D_1).ToArray <FieldDescriptor>());
                        arg_20A_0 = 2414391428u;
                        continue;
                    }

                    case 7u:
                    {
                        GeneratedCodeInfo expr_BF = generatedCodeInfo;
                        this.< ClrType > k__BackingField = ((expr_BF != null) ? expr_BF.ClrType : null);
                        arg_20A_0 = 3870743541u;
                        continue;
                    }

                    case 8u:
                        this.< EnumTypes > k__BackingField = DescriptorUtil.ConvertAndMakeReadOnly <EnumDescriptorProto, EnumDescriptor>(proto.EnumType, (EnumDescriptorProto type, int index) => new EnumDescriptor(type, file, __4__this, index, generatedCodeInfo.NestedEnums[index]));
                        arg_20A_0 = (num * 3914277205u ^ 2964567391u);
                        continue;

                    case 10u:
                        this.< Oneofs > k__BackingField = DescriptorUtil.ConvertAndMakeReadOnly <OneofDescriptorProto, OneofDescriptor>(proto.OneofDecl, (OneofDescriptorProto oneof, int index) => new OneofDescriptor(oneof, file, __4__this, index, generatedCodeInfo.OneofNames[index]));
                        arg_20A_0 = (num * 3879854900u ^ 3765292269u);
                        continue;

                    case 11u:
                        __4__this = this;
                        this.< Proto > k__BackingField = proto;
                        arg_20A_0 = (num * 1105444768u ^ 1991989292u);
                        continue;
                    }
                    return;
                }
            }
        }
Example #13
0
        internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, string clrName) : base(file, file.ComputeFullName(parent, proto.Name), index)
        {
            while (true)
            {
IL_63:
                uint arg_47_0 = 2329051274u;
                while (true)
                {
                    uint num;
                    switch ((num = (arg_47_0 ^ 3026981471u)) % 4u)
                    {
                    case 0u:
                        goto IL_63;

                    case 1u:
                        this.proto = proto;
                        arg_47_0   = (num * 378117375u ^ 1534672859u);
                        continue;

                    case 3u:
                        this.containingType = parent;
                        arg_47_0            = (num * 4267417022u ^ 3727843631u);
                        continue;
                    }
                    goto Block_1;
                }
            }
Block_1:
            file.DescriptorPool.AddSymbol(this);
            this.accessor = this.CreateAccessor(clrName);
        }
Example #14
0
        internal FieldDescriptor(FieldDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, string propertyName) : base(file, file.ComputeFullName(parent, proto.Name), index)
        {
            while (true)
            {
IL_192:
                uint arg_155_0 = 668326049u;
                while (true)
                {
                    uint num;
                    switch ((num = (arg_155_0 ^ 1907900556u)) % 12u)
                    {
                    case 0u:
                        this.containingOneof = parent.Oneofs[proto.OneofIndex];
                        arg_155_0            = 951252349u;
                        continue;

                    case 2u:
                        goto IL_192;

                    case 3u:
                        arg_155_0 = (((proto.OneofIndex != -1) ? 3178787542u : 4269045895u) ^ num * 287148678u);
                        continue;

                    case 4u:
                        arg_155_0 = (((proto.OneofIndex < 0) ? 830153714u : 1120517676u) ^ num * 2667568972u);
                        continue;

                    case 5u:
                        this.proto = proto;
                        arg_155_0  = (((proto.Type == (FieldDescriptorProto.Types.Type) 0) ? 1249293554u : 878441721u) ^ num * 64997452u);
                        continue;

                    case 6u:
                        arg_155_0 = ((this.FieldNumber > 0) ? 416220771u : 1243880467u);
                        continue;

                    case 7u:
                        goto IL_199;

                    case 8u:
                        arg_155_0 = (((proto.OneofIndex < parent.Proto.OneofDecl.Count) ? 3890232560u : 2326943442u) ^ num * 1872585197u);
                        continue;

                    case 9u:
                        this.fieldType = FieldDescriptor.GetFieldTypeFromProtoType(proto.Type);
                        arg_155_0      = (num * 2182631442u ^ 3138733388u);
                        continue;

                    case 10u:
                        goto IL_1AA;

                    case 11u:
                        this.containingType = parent;
                        arg_155_0           = 1386389043u;
                        continue;
                    }
                    goto Block_6;
                }
            }
Block_6:
            goto IL_1CF;
IL_199:
            throw new DescriptorValidationException(this, Module.smethod_33 <string>(1349002182u));
IL_1AA:
            throw new DescriptorValidationException(this, FieldDescriptor.smethod_0(Module.smethod_37 <string>(3181016348u), new object[]
            {
                parent.Name
            }));
IL_1CF:
            file.DescriptorPool.AddSymbol(this);
            this.propertyName = propertyName;
        }