Last active
April 25, 2016 13:17
-
-
Save beanieboi/da921330b2b8f12c3d6be9ccb21916a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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