コード例 #1
0
        private TypeSchema BuildCore(FixedSchema w, FixedSchema r)
        {
            bool match = this.DoNamesMatch(w, r) && w.Size == r.Size;

            if (!match)
            {
                return(null);
            }

            if (this.visited.ContainsKey(w))
            {
                return(this.visited[w]);
            }

            var attr   = new NamedEntityAttributes(new SchemaName(w.Name, w.Namespace), w.Aliases, w.Doc);
            var schema = new FixedSchema(attr, w.Size, r.RuntimeType);

            this.visited.Add(w, schema);
            return(schema);
        }
コード例 #2
0
        private FixedSchema ParseFixedType(JObject type, NamedSchema parent)
        {
            var name      = type.RequiredProperty <string>(Token.Name);
            var nspace    = this.GetNamespace(type, parent, name);
            var fixedName = new SchemaName(name, nspace);

            var size = type.RequiredProperty <int>(Token.Size);

            if (size <= 0)
            {
                throw new SerializationException(
                          string.Format(CultureInfo.InvariantCulture, "Only positive size of fixed values allowed: '{0}'.", size));
            }

            var aliases    = this.GetAliases(type, fixedName.Namespace);
            var attributes = new NamedEntityAttributes(fixedName, aliases, string.Empty);

            var customAttributes = type.GetAttributesNotIn(StandardProperties.Record);
            var result           = new FixedSchema(attributes, size, typeof(byte[]), customAttributes);

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Generates the record type schema.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="schemas">The schemas.</param>
        /// <param name="currentDepth">The current depth.</param>
        /// <returns>
        /// Instance of schema.
        /// </returns>
        private TypeSchema BuildRecordTypeSchema(Type type, Dictionary <string, NamedSchema> schemas, uint currentDepth)
        {
            if (type == typeof(DateTimeOffset))
            {
                return(this.settings.UsePosixTime
                    ? (TypeSchema) new LongSchema(type)
                    : new StringSchema(type));
            }

            NamedSchema schema;

            if (schemas.TryGetValue(type.ToString(), out schema))
            {
                return(schema);
            }

            if (type == typeof(Guid))
            {
                var recordName = new SchemaName(type.GetStrippedFullName());
                var attributes = new NamedEntityAttributes(recordName, new List <string>(), string.Empty);
                var result     = new FixedSchema(attributes, 16, type);
                schemas.Add(type.ToString(), result);
                return(result);
            }

            var attr = this.GetNamedEntityAttributesFrom(type);
            AvroContractResolver resolver = this.settings.Resolver;
            var record = new RecordSchema(
                attr,
                type);

            schemas.Add(type.ToString(), record);

            var members = resolver.ResolveMembers(type);

            this.AddRecordFields(members, schemas, currentDepth, record);
            return(record);
        }