@@ -360,6 +360,36 @@ impl Default for FileMetaTableBuilder {
360
360
}
361
361
}
362
362
363
+ /// Ensure that the string is even lengthed, by adding a trailing character
364
+ /// if not.
365
+ #[ inline]
366
+ fn padded < T > ( s : T , pad : char ) -> String
367
+ where
368
+ T : Into < String > ,
369
+ {
370
+ let mut s = s. into ( ) ;
371
+ if s. len ( ) % 2 == 1 {
372
+ s. push ( pad) ;
373
+ }
374
+ s
375
+ }
376
+
377
+ /// Ensure that the string is even lengthed with trailing '\0's.
378
+ fn ui_padded < T > ( s : T ) -> String
379
+ where
380
+ T : Into < String > ,
381
+ {
382
+ padded ( s, '\0' )
383
+ }
384
+
385
+ /// Ensure that the string is even lengthed with trailing spaces.
386
+ fn txt_padded < T > ( s : T ) -> String
387
+ where
388
+ T : Into < String > ,
389
+ {
390
+ padded ( s, ' ' )
391
+ }
392
+
363
393
impl FileMetaTableBuilder {
364
394
/// Create a new, empty builder.
365
395
pub fn new ( ) -> FileMetaTableBuilder {
@@ -379,62 +409,92 @@ impl FileMetaTableBuilder {
379
409
}
380
410
381
411
/// Define the media storage SOP class UID.
382
- pub fn media_storage_sop_class_uid ( mut self , value : String ) -> FileMetaTableBuilder {
383
- self . media_storage_sop_class_uid = Some ( value) ;
412
+ pub fn media_storage_sop_class_uid < T > ( mut self , value : T ) -> FileMetaTableBuilder
413
+ where
414
+ T : Into < String > ,
415
+ {
416
+ self . media_storage_sop_class_uid = Some ( ui_padded ( value) ) ;
384
417
self
385
418
}
386
419
387
420
/// Define the media storage SOP instance UID.
388
- pub fn media_storage_sop_instance_uid ( mut self , value : String ) -> FileMetaTableBuilder {
389
- self . media_storage_sop_instance_uid = Some ( value) ;
421
+ pub fn media_storage_sop_instance_uid < T > ( mut self , value : T ) -> FileMetaTableBuilder
422
+ where
423
+ T : Into < String > ,
424
+ {
425
+ self . media_storage_sop_instance_uid = Some ( ui_padded ( value) ) ;
390
426
self
391
427
}
392
428
393
- /// Define the transfer syntax.
394
- pub fn transfer_syntax ( mut self , value : String ) -> FileMetaTableBuilder {
395
- self . transfer_syntax = Some ( value) ;
429
+ /// Define the transfer syntax UID.
430
+ pub fn transfer_syntax < T > ( mut self , value : T ) -> FileMetaTableBuilder
431
+ where
432
+ T : Into < String > ,
433
+ {
434
+ self . transfer_syntax = Some ( ui_padded ( value) ) ;
396
435
self
397
436
}
398
437
399
438
/// Define the implementation class UID.
400
- pub fn implementation_class_uid ( mut self , value : String ) -> FileMetaTableBuilder {
401
- self . implementation_class_uid = Some ( value) ;
439
+ pub fn implementation_class_uid < T > ( mut self , value : T ) -> FileMetaTableBuilder
440
+ where
441
+ T : Into < String > ,
442
+ {
443
+ self . implementation_class_uid = Some ( ui_padded ( value) ) ;
402
444
self
403
445
}
404
446
405
447
/// Define the implementation version name.
406
- pub fn implementation_version_name ( mut self , value : String ) -> FileMetaTableBuilder {
407
- self . implementation_version_name = Some ( value) ;
448
+ pub fn implementation_version_name < T > ( mut self , value : T ) -> FileMetaTableBuilder
449
+ where
450
+ T : Into < String > ,
451
+ {
452
+ self . implementation_version_name = Some ( txt_padded ( value) ) ;
408
453
self
409
454
}
410
455
411
456
/// Define the source application entity title.
412
- pub fn source_application_entity_title ( mut self , value : String ) -> FileMetaTableBuilder {
413
- self . source_application_entity_title = Some ( value) ;
457
+ pub fn source_application_entity_title < T > ( mut self , value : T ) -> FileMetaTableBuilder
458
+ where
459
+ T : Into < String > ,
460
+ {
461
+ self . source_application_entity_title = Some ( txt_padded ( value) ) ;
414
462
self
415
463
}
416
464
417
465
/// Define the sending application entity title.
418
- pub fn sending_application_entity_title ( mut self , value : String ) -> FileMetaTableBuilder {
419
- self . sending_application_entity_title = Some ( value) ;
466
+ pub fn sending_application_entity_title < T > ( mut self , value : T ) -> FileMetaTableBuilder
467
+ where
468
+ T : Into < String > ,
469
+ {
470
+ self . sending_application_entity_title = Some ( txt_padded ( value) ) ;
420
471
self
421
472
}
422
473
423
474
/// Define the receiving application entity title.
424
- pub fn receiving_application_entity_title ( mut self , value : String ) -> FileMetaTableBuilder {
425
- self . receiving_application_entity_title = Some ( value) ;
475
+ pub fn receiving_application_entity_title < T > ( mut self , value : T ) -> FileMetaTableBuilder
476
+ where
477
+ T : Into < String > ,
478
+ {
479
+ self . receiving_application_entity_title = Some ( txt_padded ( value) ) ;
426
480
self
427
481
}
428
482
429
483
/// Define the private information creator UID.
430
- pub fn private_information_creator_uid ( mut self , value : String ) -> FileMetaTableBuilder {
431
- self . private_information_creator_uid = Some ( value) ;
484
+ pub fn private_information_creator_uid < T > ( mut self , value : T ) -> FileMetaTableBuilder
485
+ where
486
+ T : Into < String > ,
487
+ {
488
+ self . private_information_creator_uid = Some ( ui_padded ( value) ) ;
432
489
self
433
490
}
434
491
435
492
/// Define the private information as a vector of bytes.
436
- pub fn private_information ( mut self , value : Vec < u8 > ) -> FileMetaTableBuilder {
437
- self . private_information = Some ( value) ;
493
+ pub fn private_information < T > ( mut self , value : T ) -> FileMetaTableBuilder
494
+ where
495
+ T : Into < Vec < u8 > > ,
496
+ {
497
+ self . private_information = Some ( value. into ( ) ) ;
438
498
self
439
499
}
440
500
0 commit comments