private def parse()

in atlas-eval/src/main/scala/com/netflix/atlas/eval/model/LwcMessages.scala [55:141]


  private def parse(parser: JsonParser): AnyRef = {
    // This is a performance critical part of the code so the parsing is done by
    // hand rather than using ObjectMapper to minimize allocations and get peak
    // performance.
    try {
      // All
      var typeDesc: String = null

      // LwcExpression
      var expression: String = null
      var exprType: ExprType = ExprType.TIME_SERIES
      var step: Long = -1L

      // LwcSubscription
      // - expression
      // - metrics
      // LwcSubscriptionV2
      // - expression
      // - exprType
      // - subExprs
      var subExprs: List[LwcDataExpr] = Nil

      // LwcDatapoint
      var timestamp: Long = -1L
      var id: String = null
      var tags: Map[String, String] = Map.empty
      var value: Double = Double.NaN
      var samples: List[List[Any]] = Nil

      // LwcEvent
      var payload: JsonNode = NullNode.instance

      // LwcDiagnosticMessage
      // - id
      // - message: DiagnosticMessage
      var diagnosticMessage: DiagnosticMessage = null

      // LwcHeartbeat
      // - timestamp
      // - step

      // DiagnosticMessage
      // - message: String
      var message: String = null

      // Actually do the parsing work
      foreachField(parser) {
        case "type" => typeDesc = nextString(parser)

        case "expression" => expression = nextString(parser)
        case "exprType"   => exprType = ExprType.valueOf(nextString(parser))
        case "step"       => step = nextLong(parser)
        case "metrics"    => subExprs = parseDataExprs(parser)
        case "subExprs"   => subExprs = parseDataExprs(parser)

        case "timestamp" => timestamp = nextLong(parser)
        case "id"        => id = nextString(parser)
        case "tags"      => tags = parseTags(parser)
        case "value"     => value = nextDouble(parser)
        case "samples"   => samples = parseSamples(parser)

        case "payload" => payload = nextTree(parser)

        case "message" =>
          val t = parser.nextToken()
          if (t == JsonToken.VALUE_STRING)
            message = parser.getText
          else
            diagnosticMessage = parseDiagnosticMessage(parser)

        case _ => skipNext(parser)
      }

      typeDesc match {
        case "expression"      => LwcExpression(expression, exprType, step)
        case "subscription"    => LwcSubscription(expression, subExprs)
        case "subscription-v2" => LwcSubscriptionV2(expression, exprType, subExprs)
        case "datapoint"       => LwcDatapoint(timestamp, id, tags, value, samples)
        case "event"           => LwcEvent(id, payload)
        case "diagnostic"      => LwcDiagnosticMessage(id, diagnosticMessage)
        case "heartbeat"       => LwcHeartbeat(timestamp, step)
        case _                 => DiagnosticMessage(typeDesc, message, None)
      }
    } finally {
      parser.close()
    }
  }