Skip to content

Commit

Permalink
issue-#419 Add Packet Padder Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Vazquez authored and Adrian Vazquez committed Mar 4, 2022
1 parent 337da65 commit 86bf9ce
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ait/core/server/plugins/PacketPadder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from ait.core.server.plugins import Plugin
from ait.core import log


class PacketPadder(Plugin):
def __init__(self, inputs=None, outputs=None, zmq_args=None, pad_octets=0, **kwargs):
if pad_octets >= 0:
self.size_pad_octets = pad_octets
else:
self.size_pad_octets = 0
log.error(f"PacketPadder -> Pad value{pad_octets} octets must be a \
positive integer! Bypassing padding!")
super().__init__(inputs, outputs, zmq_args)

def process(self, data, topic=None):
if len(data) < self.size_pad_octets:
fill = bytearray(self.size_pad_octets - len(data))
data = data + fill
self.publish(data)
21 changes: 21 additions & 0 deletions doc/source/plugin_PacketPadder.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Packet Padder Plugin
========================
The packet padder plugin pads command processing pipeline data to a user configured size in octets.

If the size of pipeline data in octets is less than the user specified value, the pipline will pad 0s to achieve the specified size.

Configuration
-------------

Add and customize the following template in your config.yaml

.. code-block:: none
- plugin:
name: ait.core.server.plugins.PacketPadder.PacketPadder
inputs:
- PacketAccumulator
pad_octets: 987
The *pad_octets* option specifies the minimum size to pad the data to. The plugin will not modify the data if its size already meets or exceeds this value. A negative, 0, or missing value will bypass the plugin.

Use *inputs* to specify which PUB/SUB topic the plugin should receive pipeline data from.

0 comments on commit 86bf9ce

Please sign in to comment.