nsresult
Convert(const nsAString& aIn, BluetoothServiceName& aOut)
{
  NS_ConvertUTF16toUTF8 serviceNameUTF8(aIn);
  const char* str = serviceNameUTF8.get();
  size_t len = strlen(str);

  if (NS_WARN_IF(len > sizeof(aOut.mName))) {
    return NS_ERROR_ILLEGAL_VALUE;
  }

  memcpy(aOut.mName, str, len);
  memset(aOut.mName + len, 0, sizeof(aOut.mName) - len);

  return NS_OK;
}
nsresult
StringToServiceName(const nsAString& aString,
                    BluetoothServiceName& aServiceName)
{
  NS_ConvertUTF16toUTF8 serviceNameUTF8(aString);

  auto len = serviceNameUTF8.Length();

  if (len > sizeof(aServiceName.mName)) {
    BT_LOGR("Service-name string too long");
    return NS_ERROR_ILLEGAL_VALUE;
  }

  auto str = serviceNameUTF8.get();

  memcpy(aServiceName.mName, str, len);
  memset(aServiceName.mName + len, 0, sizeof(aServiceName.mName) - len);

  return NS_OK;
}