mirror of
https://github.com/amigan/aim-oscar-server.git
synced 2024-11-21 20:19:47 -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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FLAP struct {
|
||||||
|
Channel uint8
|
||||||
|
SequenceNumber uint16
|
||||||
|
DataLength uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
flap := FLAP{}
|
||||||
|
panicIfError(binary.Read(messageBuf, binary.BigEndian, &flap))
|
||||||
|
|
||||||
// Start parsing FLAP header
|
// Start parsing FLAP header
|
||||||
channel := mustReadNBytes(messageBuf, 1)[0]
|
log.Println("Message for channel: ", flap.Channel)
|
||||||
log.Println("Message for channel: ", channel)
|
log.Println("Datagram Sequence Number: ", flap.SequenceNumber)
|
||||||
|
log.Println("Data Length: ", flap.DataLength)
|
||||||
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))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
5
util.go
5
util.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -42,3 +43,7 @@ func mustReadNBytes(buf *bytes.Buffer, n int) []byte {
|
||||||
panicIfError(err)
|
panicIfError(err)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mustRead(buf *bytes.Buffer, dest interface{}) {
|
||||||
|
panicIfError(binary.Read(buf, binary.BigEndian, dest))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue