Export CommandSize constant.

This commit exports the CommandSize constant to provide callers with the
ability to know the size of the command field in a bitcoin message header.
This commit is contained in:
Dave Collins 2014-07-12 17:32:21 -05:00
parent 3a1009529f
commit dd70618cc1
3 changed files with 8 additions and 12 deletions

View file

@ -83,7 +83,7 @@ func readElement(r io.Reader, element interface{}) error {
return nil
// Message header command.
case *[commandSize]uint8:
case *[CommandSize]uint8:
_, err := io.ReadFull(r, e[:])
if err != nil {
return err
@ -233,7 +233,7 @@ func writeElement(w io.Writer, element interface{}) error {
return nil
// Message header command.
case [commandSize]uint8:
case [CommandSize]uint8:
_, err := w.Write(e[:])
if err != nil {
return err

View file

@ -31,10 +31,6 @@ const (
// MaxCountSetSubVer makes the internal maxCountSetSubVer constant
// available to the test package.
MaxCountSetSubVer = maxCountSetSubVer
// CommandSize makes the internal commandSize constant available to the
// test package.
CommandSize = commandSize
)
// TstRandomUint64 makes the internal randomUint64 function available to the

View file

@ -16,9 +16,9 @@ import (
// checksum 4 bytes.
const MessageHeaderSize = 24
// commandSize is the fixed size of all commands in the common bitcoin message
// CommandSize is the fixed size of all commands in the common bitcoin message
// header. Shorter commands must be zero padded.
const commandSize = 12
const CommandSize = 12
// MaxMessagePayload is the maximum bytes a message can be regardless of other
// individual limits imposed by messages themselves.
@ -157,7 +157,7 @@ func readMessageHeader(r io.Reader) (int, *messageHeader, error) {
// Create and populate a messageHeader struct from the raw header bytes.
hdr := messageHeader{}
var command [commandSize]byte
var command [CommandSize]byte
readElements(hr, &hdr.magic, &command, &hdr.length, &hdr.checksum)
// Strip trailing zeros from command string.
@ -193,11 +193,11 @@ func WriteMessageN(w io.Writer, msg Message, pver uint32, btcnet BitcoinNet) (in
totalBytes := 0
// Enforce max command size.
var command [commandSize]byte
var command [CommandSize]byte
cmd := msg.Command()
if len(cmd) > commandSize {
if len(cmd) > CommandSize {
str := fmt.Sprintf("command [%s] is too long [max %v]",
cmd, commandSize)
cmd, CommandSize)
return totalBytes, messageError("WriteMessage", str)
}
copy(command[:], []byte(cmd))