@@ -174,6 +174,7 @@ impl AsNumber for PyCStructType {
174174}
175175
176176/// Structure field info stored in instance
177+ #[ allow( dead_code) ]
177178#[ derive( Debug , Clone ) ]
178179pub struct FieldInfo {
179180 pub name : String ,
@@ -194,6 +195,7 @@ pub struct PyCStructure {
194195 /// Raw memory buffer for the structure
195196 pub ( super ) buffer : PyRwLock < Vec < u8 > > ,
196197 /// Field information (name -> FieldInfo)
198+ #[ allow( dead_code) ]
197199 pub ( super ) fields : PyRwLock < HashMap < String , FieldInfo > > ,
198200 /// Total size of the structure
199201 pub ( super ) size : AtomicCell < usize > ,
@@ -300,58 +302,6 @@ impl Constructor for PyCStructure {
300302// Note: GetAttr and SetAttr are not implemented here.
301303// Field access is handled by CField descriptors registered on the class.
302304
303- impl PyCStructure {
304- /// Convert bytes to a Python value
305- fn bytes_to_value ( bytes : & [ u8 ] , _type_ref : & PyTypeRef , vm : & VirtualMachine ) -> PyResult {
306- match bytes. len ( ) {
307- 1 => Ok ( vm. ctx . new_int ( bytes[ 0 ] as i8 ) . into ( ) ) ,
308- 2 => {
309- let val = i16:: from_ne_bytes ( [ bytes[ 0 ] , bytes[ 1 ] ] ) ;
310- Ok ( vm. ctx . new_int ( val) . into ( ) )
311- }
312- 4 => {
313- let val = i32:: from_ne_bytes ( [ bytes[ 0 ] , bytes[ 1 ] , bytes[ 2 ] , bytes[ 3 ] ] ) ;
314- Ok ( vm. ctx . new_int ( val) . into ( ) )
315- }
316- 8 => {
317- let val = i64:: from_ne_bytes ( [
318- bytes[ 0 ] , bytes[ 1 ] , bytes[ 2 ] , bytes[ 3 ] , bytes[ 4 ] , bytes[ 5 ] , bytes[ 6 ] , bytes[ 7 ] ,
319- ] ) ;
320- Ok ( vm. ctx . new_int ( val) . into ( ) )
321- }
322- _ => Ok ( vm. ctx . new_int ( 0 ) . into ( ) ) ,
323- }
324- }
325-
326- /// Convert a Python value to bytes
327- fn value_to_bytes ( value : & PyObjectRef , size : usize , vm : & VirtualMachine ) -> PyResult < Vec < u8 > > {
328- if let Ok ( int_val) = value. try_int ( vm) {
329- let i = int_val. as_bigint ( ) ;
330- match size {
331- 1 => {
332- let val = i. to_i8 ( ) . unwrap_or ( 0 ) ;
333- Ok ( val. to_ne_bytes ( ) . to_vec ( ) )
334- }
335- 2 => {
336- let val = i. to_i16 ( ) . unwrap_or ( 0 ) ;
337- Ok ( val. to_ne_bytes ( ) . to_vec ( ) )
338- }
339- 4 => {
340- let val = i. to_i32 ( ) . unwrap_or ( 0 ) ;
341- Ok ( val. to_ne_bytes ( ) . to_vec ( ) )
342- }
343- 8 => {
344- let val = i. to_i64 ( ) . unwrap_or ( 0 ) ;
345- Ok ( val. to_ne_bytes ( ) . to_vec ( ) )
346- }
347- _ => Ok ( vec ! [ 0u8 ; size] ) ,
348- }
349- } else {
350- Ok ( vec ! [ 0u8 ; size] )
351- }
352- }
353- }
354-
355305#[ pyclass( flags( BASETYPE , IMMUTABLETYPE ) , with( Constructor ) ) ]
356306impl PyCStructure {
357307 #[ pygetset]
0 commit comments