This repository was archived by the owner on Jun 8, 2021. It is now read-only.
File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 38
38
//! assert_eq!(num.get_str(), None);
39
39
//! ```
40
40
41
+ use bytes:: Bytes ;
41
42
use glib_sys;
42
43
use gobject_sys;
43
44
use gstring:: GString ;
@@ -141,6 +142,32 @@ impl Variant {
141
142
}
142
143
}
143
144
}
145
+
146
+ /// Constructs a new serialised-mode GVariant instance.
147
+ pub fn new_from_bytes < T : StaticVariantType > ( bytes : & Bytes ) -> Self {
148
+ unsafe {
149
+ from_glib_none ( glib_sys:: g_variant_new_from_bytes (
150
+ T :: static_variant_type ( ) . as_ptr ( ) as * const _ ,
151
+ bytes. to_glib_none ( ) . 0 ,
152
+ false . to_glib ( ) ,
153
+ ) )
154
+ }
155
+ }
156
+
157
+ /// Same as `new_from_bytes`, except checks on the passed data are skipped, which makes it a
158
+ /// potentially unsafe function. You should not use this function on data from external sources.
159
+ pub unsafe fn new_from_bytes_trusted < T : StaticVariantType > ( bytes : & Bytes ) -> Self {
160
+ from_glib_none ( glib_sys:: g_variant_new_from_bytes (
161
+ T :: static_variant_type ( ) . as_ptr ( ) as * const _ ,
162
+ bytes. to_glib_none ( ) . 0 ,
163
+ true . to_glib ( ) ,
164
+ ) )
165
+ }
166
+
167
+ /// Returns the serialised form of a GVariant instance.
168
+ pub fn get_data_as_bytes ( & self ) -> Bytes {
169
+ unsafe { from_glib_full ( glib_sys:: g_variant_get_data_as_bytes ( self . to_glib_none ( ) . 0 ) ) }
170
+ }
144
171
}
145
172
146
173
unsafe impl Send for Variant { }
You can’t perform that action at this time.
0 commit comments