Example #1
0
        static void GetSchemaTypes(Type type, HashSet<Type> schemaTypes)
        {
            while (true)
            {
                if (type.IsBondStruct())
                {
                    if (schemaTypes.Contains(type))
                        return;

                    schemaTypes.Add(type);

                    foreach (var f in type.GetSchemaFields())
                    {
                        GetSchemaTypes(f.GetSchemaType(), schemaTypes);
                    }

                    type = type.GetBaseSchemaType();
                    if (type != null)
                        continue;
                }
                else if (type.IsBondMap())
                {
                    type = type.GetKeyValueType().Value;
                    continue;
                }
                else if (type.IsBondList() || type.IsBondNullable() || type.IsBonded())
                {
                    type = type.GetValueType();
                    continue;
                }
                break;
            }
        }
        protected override IReadOnlyDictionary<string, Func<byte[], object>> BuildDeserializers(Type outputType)
        {
            Func<byte[], object> jsonDeserializer = e => this.DeserializeJson(e, outputType);

            var deserializerMap = new Dictionary<string, Func<byte[], object>>(StringComparer.Ordinal)
            {
                { Protocol.Json, jsonDeserializer },
            };

            if (outputType.IsBondStruct())
            {
                var deserializer = new Deserializer<CompactBinaryReader<InputBuffer>>(outputType);

                deserializerMap.Add(Protocol.CompactBinaryV1, e => DeserializeCompactBinary(1, e, deserializer));
                deserializerMap.Add(Protocol.CompactBinaryV2, e => DeserializeCompactBinary(2, e, deserializer));
            }

            return deserializerMap;
        }
Example #3
0
            TypeDef GetTypeDef(Type type)
            {
                TypeDef typeDef;

                if (type.IsBonded())
                {
                    typeDef = GetTypeDef(type.GetValueType());
                    typeDef.bonded_type = true;
                }
                else
                {
                    typeDef = new TypeDef {id = type.GetBondDataType()};
                }

                if (type.IsBondContainer() || type.IsBondNullable() || type.IsBondBlob())
                {
                    if (type.IsBondMap())
                    {
                        var itemType = type.GetKeyValueType();
                        typeDef.key = GetTypeDef(itemType.Key);
                        typeDef.element = GetTypeDef(itemType.Value);
                    }
                    else
                    {
                        typeDef.element = GetTypeDef(type.GetValueType());
                    }
                }

                if (type.IsBondStruct())
                {
                    var i = Schema.structs.FindIndex(
                        s => s.metadata.qualified_name.Equals(type.GetSchemaFullName()));
                    if (i != -1)
                    {
                        typeDef.struct_def = (ushort) i;
                    }
                    else
                    {
                        var schemaT = typeof (Schema<>).MakeGenericType(type);
                        var metadataProp = schemaT.GetDeclaredProperty("Metadata");
                        var fieldsProp = schemaT.GetDeclaredProperty("Fields");
                        typeDef.struct_def = GetStructDef(
                            type,
                            metadataProp.GetValue(null) as Metadata,
                            fieldsProp.GetValue(null) as Metadata[]);
                    }
                }

                return typeDef;
            }