diff --git a/ylong_http/src/h3/connection.rs b/ylong_http/src/h3/connection.rs index a77a15ee3df26c89640d5ed7baf1fe64a06d6f3a..0d03a7e33421580099df705111d841b4a3e7fbb3 100644 --- a/ylong_http/src/h3/connection.rs +++ b/ylong_http/src/h3/connection.rs @@ -9,4 +9,4 @@ // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and -// limitations under the License. \ No newline at end of file +// limitations under the License. diff --git a/ylong_http/src/h3/octets.rs b/ylong_http/src/h3/octets.rs index 02b07b77e623fd82bf11db54e12668da067f348c..05f7c7c3b689ecc4ea82458ea636c33bf1b690cc 100644 --- a/ylong_http/src/h3/octets.rs +++ b/ylong_http/src/h3/octets.rs @@ -283,26 +283,29 @@ impl<'a> WriteVarint<'a> { /// Returns how many bytes it would take to encode `v` as a variable-length /// integer. pub const fn varint_len(v: u64) -> usize { - if v <= 63 { - 1 - } else if v <= 16383 { - 2 - } else if v <= 1_073_741_823 { - 4 - } else if v <= 4_611_686_018_427_387_903 { - 8 - } else { - unreachable!() + match v { + 0..=63 => { + 1 + } + 64..=16383 => { + 2 + } + 16384..=1_073_741_823 => { + 4 + } + 1_073_741_824..=4_611_686_018_427_387_903 => { + 8 + } + _ => {unreachable!()} } } /// Returns how long the variable-length integer is, given its first byte. -pub const fn varint_parse_len(first: u8) -> usize { - match first >> 6 { - 0 => 1, - 1 => 2, - 2 => 4, - 3 => 8, - _ => unreachable!(), +pub const fn varint_parse_len(byte: u8) -> usize { + let byte = byte >> 6; + if byte <= 3 { + 1 << byte + } else { + unreachable!() } }