Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
love_飞影
Neos
Commits
fba2301f
Commit
fba2301f
authored
Mar 16, 2023
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add BufferReader in rust-src
parent
958dc3d7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
4 deletions
+78
-4
rust-src/src/adapters/damage.rs
rust-src/src/adapters/damage.rs
+1
-1
rust-src/src/buffer.rs
rust-src/src/buffer.rs
+74
-1
rust-src/src/lib.rs
rust-src/src/lib.rs
+3
-2
No files found.
rust-src/src/adapters/damage.rs
View file @
fba2301f
use
wasm_bindgen
::
prelude
::
wasm_bindgen
;
use
std
::
convert
::
TryInto
;
use
std
::
convert
::
TryInto
;
use
wasm_bindgen
::
prelude
::
wasm_bindgen
;
#[wasm_bindgen]
#[wasm_bindgen]
pub
struct
MsgUpdateHp
{
pub
struct
MsgUpdateHp
{
...
...
rust-src/src/buffer.rs
View file @
fba2301f
// TODO
//! Raw Buffer 解析工具
//!
//! 在Javascript/Typescript中数字类型只有`numbuer`,
//! 要做二进制数组的解析需要用[`DataView`],比较复杂,且性能不佳。
//! 因此这里用WASM实现两个基础的二进制数据解析模块[`BufferReader`]和[`BufferWriter`]。
use
wasm_bindgen
::
prelude
::
wasm_bindgen
;
const
OFFSET_UINT8
:
usize
=
1
;
const
OFFSET_INT8
:
usize
=
1
;
const
OFFSET_UINT16
:
usize
=
2
;
const
OFFSET_UINT32
:
usize
=
4
;
const
OFFSET_INT32
:
usize
=
4
;
#[wasm_bindgen]
pub
struct
BufferReader
{
array
:
Vec
<
u8
>
,
offset
:
usize
,
}
#[wasm_bindgen]
impl
BufferReader
{
#[wasm_bindgen(constructor)]
pub
fn
new
(
array
:
js_sys
::
Uint8Array
)
->
Self
{
Self
{
array
:
array
.to_vec
(),
offset
:
0
,
}
}
pub
fn
readUint8
(
&
mut
self
)
->
u8
{
let
ret
=
self
.array
[
self
.offset
];
self
.offset
+=
OFFSET_UINT8
;
ret
}
pub
fn
readInt8
(
&
mut
self
)
->
i8
{
let
ret
=
self
.array
[
self
.offset
]
as
i8
;
self
.offset
+=
OFFSET_INT8
;
ret
}
pub
fn
readUint16
(
&
mut
self
)
->
u16
{
let
ret
=
self
.array
[
self
.offset
..
self
.offset
+
OFFSET_UINT16
]
.try_into
()
.map
(
u16
::
from_le_bytes
)
.unwrap
();
self
.offset
+=
OFFSET_UINT16
;
ret
}
pub
fn
readUint32
(
&
mut
self
)
->
u32
{
let
ret
=
self
.array
[
self
.offset
..
self
.offset
+
OFFSET_UINT32
]
.try_into
()
.map
(
u32
::
from_le_bytes
)
.unwrap
();
self
.offset
+=
OFFSET_UINT32
;
ret
}
pub
fn
readInt32
(
&
mut
self
)
->
i32
{
let
ret
=
self
.array
[
self
.offset
..
self
.offset
+
OFFSET_INT32
]
.try_into
()
.map
(
i32
::
from_le_bytes
)
.unwrap
();
self
.offset
+=
OFFSET_INT32
;
ret
}
}
rust-src/src/lib.rs
View file @
fba2301f
#![allow(non_snake_case)]
#![allow(non_snake_case)]
mod
adapters
;
mod
buffer
;
mod
buffer
;
mod
utils
;
mod
utils
;
mod
adapters
;
pub
use
utils
::
set_panic_hook
;
pub
use
adapters
::
*
;
pub
use
adapters
::
*
;
pub
use
buffer
::
BufferReader
;
pub
use
utils
::
set_panic_hook
;
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
// allocator.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment