lnwire/features: add Encode256 and Decode256
These will allow us to serialize invoice features bits without double encoding the length.
This commit is contained in:
parent
76a2dfd8a6
commit
c6a01f02cd
@ -216,8 +216,16 @@ func (fv *RawFeatureVector) Encode(w io.Writer) error {
|
|||||||
return fv.encode(w, length, 8)
|
return fv.encode(w, length, 8)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EncodeBase256 writes the feature vector in base256 representation. Every
|
||||||
|
// feature is encoded as a bit, and the bit vector is serialized using the least
|
||||||
|
// number of bytes.
|
||||||
|
func (fv *RawFeatureVector) EncodeBase256(w io.Writer) error {
|
||||||
|
length := fv.SerializeSize()
|
||||||
|
return fv.encode(w, length, 8)
|
||||||
|
}
|
||||||
|
|
||||||
// EncodeBase32 writes the feature vector in base32 representation. Every feature
|
// EncodeBase32 writes the feature vector in base32 representation. Every feature
|
||||||
// encoded as a bit, and the bit vector is serialized using the least number of
|
// is encoded as a bit, and the bit vector is serialized using the least number of
|
||||||
// bytes.
|
// bytes.
|
||||||
func (fv *RawFeatureVector) EncodeBase32(w io.Writer) error {
|
func (fv *RawFeatureVector) EncodeBase32(w io.Writer) error {
|
||||||
length := fv.SerializeSize32()
|
length := fv.SerializeSize32()
|
||||||
@ -239,8 +247,8 @@ func (fv *RawFeatureVector) encode(w io.Writer, length, width int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Decode reads the feature vector from its byte representation. Every feature
|
// Decode reads the feature vector from its byte representation. Every feature
|
||||||
// encoded as a bit, and the bit vector is serialized using the least number of
|
// is encoded as a bit, and the bit vector is serialized using the least number
|
||||||
// bytes. Since the bit vector length is variable, the first two bytes of the
|
// of bytes. Since the bit vector length is variable, the first two bytes of the
|
||||||
// serialization represent the length.
|
// serialization represent the length.
|
||||||
func (fv *RawFeatureVector) Decode(r io.Reader) error {
|
func (fv *RawFeatureVector) Decode(r io.Reader) error {
|
||||||
// Read the length of the feature vector.
|
// Read the length of the feature vector.
|
||||||
@ -253,6 +261,13 @@ func (fv *RawFeatureVector) Decode(r io.Reader) error {
|
|||||||
return fv.decode(r, int(length), 8)
|
return fv.decode(r, int(length), 8)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DecodeBase256 reads the feature vector from its base256 representation. Every
|
||||||
|
// feature encoded as a bit, and the bit vector is serialized using the least
|
||||||
|
// number of bytes.
|
||||||
|
func (fv *RawFeatureVector) DecodeBase256(r io.Reader, length int) error {
|
||||||
|
return fv.decode(r, length, 8)
|
||||||
|
}
|
||||||
|
|
||||||
// DecodeBase32 reads the feature vector from its base32 representation. Every
|
// DecodeBase32 reads the feature vector from its base32 representation. Every
|
||||||
// feature encoded as a bit, and the bit vector is serialized using the least
|
// feature encoded as a bit, and the bit vector is serialized using the least
|
||||||
// number of bytes.
|
// number of bytes.
|
||||||
|
Loading…
Reference in New Issue
Block a user