lnwire/features: add SerializeSize32 for base32 encodings
This commit is contained in:
1 file changed
+15
-2
+15
-2
@@ -127,6 +127,20 @@ func (fv *RawFeatureVector) Unset(feature FeatureBit) {
|
|||||||
// SerializeSize returns the number of bytes needed to represent feature vector
|
// SerializeSize returns the number of bytes needed to represent feature vector
|
||||||
// in byte format.
|
// in byte format.
|
||||||
func (fv *RawFeatureVector) SerializeSize() int {
|
func (fv *RawFeatureVector) SerializeSize() int {
|
||||||
|
// We calculate byte-length via the largest bit index.
|
||||||
|
return fv.serializeSize(8)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SerializeSize32 returns the number of bytes needed to represent feature
|
||||||
|
// vector in base32 format.
|
||||||
|
func (fv *RawFeatureVector) SerializeSize32() int {
|
||||||
|
// We calculate base32-length via the largest bit index.
|
||||||
|
return fv.serializeSize(5)
|
||||||
|
}
|
||||||
|
|
||||||
|
// serializeSize returns the number of bytes required to encode the feature
|
||||||
|
// vector using at most width bits per encoded byte.
|
||||||
|
func (fv *RawFeatureVector) serializeSize(width int) int {
|
||||||
// Find the largest feature bit index
|
// Find the largest feature bit index
|
||||||
max := -1
|
max := -1
|
||||||
for feature := range fv.features {
|
for feature := range fv.features {
|
||||||
@@ -139,8 +153,7 @@ func (fv *RawFeatureVector) SerializeSize() int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// We calculate byte-length via the largest bit index
|
return max/width + 1
|
||||||
return max/8 + 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode writes the feature vector in byte representation. Every feature
|
// Encode writes the feature vector in byte representation. Every feature
|
||||||
|
|||||||
Reference in new issue
Block a user