mirror of
https://github.com/amigan/aim-oscar-server.git
synced 2024-11-21 12:09:48 -05:00
unpack with struct :o
This commit is contained in:
parent
27aea95084
commit
a23cdd7092
2 changed files with 17 additions and 9 deletions
21
main.go
21
main.go
|
@ -109,14 +109,17 @@ func handleMessage(ctx context.Context, buf []byte) {
|
|||
return
|
||||
}
|
||||
|
||||
type FLAP struct {
|
||||
Channel uint8
|
||||
SequenceNumber uint16
|
||||
DataLength uint16
|
||||
}
|
||||
|
||||
flap := FLAP{}
|
||||
panicIfError(binary.Read(messageBuf, binary.BigEndian, &flap))
|
||||
|
||||
// Start parsing FLAP header
|
||||
channel := mustReadNBytes(messageBuf, 1)[0]
|
||||
log.Println("Message for channel: ", channel)
|
||||
|
||||
datagramSeqNum := mustReadNBytes(messageBuf, 2)
|
||||
log.Println("Datagram Sequence Number: ", binary.BigEndian.Uint16(datagramSeqNum))
|
||||
|
||||
dataLength := mustReadNBytes(messageBuf, 2)
|
||||
log.Println("Data Length: ", binary.BigEndian.Uint16(dataLength))
|
||||
|
||||
log.Println("Message for channel: ", flap.Channel)
|
||||
log.Println("Datagram Sequence Number: ", flap.SequenceNumber)
|
||||
log.Println("Data Length: ", flap.DataLength)
|
||||
}
|
||||
|
|
5
util.go
5
util.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -42,3 +43,7 @@ func mustReadNBytes(buf *bytes.Buffer, n int) []byte {
|
|||
panicIfError(err)
|
||||
return res
|
||||
}
|
||||
|
||||
func mustRead(buf *bytes.Buffer, dest interface{}) {
|
||||
panicIfError(binary.Read(buf, binary.BigEndian, dest))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue