NewInstance() static private method

static private NewInstance ( Type type, JToken j, Names names ) : RecordSchema
type System.Type
j JToken
names Names
return RecordSchema
        /// <summary>
        /// Parses the messages section of a protocol definition
        /// </summary>
        /// <param name="jmessage">messages JSON object</param>
        /// <param name="names">list of parsed names</param>
        /// <param name="encspace">enclosing namespace</param>
        /// <returns></returns>
        internal static Message Parse(JProperty jmessage, SchemaNames names, string encspace)
        {
            string name   = jmessage.Name;
            string doc    = JsonHelper.GetOptionalString(jmessage.Value, "doc");
            bool?  oneway = JsonHelper.GetOptionalBoolean(jmessage.Value, "one-way");

            PropertyMap  props  = Schema.GetProperties(jmessage.Value);
            RecordSchema schema = RecordSchema.NewInstance(Schema.Type.Record, jmessage.Value as JObject, props, names, encspace);

            JToken jresponse = jmessage.Value["response"];
            var    response  = Schema.ParseJson(jresponse, names, encspace);

            JToken      jerrors      = jmessage.Value["errors"];
            UnionSchema uerrorSchema = null;

            if (null != jerrors)
            {
                Schema errorSchema = Schema.ParseJson(jerrors, names, encspace);
                if (!(errorSchema is UnionSchema))
                {
                    throw new AvroException("");
                }

                uerrorSchema = errorSchema as UnionSchema;
            }

            return(new Message(name, doc, schema, response, uerrorSchema, oneway));
        }
Example #2
0
        /// <summary>
        /// Static function to return a new instance of the named schema
        /// </summary>
        /// <param name="jo">JSON object of the named schema</param>
        /// <param name="names">list of named schemas already read</param>
        /// <param name="encspace">enclosing namespace of the named schema</param>
        /// <returns></returns>
        internal static NamedSchema NewInstance(JObject jo, PropertyMap props, SchemaNames names, string encspace)
        {
            string type = JsonHelper.GetRequiredString(jo, "type");

            switch (type)
            {
            case "fixed":
                return(FixedSchema.NewInstance(jo, props, names, encspace));

            case "enum":
                return(EnumSchema.NewInstance(jo, props, names, encspace));

            case "record":
                return(RecordSchema.NewInstance(Type.Record, jo, props, names, encspace));

            case "error":
                return(RecordSchema.NewInstance(Type.Error, jo, props, names, encspace));

            default:
                NamedSchema result;
                if (names.TryGetValue(type, null, encspace, out result))
                {
                    return(result);
                }
                return(null);
            }
        }