Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 39f3a4b2 authored by Martin Geisler's avatar Martin Geisler
Browse files

pdl: Let conforms method return Boolean directly

Test: atest pdl_tests
Change-Id: I23891e4cf1cdf753e5d7b792e4b6e4dcba3f79f5
parent d78d215b
Loading
Loading
Loading
Loading
+2 −6
Original line number Diff line number Diff line
@@ -173,12 +173,8 @@ fn generate_packet_decl(
    code.push_str(&quote_block! {
        impl #data_name {
            fn conforms(bytes: &[u8]) -> bool {
                // TODO(mgeisler): return Boolean expression directly.
                // TODO(mgeisler): skip when total_field_size == 0.
                if bytes.len() < #packet_size_bytes {
                    return false;
                }
                true
                // TODO(mgeisler): skip when packet_size_bytes == 0.
                bytes.len() >= #packet_size_bytes
            }

            fn parse(bytes: &[u8]) -> Result<Self> {
+1 −4
Original line number Diff line number Diff line
@@ -25,10 +25,7 @@ pub struct FooBuilder {

impl FooData {
    fn conforms(bytes: &[u8]) -> bool {
        if bytes.len() < 7 {
            return false;
        }
        true
        bytes.len() >= 7
    }
    fn parse(bytes: &[u8]) -> Result<Self> {
        if bytes.len() < 2 {
+1 −4
Original line number Diff line number Diff line
@@ -25,10 +25,7 @@ pub struct FooBuilder {

impl FooData {
    fn conforms(bytes: &[u8]) -> bool {
        if bytes.len() < 7 {
            return false;
        }
        true
        bytes.len() >= 7
    }
    fn parse(bytes: &[u8]) -> Result<Self> {
        if bytes.len() < 2 {
+1 −4
Original line number Diff line number Diff line
@@ -11,10 +11,7 @@ pub struct FooBuilder {}

impl FooData {
    fn conforms(bytes: &[u8]) -> bool {
        if bytes.len() < 0 {
            return false;
        }
        true
        bytes.len() >= 0
    }
    fn parse(bytes: &[u8]) -> Result<Self> {
        Ok(Self {})
+1 −4
Original line number Diff line number Diff line
@@ -19,10 +19,7 @@ pub struct FooBuilder {

impl FooData {
    fn conforms(bytes: &[u8]) -> bool {
        if bytes.len() < 6 {
            return false;
        }
        true
        bytes.len() >= 6
    }
    fn parse(bytes: &[u8]) -> Result<Self> {
        if bytes.len() < 1 {
Loading