- buf[pos] = uint8(x)
- pos += 1
- }
- // field[1] m.Count
- o.PutUint32(buf[pos:pos+4], uint32(len(m.R)))
- pos += 4
- // field[1] m.R
- for j1 := 0; j1 < len(m.R); j1++ {
- var v1 ACLRule
- if j1 < len(m.R) {
- v1 = m.R[j1]
- }
- // field[2] v1.IsPermit
- buf[pos] = uint8(v1.IsPermit)
- pos += 1
- // field[2] v1.IsIPv6
- buf[pos] = uint8(v1.IsIPv6)
- pos += 1
- // field[2] v1.SrcIPAddr
- for i := 0; i < 16; i++ {
- var x uint8
- if i < len(v1.SrcIPAddr) {
- x = uint8(v1.SrcIPAddr[i])
- }
- buf[pos] = uint8(x)
- pos += 1
- }
- // field[2] v1.SrcIPPrefixLen
- buf[pos] = uint8(v1.SrcIPPrefixLen)
- pos += 1
- // field[2] v1.DstIPAddr
- for i := 0; i < 16; i++ {
- var x uint8
- if i < len(v1.DstIPAddr) {
- x = uint8(v1.DstIPAddr[i])
- }
- buf[pos] = uint8(x)
- pos += 1
- }
- // field[2] v1.DstIPPrefixLen
- buf[pos] = uint8(v1.DstIPPrefixLen)
- pos += 1
- // field[2] v1.Proto
- buf[pos] = uint8(v1.Proto)
- pos += 1
- // field[2] v1.SrcportOrIcmptypeFirst
- o.PutUint16(buf[pos:pos+2], uint16(v1.SrcportOrIcmptypeFirst))
- pos += 2
- // field[2] v1.SrcportOrIcmptypeLast
- o.PutUint16(buf[pos:pos+2], uint16(v1.SrcportOrIcmptypeLast))
- pos += 2
- // field[2] v1.DstportOrIcmpcodeFirst
- o.PutUint16(buf[pos:pos+2], uint16(v1.DstportOrIcmpcodeFirst))
- pos += 2
- // field[2] v1.DstportOrIcmpcodeLast
- o.PutUint16(buf[pos:pos+2], uint16(v1.DstportOrIcmpcodeLast))
- pos += 2
- // field[2] v1.TCPFlagsMask
- buf[pos] = uint8(v1.TCPFlagsMask)
- pos += 1
- // field[2] v1.TCPFlagsValue
- buf[pos] = uint8(v1.TCPFlagsValue)
- pos += 1
- }
- return buf, nil
-}
-func (m *ACLAddReplace) Unmarshal(tmp []byte) error {
- o := binary.BigEndian
- _ = o
- pos := 0
- _ = pos
- // field[1] m.ACLIndex
- m.ACLIndex = uint32(o.Uint32(tmp[pos : pos+4]))
- pos += 4
- // field[1] m.Tag
- m.Tag = make([]uint8, 64)
- for i := 0; i < len(m.Tag); i++ {
- m.Tag[i] = uint8(tmp[pos])
- pos += 1
- }
- // field[1] m.Count
- m.Count = uint32(o.Uint32(tmp[pos : pos+4]))
- pos += 4
- // field[1] m.R
- m.R = make([]ACLRule, int(m.Count))
- for j1 := 0; j1 < int(m.Count); j1++ {
- // field[2] m.R[j1].IsPermit
- m.R[j1].IsPermit = uint8(tmp[pos])
- pos += 1
- // field[2] m.R[j1].IsIPv6
- m.R[j1].IsIPv6 = uint8(tmp[pos])
- pos += 1
- // field[2] m.R[j1].SrcIPAddr
- m.R[j1].SrcIPAddr = make([]uint8, 16)
- for i := 0; i < len(m.R[j1].SrcIPAddr); i++ {
- m.R[j1].SrcIPAddr[i] = uint8(tmp[pos])
- pos += 1
- }
- // field[2] m.R[j1].SrcIPPrefixLen
- m.R[j1].SrcIPPrefixLen = uint8(tmp[pos])
- pos += 1
- // field[2] m.R[j1].DstIPAddr
- m.R[j1].DstIPAddr = make([]uint8, 16)
- for i := 0; i < len(m.R[j1].DstIPAddr); i++ {
- m.R[j1].DstIPAddr[i] = uint8(tmp[pos])
- pos += 1
- }
- // field[2] m.R[j1].DstIPPrefixLen
- m.R[j1].DstIPPrefixLen = uint8(tmp[pos])
- pos += 1
- // field[2] m.R[j1].Proto
- m.R[j1].Proto = uint8(tmp[pos])
- pos += 1
- // field[2] m.R[j1].SrcportOrIcmptypeFirst
- m.R[j1].SrcportOrIcmptypeFirst = uint16(o.Uint16(tmp[pos : pos+2]))
- pos += 2
- // field[2] m.R[j1].SrcportOrIcmptypeLast
- m.R[j1].SrcportOrIcmptypeLast = uint16(o.Uint16(tmp[pos : pos+2]))
- pos += 2
- // field[2] m.R[j1].DstportOrIcmpcodeFirst
- m.R[j1].DstportOrIcmpcodeFirst = uint16(o.Uint16(tmp[pos : pos+2]))
- pos += 2
- // field[2] m.R[j1].DstportOrIcmpcodeLast
- m.R[j1].DstportOrIcmpcodeLast = uint16(o.Uint16(tmp[pos : pos+2]))
- pos += 2
- // field[2] m.R[j1].TCPFlagsMask
- m.R[j1].TCPFlagsMask = uint8(tmp[pos])
- pos += 1
- // field[2] m.R[j1].TCPFlagsValue
- m.R[j1].TCPFlagsValue = uint8(tmp[pos])
- pos += 1
+ buf.EncodeUint8(v0.IsPermit)
+ buf.EncodeUint8(v0.IsIPv6)
+ buf.EncodeBytes(v0.SrcIPAddr, 16)
+ buf.EncodeUint8(v0.SrcIPPrefixLen)
+ buf.EncodeBytes(v0.DstIPAddr, 16)
+ buf.EncodeUint8(v0.DstIPPrefixLen)
+ buf.EncodeUint8(v0.Proto)
+ buf.EncodeUint16(v0.SrcportOrIcmptypeFirst)
+ buf.EncodeUint16(v0.SrcportOrIcmptypeLast)
+ buf.EncodeUint16(v0.DstportOrIcmpcodeFirst)
+ buf.EncodeUint16(v0.DstportOrIcmpcodeLast)
+ buf.EncodeUint8(v0.TCPFlagsMask)
+ buf.EncodeUint8(v0.TCPFlagsValue)
+ }
+ return buf.Bytes(), nil
+}
+func (m *ACLAddReplace) Unmarshal(b []byte) error {
+ buf := codec.NewBuffer(b)
+ m.ACLIndex = buf.DecodeUint32()
+ m.Tag = make([]byte, 64)
+ copy(m.Tag, buf.DecodeBytes(len(m.Tag)))
+ m.Count = buf.DecodeUint32()
+ m.R = make([]ACLRule, m.Count)
+ for j0 := 0; j0 < len(m.R); j0++ {
+ m.R[j0].IsPermit = buf.DecodeUint8()
+ m.R[j0].IsIPv6 = buf.DecodeUint8()
+ m.R[j0].SrcIPAddr = make([]byte, 16)
+ copy(m.R[j0].SrcIPAddr, buf.DecodeBytes(len(m.R[j0].SrcIPAddr)))
+ m.R[j0].SrcIPPrefixLen = buf.DecodeUint8()
+ m.R[j0].DstIPAddr = make([]byte, 16)
+ copy(m.R[j0].DstIPAddr, buf.DecodeBytes(len(m.R[j0].DstIPAddr)))
+ m.R[j0].DstIPPrefixLen = buf.DecodeUint8()
+ m.R[j0].Proto = buf.DecodeUint8()
+ m.R[j0].SrcportOrIcmptypeFirst = buf.DecodeUint16()
+ m.R[j0].SrcportOrIcmptypeLast = buf.DecodeUint16()
+ m.R[j0].DstportOrIcmpcodeFirst = buf.DecodeUint16()
+ m.R[j0].DstportOrIcmpcodeLast = buf.DecodeUint16()
+ m.R[j0].TCPFlagsMask = buf.DecodeUint8()
+ m.R[j0].TCPFlagsValue = buf.DecodeUint8()