| Crates.io | csharp_binary_encoding |
| lib.rs | csharp_binary_encoding |
| version | 0.4.0 |
| created_at | 2025-03-14 08:57:07.457474+00 |
| updated_at | 2025-04-25 04:02:21.412309+00 |
| description | Decode binary data written by C#'s BinaryWriter class. |
| homepage | |
| repository | https://github.com/nilrem3/csharp_binary_encoding |
| max_upload_size | |
| id | 1591954 |
| size | 72,783 |
A crate for handling binary data in the format used by the C# System.IO.BinaryReader and System.IO.BinaryWriter Classes.
f16 Enables function for decoding f16 values. Must be compiled with nightly, since f16 is currently an unstable feature in rust.# use csharp_binary_encoding::{BinaryReader, DataDecodeError};
// &[u8] implements read
let bytes: [u8; 11] = [ 0x8F, 0x72, 0x04, 0x6D, 0x65, 0x6F, 0x77, 0xD7, 0xA3, 0xE8, 0x40 ];
// Construct a reader
let mut reader = BinaryReader::new(bytes.as_slice());
// Read values
assert_eq!(14607, reader.read_7_bit_encoded_int()?);
assert_eq!("meow".to_string(), reader.read_string()?);
assert_eq!(7.27_f32, reader.read_f32()?);
# Ok::<(), DataDecodeError>(())
# use csharp_binary_encoding::BinaryWriter;
// Vec<u8> implements write
let mut data: Vec<u8> = Vec::new();
// Construct a writer
let mut writer = BinaryWriter::new(&mut data);
//write values
writer.write_7_bit_encoded_int(14607)?;
writer.write_string("meow")?;
writer.write_f32(7.27_f32)?;
assert_eq!(
data,
vec![ 0x8F, 0x72, 0x04, 0x6D, 0x65, 0x6F, 0x77, 0xD7, 0xA3, 0xE8, 0x40 ]
);
# Ok::<(), Box<dyn std::error::Error>>(())