Skip to content

Instantly share code, notes, and snippets.

@beanieboi
Last active Apr 25, 2016
Embed
What would you like to do?
package bitmask
import (
"encoding/binary"
"bytes"
"fmt"
)
type Channelmask struct {
A3 bool
A2 bool
A1 bool
A0 bool
}
func ParseMask(b []byte) (Channelmask) {
var mask Channelmask
buf := bytes.NewReader(b)
err := binary.Read(buf, binary.LittleEndian, &mask)
if err != nil {
fmt.Println("binary.Read failed:", err)
}
return mask
}
package bitmask
import(
"testing"
"fmt"
"github.com/beanieboi/home-go/mt"
)
func TestParseMask(t *testing.T) {
var mask Channelmask
var mymask = []byte{0x01, 0x01}
mask = ParseMask(mymask)
fmt.Printf("%+v\n", mask)
mt.AssertEqual(t, true, mask.A0)
mt.AssertEqual(t, false, mask.A1)
mt.AssertEqual(t, true, mask.A2)
mt.AssertEqual(t, false, mask.A3)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment