Split SharedSpan out into a header
We were using it in enough spots it deserves a header.
Change-Id: I0b9ea59d390dac2406195d763c7a680c7004e7b7
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/BUILD b/aos/BUILD
index b6d357b..83adcd6 100644
--- a/aos/BUILD
+++ b/aos/BUILD
@@ -850,3 +850,12 @@
"//aos/events:simulated_event_loop_rs",
],
)
+
+cc_library(
+ name = "shared_span",
+ hdrs = ["shared_span.h"],
+ visibility = ["//visibility:public"],
+ deps = [
+ "@com_google_absl//absl/types:span",
+ ],
+)
diff --git a/aos/events/BUILD b/aos/events/BUILD
index ace634c..c61b3e5 100644
--- a/aos/events/BUILD
+++ b/aos/events/BUILD
@@ -116,6 +116,7 @@
"//aos:flatbuffers",
"//aos:ftrace",
"//aos:realtime",
+ "//aos:shared_span",
"//aos:uuid",
"//aos/flatbuffers:builder",
"//aos/ipc_lib:data_alignment",
diff --git a/aos/events/event_loop.h b/aos/events/event_loop.h
index d45dddf..389ea08 100644
--- a/aos/events/event_loop.h
+++ b/aos/events/event_loop.h
@@ -24,6 +24,7 @@
#include "aos/ftrace.h"
#include "aos/ipc_lib/data_alignment.h"
#include "aos/json_to_flatbuffer.h"
+#include "aos/shared_span.h"
#include "aos/time/time.h"
#include "aos/util/phased_loop.h"
#include "aos/util/status.h"
@@ -90,8 +91,6 @@
Ftrace ftrace_;
};
-using SharedSpan = std::shared_ptr<const absl::Span<const uint8_t>>;
-
// Holds storage for a span object and the data referenced by that span for
// compatibility with SharedSpan users. If constructed with MakeSharedSpan, span
// points to only the aligned segment of the entire data.
@@ -113,8 +112,6 @@
// and as a building block to implement typed senders.
class RawSender {
public:
- using SharedSpan = std::shared_ptr<const absl::Span<const uint8_t>>;
-
enum class [[nodiscard]] Error {
// Represents success and no error
kOk,
diff --git a/aos/flatbuffers/BUILD b/aos/flatbuffers/BUILD
index 0f25875..e4f7d1d 100644
--- a/aos/flatbuffers/BUILD
+++ b/aos/flatbuffers/BUILD
@@ -28,6 +28,7 @@
target_compatible_with = ["@platforms//os:linux"],
visibility = ["//visibility:public"],
deps = [
+ "//aos:shared_span",
"//aos/containers:resizeable_buffer",
"//aos/ipc_lib:data_alignment",
"@com_github_google_flatbuffers//:flatbuffers",
diff --git a/aos/flatbuffers/base.h b/aos/flatbuffers/base.h
index b3c3ef0..a98d730 100644
--- a/aos/flatbuffers/base.h
+++ b/aos/flatbuffers/base.h
@@ -18,11 +18,9 @@
#include "aos/containers/resizeable_buffer.h"
#include "aos/ipc_lib/data_alignment.h"
+#include "aos/shared_span.h"
-namespace aos {
-using SharedSpan = std::shared_ptr<const absl::Span<const uint8_t>>;
-
-namespace fbs {
+namespace aos::fbs {
using ::flatbuffers::soffset_t;
using ::flatbuffers::uoffset_t;
@@ -343,7 +341,6 @@
T t;
};
} // namespace internal
-} // namespace fbs
-} // namespace aos
+} // namespace aos::fbs
#endif // AOS_FLATBUFFERS_BASE_H_
diff --git a/aos/shared_span.h b/aos/shared_span.h
new file mode 100644
index 0000000..515c0bf
--- /dev/null
+++ b/aos/shared_span.h
@@ -0,0 +1,16 @@
+#ifndef AOS_SHARED_SPAN_H_
+#define AOS_SHARED_SPAN_H_
+
+#include <cstdint>
+#include <memory>
+
+#include "absl/types/span.h"
+
+namespace aos {
+
+// Shared pointer to a region of memory. The pointer needs to own the region.
+using SharedSpan = std::shared_ptr<const absl::Span<const uint8_t>>;
+
+} // namespace aos
+
+#endif // AOS_SHARED_SPAN_H_