Skip to content

Commit

Permalink
mgmt: Fix CsInfo message
Browse files Browse the repository at this point in the history
  • Loading branch information
zjkmxy committed Jul 11, 2023
1 parent ea23a75 commit 2e42d59
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/ndn/mgmt_2022/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ type StrategyChoiceMsg struct {
StrategyChoices []*StrategyChoice `tlv:"0x80"`
}

// Not supported by NFD yet
type CsInfo struct {
//+field:natural
Capacity uint64 `tlv:"0x83"`
Expand All @@ -330,6 +329,11 @@ type CsInfo struct {
NMisses uint64 `tlv:"0x82"`
}

type CsInfoMsg struct {
//+field:struct:CsInfo
CsInfo *CsInfo `tlv:"0x80"`
}

// No Tlv numbers assigned yet
type CsQuery struct {
Name enc.Name
Expand Down
157 changes: 157 additions & 0 deletions pkg/ndn/mgmt_2022/zz_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -9096,3 +9096,160 @@ func ParseCsInfo(reader enc.ParseReader, ignoreCritical bool) (*CsInfo, error) {
context.Init()
return context.Parse(reader, ignoreCritical)
}

type CsInfoMsgEncoder struct {
length uint

CsInfo_encoder CsInfoEncoder
}

type CsInfoMsgParsingContext struct {
CsInfo_context CsInfoParsingContext
}

func (encoder *CsInfoMsgEncoder) Init(value *CsInfoMsg) {
if value.CsInfo != nil {
encoder.CsInfo_encoder.Init(value.CsInfo)
}
l := uint(0)
if value.CsInfo != nil {
l += 1
switch x := encoder.CsInfo_encoder.length; {
case x <= 0xfc:
l += 1
case x <= 0xffff:
l += 3
case x <= 0xffffffff:
l += 5
default:
l += 9
}
l += encoder.CsInfo_encoder.length
}

encoder.length = l

}

func (context *CsInfoMsgParsingContext) Init() {
context.CsInfo_context.Init()
}

func (encoder *CsInfoMsgEncoder) EncodeInto(value *CsInfoMsg, buf []byte) {

pos := uint(0)
if value.CsInfo != nil {
buf[pos] = byte(128)
pos += 1
switch x := encoder.CsInfo_encoder.length; {
case x <= 0xfc:
buf[pos] = byte(x)
pos += 1
case x <= 0xffff:
buf[pos] = 0xfd
binary.BigEndian.PutUint16(buf[pos+1:], uint16(x))
pos += 3
case x <= 0xffffffff:
buf[pos] = 0xfe
binary.BigEndian.PutUint32(buf[pos+1:], uint32(x))
pos += 5
default:
buf[pos] = 0xff
binary.BigEndian.PutUint64(buf[pos+1:], uint64(x))
pos += 9
}
if encoder.CsInfo_encoder.length > 0 {
encoder.CsInfo_encoder.EncodeInto(value.CsInfo, buf[pos:])
pos += encoder.CsInfo_encoder.length
}
}

}

func (encoder *CsInfoMsgEncoder) Encode(value *CsInfoMsg) enc.Wire {

wire := make(enc.Wire, 1)
wire[0] = make([]byte, encoder.length)
buf := wire[0]
encoder.EncodeInto(value, buf)

return wire
}

func (context *CsInfoMsgParsingContext) Parse(reader enc.ParseReader, ignoreCritical bool) (*CsInfoMsg, error) {
if reader == nil {
return nil, enc.ErrBufferOverflow
}
progress := -1
value := &CsInfoMsg{}
var err error
var startPos int
for {
startPos = reader.Pos()
if startPos >= reader.Length() {
break
}
typ := enc.TLNum(0)
l := enc.TLNum(0)
typ, err = enc.ReadTLNum(reader)
if err != nil {
return nil, enc.ErrFailToParse{TypeNum: 0, Err: err}
}
l, err = enc.ReadTLNum(reader)
if err != nil {
return nil, enc.ErrFailToParse{TypeNum: 0, Err: err}
}
err = nil
for handled := false; !handled; progress++ {
switch typ {
case 128:
if progress+1 == 0 {
handled = true
value.CsInfo, err = context.CsInfo_context.Parse(reader.Delegate(int(l)), ignoreCritical)
}
default:
handled = true
if !ignoreCritical && ((typ <= 31) || ((typ & 1) == 1)) {
return nil, enc.ErrUnrecognizedField{TypeNum: typ}
}
err = reader.Skip(int(l))
}
if err == nil && !handled {
switch progress {
case 0 - 1:
value.CsInfo = nil
}
}
if err != nil {
return nil, enc.ErrFailToParse{TypeNum: typ, Err: err}
}
}
}
startPos = reader.Pos()
for ; progress < 1; progress++ {
switch progress {
case 0 - 1:
value.CsInfo = nil
}
}
if err != nil {
return nil, err
}
return value, nil
}

func (value *CsInfoMsg) Encode() enc.Wire {
encoder := CsInfoMsgEncoder{}
encoder.Init(value)
return encoder.Encode(value)
}

func (value *CsInfoMsg) Bytes() []byte {
return value.Encode().Join()
}

func ParseCsInfoMsg(reader enc.ParseReader, ignoreCritical bool) (*CsInfoMsg, error) {
context := CsInfoMsgParsingContext{}
context.Init()
return context.Parse(reader, ignoreCritical)
}

0 comments on commit 2e42d59

Please sign in to comment.