github.com/decred/dcrlnd@v0.7.6/channeldb/migration/lnwire21/reply_channel_range.go (about)

     1  package lnwire
     2  
     3  import "io"
     4  
     5  // ReplyChannelRange is the response to the QueryChannelRange message. It
     6  // includes the original query, and the next streaming chunk of encoded short
     7  // channel ID's as the response. We'll also include a byte that indicates if
     8  // this is the last query in the message.
     9  type ReplyChannelRange struct {
    10  	// QueryChannelRange is the corresponding query to this response.
    11  	QueryChannelRange
    12  
    13  	// Complete denotes if this is the conclusion of the set of streaming
    14  	// responses to the original query.
    15  	Complete uint8
    16  
    17  	// EncodingType is a signal to the receiver of the message that
    18  	// indicates exactly how the set of short channel ID's that follow have
    19  	// been encoded.
    20  	EncodingType ShortChanIDEncoding
    21  
    22  	// ShortChanIDs is a slice of decoded short channel ID's.
    23  	ShortChanIDs []ShortChannelID
    24  
    25  	// noSort indicates whether or not to sort the short channel ids before
    26  	// writing them out.
    27  	//
    28  	// NOTE: This should only be used for testing.
    29  	noSort bool
    30  }
    31  
    32  // NewReplyChannelRange creates a new empty ReplyChannelRange message.
    33  func NewReplyChannelRange() *ReplyChannelRange {
    34  	return &ReplyChannelRange{}
    35  }
    36  
    37  // A compile time check to ensure ReplyChannelRange implements the
    38  // lnwire.Message interface.
    39  var _ Message = (*ReplyChannelRange)(nil)
    40  
    41  // Decode deserializes a serialized ReplyChannelRange message stored in the
    42  // passed io.Reader observing the specified protocol version.
    43  //
    44  // This is part of the lnwire.Message interface.
    45  func (c *ReplyChannelRange) Decode(r io.Reader, pver uint32) error {
    46  	err := c.QueryChannelRange.Decode(r, pver)
    47  	if err != nil {
    48  		return err
    49  	}
    50  
    51  	if err := ReadElements(r, &c.Complete); err != nil {
    52  		return err
    53  	}
    54  
    55  	c.EncodingType, c.ShortChanIDs, err = decodeShortChanIDs(r)
    56  
    57  	return err
    58  }
    59  
    60  // Encode serializes the target ReplyChannelRange into the passed io.Writer
    61  // observing the protocol version specified.
    62  //
    63  // This is part of the lnwire.Message interface.
    64  func (c *ReplyChannelRange) Encode(w io.Writer, pver uint32) error {
    65  	if err := c.QueryChannelRange.Encode(w, pver); err != nil {
    66  		return err
    67  	}
    68  
    69  	if err := WriteElements(w, c.Complete); err != nil {
    70  		return err
    71  	}
    72  
    73  	return encodeShortChanIDs(w, c.EncodingType, c.ShortChanIDs, c.noSort)
    74  }
    75  
    76  // MsgType returns the integer uniquely identifying this message type on the
    77  // wire.
    78  //
    79  // This is part of the lnwire.Message interface.
    80  func (c *ReplyChannelRange) MsgType() MessageType {
    81  	return MsgReplyChannelRange
    82  }
    83  
    84  // MaxPayloadLength returns the maximum allowed payload size for a
    85  // ReplyChannelRange complete message observing the specified protocol version.
    86  //
    87  // This is part of the lnwire.Message interface.
    88  func (c *ReplyChannelRange) MaxPayloadLength(uint32) uint32 {
    89  	return MaxMessagePayload
    90  }