private void ValidateHasSerializer(FlatBufferObject obj)
    {
        FlatSharpInternal.Assert(!obj.IsStruct, "expecting only tables");
        FlatSharpAttributes attrs = new FlatSharpAttributes(obj.Attributes);

        if (attrs.DeserializationOption is null)
        {
            ErrorContext.Current.RegisterError($"RPC call '{this.fullName}' uses table '{obj.Name}', which does not specify the '{MetadataKeys.SerializerKind}' attribute.");
        }
    }
    public RpcCallSchemaModel(RpcService parentService, RpcCall call)
    {
        this.attributes = new(call.Attributes);
        this.fullName   = $"{parentService.Name}.{call.Name}";
        this.call       = call;

        new FlatSharpAttributeValidator(FlatBufferSchemaElementType.RpcCall, $"{parentService.Name}.{call.Name}")
        {
            StreamingTypeValidator = _ => AttributeValidationResult.Valid,
        }.Validate(this.attributes);

        this.ValidateHasSerializer(call.Request);
        this.ValidateHasSerializer(call.Response);
    }
Esempio n. 3
0
    protected BaseSchemaModel(
        Schema.Schema schema,
        string name,
        FlatSharpAttributes attributes)
    {
        this.Attributes = attributes;
        this.Schema     = schema;
        this.FullName   = name;

        (string ns, string typeName) = Helpers.ParseName(name);

        this.Namespace = ns;
        this.Name      = typeName;

        this.AttributeValidator = new FlatSharpAttributeValidator(this.ElementType, name);
    }
    private ValueStructSchemaModel(Schema.Schema schema, FlatBufferObject @struct) : base(schema, @struct.Name, new FlatSharpAttributes(@struct.Attributes))
    {
        FlatSharpInternal.Assert(@struct.IsStruct, "Expecting struct");
        FlatSharpInternal.Assert(this.Attributes.ValueStruct == true, "Expecting value struct");

        this.@struct       = @struct;
        this.fields        = new();
        this.structVectors = new();

        foreach (Field field in [email protected](x => x.Id))
        {
            IFlatSharpAttributes attrs = new FlatSharpAttributes(field.Attributes);

            string fieldType = field.Type.ResolveTypeOrElementTypeName(schema, this.Attributes);
            if (field.Type.BaseType == BaseType.Array)
            {
                // struct vector
                int size = field.Type.ElementType.GetScalarSize();

                List <string> vectorFields = new();
                for (int i = 0; i < field.Type.FixedLength; ++i)
                {
                    string name = $"__flatsharp__{field.Name}_{i}";

                    MutableFlatSharpAttributes tempAttrs = new MutableFlatSharpAttributes(attrs)
                    {
                        UnsafeStructVector = null,
                    };

                    vectorFields.Add(name);
                    this.fields.Add(new(field.Offset + (i * size), name, "private", fieldType, $"{field.Name}({i})", null, this, tempAttrs));
                }

                this.structVectors.Add(new(fieldType, field.Name, vectorFields, this, field.Documentation, attrs));
            }
            else
            {
                this.fields.Add(new(field.Offset, field.Name, "public", fieldType, field.Name, field.Documentation, this, attrs));
            }
        }

        this.AttributeValidator.MemoryMarshalValidator = _ => AttributeValidationResult.Valid;
    }