package main
import (
"bytes"
"encoding/binary"
"fmt"
"io"
)
type AVP struct {
Type byte
Length byte
Values []byte
}
var (
avps AVP
)
func main() {
pack := []byte{6, 6, 0, 0, 0, 2, 7, 6, 0, 0, 0, 1, 8, 6, 185, 14, 32, 1, 9,
6, 255, 255, 255, 255, 27, 6, 0, 1, 81,
128, 26, 22, 0, 0, 0, 9, 250, 16, 65, 85, 78, 76, 95, 53, 48, 77, 95, 78,
73, 71, 72, 84, 26, 14, 0, 0, 0, 9,
250, 8, 65, 76, 79, 67, 65, 76, 26, 20, 0, 0, 0, 9, 250, 14, 65, 85, 78,
76, 95, 49, 48, 77, 95, 68, 65, 89}
buf := bytes.NewBuffer(pack)
binary.Read(buf, binary.BigEndian, &avps.Type)
binary.Read(buf, binary.BigEndian, &avps.Length)
avps.Values = make([]byte, avps.Length-2)
io.ReadFull(buf, avps.Values)
fmt.Println(avps)
}
The result should come out:
{6 6 [0 0 0 2]}
{7 6 [0 0 0 1[}
{8 6[185 14 32 1]}
etc.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.