-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
8 changed files
with
213 additions
and
12 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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
[package] | ||
name = "ohos-asset-binding" | ||
version = "0.0.1" | ||
edition = "2021" | ||
name = "ohos-asset-binding" | ||
version = "0.0.1" | ||
edition = "2021" | ||
license = "MIT OR Apache-2.0" | ||
description = "OpenHarmony's asset binding for rust" | ||
|
||
[dependencies] | ||
ohos-asset-sys = {workspace = true} | ||
ohos-asset-sys = { workspace = true } |
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,16 @@ | ||
use std::mem::ManuallyDrop; | ||
|
||
use crate::AssetTag; | ||
|
||
pub type AssetBlob = Vec<u8>; | ||
|
||
pub enum AssetValue { | ||
Boolean(bool), | ||
U32IntT(u32), | ||
Blob(ManuallyDrop<AssetBlob>), | ||
} | ||
|
||
pub struct AssetAttr { | ||
pub tag: AssetTag, | ||
pub value: AssetValue, | ||
} |
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 +1,38 @@ | ||
mod r#type; | ||
mod data; | ||
mod r#type; | ||
|
||
pub use data::*; | ||
pub use r#type::*; | ||
|
||
/// add | ||
pub fn asset_add(attrs: Vec<AssetAttr>) { | ||
let count = attrs.len() as u32; | ||
let real_attrs = attrs | ||
.iter() | ||
.map(|a| match &a.value { | ||
AssetValue::Blob(blob) => { | ||
let b = ohos_asset_sys::Asset_Blob { | ||
size: blob.len() as u32, | ||
data: blob.as_ptr() as *mut u8, | ||
}; | ||
ohos_asset_sys::Asset_Attr { | ||
tag: a.tag.into(), | ||
value: ohos_asset_sys::Asset_Value { blob: b }, | ||
} | ||
} | ||
AssetValue::Boolean(boolean) => ohos_asset_sys::Asset_Attr { | ||
tag: a.tag.into(), | ||
value: ohos_asset_sys::Asset_Value { | ||
boolean: boolean.to_owned(), | ||
}, | ||
}, | ||
AssetValue::U32IntT(uint32_t) => ohos_asset_sys::Asset_Attr { | ||
tag: a.tag.into(), | ||
value: ohos_asset_sys::Asset_Value { | ||
u32_: uint32_t.to_owned(), | ||
}, | ||
}, | ||
}) | ||
.collect::<Vec<_>>(); | ||
unsafe { ohos_asset_sys::OH_Asset_Add(real_attrs.as_ptr(), count) }; | ||
} |
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