Exemple #1
0
        internal static int GetHierarchyDepth(this RuntimeSchema schema)
        {
            if (!schema.IsStruct)
            {
                return(0);
            }

            var depth = 0;

            for (var type = schema.TypeDef; type != null; type = schema.SchemaDef.structs[type.struct_def].base_def)
            {
                depth++;
            }
            return(depth);
        }
Exemple #2
0
        static void Main()
        {
            var output = new OutputBuffer();
            var writer = new CompactBinaryWriter<OutputBuffer>(output);

            // Get runtime schema for type Example and serialize SchemaDef
            Serialize.To(writer, Schema<Example>.RuntimeSchema.SchemaDef);

            var input = new InputBuffer(output.Data);
            var reader = new CompactBinaryReader<InputBuffer>(input);

            var schemaDef = Deserialize<SchemaDef>.From(reader);
            var schema = new RuntimeSchema(schemaDef);

            Debug.Assert(schema.IsStruct);
            Debug.Assert(schema.StructDef.metadata.qualified_name == "Examples.Example");
            Debug.Assert(schema.StructDef.metadata.attributes["StructAttribute"] == "Value of the attribute");
            Debug.Assert(schema.StructDef.fields[0].metadata.attributes["FieldAttribute"] == "Value of the attribute");
            Debug.Assert(schema.StructDef.fields[0].type.key.id == BondDataType.BT_UINT32);
            Debug.Assert(schema.SchemaDef.structs[1].fields[0].metadata.default_value.string_value == "this is a string");
        }
Exemple #3
0
        /// <summary>
        /// Unmarshal payload with specified schema into an instance of IBonded
        /// </summary>
        /// <typeparam name="I">Implemention of IInputStream</typeparam>
        /// <param name="input">Input stream with the payload</param>
        /// <param name="schema">Runtime schema of the payload</param>
        /// <returns>IBonded wrapping the input</returns>
        public static IBonded From <I>(I input, RuntimeSchema schema)
            where I : IInputStream, ICloneable <I>
        {
            var protocol = (ProtocolType)input.ReadUInt16();
            var version  = input.ReadUInt16();

            switch (protocol)
            {
            case ProtocolType.COMPACT_PROTOCOL:
                return(new BondedVoid <CompactBinaryReader <I> >(
                           new CompactBinaryReader <I>(input, version), schema));

            case ProtocolType.FAST_PROTOCOL:
                return(new BondedVoid <FastBinaryReader <I> >(
                           new FastBinaryReader <I>(input, version), schema));

            case ProtocolType.SIMPLE_PROTOCOL:
                return(new BondedVoid <SimpleBinaryReader <I> >(
                           new SimpleBinaryReader <I>(input, version), schema));

            default:
                throw new InvalidDataException(string.Format("Unknown ProtocolType {0}", protocol));
            }
        }
Exemple #4
0
 /// <summary>
 /// Create a deserializer instance for specified type and payload schema
 /// </summary>
 /// <param name="type">Type representing a Bond schema</param>
 /// <param name="schema">Schema of the payload</param>
 public Deserializer(Type type, RuntimeSchema schema)
     : this(type, ParserFactory <R> .Create(schema))
 {
 }
Exemple #5
0
 /// <summary>
 /// Create a deserializer instance for specified type and payload schema, using a custom object factory
 /// </summary>
 /// <param name="type">Type representing a Bond schema</param>
 /// <param name="schema">Schema of the payload</param>
 /// <param name="factory">Factory providing expressions to create objects during deserialization</param>
 public Deserializer(Type type, RuntimeSchema schema, Factory factory)
     : this(type, ParserFactory <R> .Create(schema), null, factory)
 {
 }
Exemple #6
0
 /// <summary>
 /// Create a deserializer instance for specified type and payload schema, using a custom object factory
 /// </summary>
 /// <param name="type">Type representing a Bond schema</param>
 /// <param name="schema">Schema of the payload</param>
 /// <param name="factory">Factory providing expressions to create objects during deserialization</param>
 /// <param name="inlineNested">Inline nested types if possible (optimizes for reduction of execution time
 /// at the expense of initialization time and memory)</param>
 public Deserializer(Type type, RuntimeSchema schema, Factory factory, bool inlineNested)
     : this(type, ParserFactory <R> .Create(schema), null, factory, inlineNested)
 {
 }
Exemple #7
0
 /// <summary>
 /// Create a transcoder for payloads with specified runtime schema
 /// </summary>
 /// <param name="schema">Payload schema, required for transcoding from untagged protocols</param>
 public Transcoder(RuntimeSchema schema)
     : this(schema, null)
 {
 }
Exemple #8
0
 public TwoPassTranscoderHelper(RuntimeSchema schema, IParser parser) :
     base(schema, parser)
 {
     firstPassTranscode = new Lazy <Action <R, FPW>[]>(() => GenerateFirstPass(schema, parser), LazyThreadSafetyMode.PublicationOnly);
 }
Exemple #9
0
 public TranscoderHelper(RuntimeSchema schema, IParser parser)
 {
     transcode = Generate(schema, parser);
 }
Exemple #10
0
 /// <summary>
 /// Create a transcoder for payloads with specified runtime schema
 /// </summary>
 /// <param name="schema">Payload schema, required for transcoding from untagged protocols</param>
 /// <param name="parser">Custom <see cref="IParser"/> instance</param>
 public Transcoder(RuntimeSchema schema, IParser parser)
 {
     helper = (TranscoderHelper)Activator.CreateInstance(helperType, schema, parser);
 }
Exemple #11
0
 public BondedVoid(R reader, RuntimeSchema schema)
 {
     this.reader = reader;
     this.schema = schema;
 }
Exemple #12
0
 /// <summary>
 /// Unmarshal payload with specified schema into an instance of IBonded
 /// </summary>
 /// <param name="data">Byte array segment containing the payload</param>
 /// <param name="schema">Runtime schema of the payload</param>
 public static IBonded From(ArraySegment <byte> data, RuntimeSchema schema)
 {
     return(From(new InputBuffer(data), schema));
 }
Exemple #13
0
 /// <summary>
 /// Create a transcoder for payloads with specified runtime schema
 /// </summary>
 /// <param name="schema">Payload schema, required for transcoding from untagged protocols</param>
 public Transcoder(RuntimeSchema schema)
 {
     transcode = Generate(schema);
 }
Exemple #14
0
 /// <summary>
 /// Create a deserializer instance for specified type and payload schema
 /// </summary>
 /// <param name="type">Type representing a Bond schema</param>
 /// <param name="schema">Schema of the payload</param>
 public Deserializer(Type type, RuntimeSchema schema)
     : this(type, ParserFactory <R> .Create(schema), factory : null, inlineNested : true)
 {
 }