-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmsg_stream_ack.go
More file actions
66 lines (53 loc) · 1.8 KB
/
msg_stream_ack.go
File metadata and controls
66 lines (53 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package wire
import (
"io"
)
// MsgStreamAck implements the Message interface and represents a bitcoin
// streamack message. It is sent in response to a createstream message to
// confirm the new stream has been accepted and associated.
type MsgStreamAck struct {
AssociationID []byte
StreamType StreamType
}
// Bsvdecode decodes r using the bitcoin protocol encoding into the receiver.
// This is part of the Message interface implementation.
func (msg *MsgStreamAck) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error {
var err error
msg.AssociationID, err = ReadVarBytes(r, pver, MaxAssociationIDLen, "AssociationID")
if err != nil {
return err
}
var streamType uint8
if err = readElement(r, &streamType); err != nil {
return err
}
msg.StreamType = StreamType(streamType)
return nil
}
// BsvEncode encodes the receiver to w using the bitcoin protocol encoding.
// This is part of the Message interface implementation.
func (msg *MsgStreamAck) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error {
if err := WriteVarBytes(w, pver, msg.AssociationID); err != nil {
return err
}
if err := writeElement(w, uint8(msg.StreamType)); err != nil {
return err
}
return nil
}
// Command returns the protocol command string for the message.
func (msg *MsgStreamAck) Command() string {
return CmdStreamAck
}
// MaxPayloadLength returns the maximum length the payload can be for the receiver.
func (msg *MsgStreamAck) MaxPayloadLength(_ uint32) uint64 {
// varint(association_id_len) + association_id + stream_type(1)
return MaxVarIntPayload + MaxAssociationIDLen + 1
}
// NewMsgStreamAck returns a new streamack message.
func NewMsgStreamAck(associationID []byte, streamType StreamType) *MsgStreamAck {
return &MsgStreamAck{
AssociationID: associationID,
StreamType: streamType,
}
}