cleaned up a few of the packer functions

This commit is contained in:
tigerbot 2017-03-22 12:30:56 -06:00
parent ce512ece34
commit 8fb732e3b8
3 changed files with 36 additions and 42 deletions

View File

@ -1,6 +1,8 @@
package packer
import "bytes"
import (
"bytes"
)
//packerData -- Contains packer data
type packerData struct {
@ -14,18 +16,15 @@ func newPackerData() (p *packerData) {
return
}
func (p *packerData) AppendString(dataString string) (n int, err error) {
n, err = p.buffer.WriteString(dataString)
return
func (p *packerData) AppendString(dataString string) (int, error) {
return p.buffer.WriteString(dataString)
}
func (p *packerData) AppendBytes(dataBytes []byte) (n int, err error) {
n, err = p.buffer.Write(dataBytes)
return
func (p *packerData) AppendBytes(dataBytes []byte) (int, error) {
return p.buffer.Write(dataBytes)
}
//Data --
func (p *packerData) Data() (b []byte) {
b = p.buffer.Bytes()
return
func (p *packerData) Data() []byte {
return p.buffer.Bytes()
}

View File

@ -1,7 +1,9 @@
package packer
import "net"
import "fmt"
import (
"fmt"
"net"
)
type addressFamily int
@ -37,45 +39,36 @@ func newPackerHeader() (p *packerHeader) {
//SetAddress -- Set Address. which sets address family automatically
func (p *packerHeader) SetAddress(addr string) {
p.address = net.ParseIP(addr)
err := p.address.To4()
if err != nil {
if p.address.To4() != nil {
p.family = FamilyIPv4
} else {
err := p.address.To16()
if err != nil {
} else if p.address.To16() != nil {
p.family = FamilyIPv6
} else {
panic(fmt.Sprintf("setAddress does not support %s", addr))
}
panic(fmt.Sprintf("setAddress does not support %q", addr))
}
}
func (p *packerHeader) AddressBytes() (b []byte) {
b = make([]byte, 16)
switch {
case p.address.To4() != nil:
b = make([]byte, 4)
for pos := range b {
b[pos] = p.address[pos+12]
}
return
}
return
func (p *packerHeader) AddressBytes() []byte {
if ip4 := p.address.To4(); ip4 != nil {
p.address = ip4
}
func (p *packerHeader) Address() (address net.IP) {
address = p.address
return
return []byte(p.address)
}
func (p *packerHeader) Family() (family addressFamily) {
family = p.family
return
func (p *packerHeader) AddressString() string {
return p.address.String()
}
func (p *packerHeader) FamilyText() (familyText string) {
familyText = addressFamilyText[p.family]
return
func (p *packerHeader) Address() net.IP {
return p.address
}
func (p *packerHeader) Family() addressFamily {
return p.family
}
func (p *packerHeader) FamilyText() string {
return addressFamilyText[p.family]
}

View File

@ -1,7 +1,9 @@
package packer
import "log"
import "os"
import (
"log"
"os"
)
var (
loginfo *log.Logger