31 lines
641 B
Go
31 lines
641 B
Go
package pdu
|
|
|
|
type (
|
|
PDU interface {
|
|
Encode() []byte
|
|
Decode([]byte)
|
|
}
|
|
|
|
PDU_HEADER struct {
|
|
command_length uint32
|
|
command_id uint32
|
|
command_status uint32
|
|
sequence_number uint32
|
|
}
|
|
|
|
GENERIC_NACK struct {
|
|
PDU_HEADER
|
|
}
|
|
)
|
|
|
|
func (p *PDU_HEADER) Encode() []byte {
|
|
// Encode PDU_HEADER fields to byte slice
|
|
// (For simplicity, we assume little-endian encoding)
|
|
buf := make([]byte, 16)
|
|
encodeUint32(buf[0:4], p.command_length)
|
|
encodeUint32(buf[4:8], p.command_id)
|
|
encodeUint32(buf[8:12], p.command_status)
|
|
encodeUint32(buf[12:16], p.sequence_number)
|
|
return buf
|
|
}
|