Skip to content

Instantly share code, notes, and snippets.

@beanieboi
Last active April 25, 2016 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beanieboi/da921330b2b8f12c3d6be9ccb21916a2 to your computer and use it in GitHub Desktop.
Save beanieboi/da921330b2b8f12c3d6be9ccb21916a2 to your computer and use it in GitHub Desktop.
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