Call mojo Deserialize manually

24 views
Skip to first unread message

xz...@google.com

unread,
Oct 4, 2019, 1:53:08 PM10/4/19
to chromium-mojo
I would like to serialize/Deserialize a mojo structure and put it inside a protobuf, how can I do this? 


and put it in a protobuf.

It seems that there is a Deserialize fucntion in the generated mojom.h file:


But when I try to call it from my code like this:

blink::mojom::PublicKeyCredentialCreationOptions::Deserialize(proto_request,
                                                                &options);


I got errors while compiling. Any ideals how I can do this? Any examples?

In file included from ../../chrome/browser/chromeos/dbus/cryptohome_key_delegate_service_provider.cc:5:
In file included from ../../chrome/browser/chromeos/dbus/cryptohome_key_delegate_service_provider.h:15:
In file included from ../../content/public/browser/chromeos/cros_login_authenticator_proxy.h:9:
In file included from ../../content/browser/webauth/cros_login_authenticator_impl.h:12:
In file included from gen/third_party/blink/public/mojom/webauthn/authenticator.mojom.h:26:
In file included from ../../mojo/public/cpp/bindings/lib/serialization.h:15:
In file included from ../../mojo/public/cpp/bindings/lib/array_serialization.h:17:
In file included from ../../mojo/public/cpp/bindings/array_data_view.h:13:
In file included from ../../mojo/public/cpp/bindings/lib/serialization_forward.h:15:
../../mojo/public/cpp/bindings/struct_traits.h:162:3: error: static_assert failed due to requirement 'internal::AlwaysFalse<blink::mojom::PublicKeyCredentialCreationOptions>::value' "Cannot find the mojo::StructTraits specialization. Did you forget to include the corresponding header file?"
  static_assert(internal::AlwaysFalse<T>::value,
  ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../mojo/public/cpp/bindings/lib/serialization_util.h:51:29: note: in instantiation of template class 'mojo::StructTraits<blink::mojom::PublicKeyCredentialCreationOptionsDataView, blink::mojom::PublicKeyCredentialCreationOptions>' requested here
  static char Test(decltype(U::SetToNull) *);
                            ^
../../mojo/public/cpp/bindings/lib/serialization_util.h:54:36: note: while substituting explicitly-specified template arguments into function template 'Test' 
  static const bool value = sizeof(Test<T>(0)) == sizeof(char);
                                   ^
../../mojo/public/cpp/bindings/lib/serialization_util.h:63:29: note: in instantiation of template class 'mojo::internal::HasSetToNullMethod<mojo::StructTraits<blink::mojom::PublicKeyCredentialCreationOptionsDataView, blink::mojom::PublicKeyCredentialCreationOptions> >' requested here
    typename std::enable_if<HasSetToNullMethod<Traits>::value>::type* = nullptr>
                            ^
../../mojo/public/cpp/bindings/lib/serialization_util.h:64:6: note: while substituting prior template arguments into non-type template parameter [with Traits = mojo::StructTraits<blink::mojom::PublicKeyCredentialCreationOptionsDataView, blink::mojom::PublicKeyCredentialCreationOptions>, UserType = blink::mojom::PublicKeyCredentialCreationOptions]
bool CallSetToNullIfExists(UserType* output) {
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gen/third_party/blink/public/mojom/webauthn/authenticator.mojom-shared.h:1969:14: note: while substituting deduced template arguments into function template 'CallSetToNullIfExists' [with Traits = mojo::StructTraits<blink::mojom::PublicKeyCredentialCreationOptionsDataView, blink::mojom::PublicKeyCredentialCreationOptions>, UserType = blink::mojom::PublicKeyCredentialCreationOptions, $2 = (no value)]
      return CallSetToNullIfExists<Traits>(output);
             ^
../../mojo/public/cpp/bindings/lib/serialization_forward.h:55:48: note: in instantiation of member function 'mojo::internal::Serializer<blink::mojom::PublicKeyCredentialCreationOptionsDataView, blink::mojom::PublicKeyCredentialCreationOptions>::Deserialize' requested here
  return Serializer<MojomType, InputUserType>::Deserialize(
                                               ^
../../mojo/public/cpp/bindings/lib/serialization.h:119:14: note: in instantiation of function template specialization 'mojo::internal::Deserialize<blink::mojom::PublicKeyCredentialCreationOptionsDataView, blink::mojom::internal::PublicKeyCredentialCreationOptions_Data *, blink::mojom::PublicKeyCredentialCreationOptions, mojo::internal::SerializationContext *, nullptr>' requested here
    result = Deserialize<MojomType>(
             ^
gen/third_party/blink/public/mojom/webauthn/authenticator.mojom.h:1674:28: note: in instantiation of function template specialization 'mojo::internal::DeserializeImpl<blink::mojom::PublicKeyCredentialCreationOptionsDataView, blink::mojom::PublicKeyCredentialCreationOptions>' requested here
    return mojo::internal::DeserializeImpl<PublicKeyCredentialCreationOptions::DataView>(
                           ^
gen/third_party/blink/public/mojom/webauthn/authenticator.mojom.h:1681:48: note: in instantiation of function template specialization 'blink::mojom::PublicKeyCredentialCreationOptions::Deserialize<blink::mojom::PublicKeyCredentialCreationOptions>' requested here
    return PublicKeyCredentialCreationOptions::Deserialize(
                                               ^
../../chrome/browser/chromeos/dbus/cryptohome_key_delegate_service_provider.cc:300:53: note: in instantiation of function template specialization 'blink::mojom::PublicKeyCredentialCreationOptions::Deserialize<blink::mojom::PublicKeyCredentialCreationOptions>' requested here
  blink::mojom::PublicKeyCredentialCreationOptions::Deserialize(proto_request,
                                                    ^
In file included from ../../chrome/browser/chromeos/dbus/cryptohome_key_delegate_service_provider.cc:5:
In file included from ../../chrome/browser/chromeos/dbus/cryptohome_key_delegate_service_provider.h:15:
In file included from ../../content/public/browser/chromeos/cros_login_authenticator_proxy.h:9:
In file included from ../../content/browser/webauth/cros_login_authenticator_impl.h:12:
In file included from gen/third_party/blink/public/mojom/webauthn/authenticator.mojom.h:30:
gen/third_party/blink/public/mojom/webauthn/authenticator.mojom-shared.h:1972:20: error: no member named 'Read' in 'mojo::StructTraits<blink::mojom::PublicKeyCredentialCreationOptionsDataView, blink::mojom::PublicKeyCredentialCreationOptions>'
    return Traits::Read(data_view, output);
           ~~~~~~~~^
../../mojo/public/cpp/bindings/lib/serialization_forward.h:55:48: note: in instantiation of member function 'mojo::internal::Serializer<blink::mojom::PublicKeyCredentialCreationOptionsDataView, blink::mojom::PublicKeyCredentialCreationOptions>::Deserialize' requested here
  return Serializer<MojomType, InputUserType>::Deserialize(
                                               ^
../../mojo/public/cpp/bindings/lib/serialization.h:119:14: note: in instantiation of function template specialization 'mojo::internal::Deserialize<blink::mojom::PublicKeyCredentialCreationOptionsDataView, blink::mojom::internal::PublicKeyCredentialCreationOptions_Data *, blink::mojom::PublicKeyCredentialCreationOptions, mojo::internal::SerializationContext *, nullptr>' requested here
    result = Deserialize<MojomType>(
             ^
gen/third_party/blink/public/mojom/webauthn/authenticator.mojom.h:1674:28: note: in instantiation of function template specialization 'mojo::internal::DeserializeImpl<blink::mojom::PublicKeyCredentialCreationOptionsDataView, blink::mojom::PublicKeyCredentialCreationOptions>' requested here
    return mojo::internal::DeserializeImpl<PublicKeyCredentialCreationOptions::DataView>(
                           ^
gen/third_party/blink/public/mojom/webauthn/authenticator.mojom.h:1681:48: note: in instantiation of function template specialization 'blink::mojom::PublicKeyCredentialCreationOptions::Deserialize<blink::mojom::PublicKeyCredentialCreationOptions>' requested here
    return PublicKeyCredentialCreationOptions::Deserialize(
                                               ^
../../chrome/browser/chromeos/dbus/cryptohome_key_delegate_service_provider.cc:300:53: note: in instantiation of function template specialization 'blink::mojom::PublicKeyCredentialCreationOptions::Deserialize<blink::mojom::PublicKeyCredentialCreationOptions>' requested here
  blink::mojom::PublicKeyCredentialCreationOptions::Deserialize(proto_request,
                                                    ^
2 errors generated.
ninja: build stopped: subcommand failed.

Ken Rockot

unread,
Oct 4, 2019, 2:04:00 PM10/4/19
to xz...@google.com, chromium-mojo
It's difficult to surface more useful errors here (like emitting specific problematic typenames), but I suspect the problem is that you have not included all the necessary traits headers for serializing the fields of the options struct.

Specifically it seems like you'll need mojo/public/cpp/base/time_mojom_traits.h and content/browser/webauthn/authenticator_mojom_traits.h.



--
You received this message because you are subscribed to the Google Groups "chromium-mojo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-moj...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-mojo/c0717637-2959-4874-8f9a-0bdc98cefb3b%40chromium.org.

xz...@google.com

unread,
Oct 4, 2019, 2:22:01 PM10/4/19
to chromium-mojo, xz...@google.com


Thanks for the quick reply. 

I added includes for both files, but still the same error. 

Did I call those functions correctly like this? 

  blink::mojom::PublicKeyCredentialCreationOptions options;
  blink::mojom::PublicKeyCredentialCreationOptions::Deserialize(proto_request,
                                                                &options);
To unsubscribe from this group and stop receiving emails from it, send an email to chromi...@chromium.org.

Ken Rockot

unread,
Oct 4, 2019, 2:29:00 PM10/4/19
to Xiaoyong Zhou, chromium-mojo
Ah. good point! The generated serializer works with the StructPtr type, not the raw struct type. So you want:

blink::mojom::PublicKeyCredentialCreationOptionsPtr options;
blink::mojom::PublicKeyCredentialCreationOptions::Deserialize(proto_request, &options);

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-moj...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-mojo/7af5dd29-c43f-4b8a-b7df-229a7ea04c4c%40chromium.org.

xz...@google.com

unread,
Oct 4, 2019, 3:21:31 PM10/4/19
to chromium-mojo, xz...@google.com
Yeah, it worked!

Thank you so much, Ken!
Reply all
Reply to author
Forward
0 new messages