1
1
const std = @import ("std" );
2
2
3
- pub const c = @import ("c.zig" );
3
+ pub const c = @import ("zenoh_c" );
4
+
5
+ // pub const c = @import("c.zig");
4
6
5
7
pub const Error = error {ZenohError };
6
8
7
- pub fn err (code : c.Result ) Error ! void {
9
+ pub fn err (code : c.z_result_t ) Error ! void {
8
10
if (code < 0 ) {
9
11
return error .ZenohError ;
10
12
}
11
13
}
12
14
13
15
pub const Config = struct {
14
- _c : c.Config ,
16
+ _c : c.z_owned_config_t ,
15
17
16
18
pub fn initDefault () Error ! Config {
17
- var c_config : c.Config = undefined ;
19
+ var c_config : c.z_owned_config_t = undefined ;
18
20
try err (c .z_config_default (& c_config ));
19
21
return Config { ._c = c_config };
20
22
}
21
23
22
24
pub fn initFromEnv () Error ! Config {
23
- var c_config : c.Config = undefined ;
25
+ var c_config : c.z_owned_config_t = undefined ;
24
26
try err (c .zc_config_from_env (& c_config ));
25
27
return Config { ._c = c_config };
26
28
}
27
29
28
30
pub fn initFromFile (path : [:0 ]const u8 ) Error ! Config {
29
- var c_config : c.Config = undefined ;
31
+ var c_config : c.z_owned_config_t = undefined ;
30
32
try err (c .zc_config_from_file (& c_config , path .ptr ));
31
33
return Config { ._c = c_config };
32
34
}
33
35
34
36
pub fn initFromString (str : [:0 ]const u8 ) Error ! Config {
35
- var c_config : c.Config = undefined ;
37
+ var c_config : c.z_owned_config_t = undefined ;
36
38
try err (c .zc_config_from_str (& c_config , str .ptr ));
37
39
return Config { ._c = c_config };
38
40
}
39
41
40
42
pub fn deinit (self : * Config ) void {
41
- c .z_config_drop (& self ._c );
43
+ c .z_config_drop (c . z_config_move ( & self ._c ) );
42
44
}
43
45
};
44
46
@@ -51,48 +53,48 @@ pub const ZID = struct {
51
53
};
52
54
53
55
pub const Session = struct {
54
- _c : c.Session ,
56
+ _c : c.z_owned_session_t ,
55
57
56
58
pub const OpenOptions = struct {
57
- _c : c.OpenOptions ,
59
+ _c : c.z_open_options_t ,
58
60
59
61
pub fn init () OpenOptions {
60
- var c_openoptions : c.OpenOptions = undefined ;
62
+ var c_openoptions : c.z_open_options_t = undefined ;
61
63
c .z_open_options_default (& c_openoptions );
62
64
return OpenOptions { ._c = c_openoptions };
63
65
}
64
66
};
65
67
66
68
pub fn open (config : * Config , options : * const OpenOptions ) Error ! Session {
67
- var c_session : c.Session = undefined ;
68
- try err (c .z_open (& c_session , & config ._c , & options ._c ));
69
+ var c_session : c.z_owned_session_t = undefined ;
70
+ try err (c .z_open (& c_session , c . z_config_move ( & config ._c ) , & options ._c ));
69
71
return Session { ._c = c_session };
70
72
}
71
73
72
74
pub fn deinit (self : * Session ) void {
73
- c .z_session_drop (& self ._c );
75
+ c .z_session_drop (c . z_session_move ( & self ._c ) );
74
76
}
75
77
76
78
pub const CloseOptions = struct {
77
- _c : c.CloseOptions ,
79
+ _c : c.z_close_options_t ,
78
80
79
81
pub fn init () CloseOptions {
80
- var c_closeoptions : c.CloseOptions = undefined ;
82
+ var c_closeoptions : c.z_close_options_t = undefined ;
81
83
c .z_close_options_default (& c_closeoptions );
82
84
return CloseOptions { ._c = c_closeoptions };
83
85
}
84
86
};
85
87
86
88
pub fn close (self : * Session , options : * CloseOptions ) Error ! void {
87
- try err (c .z_close (c .z_session_loan_mut (self ), options ));
89
+ try err (c .z_close (c .z_session_loan_mut (self ), & options . _c ));
88
90
}
89
91
90
92
pub fn isClosed (self : * const Session ) bool {
91
- return c .z_session_is_closed (c .z_session_loan (self ));
93
+ return c .z_session_is_closed (c .z_session_loan (& self . _c ));
92
94
}
93
95
94
96
pub fn infoZid (self : * const Session ) error {InvalidSession }! ZID {
95
- const c_zid = c .z_info_zid (c .z_session_loan (self ));
97
+ const c_zid = c .z_info_zid (c .z_session_loan (& self . _c ));
96
98
const zid = ZID { ._c = c_zid };
97
99
if (! zid .isValid ()) return error .InvalidSession ;
98
100
return zid ;
@@ -101,48 +103,48 @@ pub const Session = struct {
101
103
// TODO: other zid stuff
102
104
103
105
pub const PutOptions = struct {
104
- _c : c.PutOptions ,
106
+ _c : c.z_put_options_t ,
105
107
106
108
pub fn init () PutOptions {
107
- var c_options : c.PutOptions = undefined ;
109
+ var c_options : c.z_put_options_t = undefined ;
108
110
c .z_put_options_default (& c_options );
109
111
return PutOptions { ._c = c_options };
110
112
}
111
113
};
112
114
113
115
pub fn put (self : * const Session , key_expr : [:0 ]const u8 , bytes : * Bytes , options : * PutOptions ) Error ! void {
114
- var view_keyexpr : c.ViewKeyexpr = undefined ;
116
+ var view_keyexpr : c.z_view_keyexpr_t = undefined ;
115
117
try err (c .z_view_keyexpr_from_str (& view_keyexpr , key_expr .ptr ));
116
118
117
119
try err (c .z_put (
118
120
c .z_session_loan (& self ._c ),
119
121
c .z_view_keyexpr_loan (& view_keyexpr ),
120
- & bytes ._c ,
122
+ c . z_bytes_move ( & bytes ._c ) ,
121
123
& options ._c ,
122
124
));
123
125
}
124
126
};
125
127
126
128
pub const Bytes = struct {
127
- _c : c.Bytes ,
129
+ _c : c.z_owned_bytes_t ,
128
130
129
131
pub fn initFromStaticString (string : [:0 ]const u8 ) Error ! Bytes {
130
- var c_bytes : c.Bytes = undefined ;
132
+ var c_bytes : c.z_owned_bytes_t = undefined ;
131
133
try err (c .z_bytes_from_static_str (& c_bytes , string .ptr ));
132
134
return Bytes { ._c = c_bytes };
133
135
}
134
136
135
137
pub fn deinit (self : * Bytes ) void {
136
- c .z_bytes_drop (& self ._c );
138
+ c .z_bytes_drop (c . z_bytes_move ( & self ._c ) );
137
139
}
138
140
};
139
141
140
142
pub const KeyExpr = struct {
141
- _c : c.Keyexpr ,
143
+ _c : c.z_owned_keyexpr_t ,
142
144
};
143
145
144
146
pub const ViewKeyExpr = struct {
145
- _c : c.ViewKeyexpr ,
147
+ _c : c.z_view_keyexpr_t ,
146
148
};
147
149
148
150
test "sanity check" {
0 commit comments