Skip to content

Commit 7330c93

Browse files
committed
Change max inline to 30 bytes and document assumptions
1 parent 707276a commit 7330c93

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

misc/multiaddr/src/storage.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
use std::sync::Arc;
22

3-
/// MAX_INLINE is the maximum size of a multiaddr that can be stored inline
4-
const MAX_INLINE: usize = 38;
3+
/// MAX_INLINE is the maximum size of a multiaddr that can be stored inline.
4+
/// There is an overhead of 2 bytes, 1 for the length and 1 for the enum discriminator.
5+
/// 30 is chosen so that the overall size is 32. This should still be big enough to fit
6+
/// a multiaddr containing an ipv4 or ipv6 address and port.
7+
///
8+
/// More complex multiaddrs like those containing peer ids will be stored on the heap.
9+
const MAX_INLINE: usize = 30;
510

611
#[derive(Clone)]
712
pub(crate) enum Storage {
@@ -42,7 +47,7 @@ mod tests {
4247
#[test]
4348
fn struct_size() {
4449
// this should be true for both 32 and 64 bit archs
45-
assert_eq!(std::mem::size_of::<Storage>(), 40);
50+
assert_eq!(std::mem::size_of::<Storage>(), 32);
4651
}
4752

4853
#[test]

0 commit comments

Comments
 (0)