-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9167 from ellemouton/mcEncodingToTLV
routing+migration32: update migration 32 to use pure TLV encoding for mission control results
- Loading branch information
Showing
13 changed files
with
1,716 additions
and
666 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package lnwire | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/lightningnetwork/lnd/tlv" | ||
) | ||
|
||
// TrueBoolean is a record that indicates true or false using the presence of | ||
// the record. If the record is absent, it indicates false. If it is present, | ||
// it indicates true. | ||
type TrueBoolean struct{} | ||
|
||
// Record returns the tlv record for the boolean entry. | ||
func (b *TrueBoolean) Record() tlv.Record { | ||
return tlv.MakeStaticRecord( | ||
0, b, 0, booleanEncoder, booleanDecoder, | ||
) | ||
} | ||
|
||
func booleanEncoder(_ io.Writer, val interface{}, _ *[8]byte) error { | ||
if _, ok := val.(*TrueBoolean); ok { | ||
return nil | ||
} | ||
|
||
return tlv.NewTypeForEncodingErr(val, "TrueBoolean") | ||
} | ||
|
||
func booleanDecoder(_ io.Reader, val interface{}, _ *[8]byte, | ||
l uint64) error { | ||
|
||
if _, ok := val.(*TrueBoolean); ok && (l == 0 || l == 1) { | ||
return nil | ||
} | ||
|
||
return tlv.NewTypeForEncodingErr(val, "TrueBoolean") | ||
} |
Oops, something went wrong.