lnwire: revamp previous encode/decode tests to passing state
This commit is contained in:
15 files changed
+269
-266
No files matched your search
+24
-22
@@ -14,33 +14,14 @@ type ErrorGeneric struct {
|
||||
// within.
|
||||
ChannelID uint64
|
||||
|
||||
// TODO(roasbeef): uint16 for problem type?
|
||||
// ErrorID uint16
|
||||
// ErrorID quickly defines the nature of the error according to error
|
||||
// type.
|
||||
ErrorID uint16
|
||||
|
||||
// Problem is a human-readable string further elaborating upon the
|
||||
// nature of the exact error. The maxmium allowed length of this
|
||||
// message is 8192 bytes.
|
||||
Problem string
|
||||
|
||||
// TODO(roasbeef): add SerializeSize?
|
||||
}
|
||||
|
||||
// Decode deserializes a serialized ErrorGeneric message stored in the
|
||||
// passed io.Reader observing the specified protocol version.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *ErrorGeneric) Decode(r io.Reader, pver uint32) error {
|
||||
// ChannelID(8)
|
||||
// Problem
|
||||
err := readElements(r,
|
||||
&c.ChannelID,
|
||||
&c.Problem,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewErrorGeneric creates a new ErrorGeneric message.
|
||||
@@ -52,6 +33,25 @@ func NewErrorGeneric() *ErrorGeneric {
|
||||
// interface.
|
||||
var _ Message = (*ErrorGeneric)(nil)
|
||||
|
||||
// Decode deserializes a serialized ErrorGeneric message stored in the
|
||||
// passed io.Reader observing the specified protocol version.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *ErrorGeneric) Decode(r io.Reader, pver uint32) error {
|
||||
// ChannelID(8)
|
||||
// Problem
|
||||
err := readElements(r,
|
||||
&c.ChannelID,
|
||||
&c.ErrorID,
|
||||
&c.Problem,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Encode serializes the target ErrorGeneric into the passed io.Writer
|
||||
// observing the protocol version specified.
|
||||
//
|
||||
@@ -59,6 +59,7 @@ var _ Message = (*ErrorGeneric)(nil)
|
||||
func (c *ErrorGeneric) Encode(w io.Writer, pver uint32) error {
|
||||
err := writeElements(w,
|
||||
c.ChannelID,
|
||||
c.ErrorID,
|
||||
c.Problem,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -104,6 +105,7 @@ func (c *ErrorGeneric) Validate() error {
|
||||
func (c *ErrorGeneric) String() string {
|
||||
return fmt.Sprintf("\n--- Begin ErrorGeneric ---\n") +
|
||||
fmt.Sprintf("ChannelID:\t%d\n", c.ChannelID) +
|
||||
fmt.Sprintf("ErrorID:\t%d\n", c.ErrorID) +
|
||||
fmt.Sprintf("Problem:\t%s\n", c.Problem) +
|
||||
fmt.Sprintf("--- End ErrorGeneric ---\n")
|
||||
}
|
||||
Reference in new issue
Block a user