generated from Serial-ATA/sscrt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c525405
commit 9bb456b
Showing
80 changed files
with
2,522 additions
and
900 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
use super::{Annotation, ElementValue, ElementValuePair, ElementValueTag, ElementValueType}; | ||
use crate::constant_pool::ConstantPool; | ||
|
||
use common::int_types::{s4, s8, u2}; | ||
|
||
pub struct ResolvedAnnotation { | ||
pub name: String, | ||
pub element_value_pairs: Vec<ResolvedElementValuePair>, | ||
} | ||
|
||
impl ResolvedAnnotation { | ||
pub(crate) fn resolve_from(raw_annotation: &Annotation, constant_pool: &ConstantPool) -> Self { | ||
let name = constant_pool.get_constant_utf8(raw_annotation.type_index); | ||
let element_value_pairs = raw_annotation | ||
.element_value_pairs | ||
.iter() | ||
.map(|pair| ResolvedElementValuePair::resolve_from(pair, constant_pool)) | ||
.collect(); | ||
|
||
Self { | ||
name: String::from_utf8(name.to_vec()).unwrap(), | ||
element_value_pairs, | ||
} | ||
} | ||
} | ||
|
||
pub struct ResolvedElementValuePair { | ||
pub element_name: String, | ||
pub value: ResolvedElementValue, | ||
} | ||
|
||
impl ResolvedElementValuePair { | ||
fn resolve_from(raw_value_pair: &ElementValuePair, constant_pool: &ConstantPool) -> Self { | ||
let element_name = constant_pool.get_constant_utf8(raw_value_pair.element_name_index); | ||
let value = ResolvedElementValue::resolve_from(&raw_value_pair.value, constant_pool); | ||
|
||
Self { | ||
element_name: String::from_utf8(element_name.to_vec()).unwrap(), | ||
value, | ||
} | ||
} | ||
} | ||
|
||
pub struct ResolvedElementValue { | ||
pub tag: ElementValueTag, | ||
pub value: ResolvedElementValueType, | ||
} | ||
|
||
impl ResolvedElementValue { | ||
fn resolve_from(raw_element_value: &ElementValue, constant_pool: &ConstantPool) -> Self { | ||
let tag = raw_element_value.tag; | ||
let value = match &raw_element_value.ty { | ||
ElementValueType::Byte { const_value_index } => { | ||
ResolvedElementValueType::Byte(constant_pool.get_integer(*const_value_index)) | ||
}, | ||
ElementValueType::Char { const_value_index } => { | ||
ResolvedElementValueType::Char(constant_pool.get_integer(*const_value_index)) | ||
}, | ||
ElementValueType::Double { const_value_index } => { | ||
ResolvedElementValueType::Double(constant_pool.get_double(*const_value_index)) | ||
}, | ||
ElementValueType::Float { const_value_index } => { | ||
ResolvedElementValueType::Float(constant_pool.get_float(*const_value_index)) | ||
}, | ||
ElementValueType::Int { const_value_index } => { | ||
ResolvedElementValueType::Int(constant_pool.get_integer(*const_value_index)) | ||
}, | ||
ElementValueType::Long { const_value_index } => { | ||
ResolvedElementValueType::Long(constant_pool.get_long(*const_value_index)) | ||
}, | ||
ElementValueType::Short { const_value_index } => { | ||
ResolvedElementValueType::Short(constant_pool.get_integer(*const_value_index)) | ||
}, | ||
ElementValueType::Boolean { const_value_index } => { | ||
ResolvedElementValueType::Boolean(constant_pool.get_integer(*const_value_index)) | ||
}, | ||
|
||
ElementValueType::String { const_value_index } => { | ||
let value = constant_pool.get_constant_utf8(*const_value_index); | ||
ResolvedElementValueType::String(String::from_utf8(value.to_vec()).unwrap()) | ||
}, | ||
ElementValueType::Enum { | ||
type_name_index, | ||
const_value_index, | ||
} => { | ||
let type_name = constant_pool.get_constant_utf8(*type_name_index); | ||
let const_value = constant_pool.get_constant_utf8(*const_value_index); | ||
ResolvedElementValueType::Enum { | ||
type_name: String::from_utf8(type_name.to_vec()).unwrap(), | ||
const_value: String::from_utf8(const_value.to_vec()).unwrap(), | ||
} | ||
}, | ||
ElementValueType::Class { .. } => todo!(), | ||
ElementValueType::Annotation { annotation } => { | ||
let annotation = ResolvedAnnotation::resolve_from(annotation, constant_pool); | ||
ResolvedElementValueType::Annotation { annotation } | ||
}, | ||
ElementValueType::Array { values } => { | ||
let values = values | ||
.iter() | ||
.map(|value| ResolvedElementValue::resolve_from(value, constant_pool)) | ||
.collect(); | ||
ResolvedElementValueType::Array { values } | ||
}, | ||
}; | ||
|
||
Self { tag, value } | ||
} | ||
} | ||
|
||
pub enum ResolvedElementValueType { | ||
Byte(s4), | ||
Char(s4), | ||
Double(f64), | ||
Float(f32), | ||
Int(s4), | ||
Long(s8), | ||
Short(s4), | ||
Boolean(s4), | ||
String(String), | ||
Enum { | ||
type_name: String, | ||
const_value: String, | ||
}, | ||
Class { | ||
class_info_index: u2, | ||
}, | ||
Annotation { | ||
annotation: ResolvedAnnotation, | ||
}, | ||
Array { | ||
values: Vec<ResolvedElementValue>, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ pub mod endian; | |
pub mod error; | ||
pub mod int_types; | ||
pub mod macros; | ||
pub mod sync; | ||
pub mod traits; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::ops::Deref; | ||
|
||
pub struct ForceSync<T>(pub T); | ||
|
||
unsafe impl<T> Sync for ForceSync<T> {} | ||
|
||
impl<T> ForceSync<T> { | ||
pub const fn new(value: T) -> Self { | ||
ForceSync(value) | ||
} | ||
} | ||
|
||
impl<T> Deref for ForceSync<T> { | ||
type Target = T; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use std::fs::File; | ||
use std::os::unix::fs::FileExt; | ||
|
||
pub fn write_at(file: &mut File, content: &[u8], offset: u64) -> std::io::Result<usize> { | ||
file.write_at(content, offset) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,6 @@ match_cfg_meta! { | |
|
||
// Exports | ||
|
||
pub mod io; | ||
pub mod properties; | ||
pub(super) mod signals; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use std::fs::File; | ||
use std::os::windows::fs::FileExt; | ||
|
||
pub fn write_at(file: &mut File, content: &[u8], offset: u64) -> std::io::Result<usize> { | ||
file.seek_write(content, offset) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod io; | ||
pub mod properties; | ||
pub(super) mod signals; |
Oops, something went wrong.