1 /// Encode u64 as varint.
2 /// Panics if buffer length is less than 10.
3 #[inline]
encode_varint64(mut value: u64, buf: &mut [u8]) -> usize4 pub fn encode_varint64(mut value: u64, buf: &mut [u8]) -> usize {
5     assert!(buf.len() >= 10);
6 
7     unsafe {
8         let mut i = 0;
9         while (value & !0x7F) > 0 {
10             *buf.get_unchecked_mut(i) = ((value & 0x7F) | 0x80) as u8;
11             value >>= 7;
12             i += 1;
13         }
14         *buf.get_unchecked_mut(i) = value as u8;
15         i + 1
16     }
17 }
18 
19 /// Encode u32 value as varint.
20 /// Panics if buffer length is less than 5.
21 #[inline]
encode_varint32(mut value: u32, buf: &mut [u8]) -> usize22 pub fn encode_varint32(mut value: u32, buf: &mut [u8]) -> usize {
23     assert!(buf.len() >= 5);
24 
25     unsafe {
26         let mut i = 0;
27         while (value & !0x7F) > 0 {
28             *buf.get_unchecked_mut(i) = ((value & 0x7F) | 0x80) as u8;
29             value >>= 7;
30             i += 1;
31         }
32         *buf.get_unchecked_mut(i) = value as u8;
33         i + 1
34     }
35 }
36