Created
May 12, 2014 14:36
-
-
Save AeroNotix/05b59572c91ee98f8e16 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 main | |
import ( | |
"bytes" | |
"encoding/binary" | |
"errors" | |
"fmt" | |
"io" | |
"io/ioutil" | |
) | |
const ( | |
TNBU = 1414414933 | |
) | |
var ( | |
InvalidMagic = errors.New("Invalid magic in packet.") | |
InvalidVersion = errors.New("Invalid packet version.") | |
) | |
type airosPacket struct { | |
Magic int32 | |
PacketVersion int32 | |
MessageFlags int8 | |
MessageFormat int8 | |
MessageType int16 | |
RequestId [16]byte | |
PayloadLength int32 | |
} | |
var packet = []byte{ | |
84, 78, 66, 85, 0, 0, 0, 2, | |
0, 1, 0, 3, 154, 11, 151, 40, | |
171, 175, 65, 83, 180, 239, | |
231, 4, 78, 178, 109, 144, | |
0, 0, 0, 3, 102, 111, 111, | |
} | |
func ReadPacket(buf io.Reader, into interface{}) (airosPacket, error) { | |
ap := airosPacket{} | |
err := binary.Read(buf, binary.BigEndian, &ap) | |
if err != nil { | |
return ap, err | |
} | |
} | |
func main() { | |
rdr := bytes.NewReader(packet) | |
ap := airosPacket{} | |
fmt.Println(binary.Read(rdr, binary.BigEndian, &ap)) | |
fmt.Println(ap) | |
b, _ := ioutil.ReadAll(rdr) | |
fmt.Println(string(b)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment