Struct DotNetResourceEncoder
pub struct DotNetResourceEncoder { /* private fields */ }Expand description
Specialized encoder for .NET resource file format.
The crate::metadata::resources::encoder::DotNetResourceEncoder creates resource files compatible with
the .NET resource system, including proper magic numbers, type headers, and
data serialization according to the .NET binary format specification.
§.NET Resource Format
The .NET resource format includes:
- Magic Number:
0xBEEFCACEto identify the format - Version Information: Resource format version numbers
- Type Table: Names and indices of resource types used
- Resource Table: Names and data offsets for each resource
- Data Section: Actual resource data with type information
§Usage Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
// Add various .NET resource types
encoder.add_string("WelcomeMessage", "Welcome to the application!")?;
encoder.add_int32("MaxRetries", 3)?;
encoder.add_boolean("DebugMode", true)?;
encoder.add_byte_array("ConfigData", &[1, 2, 3, 4])?;
// Generate .NET resource file
let resource_file = encoder.encode_dotnet_format()?;§Thread Safety
This type is not Send or Sync because it maintains mutable state
during resource building. Create separate instances for concurrent encoding.
Implementations§
§impl DotNetResourceEncoder
impl DotNetResourceEncoder
pub fn new() -> Self
pub fn new() -> Self
Creates a new .NET resource encoder.
Initializes an empty encoder configured for .NET resource file format generation with the current format version.
§Returns
Returns a new crate::metadata::resources::encoder::DotNetResourceEncoder instance ready for resource addition.
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
assert_eq!(encoder.resource_count(), 0);pub fn add_string(&mut self, name: &str, value: &str) -> Result<()>
pub fn add_string(&mut self, name: &str, value: &str) -> Result<()>
Adds a string resource.
Registers a string value with the specified name. String resources are encoded using the .NET string serialization format.
§Arguments
name- Unique name for the resourcevalue- String value to store
§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
encoder.add_string("ApplicationName", "My Application")?;
encoder.add_string("Version", "1.0.0")?;pub fn add_int32(&mut self, name: &str, value: i32) -> Result<()>
pub fn add_int32(&mut self, name: &str, value: i32) -> Result<()>
Adds a 32-bit integer resource.
Registers an integer value with the specified name. Integer resources use the .NET Int32 serialization format.
§Arguments
name- Unique name for the resourcevalue- Integer value to store
§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
encoder.add_int32("MaxConnections", 100)?;
encoder.add_int32("TimeoutSeconds", 30)?;pub fn add_boolean(&mut self, name: &str, value: bool) -> Result<()>
pub fn add_boolean(&mut self, name: &str, value: bool) -> Result<()>
Adds a boolean resource.
Registers a boolean value with the specified name. Boolean resources use the .NET Boolean serialization format.
§Arguments
name- Unique name for the resourcevalue- Boolean value to store
§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
encoder.add_boolean("DebugMode", true)?;
encoder.add_boolean("EnableLogging", false)?;pub fn add_byte_array(&mut self, name: &str, data: &[u8]) -> Result<()>
pub fn add_byte_array(&mut self, name: &str, data: &[u8]) -> Result<()>
Adds a byte array resource.
Registers binary data as a byte array resource. Byte array resources use the .NET byte array serialization format with length prefix.
§Arguments
name- Unique name for the resourcedata- Binary data to store
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
let config_data = vec![0x01, 0x02, 0x03, 0x04];
encoder.add_byte_array("ConfigurationData", &config_data)?;
// For file data, read the file first
// let icon_data = std::fs::read("icon.png")?;
// encoder.add_byte_array("ApplicationIcon", &icon_data)?;§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
pub fn add_stream(&mut self, name: &str, data: &[u8]) -> Result<()>
pub fn add_stream(&mut self, name: &str, data: &[u8]) -> Result<()>
Adds a stream resource.
Registers binary data as a stream resource. Stream resources use the same
storage format as byte arrays (4-byte LE length prefix + data), but are
returned as a Stream by .NET’s ResourceReader instead of a byte[].
This allows for memory-mapped access and streaming reads for large resources.
§Arguments
name- Unique name for the resourcedata- Binary data to store
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
let image_data = vec![0x89, 0x50, 0x4E, 0x47]; // PNG header
encoder.add_stream("BackgroundImage", &image_data)?;§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
pub fn add_byte(&mut self, name: &str, value: u8) -> Result<()>
pub fn add_byte(&mut self, name: &str, value: u8) -> Result<()>
Adds an unsigned 8-bit integer resource.
Registers a byte value with the specified name.
§Arguments
name- Unique name for the resourcevalue- Byte value to store (0-255)
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
encoder.add_byte("MaxRetries", 5)?;§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
pub fn add_sbyte(&mut self, name: &str, value: i8) -> Result<()>
pub fn add_sbyte(&mut self, name: &str, value: i8) -> Result<()>
Adds a signed 8-bit integer resource.
Registers a signed byte value with the specified name.
§Arguments
name- Unique name for the resourcevalue- Signed byte value to store (-128 to 127)
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
encoder.add_sbyte("TemperatureOffset", -10)?;§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
pub fn add_char(&mut self, name: &str, value: char) -> Result<()>
pub fn add_char(&mut self, name: &str, value: char) -> Result<()>
Adds a character resource.
Registers a Unicode character with the specified name.
§Arguments
name- Unique name for the resourcevalue- Character value to store
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
encoder.add_char("Separator", ',')?;
encoder.add_char("Delimiter", '|')?;§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
pub fn add_int16(&mut self, name: &str, value: i16) -> Result<()>
pub fn add_int16(&mut self, name: &str, value: i16) -> Result<()>
Adds a signed 16-bit integer resource.
Registers a 16-bit signed integer value with the specified name.
§Arguments
name- Unique name for the resourcevalue- 16-bit signed integer value to store
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
encoder.add_int16("PortNumber", 8080)?;§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
pub fn add_uint16(&mut self, name: &str, value: u16) -> Result<()>
pub fn add_uint16(&mut self, name: &str, value: u16) -> Result<()>
Adds an unsigned 16-bit integer resource.
Registers a 16-bit unsigned integer value with the specified name.
§Arguments
name- Unique name for the resourcevalue- 16-bit unsigned integer value to store
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
encoder.add_uint16("MaxConnections", 65535)?;§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
pub fn add_uint32(&mut self, name: &str, value: u32) -> Result<()>
pub fn add_uint32(&mut self, name: &str, value: u32) -> Result<()>
Adds an unsigned 32-bit integer resource.
Registers a 32-bit unsigned integer value with the specified name.
§Arguments
name- Unique name for the resourcevalue- 32-bit unsigned integer value to store
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
encoder.add_uint32("FileSize", 1024000)?;§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
pub fn add_int64(&mut self, name: &str, value: i64) -> Result<()>
pub fn add_int64(&mut self, name: &str, value: i64) -> Result<()>
Adds a signed 64-bit integer resource.
Registers a 64-bit signed integer value with the specified name.
§Arguments
name- Unique name for the resourcevalue- 64-bit signed integer value to store
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
encoder.add_int64("TimestampTicks", 637500000000000000)?;§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
pub fn add_uint64(&mut self, name: &str, value: u64) -> Result<()>
pub fn add_uint64(&mut self, name: &str, value: u64) -> Result<()>
Adds an unsigned 64-bit integer resource.
Registers a 64-bit unsigned integer value with the specified name.
§Arguments
name- Unique name for the resourcevalue- 64-bit unsigned integer value to store
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
encoder.add_uint64("MaxFileSize", 18446744073709551615)?;§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
pub fn add_single(&mut self, name: &str, value: f32) -> Result<()>
pub fn add_single(&mut self, name: &str, value: f32) -> Result<()>
Adds a 32-bit floating point resource.
Registers a single-precision floating point value with the specified name.
§Arguments
name- Unique name for the resourcevalue- 32-bit floating point value to store
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
encoder.add_single("ScaleFactor", 1.5)?;
encoder.add_single("Pi", 3.14159)?;§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
pub fn add_double(&mut self, name: &str, value: f64) -> Result<()>
pub fn add_double(&mut self, name: &str, value: f64) -> Result<()>
Adds a 64-bit floating point resource.
Registers a double-precision floating point value with the specified name.
§Arguments
name- Unique name for the resourcevalue- 64-bit floating point value to store
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
encoder.add_double("PreciseValue", 3.14159265358979323846)?;
encoder.add_double("EulerNumber", 2.71828182845904523536)?;§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
pub fn add_decimal(
&mut self,
name: &str,
lo: i32,
mid: i32,
hi: i32,
flags: i32,
) -> Result<()>
pub fn add_decimal( &mut self, name: &str, lo: i32, mid: i32, hi: i32, flags: i32, ) -> Result<()>
Adds a .NET Decimal resource using raw bit representation.
Registers a 128-bit decimal value with the specified name using the same
binary format as .NET’s System.Decimal. The four 32-bit integers represent
the internal structure of a .NET decimal number.
§Arguments
name- Unique name for the resourcelo- Low 32 bits of the 96-bit mantissamid- Middle 32 bits of the 96-bit mantissahi- High 32 bits of the 96-bit mantissaflags- Sign (bit 31) and scale (bits 16-23, valid range 0-28)
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
// Represents 3.261 (mantissa=3261, scale=3, positive)
// flags = 0x00030000 (scale 3 in bits 16-23)
encoder.add_decimal("Price", 3261, 0, 0, 0x00030000)?;
// Represents -123.45 (mantissa=12345, scale=2, negative)
// flags = 0x80020000 (sign bit + scale 2)
encoder.add_decimal("Discount", 12345, 0, 0, 0x80020000_u32 as i32)?;§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
pub fn add_datetime(&mut self, name: &str, binary_value: i64) -> Result<()>
pub fn add_datetime(&mut self, name: &str, binary_value: i64) -> Result<()>
Adds a .NET DateTime resource using binary representation.
Registers a date/time value with the specified name using the same binary
format as .NET’s DateTime.ToBinary(). The 64-bit value encodes both the
ticks and the DateTimeKind.
§Arguments
name- Unique name for the resourcebinary_value- The binary representation fromDateTime.ToBinary()- Bits 0-61: Ticks (100-nanosecond intervals since 01/01/0001 00:00:00)
- Bits 62-63: DateTimeKind (0=Unspecified, 1=UTC, 2=Local)
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
// Ticks for 2024-01-01 00:00:00 UTC (kind=1, so bits 62-63 = 0b01)
let ticks: i64 = 638_396_736_000_000_000; // Ticks component
let kind: i64 = 1 << 62; // UTC kind
encoder.add_datetime("ReleaseDate", ticks | kind)?;§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
pub fn add_timespan(&mut self, name: &str, ticks: i64) -> Result<()>
pub fn add_timespan(&mut self, name: &str, ticks: i64) -> Result<()>
Adds a .NET TimeSpan resource using ticks.
Registers a time interval with the specified name. The 64-bit signed value represents the number of 100-nanosecond intervals in the time span.
§Arguments
name- Unique name for the resourceticks- Number of 100-nanosecond intervals (negative for negative spans)
§Conversion Reference
Common tick conversions:
- 1 millisecond = 10,000 ticks
- 1 second = 10,000,000 ticks
- 1 minute = 600,000,000 ticks
- 1 hour = 36,000,000,000 ticks
- 1 day = 864,000,000,000 ticks
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
// 1 hour timeout
encoder.add_timespan("Timeout", 36_000_000_000)?;
// 30 seconds
encoder.add_timespan("RetryDelay", 300_000_000)?;
// Negative 5 minutes
encoder.add_timespan("TimeOffset", -3_000_000_000)?;§Errors
Currently always returns Ok(()). Future versions may return errors
for invalid resource names or encoding issues.
pub fn resource_count(&self) -> usize
pub fn resource_count(&self) -> usize
Returns the number of resources in the encoder.
§Returns
The total number of resources that have been added.
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
assert_eq!(encoder.resource_count(), 0);
encoder.add_string("test", "value")?;
assert_eq!(encoder.resource_count(), 1);pub fn encode_dotnet_format(&self) -> Result<Vec<u8>>
pub fn encode_dotnet_format(&self) -> Result<Vec<u8>>
Encodes all resources into .NET resource file format.
Generates a complete .NET resource file including magic number, headers, type information, and resource data according to the .NET specification.
§Returns
Returns the encoded .NET resource file as a byte vector.
§Errors
Returns crate::Error if encoding fails due to invalid resource data
or serialization errors.
§Examples
use dotscope::metadata::resources::DotNetResourceEncoder;
let mut encoder = DotNetResourceEncoder::new();
encoder.add_string("AppName", "My Application")?;
encoder.add_int32("Version", 1)?;
let resource_file = encoder.encode_dotnet_format()?;
// The encoded data can be saved to a file or embedded in an assembly
assert!(!resource_file.is_empty());Trait Implementations§
§impl Clone for DotNetResourceEncoder
impl Clone for DotNetResourceEncoder
§fn clone(&self) -> DotNetResourceEncoder
fn clone(&self) -> DotNetResourceEncoder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for DotNetResourceEncoder
impl Debug for DotNetResourceEncoder
Auto Trait Implementations§
impl Freeze for DotNetResourceEncoder
impl RefUnwindSafe for DotNetResourceEncoder
impl Send for DotNetResourceEncoder
impl Sync for DotNetResourceEncoder
impl Unpin for DotNetResourceEncoder
impl UnsafeUnpin for DotNetResourceEncoder
impl UnwindSafe for DotNetResourceEncoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for T
impl<T> Downcast for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.