aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
authorChris Luke <chrisy@flirble.org>2019-05-17 10:17:16 -0400
committerChris Luke <chrisy@flirble.org>2019-05-17 10:28:34 -0400
commit5022c6ce34b5215e63a4ea5972ca0ed0fd196ab0 (patch)
treef66add0066ed37b1e1ac6e81e26dfd130845e2bd /src/vppinfra
parentd8a34a57b12200000bb42d1c55f1a99a0a473f4b (diff)
Fix 'terminal history off' crasher
- 'set terminal history off' or '... limit 0' has an incorrect terminal condition and tries to vec_delete one-too-many times causing a crash. - Changing >= to > fixes this. - In any case, a single vec_delete is more efficient, so do that instead. Change-Id: Ia0db63b6c5c7891d75b302e793b4e4985dd86ebb Signed-off-by: Chris Luke <chrisy@flirble.org>
Diffstat (limited to 'src/vppinfra')
0 files changed, 0 insertions, 0 deletions
.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
//  Copyright (c) 2020 Cisco and/or its affiliates.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at:
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.

package codec

import (
	"bytes"
	"reflect"

	"github.com/lunixbochs/struc"

	"git.fd.io/govpp.git/api"
)

// Marshaler is the interface implemented by the binary API messages that can
// marshal itself into binary form for the wire.
type Marshaler interface {
	Size() int
	Marshal([]byte) ([]byte, error)
}

// Unmarshaler is the interface implemented by the binary API messages that can
// unmarshal a binary representation of itself from the wire.
type Unmarshaler interface {
	Unmarshal([]byte) error
}

type Wrapper struct {
	api.Message
}

func (w Wrapper) Size() int {
	if size, err := struc.Sizeof(w.Message); err != nil {
		return 0
	} else {
		return size
	}
}

func (w Wrapper) Marshal(b []byte) ([]byte, error) {
	buf := new(bytes.Buffer)
	if reflect.TypeOf(w.Message).Elem().NumField() > 0 {
		if err := struc.Pack(buf, w.Message); err != nil {
			return nil, err
		}
	}
	if b != nil {
		copy(b, buf.Bytes())
	}
	return buf.Bytes(), nil
}

func (w Wrapper) Unmarshal(data []byte) error {
	buf := bytes.NewReader(data)
	if err := struc.Unpack(buf, w.Message); err != nil {
		return err
	}
	return nil
}