1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42

media / mojo / mojom / speech_recognition_recognition_context_mojom_traits.cc [blame]

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/mojo/mojom/speech_recognition_recognition_context_mojom_traits.h"

namespace mojo {

bool StructTraits<media::mojom::SpeechRecognitionPhraseDataView,
                  media::SpeechRecognitionPhrase>::
    Read(media::mojom::SpeechRecognitionPhraseDataView data,
         media::SpeechRecognitionPhrase* out) {
  std::string phrase;

  if (!data.ReadPhrase(&phrase) || phrase.empty()) {
    return false;
  }

  if (data.boost() < 0 || data.boost() > 10) {
    return false;
  }

  out->phrase = std::move(phrase);
  out->boost = data.boost();
  return true;
}

bool StructTraits<media::mojom::SpeechRecognitionRecognitionContextDataView,
                  media::SpeechRecognitionRecognitionContext>::
    Read(media::mojom::SpeechRecognitionRecognitionContextDataView data,
         media::SpeechRecognitionRecognitionContext* out) {
  std::vector<media::SpeechRecognitionPhrase> phrases;

  if (!data.ReadPhrases(&phrases) || phrases.empty()) {
    return false;
  }

  out->phrases = std::move(phrases);
  return true;
}

}  // namespace mojo