Exemple #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var type  = new DAPMessageTypeHint();
            int depth = 0;

            while (type.type == null || type.message == null || type.seq == 0)
            {
                while (reader.Read() && reader.TokenType != JsonToken.PropertyName)
                {
                    if (reader.TokenType == JsonToken.StartObject)
                    {
                        depth++;
                    }
                    else if (reader.TokenType == JsonToken.EndObject)
                    {
                        depth--;
                    }
                }

                if (reader.TokenType != JsonToken.PropertyName)
                {
                    throw new InvalidDataException("Could not get property name in DAP payload");
                }

                if (depth == 0)
                {
                    var propertyName = (string)reader.Value;
                    if (propertyName == "seq")
                    {
                        if (!reader.Read() || reader.TokenType != JsonToken.Integer)
                        {
                            throw new InvalidDataException("Could not get sequence number in DAP payload");
                        }

                        type.seq = (int)(Int64)reader.Value;
                    }
                    else if (propertyName == "type")
                    {
                        if (!reader.Read() || reader.TokenType != JsonToken.String)
                        {
                            throw new InvalidDataException("Could not get property value in DAP payload");
                        }

                        type.type = (string)reader.Value;
                    }
                    else if (propertyName == "command" || propertyName == "event")
                    {
                        if (!reader.Read() || reader.TokenType != JsonToken.String)
                        {
                            throw new InvalidDataException("Could not get property value in DAP payload");
                        }

                        type.message = (string)reader.Value;
                    }
                }
            }

            return(type);
        }
Exemple #2
0
 public DAPJSONMessageConverter(DAPMessageTypeHint typeHint)
 {
     TypeHint = typeHint;
 }