protocol-media-registry 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,48 @@
1
+ // Released under the MIT License.
2
+ // Copyright, 2026, by Samuel Williams.
3
+
4
+ #include <ruby.h>
5
+
6
+ #include "extensions.h"
7
+ #include "records.h"
8
+
9
+ static VALUE Protocol_Media_Registry_lookup(VALUE _self, VALUE name)
10
+ {
11
+ StringValue(name);
12
+
13
+ const struct MediaTypeRecord *record = lookup_record(RSTRING_PTR(name), (unsigned int)RSTRING_LEN(name));
14
+ if (!record) return Qnil;
15
+
16
+ VALUE result = rb_ary_new_capa(3);
17
+ rb_ary_push(result, rb_str_new_cstr(record->name));
18
+ rb_ary_push(result, record->encoding ? rb_str_new_cstr(record->encoding) : Qnil);
19
+
20
+ if (record->extensions) {
21
+ rb_ary_push(result, rb_str_split(rb_str_new_cstr(record->extensions), " "));
22
+ } else {
23
+ rb_ary_push(result, Qnil);
24
+ }
25
+
26
+ return result;
27
+ }
28
+
29
+ static VALUE Protocol_Media_Registry_lookup_extension(VALUE _self, VALUE extension)
30
+ {
31
+ StringValue(extension);
32
+
33
+ const struct ExtensionRecord *record = lookup_extension(RSTRING_PTR(extension), (unsigned int)RSTRING_LEN(extension));
34
+ if (!record) return Qnil;
35
+
36
+ return rb_str_new_cstr(record->name);
37
+ }
38
+
39
+ void Init_Protocol_Media_Registry(void)
40
+ {
41
+ VALUE protocol = rb_define_module("Protocol");
42
+ VALUE media = rb_define_module_under(protocol, "Media");
43
+ VALUE registry = rb_define_module_under(media, "Registry");
44
+ VALUE native = rb_define_module_under(registry, "Native");
45
+
46
+ rb_define_singleton_method(native, "lookup", Protocol_Media_Registry_lookup, 1);
47
+ rb_define_singleton_method(native, "lookup_extension", Protocol_Media_Registry_lookup_extension, 1);
48
+ }