feat(users/Profpatsch/netencode): add dec::AnyU
as id
Change-Id: I3037882dff15243bd7a5c1c78331f8e2ffdbda84 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2493 Reviewed-by: Profpatsch <mail@profpatsch.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
3faf5b6f09
commit
3226e6243f
1 changed files with 26 additions and 0 deletions
|
@ -604,6 +604,24 @@ pub mod dec {
|
||||||
fn dec(u: U<'a>) -> Result<Self::A, DecodeError>;
|
fn dec(u: U<'a>) -> Result<Self::A, DecodeError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct AnyT;
|
||||||
|
pub struct AnyU;
|
||||||
|
|
||||||
|
// impl Decoder for AnyT {
|
||||||
|
// type A = T;
|
||||||
|
// fn dec(u: U) -> Result<Self::A, DecodeError> {
|
||||||
|
// // TODO: implement
|
||||||
|
// parse::u_into_t(u)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
impl<'a> Decoder<'a> for AnyU {
|
||||||
|
type A = U<'a>;
|
||||||
|
fn dec(u: U<'a>) -> Result<Self::A, DecodeError> {
|
||||||
|
Ok(u)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ScalarAsBytes;
|
pub struct ScalarAsBytes;
|
||||||
|
|
||||||
impl<'a> Decoder<'a> for ScalarAsBytes {
|
impl<'a> Decoder<'a> for ScalarAsBytes {
|
||||||
|
@ -637,4 +655,12 @@ pub mod dec {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dec_u(b: &[u8]) -> Result<U, DecodeError> {
|
||||||
|
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))),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue