-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from taubyte/1-required-changes-for-lit-impleme…
…ntation add bytes slice codec
- Loading branch information
Showing
7 changed files
with
41 additions
and
16 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
This file was deleted.
Oops, something went wrong.
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,25 @@ | ||
pub fn to(buf:Vec<u8>) -> Vec<Vec<u8>> { | ||
let mut result: Vec<Vec<u8>> = Vec::new(); | ||
let mut idx = 0; | ||
while idx < buf.len(){ | ||
if idx+2 >= buf.len(){ | ||
break | ||
} | ||
let size = u16::from_le_bytes([buf[idx], buf[idx+1]]) as usize; | ||
idx += 2; | ||
if idx+size > buf.len(){ | ||
break | ||
} | ||
result.push(buf[idx..idx+size].to_vec()); | ||
idx += size; | ||
} | ||
result | ||
} | ||
pub fn from(vec: Vec<Vec<u8>>) -> Vec<u8> { | ||
let mut result: Vec<u8> = Vec::new(); | ||
for mut s in vec { | ||
result.append(&mut s.len().to_le_bytes().to_vec()); | ||
result.append(&mut s); | ||
} | ||
result | ||
} |
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,5 +1,5 @@ | ||
pub mod codec { | ||
pub mod byte_slice; | ||
pub mod bytes_slice; | ||
pub mod cid; | ||
pub mod string_slice; | ||
} | ||
|
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