Rerun C++ SDK
Loading...
Searching...
No Matches
media_type.hpp
1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/store/re_types/definitions/rerun/components/media_type.fbs".
3
4#pragma once
5
6#include "../component_descriptor.hpp"
7#include "../datatypes/utf8.hpp"
8#include "../result.hpp"
9
10#include <cstdint>
11#include <filesystem>
12#include <memory>
13#include <string>
14#include <utility>
15
16namespace rerun::components {
17 /// **Component**: A standardized media type (RFC2046, formerly known as MIME types), encoded as a string.
18 ///
19 /// The complete reference of officially registered media types is maintained by the IANA and can be
20 /// consulted at <https://www.iana.org/assignments/media-types/media-types.xhtml>.
21 struct MediaType {
23
24 public: // START of extensions from media_type_ext.cpp:
25 /// Construct media type from a null-terminated UTF8 string.
26 MediaType(const char* media_type) : value(media_type) {}
27
28 // TODO(#2388): come up with some DSL in our flatbuffers definitions so that we can
29 // declare these constants directly in there.
30
31 /// `text/plain`
33 return "text/plain";
34 }
35
36 /// `text/markdown`
37 ///
38 /// <https://www.iana.org/assignments/media-types/text/markdown>
40 return "text/markdown";
41 }
42
43 // ------------------------------------------------
44 // Images:
45
46 /// [JPEG image](https://en.wikipedia.org/wiki/JPEG): `image/jpeg`.
47 static MediaType jpeg() {
48 return "image/jpeg";
49 }
50
51 /// [PNG image](https://en.wikipedia.org/wiki/PNG): `image/png`.
52 ///
53 /// <https://www.iana.org/assignments/media-types/image/png>
54 static MediaType png() {
55 return "image/png";
56 }
57
58 // ------------------------------------------------
59 // Meshes:
60
61 /// [`glTF`](https://en.wikipedia.org/wiki/GlTF): `model/gltf+json`.
62 ///
63 /// <https://www.iana.org/assignments/media-types/model/gltf+json>
64 static MediaType gltf() {
65 return "model/gltf+json";
66 }
67
68 /// [Binary `glTF`](https://en.wikipedia.org/wiki/GlTF): `model/gltf-binary`.
69 ///
70 /// <https://www.iana.org/assignments/media-types/model/gltf-binary>
71 static MediaType glb() {
72 return "model/gltf-binary";
73 }
74
75 /// [Wavefront `obj`](https://en.wikipedia.org/wiki/Wavefront_.obj_file): `model/obj`.
76 ///
77 /// <https://www.iana.org/assignments/media-types/model/obj>
78 static MediaType obj() {
79 return "model/obj";
80 }
81
82 /// [Stereolithography Model `stl`](https://en.wikipedia.org/wiki/STL_(file_format)): `model/stl`.
83 ///
84 /// Either binary or ASCII.
85 /// <https://www.iana.org/assignments/media-types/model/stl>
86 static MediaType stl() {
87 return "model/stl";
88 }
89
90 // -------------------------------------------------------
91 /// Videos:
92
93 /// [MP4 video](https://en.wikipedia.org/wiki/MP4_file_format): `video/mp4`.
94 ///
95 /// <https://www.iana.org/assignments/media-types/video/mp4>
96 static MediaType mp4() {
97 return "video/mp4";
98 }
99
100 static std::optional<MediaType> guess_from_path(const std::filesystem::path& path);
101
102 // END of extensions from media_type_ext.cpp, start of generated code:
103
104 public:
105 MediaType() = default;
106
107 MediaType(rerun::datatypes::Utf8 value_) : value(std::move(value_)) {}
108
109 MediaType& operator=(rerun::datatypes::Utf8 value_) {
110 value = std::move(value_);
111 return *this;
112 }
113
114 MediaType(std::string value_) : value(std::move(value_)) {}
115
116 MediaType& operator=(std::string value_) {
117 value = std::move(value_);
118 return *this;
119 }
120
121 /// Cast to the underlying Utf8 datatype
122 operator rerun::datatypes::Utf8() const {
123 return value;
124 }
125 };
126} // namespace rerun::components
127
128namespace rerun {
129 static_assert(sizeof(rerun::datatypes::Utf8) == sizeof(components::MediaType));
130
131 /// \private
132 template <>
133 struct Loggable<components::MediaType> {
134 static constexpr ComponentDescriptor Descriptor = "rerun.components.MediaType";
135
136 /// Returns the arrow data type this type corresponds to.
137 static const std::shared_ptr<arrow::DataType>& arrow_datatype() {
138 return Loggable<rerun::datatypes::Utf8>::arrow_datatype();
139 }
140
141 /// Serializes an array of `rerun::components::MediaType` into an arrow array.
142 static Result<std::shared_ptr<arrow::Array>> to_arrow(
143 const components::MediaType* instances, size_t num_instances
144 ) {
145 if (num_instances == 0) {
146 return Loggable<rerun::datatypes::Utf8>::to_arrow(nullptr, 0);
147 } else if (instances == nullptr) {
148 return rerun::Error(
149 ErrorCode::UnexpectedNullArgument,
150 "Passed array instances is null when num_elements> 0."
151 );
152 } else {
153 return Loggable<rerun::datatypes::Utf8>::to_arrow(&instances->value, num_instances);
154 }
155 }
156 };
157} // namespace rerun
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:95
All built-in components. See Types in the Rerun manual.
Definition rerun.hpp:80
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
Component: A standardized media type (RFC2046, formerly known as MIME types), encoded as a string.
Definition media_type.hpp:21
static MediaType glb()
Binary glTF: model/gltf-binary.
Definition media_type.hpp:71
static MediaType obj()
Wavefront obj: model/obj.
Definition media_type.hpp:78
static MediaType gltf()
glTF: model/gltf+json.
Definition media_type.hpp:64
MediaType(const char *media_type)
Construct media type from a null-terminated UTF8 string.
Definition media_type.hpp:26
static MediaType mp4()
Videos:
Definition media_type.hpp:96
static MediaType markdown()
text/markdown
Definition media_type.hpp:39
static MediaType stl()
Stereolithography Model stl: model/stl.
Definition media_type.hpp:86
static MediaType jpeg()
JPEG image: image/jpeg.
Definition media_type.hpp:47
static MediaType png()
PNG image: image/png.
Definition media_type.hpp:54
static MediaType plain_text()
text/plain
Definition media_type.hpp:32
Datatype: A string of text, encoded as UTF-8.
Definition utf8.hpp:22