Skip to content

Commit

Permalink
fix: fix bytes export for cpc header.
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeLS committed Jun 11, 2019
1 parent ced54f9 commit 8fcab3d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions cpc/cpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewCpcHeader(f *os.File) (*CpcHead, error) {
}


func BytesCpcHeader( b []byte)(*CpcHead,error) {
func BytesCpcHeader(b []byte)(*CpcHead,error) {
header := &CpcHead{}
buff := bytes.NewReader(b)
err := binary.Read(buff,binary.LittleEndian,header)
Expand All @@ -53,11 +53,12 @@ func BytesCpcHeader( b []byte)(*CpcHead,error) {
return header,nil
}

func (c* CpcHead) Bytes() []byte {
data := make([]byte,128)
buff := bytes.NewBuffer(data)
binary.Write(buff,binary.LittleEndian,c)
return buff.Bytes()
func (c* CpcHead) Bytes() ([]byte,error) {
var b bytes.Buffer
if err := binary.Write(&b,binary.LittleEndian,c); err != nil {
return b.Bytes(), err
}
return b.Bytes(), nil
}

func (c *CpcHead) ComputedChecksum16() uint16 {
Expand Down

0 comments on commit 8fcab3d

Please sign in to comment.