-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframework_ip_wrappers.go
1051 lines (964 loc) · 58.7 KB
/
framework_ip_wrappers.go
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
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package goip
import (
"github.com/pchchv/goip/address_error"
"github.com/pchchv/goip/address_string"
)
var _, _ ExtendedIPSegmentSeries = WrappedIPAddress{}, WrappedIPAddressSection{}
// WrappedIPAddress is the implementation of ExtendedIPSegmentSeries for IP addresses.
type WrappedIPAddress struct {
*IPAddress
}
// GetSection returns the backing section for this series, comprising all segments.
func (addr WrappedIPAddress) GetSection() *IPAddressSection {
return addr.IPAddress.GetSection()
}
// SequentialBlockIterator iterates through the sequential series that make up this series.
//
// Practically, this means finding the count of segments for which the segments that follow are not full range,
// and then using BlockIterator with that segment count.
//
// Use GetSequentialBlockCount to get the number of iterated elements.
func (addr WrappedIPAddress) SequentialBlockIterator() Iterator[ExtendedIPSegmentSeries] {
return ipaddressSeriesIterator{addr.IPAddress.SequentialBlockIterator()}
}
// BlockIterator Iterates through the series that can be obtained
// by iterating through all the upper segments up to the given segment count.
// The segments following remain the same in all iterated series.
func (addr WrappedIPAddress) BlockIterator(segmentCount int) Iterator[ExtendedIPSegmentSeries] {
return ipaddressSeriesIterator{addr.IPAddress.BlockIterator(segmentCount)}
}
// Iterator provides an iterator to iterate through the individual series of this series.
//
// When iterating, the prefix length is preserved.
// Remove it using WithoutPrefixLen prior to iterating if you wish to drop it from all individual series.
//
// Call IsMultiple to determine if this instance represents multiple series,
// or GetCount for the count.
func (addr WrappedIPAddress) Iterator() Iterator[ExtendedIPSegmentSeries] {
return ipaddressSeriesIterator{addr.IPAddress.Iterator()}
}
// ToZeroHostLen converts the subnet to one in which all individual addresses have a host of zero,
// the host being the bits following the given prefix length.
// If this address has the same prefix length,
// then the returned one will too, otherwise the returned series will have no prefix length.
//
// This returns an error if the subnet is a range which cannot be converted to
// a range in which all addresses have zero hosts,
// because the conversion results in a segment that is not a sequential range of values.
func (addr WrappedIPAddress) ToZeroHostLen(bitCount BitCount) (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPAddrWithErr(addr.IPAddress.ToZeroHostLen(bitCount)) //in IPAddress/Section
}
// ToZeroHost converts the subnet to one in which all individual addresses have a host of zero,
// the host being the bits following the prefix length.
// If the subnet has no prefix length, then it returns an all-zero series.
//
// The returned series will have the same prefix length.
//
// For instance, the zero host of "1.2.3.4/16" is the individual address "1.2.0.0/16".
//
// This returns an error if the series is a range which cannot be converted to
// a range in which all individual elements have zero hosts,
// because the conversion results in a series segment that is not a sequential range of values.
func (addr WrappedIPAddress) ToZeroHost() (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPAddrWithErr(addr.IPAddress.ToZeroHost()) // in IPAddress/Section/Segment
}
// ToMaxHostLen converts the address or subnet to one in which all individual addresses have a host of all one-bits, the max host,
// the host being the bits following the given prefix length.
// If this address or subnet has the same prefix length,
// then the resulting one will too, otherwise the resulting series will have no prefix length.
//
// For instance, the zero host of "1.2.3.4" for the prefix length of 16 is the address "1.2.255.255".
//
// This returns an error if the address or subnet is a range which cannot be converted to
// a range in which all individual addresses have max hosts,
// because the conversion results in a series segment that is not a sequential range of values.
func (addr WrappedIPAddress) ToMaxHostLen(bitCount BitCount) (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPAddrWithErr(addr.IPAddress.ToMaxHostLen(bitCount))
}
// ToMaxHost converts the subnet to one in which all individual addresses have a host of all one-bits, the max value,
// the host being the bits following the prefix length.
// If the subnet has no prefix length, then it returns an all-ones address, the max address.
//
// The returned series will have the same prefix length.
//
// For instance, the max host of "1.2.3.4/16" gives the broadcast address "1.2.255.255/16".
//
// This returns an error if the series is a range which cannot be converted to
// a range in which all individual elements have max hosts,
// because the conversion results in a series segment that is not a sequential range of values.
func (addr WrappedIPAddress) ToMaxHost() (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPAddrWithErr(addr.IPAddress.ToMaxHost())
}
// AssignPrefixForSingleBlock returns the equivalent prefix block that matches exactly the range of values in this series.
// The returned block will have an assigned prefix length indicating the prefix length for the block.
//
// There may be no such series - it is required that the range of values match the range of a prefix block.
// If there is no such series, then nil is returned.
func (addr WrappedIPAddress) AssignPrefixForSingleBlock() ExtendedIPSegmentSeries {
return convIPAddrToIntf(addr.IPAddress.AssignPrefixForSingleBlock())
}
// SpanWithPrefixBlocks returns an array of prefix blocks
// that spans the same set of individual series as this subnet.
func (addr WrappedIPAddress) SpanWithPrefixBlocks() []ExtendedIPSegmentSeries {
return addr.IPAddress.spanWithPrefixBlocks()
}
// SpanWithSequentialBlocks produces the smallest slice of sequential blocks
// that cover the same set of individual addresses as this subnet.
//
// This slice can be shorter than that produced by SpanWithPrefixBlocks and is never longer.
func (addr WrappedIPAddress) SpanWithSequentialBlocks() []ExtendedIPSegmentSeries {
return addr.IPAddress.spanWithSequentialBlocks()
}
// CoverWithPrefixBlock returns the minimal-size prefix block that covers all the addresses in this subnet.
// The resulting block will have a larger subnet size than this,
// unless this series is already a prefix block.
func (addr WrappedIPAddress) CoverWithPrefixBlock() ExtendedIPSegmentSeries {
return addr.IPAddress.coverSeriesWithPrefixBlock()
}
// SetPrefixLenZeroed sets the prefix length.
//
// A prefix length will not be set to a value lower than zero or beyond the bit length of the series.
// The provided prefix length will be adjusted to these boundaries if necessary.
//
// If this series has a prefix length, and the prefix length is increased when setting the new prefix length,
// the bits moved within the prefix become zero.
// If this series has a prefix length, and the prefix length is decreased when setting the new prefix length,
// the bits moved outside the prefix become zero.
//
// In other words, bits that move from one side of the prefix length to the other
// (bits moved into the prefix or outside the prefix) are zeroed.
//
// If the result cannot be zeroed because zeroing out bits results in a non-contiguous segment, an error is returned.
func (addr WrappedIPAddress) SetPrefixLenZeroed(prefixLen BitCount) (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPAddrWithErr(addr.IPAddress.SetPrefixLenZeroed(prefixLen))
}
// AdjustPrefixLenZeroed increases or decreases the prefix length by
// the given increment while zeroing out the bits that have moved into or outside the prefix.
//
// A prefix length will not be adjusted lower than zero or beyond the bit length of the series.
//
// If this series has no prefix length, then the prefix length will be set to the adjustment if positive,
// or it will be set to the adjustment added to the bit count if negative.
//
// When prefix length is increased, the bits moved within the prefix become zero.
// When a prefix length is decreased, the bits moved outside the prefix become zero.
//
// If the result cannot be zeroed because zeroing out bits results in a non-contiguous segment, an error is returned.
func (addr WrappedIPAddress) AdjustPrefixLenZeroed(prefixLen BitCount) (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPAddrWithErr(addr.IPAddress.AdjustPrefixLenZeroed(prefixLen))
}
// ReverseBytes returns a new segment series with the bytes reversed. Any prefix length is dropped.
//
// If each segment is more than 1 byte long, and the bytes within a single segment cannot be reversed because the segment represents a range,
// and reversing the segment values results in a range that is not contiguous, then this returns an error.
//
// In practice this means that to be reversible, a range must include all values except possibly the largest and/or smallest, which reverse to themselves.
func (addr WrappedIPAddress) ReverseBytes() (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPAddrWithErr(addr.IPAddress.ReverseBytes())
}
// ReverseBits returns a new segment series with the bits reversed. Any prefix length is dropped.
//
// If the bits within a single segment cannot be reversed because the segment represents a range,
// and reversing the segment values results in a range that is not contiguous, this returns an error.
//
// In practice this means that to be reversible, a range must include all values except possibly the largest and/or smallest, which reverse to themselves.
//
// If perByte is true, the bits are reversed within each byte, otherwise all the bits are reversed.
func (addr WrappedIPAddress) ReverseBits(perByte bool) (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPAddrWithErr(addr.IPAddress.ReverseBits(perByte))
}
// Unwrap returns the wrapped address as an interface, IPAddressSegmentSeries.
func (addr WrappedIPAddress) Unwrap() IPAddressSegmentSeries {
res := addr.IPAddress
if res == nil {
return nil
}
return res
}
// ToIPv4 converts to an IPv4AddressSegmentSeries if this address originated as an IPv4 section.
// If not, ToIPv4 returns nil.
//
// ToIPv4 can be called with a nil receiver,
// enabling you to chain this method with methods that might return a nil pointer.
func (addr WrappedIPAddress) ToIPv4() IPv4AddressSegmentSeries {
return addr.IPAddress.ToIPv4()
}
// ToIPv6 converts to an IPv6AddressSegmentSeries if this address originated as an IPv6 section.
// If not, ToIPv6 returns nil.
//
// ToIPv6 can be called with a nil receiver,
// enabling you to chain this method with methods that might return a nil pointer.
func (addr WrappedIPAddress) ToIPv6() IPv6AddressSegmentSeries {
return addr.IPAddress.ToIPv6()
}
// AdjustPrefixLen increases or decreases the prefix length by the given increment.
//
// A prefix length will not be adjusted lower than zero or beyond the bit length of the series.
//
// If this series has no prefix length, then the prefix length will be set to the adjustment if positive,
// or it will be set to the adjustment added to the bit count if negative.
func (addr WrappedIPAddress) AdjustPrefixLen(prefixLen BitCount) ExtendedIPSegmentSeries {
return wrapIPAddress(addr.IPAddress.AdjustPrefixLen(prefixLen))
}
// ReverseSegments returns a new series with the segments reversed.
func (addr WrappedIPAddress) ReverseSegments() ExtendedIPSegmentSeries {
return wrapIPAddress(addr.IPAddress.ReverseSegments())
}
// GetNetworkMask returns the network mask associated with the CIDR network prefix length of this address or subnet.
// If this series has no prefix length, then the all-ones mask is returned.
func (addr WrappedIPAddress) GetNetworkMask() ExtendedIPSegmentSeries {
return wrapIPAddress(addr.IPAddress.GetNetworkMask())
}
// GetHostMask returns the host mask associated with the CIDR network prefix length of this address or subnet.
// If this series has no prefix length, then the all-ones mask is returned.
func (addr WrappedIPAddress) GetHostMask() ExtendedIPSegmentSeries {
return wrapIPAddress(addr.IPAddress.GetHostMask())
}
// ToBlock creates a new series block by changing the segment at the given index to have the given lower and upper value,
// and changing the following segments to be full-range.
func (addr WrappedIPAddress) ToBlock(segmentIndex int, lower, upper SegInt) ExtendedIPSegmentSeries {
return wrapIPAddress(addr.IPAddress.ToBlock(segmentIndex, lower, upper))
}
// ToPrefixBlockLen returns the series with the same prefix of
// the given length as this series while the remaining bits span all values.
// The returned series will be the block of all series with the same prefix.
func (addr WrappedIPAddress) ToPrefixBlockLen(bitCount BitCount) ExtendedIPSegmentSeries {
return wrapIPAddress(addr.IPAddress.ToPrefixBlockLen(bitCount))
}
// ToPrefixBlock returns the series with the same prefix as this series while the remaining bits span all values.
// The series will be the block of all series with the same prefix.
//
// If this series has no prefix, this series is returned.
func (addr WrappedIPAddress) ToPrefixBlock() ExtendedIPSegmentSeries {
return wrapIPAddress(addr.IPAddress.ToPrefixBlock())
}
// ToZeroNetwork converts the address or subnet to one in which all individual addresses have a network of zero,
// the network being the bits within the prefix length.
// If the address or subnet has no prefix length, then it returns an all-zero address.
//
// The returned address or subnet will have the same prefix length.
func (addr WrappedIPAddress) ToZeroNetwork() ExtendedIPSegmentSeries {
return wrapIPAddress(addr.IPAddress.ToZeroNetwork()) //IPAddress/Section. ToZeroHost() is in IPAddress/Section/Segment
}
// GetLower returns the series in the range with the lowest numeric value,
// which will be the same series if it represents a single value.
// For example, for "1.2-3.4.5-6", the series "1.2.4.5" is returned.
func (addr WrappedIPAddress) GetLower() ExtendedIPSegmentSeries {
return wrapIPAddress(addr.IPAddress.GetLower())
}
// GetUpper returns the series in the range with the highest numeric value,
// which will be the same series if it represents a single value.
// For example, for the subnet "1.2-3.4.5-6", the address "1.3.4.6" is returned.
func (addr WrappedIPAddress) GetUpper() ExtendedIPSegmentSeries {
return wrapIPAddress(addr.IPAddress.GetUpper())
}
// AssignMinPrefixForBlock returns an equivalent series, assigned the smallest prefix length possible,
// such that the prefix block for that prefix length is in this series.
//
// In other words, this method assigns a prefix length to this series matching the largest prefix block in this series.
func (addr WrappedIPAddress) AssignMinPrefixForBlock() ExtendedIPSegmentSeries {
return wrapIPAddress(addr.IPAddress.AssignMinPrefixForBlock())
}
// WithoutPrefixLen provides the same address series but with no prefix length. The values remain unchanged.
func (addr WrappedIPAddress) WithoutPrefixLen() ExtendedIPSegmentSeries {
return wrapIPAddress(addr.IPAddress.WithoutPrefixLen())
}
// SetPrefixLen sets the prefix length.
//
// A prefix length will not be set to a value lower than zero or beyond the bit length of the series.
// The provided prefix length will be adjusted to these boundaries if necessary.
func (addr WrappedIPAddress) SetPrefixLen(prefixLen BitCount) ExtendedIPSegmentSeries {
return wrapIPAddress(addr.IPAddress.SetPrefixLen(prefixLen))
}
// Contains returns whether this is same type and version as the given address series and whether it contains all values in the given series.
//
// Series must also have the same number of segments to be comparable, otherwise false is returned.
func (addr WrappedIPAddress) Contains(other ExtendedIPSegmentSeries) bool {
a, ok := other.Unwrap().(AddressType)
return ok && addr.IPAddress.Contains(a)
}
// Equal returns whether the given address series is equal to this address series.
// Two address series are equal if they represent the same set of series.
// Both must be equal addresses.
func (addr WrappedIPAddress) Equal(other ExtendedIPSegmentSeries) bool {
a, ok := other.Unwrap().(AddressType)
return ok && addr.IPAddress.Equal(a)
}
// PrefixIterator provides an iterator to iterate through the individual prefixes of this series,
// each iterated element spanning the range of values for its prefix.
//
// It is similar to the prefix block iterator,
// except for possibly the first and last iterated elements,
// which might not be prefix blocks,
// instead constraining themselves to values from this series.
//
// If the series has no prefix length, then this is equivalent to Iterator.
func (addr WrappedIPAddress) PrefixIterator() Iterator[ExtendedIPSegmentSeries] {
return ipaddressSeriesIterator{addr.IPAddress.PrefixIterator()}
}
// PrefixBlockIterator provides an iterator to iterate through the individual prefix blocks,
// one for each prefix of this series.
// Each iterated series will be a prefix block with the same prefix length as this series.
//
// If this series has no prefix length, then this is equivalent to Iterator.
func (addr WrappedIPAddress) PrefixBlockIterator() Iterator[ExtendedIPSegmentSeries] {
return ipaddressSeriesIterator{addr.IPAddress.PrefixBlockIterator()}
}
// Increment returns the item that is the given increment upwards into the range,
// with the increment of 0 returning the first in the range.
//
// If the increment i matches or exceeds the range count c, then i - c + 1
// is added to the upper item of the range.
// An increment matching the count gives you the item just above the highest in the range.
//
// If the increment is negative, it is added to the lowest of the range.
// To get the item just below the lowest of the range, use the increment -1.
//
// If this represents just a single value, the item is simply incremented by the given increment, positive or negative.
//
// If this item represents multiple values, a positive increment i is equivalent i + 1 values from the iterator and beyond.
// For instance, a increment of 0 is the first value from the iterator, an increment of 1 is the second value from the iterator, and so on.
// An increment of a negative value added to the count is equivalent to the same number of iterator values preceding the last value of the iterator.
// For instance, an increment of count - 1 is the last value from the iterator, an increment of count - 2 is the second last value, and so on.
//
// On overflow or underflow, Increment returns nil.
func (addr WrappedIPAddress) Increment(i int64) ExtendedIPSegmentSeries {
return convIPAddrToIntf(addr.IPAddress.Increment(i))
}
// IncrementBoundary returns the item that is the given increment from the range boundaries of this item.
//
// If the given increment is positive, adds the value to the highest (GetUpper) in the range to produce a new item.
// If the given increment is negative, adds the value to the lowest (GetLower) in the range to produce a new item.
// If the increment is zero, returns this.
//
// If this represents just a single value, this item is simply incremented by the given increment value, positive or negative.
//
// On overflow or underflow, IncrementBoundary returns nil.
func (addr WrappedIPAddress) IncrementBoundary(i int64) ExtendedIPSegmentSeries {
return convIPAddrToIntf(addr.IPAddress.IncrementBoundary(i))
}
// ExtendedIPSegmentSeries wraps either an [IPAddress] or [IPAddressSection].
// ExtendedIPSegmentSeries can be used to write code that works with both IP addresses and IP address sections,
// going further than [IPAddressSegmentSeries] to offer additional methods, methods with the series types in their signature.
type ExtendedIPSegmentSeries interface {
IPAddressSegmentSeries
// Unwrap returns the wrapped IP address or IP address section as an interface, IPAddressSegmentSeries.
Unwrap() IPAddressSegmentSeries
// Equal returns whether the given address series is equal to this address series.
// Two address series are equal if they represent the same set of series.
// Both must be equal addresses or both must be equal sections.
Equal(ExtendedIPSegmentSeries) bool
// Contains returns whether this is same type and version as the
// given address series and whether it contains all values in the given series.
//
// Series must also have the same number of segments to be comparable, otherwise false is returned.
Contains(ExtendedIPSegmentSeries) bool
// GetSection returns the backing section for this series, comprising all segments.
GetSection() *IPAddressSection
// GetTrailingSection returns an ending subsection of the full address section.
GetTrailingSection(index int) *IPAddressSection
// GetSubSection returns a subsection of the full address section.
GetSubSection(index, endIndex int) *IPAddressSection
// GetNetworkSection returns an address section containing the segments with the network of the series, the prefix bits.
// The returned section will have only as many segments as needed as determined by the existing CIDR network prefix length.
//
// If this series has no CIDR prefix length, the returned network section will
// be the entire series as a prefixed section with prefix length matching the address bit length.
GetNetworkSection() *IPAddressSection
// GetHostSection returns a section containing the segments with the host of the series,
// the bits beyond the CIDR network prefix length.
// The returned section will have only as many segments as needed to contain the host.
//
// If this series has no prefix length, the returned host section will be the full section.
GetHostSection() *IPAddressSection
// GetNetworkSectionLen returns a section containing the segments with the network of the series,
// the prefix bits according to the given prefix length.
// The returned section will have only as many segments as needed to contain the network.
//
// The new section will be assigned the given prefix length,
// unless the existing prefix length is smaller, in which case the existing prefix length will be retained.
GetNetworkSectionLen(BitCount) *IPAddressSection
// GetHostSectionLen returns a section containing the segments with the host of the series,
// the bits beyond the given CIDR network prefix length.
// The returned section will have only as many segments as needed to contain the host.
GetHostSectionLen(BitCount) *IPAddressSection
// GetNetworkMask returns the network mask associated with the CIDR network prefix length of this series.
// If this series has no prefix length, then the all-ones mask is returned.
GetNetworkMask() ExtendedIPSegmentSeries
// GetHostMask returns the host mask associated with the CIDR network prefix length of this series.
// If this series has no prefix length, then the all-ones mask is returned.
GetHostMask() ExtendedIPSegmentSeries
// GetSegment returns the segment at the given index.
// The first segment is at index 0.
// GetSegment will panic given a negative index or an index matching or larger than the segment count.
GetSegment(index int) *IPAddressSegment
// GetSegments returns a slice with the address segments. The returned slice is not backed by the same array as this section.
GetSegments() []*IPAddressSegment
// CopySegments copies the existing segments into the given slice,
// as much as can be fit into the slice, returning the number of segments copied.
CopySegments(segs []*IPAddressSegment) (count int)
// CopySubSegments copies the existing segments from the given start index until but not including the segment at the given end index,
// into the given slice, as much as can be fit into the slice, returning the number of segments copied.
CopySubSegments(start, end int, segs []*IPAddressSegment) (count int)
// IsIPv4 returns true if this series originated as an IPv4 series.
// If so, use ToIPv4 to convert back to the IPv4-specific type.
IsIPv4() bool
// IsIPv6 returns true if this series originated as an IPv6 series.
// If so, use ToIPv6 to convert back to the IPv6-specific type.
IsIPv6() bool
// ToIPv4 converts to an IPv4AddressSegmentSeries if this series originated as an IPv4 series.
// If not, ToIPv4 returns nil.
//
// ToIPv4 implementations can be called with a nil receiver, enabling you to chain this method with methods that might return a nil pointer.
ToIPv4() IPv4AddressSegmentSeries
// ToIPv6 converts to an IPv4AddressSegmentSeries if this series originated as an IPv6 series.
// If not, ToIPv6 returns nil.
//
// ToIPv6 implementations can be called with a nil receiver, enabling you to chain this method with methods that might return a nil pointer.
ToIPv6() IPv6AddressSegmentSeries
// ToBlock creates a new series block by changing the segment at the given index to have the given lower and upper value,
// and changing the following segments to be full-range.
ToBlock(segmentIndex int, lower, upper SegInt) ExtendedIPSegmentSeries
// ToPrefixBlock returns the series with the same prefix as this series while the remaining bits span all values.
// The series will be the block of all series with the same prefix.
//
// If this series has no prefix, this series is returned.
ToPrefixBlock() ExtendedIPSegmentSeries
// ToPrefixBlockLen returns the series with the same prefix of the given length as this series while the remaining bits span all values.
// The returned series will be the block of all series with the same prefix.
ToPrefixBlockLen(BitCount) ExtendedIPSegmentSeries
// ToZeroHostLen converts the series to one in which all individual series have a host of zero,
// the host being the bits following the given prefix length.
// If this series has the same prefix length, then the returned one will too, otherwise the returned series will have no prefix length.
//
// This returns an error if the series is a range which cannot be converted to a range in which all series have zero hosts,
// because the conversion results in a segment that is not a sequential range of values.
ToZeroHostLen(BitCount) (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError)
// ToZeroHost converts the series to one in which all individual series have a host of zero,
// the host being the bits following the prefix length.
// If the series has no prefix length, then it returns an all-zero series.
//
// The returned series will have the same prefix length.
//
// For instance, the zero host of "1.2.3.4/16" is the individual address "1.2.0.0/16".
//
// This returns an error if the series is a range which cannot be converted to a range in which all individual elements have zero hosts,
// because the conversion results in a series segment that is not a sequential range of values.
ToZeroHost() (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError)
// ToMaxHostLen converts the series to one in which all individual series have a host of all one-bits, the max host,
// the host being the bits following the given prefix length.
// If this series has the same prefix length, then the resulting series will too, otherwise the resulting series will have no prefix length.
//
// For instance, the zero host of "1.2.3.4" for the prefix length of 16 is the address "1.2.255.255".
//
// This returns an error if the series is a range which cannot be converted to a range in which all individual elements have max hosts,
// because the conversion results in a series segment that is not a sequential range of values.
ToMaxHostLen(BitCount) (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError)
// ToMaxHost converts the series to one in which all individual series have a host of all one-bits, the max value,
// the host being the bits following the prefix length.
// If the series has no prefix length, then it returns an all-ones series, the max series.
//
// The returned series will have the same prefix length.
//
// For instance, the max host of "1.2.3.4/16" gives the broadcast address "1.2.255.255/16".
//
// This returns an error if the series is a range which cannot be converted to a range in which all individual elements have max hosts,
// because the conversion results in a series segment that is not a sequential range of values.
ToMaxHost() (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError)
// ToZeroNetwork converts the series to one in which all individual addresses or address sections have a network of zero,
// the network being the bits within the prefix length.
// If the series has no prefix length, then it returns an all-zero series.
//
// The returned series will have the same prefix length.
ToZeroNetwork() ExtendedIPSegmentSeries
// Increment returns the item that is the given increment upwards into the range,
// with the increment of 0 returning the first in the range.
//
// If the increment i matches or exceeds the range count c, then i - c + 1
// is added to the upper item of the range.
// An increment matching the count gives you the item just above the highest in the range.
//
// If the increment is negative, it is added to the lowest of the range.
// To get the item just below the lowest of the range, use the increment -1.
//
// If this represents just a single value, the item is simply incremented by the given increment, positive or negative.
//
// If this item represents multiple values, a positive increment i is equivalent i + 1 values from the iterator and beyond.
// For instance, a increment of 0 is the first value from the iterator, an increment of 1 is the second value from the iterator, and so on.
// An increment of a negative value added to the count is equivalent to the same number of iterator values preceding the last value of the iterator.
// For instance, an increment of count - 1 is the last value from the iterator, an increment of count - 2 is the second last value, and so on.
//
// On overflow or underflow, Increment returns nil.
Increment(int64) ExtendedIPSegmentSeries
// IncrementBoundary returns the item that is the given increment from the range boundaries of this item.
//
// If the given increment is positive, adds the value to the highest (GetUpper) in the range to produce a new item.
// If the given increment is negative, adds the value to the lowest (GetLower) in the range to produce a new item.
// If the increment is zero, returns this.
//
// If this represents just a single value, this item is simply incremented by the given increment value, positive or negative.
//
// On overflow or underflow, IncrementBoundary returns nil.
IncrementBoundary(int64) ExtendedIPSegmentSeries
// GetLower returns the series in the range with the lowest numeric value,
// which will be the same series if it represents a single value.
// For example, for "1.2-3.4.5-6", the series "1.2.4.5" is returned.
GetLower() ExtendedIPSegmentSeries
// GetUpper returns the series in the range with the highest numeric value,
// which will be the same series if it represents a single value.
// For example, for the subnet "1.2-3.4.5-6", the address "1.3.4.6" is returned.
GetUpper() ExtendedIPSegmentSeries
// AssignPrefixForSingleBlock returns the equivalent prefix block that matches exactly the range of values in this series.
// The returned block will have an assigned prefix length indicating the prefix length for the block.
//
// There may be no such series - it is required that the range of values match the range of a prefix block.
// If there is no such series, then nil is returned.
AssignPrefixForSingleBlock() ExtendedIPSegmentSeries
// AssignMinPrefixForBlock returns an equivalent series, assigned the smallest prefix length possible,
// such that the prefix block for that prefix length is in this series.
//
// In other words, this method assigns a prefix length to this series matching the largest prefix block in this series.
AssignMinPrefixForBlock() ExtendedIPSegmentSeries
// Iterator provides an iterator to iterate through the individual series of this series.
//
// When iterating, the prefix length is preserved. Remove it using WithoutPrefixLen prior to iterating if you wish to drop it from all individual series.
//
// Call IsMultiple to determine if this instance represents multiple series, or GetCount for the count.
Iterator() Iterator[ExtendedIPSegmentSeries]
// PrefixIterator provides an iterator to iterate through the individual prefixes of this series,
// each iterated element spanning the range of values for its prefix.
//
// It is similar to the prefix block iterator, except for possibly the first and last iterated elements, which might not be prefix blocks,
// instead constraining themselves to values from this series.
//
// If the series has no prefix length, then this is equivalent to Iterator.
PrefixIterator() Iterator[ExtendedIPSegmentSeries]
// PrefixBlockIterator provides an iterator to iterate through the individual prefix blocks, one for each prefix of this series.
// Each iterated series will be a prefix block with the same prefix length as this series.
//
// If this series has no prefix length, then this is equivalent to Iterator.
PrefixBlockIterator() Iterator[ExtendedIPSegmentSeries]
// SequentialBlockIterator iterates through the sequential series that make up this series.
//
// Practically, this means finding the count of segments for which the segments that follow are not full range, and then using BlockIterator with that segment count.
//
// Use GetSequentialBlockCount to get the number of iterated elements.
SequentialBlockIterator() Iterator[ExtendedIPSegmentSeries]
// BlockIterator Iterates through the series that can be obtained by iterating through all the upper segments up to the given segment count.
// The segments following remain the same in all iterated series.
BlockIterator(segmentCount int) Iterator[ExtendedIPSegmentSeries]
// SpanWithPrefixBlocks returns an array of prefix blocks that spans the same set of individual series as this address series.
SpanWithPrefixBlocks() []ExtendedIPSegmentSeries
// SpanWithSequentialBlocks produces the smallest slice of sequential blocks that cover the same set of individual series as this series.
//
// This slice can be shorter than that produced by SpanWithPrefixBlocks and is never longer.
SpanWithSequentialBlocks() []ExtendedIPSegmentSeries
// CoverWithPrefixBlock returns the minimal-size prefix block that covers all the values in this series.
// The resulting block will have a larger series count than this, unless this series is already a prefix block.
CoverWithPrefixBlock() ExtendedIPSegmentSeries
// AdjustPrefixLen increases or decreases the prefix length by the given increment.
//
// A prefix length will not be adjusted lower than zero or beyond the bit length of the series.
//
// If this series has no prefix length, then the prefix length will be set to the adjustment if positive,
// or it will be set to the adjustment added to the bit count if negative.
AdjustPrefixLen(BitCount) ExtendedIPSegmentSeries
// AdjustPrefixLenZeroed increases or decreases the prefix length by the given increment while zeroing out the bits that have moved into or outside the prefix.
//
// A prefix length will not be adjusted lower than zero or beyond the bit length of the series.
//
// If this series has no prefix length, then the prefix length will be set to the adjustment if positive,
// or it will be set to the adjustment added to the bit count if negative.
//
// When prefix length is increased, the bits moved within the prefix become zero.
// When a prefix length is decreased, the bits moved outside the prefix become zero.
//
// If the result cannot be zeroed because zeroing out bits results in a non-contiguous segment, an error is returned.
AdjustPrefixLenZeroed(BitCount) (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError)
// SetPrefixLen sets the prefix length.
//
// A prefix length will not be set to a value lower than zero or beyond the bit length of the series.
// The provided prefix length will be adjusted to these boundaries if necessary.
SetPrefixLen(BitCount) ExtendedIPSegmentSeries
// SetPrefixLenZeroed sets the prefix length.
//
// A prefix length will not be set to a value lower than zero or beyond the bit length of the series.
// The provided prefix length will be adjusted to these boundaries if necessary.
//
// If this series has a prefix length, and the prefix length is increased when setting the new prefix length, the bits moved within the prefix become zero.
// If this series has a prefix length, and the prefix length is decreased when setting the new prefix length, the bits moved outside the prefix become zero.
//
// In other words, bits that move from one side of the prefix length to the other (bits moved into the prefix or outside the prefix) are zeroed.
//
// If the result cannot be zeroed because zeroing out bits results in a non-contiguous segment, an error is returned.
SetPrefixLenZeroed(BitCount) (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError)
// WithoutPrefixLen provides the same address series but with no prefix length. The values remain unchanged.
WithoutPrefixLen() ExtendedIPSegmentSeries
// ReverseBytes returns a new segment series with the bytes reversed. Any prefix length is dropped.
//
// If each segment is more than 1 byte long, and the bytes within a single segment cannot be reversed because the segment represents a range,
// and reversing the segment values results in a range that is not contiguous, then this returns an error.
//
// In practice this means that to be reversible, a range must include all values except possibly the largest and/or smallest, which reverse to themselves.
ReverseBytes() (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError)
// ReverseBits returns a new segment series with the bits reversed. Any prefix length is dropped.
//
// If the bits within a single segment cannot be reversed because the segment represents a range,
// and reversing the segment values results in a range that is not contiguous, this returns an error.
//
// In practice this means that to be reversible, a range must include all values except possibly the largest and/or smallest, which reverse to themselves.
//
// If perByte is true, the bits are reversed within each byte, otherwise all the bits are reversed.
ReverseBits(perByte bool) (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError)
// ReverseSegments returns a new series with the segments reversed.
ReverseSegments() ExtendedIPSegmentSeries
// ToCustomString creates a customized string from this series according to the given string option parameters.
ToCustomString(stringOptions address_string.IPStringOptions) string
}
// WrappedIPAddressSection is the implementation of ExtendedIPSegmentSeries for IP address sections.
type WrappedIPAddressSection struct {
*IPAddressSection
}
// GetSection returns the backing section for this series, comprising all segments.
func (section WrappedIPAddressSection) GetSection() *IPAddressSection {
return section.IPAddressSection
}
// Contains returns whether this is same type and version as
// the given address series and whether it contains all values in the given series.
//
// Series must also have the same number of segments to be comparable, otherwise false is returned.
func (section WrappedIPAddressSection) Contains(other ExtendedIPSegmentSeries) bool {
s, ok := other.Unwrap().(AddressSectionType)
return ok && section.IPAddressSection.Contains(s)
}
// Equal returns whether the given address series is equal to this address series.
// Two address series are equal if they represent the same set of series.
// Both must be equal sections.
func (section WrappedIPAddressSection) Equal(other ExtendedIPSegmentSeries) bool {
s, ok := other.Unwrap().(AddressSectionType)
return ok && section.IPAddressSection.Equal(s)
}
// ToIPv4 converts to an IPv4AddressSegmentSeries if this section originated as an IPv4 section.
// If not, ToIPv4 returns nil.
//
// ToIPv4 can be called with a nil receiver, enabling you to chain this method with methods that might return a nil pointer.
func (section WrappedIPAddressSection) ToIPv4() IPv4AddressSegmentSeries {
return section.IPAddressSection.ToIPv4()
}
// ToIPv6 converts to an IPv6AddressSegmentSeries if this section originated as an IPv6 section.
// If not, ToIPv6 returns nil.
//
// ToIPv6 can be called with a nil receiver, enabling you to chain this method with methods that might return a nil pointer.
func (section WrappedIPAddressSection) ToIPv6() IPv6AddressSegmentSeries {
return section.IPAddressSection.ToIPv6()
}
// GetNetworkMask returns the network mask associated with the CIDR network prefix length of this address section.
// If this series has no prefix length, then the all-ones mask is returned.
func (section WrappedIPAddressSection) GetNetworkMask() ExtendedIPSegmentSeries {
return wrapIPSection(section.IPAddressSection.GetNetworkMask())
}
// GetHostMask returns the host mask associated with the CIDR network prefix length of this address section.
// If this series has no prefix length, then the all-ones mask is returned.
func (section WrappedIPAddressSection) GetHostMask() ExtendedIPSegmentSeries {
return wrapIPSection(section.IPAddressSection.GetHostMask())
}
// Unwrap returns the wrapped address section as an interface, IPAddressSegmentSeries.
func (section WrappedIPAddressSection) Unwrap() IPAddressSegmentSeries {
res := section.IPAddressSection
if res == nil {
return nil
}
return res
}
// SequentialBlockIterator iterates through the sequential series that make up this series.
//
// Practically, this means finding the count of segments for which the segments that follow are not full range,
// and then using BlockIterator with that segment count.
//
// Use GetSequentialBlockCount to get the number of iterated elements.
func (section WrappedIPAddressSection) SequentialBlockIterator() Iterator[ExtendedIPSegmentSeries] {
return ipSectionSeriesIterator{section.IPAddressSection.SequentialBlockIterator()}
}
// BlockIterator Iterates through the series that can be obtained by iterating through all the upper segments up to the given segment count.
// The segments following remain the same in all iterated series.
func (section WrappedIPAddressSection) BlockIterator(segmentCount int) Iterator[ExtendedIPSegmentSeries] {
return ipSectionSeriesIterator{section.IPAddressSection.BlockIterator(segmentCount)}
}
// Iterator provides an iterator to iterate through the individual series of this series.
//
// When iterating, the prefix length is preserved. Remove it using WithoutPrefixLen prior to iterating if you wish to drop it from all individual series.
//
// Call IsMultiple to determine if this instance represents multiple series, or GetCount for the count.
func (section WrappedIPAddressSection) Iterator() Iterator[ExtendedIPSegmentSeries] {
return ipSectionSeriesIterator{section.IPAddressSection.Iterator()}
}
// PrefixIterator provides an iterator to iterate through the individual prefixes of this series,
// each iterated element spanning the range of values for its prefix.
//
// It is similar to the prefix block iterator, except for possibly the first and last iterated elements, which might not be prefix blocks,
// instead constraining themselves to values from this series.
//
// If the series has no prefix length, then this is equivalent to Iterator.
func (section WrappedIPAddressSection) PrefixIterator() Iterator[ExtendedIPSegmentSeries] {
return ipSectionSeriesIterator{section.IPAddressSection.PrefixIterator()}
}
// PrefixBlockIterator provides an iterator to iterate through the individual prefix blocks, one for each prefix of this series.
// Each iterated series will be a prefix block with the same prefix length as this series.
//
// If this series has no prefix length, then this is equivalent to Iterator.
func (section WrappedIPAddressSection) PrefixBlockIterator() Iterator[ExtendedIPSegmentSeries] {
return ipSectionSeriesIterator{section.IPAddressSection.PrefixBlockIterator()}
}
// ToZeroHostLen converts the section to one in which all individual sections have a host of zero,
// the host being the bits following the given prefix length.
// If this section has the same prefix length, then the returned one will too, otherwise the returned series will have no prefix length.
//
// This returns an error if the section is a range which cannot be converted to a range in which all individual sections have zero hosts,
// because the conversion results in a segment that is not a sequential range of values.
func (section WrappedIPAddressSection) ToZeroHostLen(bitCount BitCount) (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPSectWithErr(section.IPAddressSection.ToZeroHostLen(bitCount))
}
// ToZeroHost converts the section to one in which all individual sections have a host of zero,
// the host being the bits following the prefix length.
// If the section has no prefix length, then it returns an all-zero section.
//
// The returned series will have the same prefix length.
//
// This returns an error if the section is a range which cannot be converted to a range in which all individual elements have zero hosts,
// because the conversion results in a segment that is not a sequential range of values.
func (section WrappedIPAddressSection) ToZeroHost() (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPSectWithErr(section.IPAddressSection.ToZeroHost())
}
// ToMaxHostLen converts the address section to one in which all individual address sections have a host of all one-bits, the max host,
// the host being the bits following the given prefix length.
// If this address section has the same prefix length, then the resulting series will too, otherwise the resulting series will have no prefix length.
//
// This returns an error if the address section is a range which cannot be converted to a range in which all individual address sections have max hosts,
// because the conversion results in a series segment that is not a sequential range of values.
func (section WrappedIPAddressSection) ToMaxHostLen(bitCount BitCount) (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPSectWithErr(section.IPAddressSection.ToMaxHostLen(bitCount))
}
// ToMaxHost converts the address section to one in which all individual address sections have a host of all one-bits, the max value,
// the host being the bits following the prefix length.
// If the section has no prefix length, then it returns an all-ones section, the max address section.
//
// The returned series will have the same prefix length.
//
// This returns an error if the series is a range which cannot be converted to a range in which all individual elements have max hosts,
// because the conversion results in a series segment that is not a sequential range of values.
func (section WrappedIPAddressSection) ToMaxHost() (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPSectWithErr(section.IPAddressSection.ToMaxHost())
}
// Increment returns the item that is the given increment upwards into the range,
// with the increment of 0 returning the first in the range.
//
// If the increment i matches or exceeds the range count c, then i - c + 1
// is added to the upper item of the range.
// An increment matching the count gives you the item just above the highest in the range.
//
// If the increment is negative, it is added to the lowest of the range.
// To get the item just below the lowest of the range, use the increment -1.
//
// If this represents just a single value, the item is simply incremented by the given increment, positive or negative.
//
// If this item represents multiple values, a positive increment i is equivalent i + 1 values from the iterator and beyond.
// For instance, a increment of 0 is the first value from the iterator, an increment of 1 is the second value from the iterator, and so on.
// An increment of a negative value added to the count is equivalent to the same number of iterator values preceding the last value of the iterator.
// For instance, an increment of count - 1 is the last value from the iterator, an increment of count - 2 is the second last value, and so on.
//
// On overflow or underflow, Increment returns nil.
func (section WrappedIPAddressSection) Increment(i int64) ExtendedIPSegmentSeries {
return convIPSectToIntf(section.IPAddressSection.Increment(i))
}
// IncrementBoundary returns the item that is the given increment from the range boundaries of this item.
//
// If the given increment is positive, adds the value to the highest (GetUpper) in the range to produce a new item.
// If the given increment is negative, adds the value to the lowest (GetLower) in the range to produce a new item.
// If the increment is zero, returns this.
//
// If this represents just a single value, this item is simply incremented by the given increment value, positive or negative.
//
// On overflow or underflow, IncrementBoundary returns nil.
func (section WrappedIPAddressSection) IncrementBoundary(i int64) ExtendedIPSegmentSeries {
return convIPSectToIntf(section.IPAddressSection.IncrementBoundary(i))
}
// AssignPrefixForSingleBlock returns the equivalent prefix block that matches exactly the range of values in this series.
// The returned block will have an assigned prefix length indicating the prefix length for the block.
//
// There may be no such series - it is required that the range of values match the range of a prefix block.
// If there is no such series, then nil is returned.
func (section WrappedIPAddressSection) AssignPrefixForSingleBlock() ExtendedIPSegmentSeries {
return convIPSectToIntf(section.IPAddressSection.AssignPrefixForSingleBlock())
}
// SpanWithPrefixBlocks returns an array of prefix blocks that spans the same set of individual series as this subnet section.
func (section WrappedIPAddressSection) SpanWithPrefixBlocks() []ExtendedIPSegmentSeries {
return section.IPAddressSection.spanWithPrefixBlocks()
}
// SpanWithSequentialBlocks produces the smallest slice of sequential blocks that cover the same set of individual address sections as this series.
//
// This slice can be shorter than that produced by SpanWithPrefixBlocks and is never longer.
func (section WrappedIPAddressSection) SpanWithSequentialBlocks() []ExtendedIPSegmentSeries {
return section.IPAddressSection.spanWithSequentialBlocks()
}
// SetPrefixLenZeroed sets the prefix length.
//
// A prefix length will not be set to a value lower than zero or beyond the bit length of the series.
// The provided prefix length will be adjusted to these boundaries if necessary.
//
// If this series has a prefix length, and the prefix length is increased when setting the new prefix length, the bits moved within the prefix become zero.
// If this series has a prefix length, and the prefix length is decreased when setting the new prefix length, the bits moved outside the prefix become zero.
//
// In other words, bits that move from one side of the prefix length to the other (bits moved into the prefix or outside the prefix) are zeroed.
//
// If the result cannot be zeroed because zeroing out bits results in a non-contiguous segment, an error is returned.
func (section WrappedIPAddressSection) SetPrefixLenZeroed(prefixLen BitCount) (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPSectWithErr(section.IPAddressSection.SetPrefixLenZeroed(prefixLen))
}
// AdjustPrefixLenZeroed increases or decreases the prefix length by the given increment while zeroing out the bits that have moved into or outside the prefix.
//
// A prefix length will not be adjusted lower than zero or beyond the bit length of the series.
//
// If this series has no prefix length, then the prefix length will be set to the adjustment if positive,
// or it will be set to the adjustment added to the bit count if negative.
//
// When prefix length is increased, the bits moved within the prefix become zero.
// When a prefix length is decreased, the bits moved outside the prefix become zero.
//
// If the result cannot be zeroed because zeroing out bits results in a non-contiguous segment, an error is returned.
func (section WrappedIPAddressSection) AdjustPrefixLenZeroed(prefixLen BitCount) (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPSectWithErr(section.IPAddressSection.AdjustPrefixLenZeroed(prefixLen))
}
// ReverseBytes returns a new segment series with the bytes reversed.
// Any prefix length is dropped.
//
// If each segment is more than 1 byte long, and the bytes within a single segment cannot be reversed because the segment represents a range,
// and reversing the segment values results in a range that is not contiguous, then this returns an error.
//
// In practice this means that to be reversible,
// a range must include all values except possibly the largest and/or smallest, which reverse to themselves.
func (section WrappedIPAddressSection) ReverseBytes() (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPSectWithErr(section.IPAddressSection.ReverseBytes())
}
// ReverseBits returns a new segment series with the bits reversed.
// Any prefix length is dropped.
//
// If the bits within a single segment cannot be reversed because the segment represents a range,
// and reversing the segment values results in a range that is not contiguous, this returns an error.
//
// In practice this means that to be reversible,
// a range must include all values except possibly the largest and/or smallest, which reverse to themselves.
//
// If perByte is true, the bits are reversed within each byte, otherwise all the bits are reversed.
func (section WrappedIPAddressSection) ReverseBits(perByte bool) (ExtendedIPSegmentSeries, address_error.IncompatibleAddressError) {
return wrapIPSectWithErr(section.IPAddressSection.ReverseBits(perByte))
}
// GetLower returns the series in the range with the lowest numeric value,
// which will be the same series if it represents a single value.
// For example, for "1.2-3.4.5-6", the series "1.2.4.5" is returned.
func (section WrappedIPAddressSection) GetLower() ExtendedIPSegmentSeries {
return wrapIPSection(section.IPAddressSection.GetLower())
}
// GetUpper returns the series in the range with the highest numeric value,
// which will be the same series if it represents a single value.
// For example, for the subnet "1.2-3.4.5-6", the address "1.3.4.6" is returned.
func (section WrappedIPAddressSection) GetUpper() ExtendedIPSegmentSeries {
return wrapIPSection(section.IPAddressSection.GetUpper())
}
// AssignMinPrefixForBlock returns an equivalent series, assigned the smallest prefix length possible,
// such that the prefix block for that prefix length is in this series.
//
// In other words, this method assigns a prefix length to this series matching the largest prefix block in this series.
func (section WrappedIPAddressSection) AssignMinPrefixForBlock() ExtendedIPSegmentSeries {
return wrapIPSection(section.IPAddressSection.AssignMinPrefixForBlock())
}
// WithoutPrefixLen provides the same address series but with no prefix length.
// The values remain unchanged.
func (section WrappedIPAddressSection) WithoutPrefixLen() ExtendedIPSegmentSeries {
return wrapIPSection(section.IPAddressSection.WithoutPrefixLen())
}
// SetPrefixLen sets the prefix length.
//
// A prefix length will not be set to a value lower than zero or beyond the bit length of the series.
// The provided prefix length will be adjusted to these boundaries if necessary.
func (section WrappedIPAddressSection) SetPrefixLen(prefixLen BitCount) ExtendedIPSegmentSeries {
return wrapIPSection(section.IPAddressSection.SetPrefixLen(prefixLen))
}
// AdjustPrefixLen increases or decreases the prefix length by the given increment.
//
// A prefix length will not be adjusted lower than zero or beyond the bit length of the series.
//
// If this series has no prefix length,
// then the prefix length will be set to the adjustment if positive,
// or it will be set to the adjustment added to the bit count if negative.
func (section WrappedIPAddressSection) AdjustPrefixLen(prefixLen BitCount) ExtendedIPSegmentSeries {
return wrapIPSection(section.IPAddressSection.AdjustPrefixLen(prefixLen))
}
// CoverWithPrefixBlock returns the minimal-size prefix block that covers all the individual address sections in this section.
// The resulting block will have a larger count than this,
// unless this section is already a prefix block.
func (section WrappedIPAddressSection) CoverWithPrefixBlock() ExtendedIPSegmentSeries {
return section.IPAddressSection.coverSeriesWithPrefixBlock()
}
// ToBlock creates a new series block by changing the segment at the given index to have the given lower and upper value,
// and changing the following segments to be full-range.
func (section WrappedIPAddressSection) ToBlock(segmentIndex int, lower, upper SegInt) ExtendedIPSegmentSeries {
return wrapIPSection(section.IPAddressSection.ToBlock(segmentIndex, lower, upper))
}
// ToPrefixBlockLen returns the series with the same prefix of the given length as
// this series while the remaining bits span all values.
// The returned series will be the block of all series with the same prefix.
func (section WrappedIPAddressSection) ToPrefixBlockLen(bitCount BitCount) ExtendedIPSegmentSeries {
return wrapIPSection(section.IPAddressSection.ToPrefixBlockLen(bitCount))
}
// ToPrefixBlock returns the series with the same prefix as
// this series while the remaining bits span all values.
// The series will be the block of all series with the same prefix.
//
// If this series has no prefix, this series is returned.
func (section WrappedIPAddressSection) ToPrefixBlock() ExtendedIPSegmentSeries {
return wrapIPSection(section.IPAddressSection.ToPrefixBlock())
}