Пример #1
0
func (p *ReusingLayerParser) recycleOne(layer gopacket.DecodingLayer) {
	typ := layer.CanDecode().LayerTypes()[0]
	lc := p.layerCache[typ]
	if lc == nil {
		lc = &[]gopacket.DecodingLayer{}
		p.layerCache[typ] = lc
	}
	*lc = append(*lc, layer)
}
Пример #2
0
func (p *ReusingLayerParser) tryDecode(tp *TypedPayload, oldLayer gopacket.DecodingLayer) (layer gopacket.DecodingLayer, err error) {
	if oldLayer != nil && oldLayer.CanDecode().Contains(tp.Type) {
		layer = oldLayer
	} else {
		if oldLayer != nil {
			p.recycleOne(oldLayer)
		}
		if layer, err = p.getDecodingLayer(tp.Type); err != nil {
			return
		}
	}
	if err = layer.DecodeFromBytes(tp.Payload, p.df); err != nil {
		p.recycleOne(layer)
		layer = nil
	}
	return
}