forked from lightningnetwork/lnd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0578b80
commit a2700af
Showing
6 changed files
with
738 additions
and
256 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 presence, | ||
// 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.