@@ -345,6 +345,7 @@ type writer =
345
345
impure fn write_bytes ( vec[ u8] bytes) ;
346
346
impure fn write_le_uint ( uint n, uint size) ;
347
347
impure fn write_le_int ( int n, uint size) ;
348
+ impure fn write_be_uint ( uint n, uint size) ;
348
349
} ;
349
350
350
351
fn uint_to_le_bytes( uint n, uint size) -> vec[ u8 ] {
@@ -357,6 +358,16 @@ fn uint_to_le_bytes(uint n, uint size) -> vec[u8] {
357
358
ret bytes;
358
359
}
359
360
361
+ fn uint_to_be_bytes ( uint n, uint size) -> vec[ u8 ] {
362
+ let vec[ u8] bytes = vec ( ) ;
363
+ auto i = ( size - 1 u) as int ;
364
+ while ( i >= 0 ) {
365
+ bytes += vec ( ( ( n >> ( ( i * 8 ) as uint ) ) & 255 u) as u8 ) ;
366
+ i -= 1 ;
367
+ }
368
+ ret bytes;
369
+ }
370
+
360
371
state obj new_writer ( buf_writer out) {
361
372
fn get_buf_writer ( ) -> buf_writer {
362
373
ret out;
@@ -383,6 +394,9 @@ state obj new_writer(buf_writer out) {
383
394
impure fn write_le_int ( int n, uint size) {
384
395
out. write ( uint_to_le_bytes ( n as uint , size) ) ;
385
396
}
397
+ impure fn write_be_uint ( uint n, uint size) {
398
+ out. write ( uint_to_be_bytes ( n, size) ) ;
399
+ }
386
400
}
387
401
388
402
// FIXME: Remove me once objects are exported.
0 commit comments