message_mojom_traits.cc 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ipc/message_mojom_traits.h"
  5. namespace mojo {
  6. // static
  7. base::span<const uint8_t>
  8. StructTraits<IPC::mojom::MessageDataView, IPC::MessageView>::bytes(
  9. IPC::MessageView& view) {
  10. return view.bytes();
  11. }
  12. // static
  13. absl::optional<std::vector<mojo::native::SerializedHandlePtr>>
  14. StructTraits<IPC::mojom::MessageDataView, IPC::MessageView>::handles(
  15. IPC::MessageView& view) {
  16. return view.TakeHandles();
  17. }
  18. // static
  19. bool StructTraits<IPC::mojom::MessageDataView, IPC::MessageView>::Read(
  20. IPC::mojom::MessageDataView data,
  21. IPC::MessageView* out) {
  22. mojo::ArrayDataView<uint8_t> bytes;
  23. data.GetBytesDataView(&bytes);
  24. absl::optional<std::vector<mojo::native::SerializedHandlePtr>> handles;
  25. if (!data.ReadHandles(&handles))
  26. return false;
  27. *out = IPC::MessageView(bytes, std::move(handles));
  28. return true;
  29. }
  30. } // namespace mojo