Skip to content

Commit

Permalink
nil pointer protection
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSnow committed Feb 5, 2017
1 parent b0de767 commit 148f874
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions p2p/parcel.go
Expand Up @@ -328,21 +328,33 @@ func (p *ParcelHeader) Print() {
}

func (p *Parcel) Print() {
if p == nil {
return
}
debug("parcel", "Pretty Printing Parcel:")
p.Header.Print()
s := strconv.Quote(string(p.Payload))
debug("parcel", "\t\tPayload: %s", s)
}

func (p *Parcel) MessageType() string {
if p == nil {
return ""
}
return (fmt.Sprintf("[%s]", CommandStrings[p.Header.Type]))
}

func (p *Parcel) PrintMessageType() {
if p == nil {
return
}
fmt.Printf("[%+v]", CommandStrings[p.Header.Type])
}

func (p *Parcel) String() string {
if p == nil {
return ""
}
var output string
s := strconv.Quote(string(p.Payload))
output = fmt.Sprintf("%s\t Network:\t%+v\n", output, p.Header.Network.String())
Expand Down

0 comments on commit 148f874

Please sign in to comment.