From 3226e6243f453d2171787e5a5bfbecda9ab469fb Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sun, 7 Feb 2021 09:16:28 +0100 Subject: feat(users/Profpatsch/netencode): add `dec::AnyU` as id Change-Id: I3037882dff15243bd7a5c1c78331f8e2ffdbda84 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2493 Reviewed-by: Profpatsch Tested-by: BuildkiteCI --- users/Profpatsch/netencode/netencode.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'users/Profpatsch/netencode') diff --git a/users/Profpatsch/netencode/netencode.rs b/users/Profpatsch/netencode/netencode.rs index c8c631689a02..e15cd8b38327 100644 --- a/users/Profpatsch/netencode/netencode.rs +++ b/users/Profpatsch/netencode/netencode.rs @@ -604,6 +604,24 @@ pub mod dec { fn dec(u: U<'a>) -> Result; } + pub struct AnyT; + pub struct AnyU; + + // impl Decoder for AnyT { + // type A = T; + // fn dec(u: U) -> Result { + // // TODO: implement + // parse::u_into_t(u) + // } + // } + + impl<'a> Decoder<'a> for AnyU { + type A = U<'a>; + fn dec(u: U<'a>) -> Result { + Ok(u) + } + } + pub struct ScalarAsBytes; impl<'a> Decoder<'a> for ScalarAsBytes { @@ -637,4 +655,12 @@ pub mod dec { } } } + + fn dec_u(b: &[u8]) -> Result { + match parse::u_u(b) { + Ok((b"", u)) => Ok(u), + Ok((rest, _)) => Err(DecodeError(format!("Cannot decode nested U, it contains trailing bytes"))), + Err(err) => Err(DecodeError(format!("Cannot decode nested U bytes: {:?}", err))), + } + } } -- cgit 1.4.1