-
Notifications
You must be signed in to change notification settings - Fork 683
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
a8435a8
commit c027acf
Showing
57 changed files
with
6,322 additions
and
612 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Cargo.lock linguist-generated=true -diff | ||
core/protos/src/autogenerated/* linguist-generated=true -diff | ||
nearlib/protos.js linguist-generated=true -diff | ||
scripts/protos/* linguist-generated=true -diff |
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ core/wasm/**/Cargo.lock | |
|
||
# Python env | ||
.env | ||
*.pyc | ||
|
||
# Integration tests | ||
tmp/ | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,5 @@ | ||
use protos_autogen; | ||
|
||
fn main() { | ||
protos_autogen::autogenerate(); | ||
} |
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 |
---|---|---|
@@ -1,32 +1,33 @@ | ||
use std::io; | ||
|
||
use serde::{de::DeserializeOwned, Serialize}; | ||
|
||
pub type EncodeType = Result<Vec<u8>, String>; | ||
pub type DecodeType<T> = Result<T, String>; | ||
pub type EncodeResult = Result<Vec<u8>, io::Error>; | ||
pub type DecodeResult<T> = Result<T, io::Error>; | ||
|
||
// encode a type to byte array | ||
pub trait Encode { | ||
fn encode(&self) -> EncodeType; | ||
fn encode(&self) -> EncodeResult; | ||
} | ||
|
||
// decode from byte array | ||
pub trait Decode: Sized { | ||
fn decode(data: &[u8]) -> DecodeType<Self>; | ||
fn decode(data: &[u8]) -> DecodeResult<Self>; | ||
} | ||
|
||
impl<T> Encode for T | ||
where | ||
T: Serialize, | ||
{ | ||
fn encode(&self) -> EncodeType { | ||
bincode::serialize(&self).map_err(|_| "Failed to serialize".to_string()) | ||
impl<T: Serialize> Encode for T { | ||
fn encode(&self) -> EncodeResult { | ||
bincode::serialize(&self) | ||
.map_err(|_| io::Error::new(io::ErrorKind::Other, "Failed to serialize")) | ||
} | ||
} | ||
|
||
impl<T> Decode for T | ||
where | ||
T: DeserializeOwned, | ||
{ | ||
fn decode(data: &[u8]) -> DecodeType<Self> { | ||
bincode::deserialize(data).map_err(|_| "Failed to deserialize".to_string()) | ||
fn decode(data: &[u8]) -> DecodeResult<Self> { | ||
bincode::deserialize(data) | ||
.map_err(|_| io::Error::new(io::ErrorKind::Other, "Failed to deserialize")) | ||
} | ||
} |
Oops, something went wrong.