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); }
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"); }
/// <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)); } }
/// <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)) { }
/// <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) { }
/// <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) { }
/// <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) { }
public TwoPassTranscoderHelper(RuntimeSchema schema, IParser parser) : base(schema, parser) { firstPassTranscode = new Lazy <Action <R, FPW>[]>(() => GenerateFirstPass(schema, parser), LazyThreadSafetyMode.PublicationOnly); }
public TranscoderHelper(RuntimeSchema schema, IParser parser) { transcode = Generate(schema, parser); }
/// <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); }
public BondedVoid(R reader, RuntimeSchema schema) { this.reader = reader; this.schema = schema; }
/// <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)); }
/// <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); }
/// <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) { }