1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
//! Three-Word Group IPv6 Encoder
//!
//! This module implements IPv6 encoding using groups of three words.
//! IPv6 addresses are encoded as either 6 words (common patterns) or 9 words (full addresses).
//! This maintains the clean "groups of three" UX pattern established by IPv4 encoding.
use crate::dictionary65k::{Dictionary65K, get_global_dictionary};
use crate::ipv6_compression::{CompressedIpv6, Ipv6Category, Ipv6Compressor};
use crate::{FourWordError, Result};
use std::fmt;
use std::net::Ipv6Addr;
/// IPv6 encoding result using groups of three words
#[derive(Debug, Clone, PartialEq)]
pub enum Ipv6ThreeWordGroupEncoding {
/// 6 words (2 groups) for common/compressed IPv6 patterns
SixWords {
groups: [ThreeWordGroup; 2],
original_ip: Ipv6Addr,
original_port: u16,
category: Ipv6Category,
},
/// 9 words (3 groups) for full IPv6 addresses
NineWords {
groups: [ThreeWordGroup; 3],
original_ip: Ipv6Addr,
original_port: u16,
},
}
/// A group of three words
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ThreeWordGroup {
pub words: [String; 3],
}
impl fmt::Display for ThreeWordGroup {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}.{}.{}", self.words[0], self.words[1], self.words[2])
}
}
impl ThreeWordGroup {
/// Get words as slice
pub fn words(&self) -> &[String; 3] {
&self.words
}
}
impl fmt::Display for Ipv6ThreeWordGroupEncoding {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Ipv6ThreeWordGroupEncoding::SixWords { groups, .. } => {
write!(f, "{} | {}", groups[0], groups[1])
}
Ipv6ThreeWordGroupEncoding::NineWords { groups, .. } => {
write!(f, "{} | {} | {}", groups[0], groups[1], groups[2])
}
}
}
}
impl Ipv6ThreeWordGroupEncoding {
/// Get total word count
pub fn word_count(&self) -> usize {
match self {
Ipv6ThreeWordGroupEncoding::SixWords { .. } => 6,
Ipv6ThreeWordGroupEncoding::NineWords { .. } => 9,
}
}
/// Get all words as a flat vector
pub fn all_words(&self) -> Vec<String> {
match self {
Ipv6ThreeWordGroupEncoding::SixWords { groups, .. } => groups
.iter()
.flat_map(|g| g.words.iter().cloned())
.collect(),
Ipv6ThreeWordGroupEncoding::NineWords { groups, .. } => groups
.iter()
.flat_map(|g| g.words.iter().cloned())
.collect(),
}
}
}
/// Three-word group encoder for IPv6 addresses
pub struct ThreeWordIpv6Encoder {
dictionary: &'static Dictionary65K,
}
impl ThreeWordIpv6Encoder {
/// Create a new IPv6 three-word group encoder
pub fn new() -> Result<Self> {
let dictionary = get_global_dictionary()
.map_err(|e| FourWordError::InvalidInput(format!("Dictionary error: {e}")))?;
Ok(Self { dictionary })
}
/// Encode IPv6 address and port using three-word groups
pub fn encode(&self, ip: Ipv6Addr, port: u16) -> Result<Ipv6ThreeWordGroupEncoding> {
// Try to compress the IPv6 address
let compressed = Ipv6Compressor::compress(ip, Some(port))?;
let category = compressed.category;
// Determine if we can use 6 words (96 bits) or need 9 words (144 bits)
// We need: 1 byte for category + compressed data + 2 bytes for port
let actual_bytes_needed = 1 + compressed.compressed_data.len() + 2;
let actual_bits_needed = actual_bytes_needed * 8;
if actual_bits_needed <= 96 {
// Can fit in 6 words (2 groups)
self.encode_six_words(ip, port, compressed, category)
} else {
// Need 9 words (3 groups)
self.encode_nine_words(ip, port)
}
}
/// Decode IPv6 from three-word groups
pub fn decode(&self, encoding: &Ipv6ThreeWordGroupEncoding) -> Result<(Ipv6Addr, u16)> {
match encoding {
Ipv6ThreeWordGroupEncoding::SixWords {
groups, category, ..
} => self.decode_six_words(groups, category),
Ipv6ThreeWordGroupEncoding::NineWords { groups, .. } => self.decode_nine_words(groups),
}
}
/// Decode IPv6 from words array (for adaptive encoder compatibility)
pub fn decode_from_words(&self, words: &[&str]) -> Result<(Ipv6Addr, u16)> {
if words.len() != 6 && words.len() != 9 {
return Err(FourWordError::InvalidInput(format!(
"IPv6 requires 6 or 9 words, got {}",
words.len()
)));
}
// Group words into ThreeWordGroups
let groups_count = words.len() / 3;
let mut groups = Vec::new();
for i in 0..groups_count {
let group = ThreeWordGroup {
words: [
words[i * 3].to_string(),
words[i * 3 + 1].to_string(),
words[i * 3 + 2].to_string(),
],
};
groups.push(group);
}
// Create appropriate encoding structure
let encoding = if words.len() == 6 {
Ipv6ThreeWordGroupEncoding::SixWords {
groups: [groups[0].clone(), groups[1].clone()],
category: Ipv6Category::GlobalUnicast, // Default, will be detected during decode
original_ip: Ipv6Addr::UNSPECIFIED,
original_port: 0,
}
} else {
Ipv6ThreeWordGroupEncoding::NineWords {
groups: [groups[0].clone(), groups[1].clone(), groups[2].clone()],
original_ip: Ipv6Addr::UNSPECIFIED,
original_port: 0,
}
};
self.decode(&encoding)
}
/// Encode using 6 words (for compressed patterns)
fn encode_six_words(
&self,
ip: Ipv6Addr,
port: u16,
compressed: CompressedIpv6,
category: Ipv6Category,
) -> Result<Ipv6ThreeWordGroupEncoding> {
// Get compressed data
let compressed_data = &compressed.compressed_data;
// Pack into 96 bits
let mut packed = [0u8; 12]; // 96 bits = 12 bytes
// Store category in first byte
packed[0] = category as u8;
// Store compressed data
let data_len = compressed_data.len().min(10); // Leave room for port
packed[1..1 + data_len].copy_from_slice(&compressed_data[..data_len]);
// Store port in last 2 bytes
packed[10] = (port >> 8) as u8;
packed[11] = (port & 0xFF) as u8;
// Convert to 6 words (2 groups of 3)
let groups = self.pack_bytes_to_groups_6(&packed)?;
Ok(Ipv6ThreeWordGroupEncoding::SixWords {
groups,
original_ip: ip,
original_port: port,
category,
})
}
/// Encode using 9 words (for full addresses)
fn encode_nine_words(&self, ip: Ipv6Addr, port: u16) -> Result<Ipv6ThreeWordGroupEncoding> {
// Pack full IPv6 address (128 bits) + port (16 bits) = 144 bits
let mut packed = [0u8; 18]; // 144 bits = 18 bytes
// Store IPv6 address
packed[0..16].copy_from_slice(&ip.octets());
// Store port
packed[16] = (port >> 8) as u8;
packed[17] = (port & 0xFF) as u8;
// Convert to 9 words (3 groups of 3)
let groups = self.pack_bytes_to_groups_9(&packed)?;
Ok(Ipv6ThreeWordGroupEncoding::NineWords {
groups,
original_ip: ip,
original_port: port,
})
}
/// Decode from 6 words
fn decode_six_words(
&self,
groups: &[ThreeWordGroup; 2],
_category: &Ipv6Category, // Parameter kept for compatibility but not used
) -> Result<(Ipv6Addr, u16)> {
// Unpack from groups to bytes
let packed = self.unpack_groups_to_bytes_6(groups)?;
// Extract the actual category from the first byte
let category_byte = packed[0];
let category = match category_byte {
0 => Ipv6Category::Loopback,
1 => Ipv6Category::LinkLocal,
2 => Ipv6Category::UniqueLocal,
3 => Ipv6Category::Documentation,
4 => Ipv6Category::GlobalUnicast,
5 => Ipv6Category::Unspecified,
6 => Ipv6Category::Special,
_ => {
return Err(FourWordError::InvalidInput(format!(
"Invalid category byte: {category_byte}"
)));
}
};
// Extract port from last 2 bytes
let port = ((packed[10] as u16) << 8) | (packed[11] as u16);
// Extract compressed data (skipping category byte)
let compressed_data = &packed[1..10];
// Reconstruct based on the actual category
let ip = self.reconstruct_from_category(category, compressed_data)?;
Ok((ip, port))
}
/// Decode from 9 words
fn decode_nine_words(&self, groups: &[ThreeWordGroup; 3]) -> Result<(Ipv6Addr, u16)> {
// Unpack from groups to bytes
let packed = self.unpack_groups_to_bytes_9(groups)?;
// Extract IPv6 address (first 16 bytes)
let mut ip_bytes = [0u8; 16];
ip_bytes.copy_from_slice(&packed[0..16]);
let ip = Ipv6Addr::from(ip_bytes);
// Extract port (last 2 bytes)
let port = ((packed[16] as u16) << 8) | (packed[17] as u16);
Ok((ip, port))
}
/// Pack 12 bytes (96 bits) into 2 three-word groups
fn pack_bytes_to_groups_6(&self, bytes: &[u8; 12]) -> Result<[ThreeWordGroup; 2]> {
// First group: bytes 0-5 (48 bits)
let group1 = self.pack_48_bits_to_group(&bytes[0..6])?;
// Second group: bytes 6-11 (48 bits)
let group2 = self.pack_48_bits_to_group(&bytes[6..12])?;
Ok([group1, group2])
}
/// Pack 18 bytes (144 bits) into 3 three-word groups
fn pack_bytes_to_groups_9(&self, bytes: &[u8; 18]) -> Result<[ThreeWordGroup; 3]> {
// First group: bytes 0-5 (48 bits)
let group1 = self.pack_48_bits_to_group(&bytes[0..6])?;
// Second group: bytes 6-11 (48 bits)
let group2 = self.pack_48_bits_to_group(&bytes[6..12])?;
// Third group: bytes 12-17 (48 bits)
let group3 = self.pack_48_bits_to_group(&bytes[12..18])?;
Ok([group1, group2, group3])
}
/// Pack 48 bits (6 bytes) into a three-word group
fn pack_48_bits_to_group(&self, bytes: &[u8]) -> Result<ThreeWordGroup> {
if bytes.len() != 6 {
return Err(FourWordError::InvalidInput(
"Expected 6 bytes for group".to_string(),
));
}
// Convert 6 bytes to u64 for easier manipulation
let mut value = 0u64;
for (i, &byte) in bytes.iter().enumerate() {
value |= (byte as u64) << (40 - i * 8);
}
// Apply Feistel mixing for bit diffusion
let mixed = self.feistel_mix_48(value)?;
// Split into three 16-bit indices
let idx1 = ((mixed >> 32) & 0xFFFF) as u16;
let idx2 = ((mixed >> 16) & 0xFFFF) as u16;
let idx3 = (mixed & 0xFFFF) as u16;
// Convert to words
let words = [
self.dictionary
.get_word(idx1)
.map_err(|e| FourWordError::InvalidInput(format!("Dictionary error: {e}")))?
.to_string(),
self.dictionary
.get_word(idx2)
.map_err(|e| FourWordError::InvalidInput(format!("Dictionary error: {e}")))?
.to_string(),
self.dictionary
.get_word(idx3)
.map_err(|e| FourWordError::InvalidInput(format!("Dictionary error: {e}")))?
.to_string(),
];
Ok(ThreeWordGroup { words })
}
/// Unpack 2 three-word groups back to 12 bytes
fn unpack_groups_to_bytes_6(&self, groups: &[ThreeWordGroup; 2]) -> Result<[u8; 12]> {
let mut result = [0u8; 12];
// Unpack first group
let bytes1 = self.unpack_group_to_48_bits(&groups[0])?;
result[0..6].copy_from_slice(&bytes1);
// Unpack second group
let bytes2 = self.unpack_group_to_48_bits(&groups[1])?;
result[6..12].copy_from_slice(&bytes2);
Ok(result)
}
/// Unpack 3 three-word groups back to 18 bytes
fn unpack_groups_to_bytes_9(&self, groups: &[ThreeWordGroup; 3]) -> Result<[u8; 18]> {
let mut result = [0u8; 18];
// Unpack first group
let bytes1 = self.unpack_group_to_48_bits(&groups[0])?;
result[0..6].copy_from_slice(&bytes1);
// Unpack second group
let bytes2 = self.unpack_group_to_48_bits(&groups[1])?;
result[6..12].copy_from_slice(&bytes2);
// Unpack third group
let bytes3 = self.unpack_group_to_48_bits(&groups[2])?;
result[12..18].copy_from_slice(&bytes3);
Ok(result)
}
/// Unpack a three-word group back to 48 bits (6 bytes)
fn unpack_group_to_48_bits(&self, group: &ThreeWordGroup) -> Result<[u8; 6]> {
// Get indices from words
let idx1 = self
.dictionary
.get_index(&group.words[0])
.map_err(|e| FourWordError::InvalidInput(format!("Dictionary error: {e}")))?;
let idx2 = self
.dictionary
.get_index(&group.words[1])
.map_err(|e| FourWordError::InvalidInput(format!("Dictionary error: {e}")))?;
let idx3 = self
.dictionary
.get_index(&group.words[2])
.map_err(|e| FourWordError::InvalidInput(format!("Dictionary error: {e}")))?;
// Combine into 48-bit value
let mixed = ((idx1 as u64) << 32) | ((idx2 as u64) << 16) | (idx3 as u64);
// Reverse Feistel mixing
let value = self.feistel_unmix_48(mixed)?;
// Convert back to bytes
let mut bytes = [0u8; 6];
for i in 0..6 {
bytes[i] = ((value >> (40 - i * 8)) & 0xFF) as u8;
}
Ok(bytes)
}
/// Feistel mixing for 48-bit values
fn feistel_mix_48(&self, input: u64) -> Result<u64> {
const ROUNDS: u32 = 6;
let mut left = ((input >> 24) & 0xFFFFFF) as u32;
let mut right = (input & 0xFFFFFF) as u32;
for round in 0..ROUNDS {
let new_right = left ^ self.feistel_round_function(right, round);
left = right;
right = new_right;
}
Ok(((left as u64) << 24) | (right as u64))
}
/// Reverse Feistel mixing
fn feistel_unmix_48(&self, input: u64) -> Result<u64> {
const ROUNDS: u32 = 6;
let mut left = ((input >> 24) & 0xFFFFFF) as u32;
let mut right = (input & 0xFFFFFF) as u32;
for round in (0..ROUNDS).rev() {
let new_left = right ^ self.feistel_round_function(left, round);
right = left;
left = new_left;
}
Ok(((left as u64) << 24) | (right as u64))
}
/// Feistel round function (shared with IPv4 encoder)
fn feistel_round_function(&self, input: u32, round: u32) -> u32 {
let mut hash = input.wrapping_mul(0x9E3779B9);
hash ^= round.wrapping_mul(0x85EBCA6B);
hash ^= hash >> 16;
hash = hash.wrapping_mul(0x85EBCA6B);
hash ^= hash >> 13;
hash = hash.wrapping_mul(0xC2B2AE35);
hash ^= hash >> 16;
hash & 0xFFFFFF
}
/// Reconstruct IPv6 from category and compressed data
fn reconstruct_from_category(&self, category: Ipv6Category, data: &[u8]) -> Result<Ipv6Addr> {
// Reconstruct based on category with simplified logic
match category {
Ipv6Category::Loopback => Ok(Ipv6Addr::LOCALHOST),
Ipv6Category::Unspecified => Ok(Ipv6Addr::UNSPECIFIED),
Ipv6Category::LinkLocal => {
// Reconstruct fe80::X address
let mut segments = [0u16; 8];
segments[0] = 0xfe80;
// The link-local compressed data from ipv6_compression has different patterns:
// Pattern 0: All zeros pattern: fe80::
// Pattern 1: Single small value (<=255): fe80::1
// Pattern 2: EUI-64 derived address
// Pattern 3: Complex pattern with RLE for larger values like fe80::e00:0:0:0
match data.get(0) {
Some(0) => {
// All zeros pattern: fe80::
// segments already initialized correctly
}
Some(1) => {
// Single value pattern
if data.len() >= 3 {
let pos = data[1] as usize + 4; // Convert back to absolute position
let val = data[2] as u16;
if (4..8).contains(&pos) {
segments[pos] = val;
}
}
}
Some(2) => {
// EUI-64 derived address
if data.len() >= 7 {
segments[4] = ((data[2] as u16) << 8) | (data[1] as u16) | 0x0200;
segments[5] = ((data[4] as u16) << 8) | (data[3] as u16);
segments[6] = ((data[6] as u16) << 8) | (data[5] as u16);
// segments[7] remains 0 - simplified reconstruction
}
}
Some(3) => {
// Complex pattern with RLE - this is what handles fe80::e00:0:0:1
let mut i = 1;
while i < data.len() && data[i] != 255 {
if i + 2 < data.len() {
let pos = data[i] as usize + 4; // Convert back to absolute position
let val = ((data[i + 1] as u16) << 8) | (data[i + 2] as u16);
if (4..8).contains(&pos) {
segments[pos] = val;
}
i += 3;
} else {
break;
}
}
}
_ => {
// Fallback: interpret as direct value at segment 7
if data.len() >= 2 {
let val = ((data[0] as u16) << 8) | (data[1] as u16);
segments[7] = val;
}
}
}
Ok(Ipv6Addr::from(segments))
}
Ipv6Category::UniqueLocal => {
// Reconstruct fc00::/7 addresses
// Handle both 8-byte and 16-byte compressed data from the compression module
if data.len() >= 8 {
// Extract first 8 bytes for prefix + global ID + subnet
let segments = [
((data[0] as u16) << 8) | (data[1] as u16), // segments[0] (fc/fd prefix)
((data[2] as u16) << 8) | (data[3] as u16), // segments[1]
((data[4] as u16) << 8) | (data[5] as u16), // segments[2]
((data[6] as u16) << 8) | (data[7] as u16), // segments[3] (subnet)
if data.len() >= 10 { ((data[8] as u16) << 8) | (data[9] as u16) } else { 0x0000 }, // segments[4]
if data.len() >= 12 { ((data[10] as u16) << 8) | (data[11] as u16) } else { 0x0000 }, // segments[5]
if data.len() >= 14 { ((data[12] as u16) << 8) | (data[13] as u16) } else { 0x0000 }, // segments[6]
if data.len() >= 16 { ((data[14] as u16) << 8) | (data[15] as u16) } else { 0x0000 }, // segments[7]
];
Ok(Ipv6Addr::from(segments))
} else {
Err(FourWordError::InvalidInput(format!(
"Invalid unique local data length: {} (expected at least 8 bytes)",
data.len()
)))
}
}
Ipv6Category::Documentation => {
// Reconstruct 2001:db8::/32 addresses
let mut segments = [0u16; 8];
segments[0] = 0x2001;
segments[1] = 0x0db8;
// The compressed data from ipv6_compression has format:
// For 2001:db8::1, it's [01, 07, 01, 00, 00, 00, 00]
// We need to extract the actual address data
if data.len() >= 3 {
// Skip the first two bytes (metadata) and get the actual value
segments[7] = data[2] as u16;
} else if data.len() >= 2 {
// Fallback: interpret as direct value
segments[7] = ((data[0] as u16) << 8) | (data[1] as u16);
}
Ok(Ipv6Addr::from(segments))
}
_ => {
// For GlobalUnicast and Special, reconstruct from packed data
// Note: This is a simplified reconstruction that assumes
// the encoder packed the most significant segments
let mut segments = [0u16; 8];
// Extract as many segments as we have data for
let segment_count = (data.len() / 2).min(8);
for i in 0..segment_count {
segments[i] = ((data[i * 2] as u16) << 8) | (data[i * 2 + 1] as u16);
}
Ok(Ipv6Addr::from(segments))
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::str::FromStr;
#[test]
fn test_ipv6_six_word_encoding() {
let encoder = ThreeWordIpv6Encoder::new().unwrap();
// Test loopback (should fit in 6 words)
let ip = Ipv6Addr::LOCALHOST;
let port = 443;
let encoded = encoder.encode(ip, port).unwrap();
assert_eq!(encoded.word_count(), 6);
let (decoded_ip, decoded_port) = encoder.decode(&encoded).unwrap();
assert_eq!(decoded_ip, ip);
assert_eq!(decoded_port, port);
}
#[test]
fn test_ipv6_nine_word_encoding() {
let encoder = ThreeWordIpv6Encoder::new().unwrap();
// Test complex address (should need 9 words)
let ip = Ipv6Addr::from_str("2001:db8:85a3::8a2e:370:7334").unwrap();
let port = 8080;
let encoded = encoder.encode(ip, port).unwrap();
assert_eq!(encoded.word_count(), 9);
let (decoded_ip, decoded_port) = encoder.decode(&encoded).unwrap();
assert_eq!(decoded_ip, ip);
assert_eq!(decoded_port, port);
}
#[test]
fn test_group_formatting() {
let encoder = ThreeWordIpv6Encoder::new().unwrap();
let ip = Ipv6Addr::LOCALHOST;
let port = 80;
let encoded = encoder.encode(ip, port).unwrap();
let formatted = encoded.to_string();
// Should have group separators
assert!(formatted.contains(" | "));
// Should have correct number of groups
match encoded {
Ipv6ThreeWordGroupEncoding::SixWords { .. } => {
assert_eq!(formatted.matches(" | ").count(), 1); // 2 groups
}
Ipv6ThreeWordGroupEncoding::NineWords { .. } => {
assert_eq!(formatted.matches(" | ").count(), 2); // 3 groups
}
}
}
}