Skip to main content

Opcode

Enum Opcode 

Source
#[repr(u8)]
pub enum Opcode {
Show 28 variants PushTrue = 1, PushFalse = 2, Contains = 16, StartsWith = 17, EndsWith = 18, Equals = 19, Matches = 32, And = 48, Or = 49, Not = 50, PartContains = 64, PartStartsWith = 65, PartEndsWith = 66, PartEquals = 67, PartMatches = 68, PartIsEmpty = 69, PartNotEmpty = 70, PartInSet = 71, PartIEquals = 72, PartIContains = 73, HeaderEquals = 80, HeaderIEquals = 81, HeaderContains = 82, HeaderExists = 83, JumpIfFalse = 112, JumpIfTrue = 113, Rand = 96, Return = 255,
}
Expand description

Bytecode opcodes for the filter VM.

Encoding:

  • 1-byte opcode
  • Variable operands depending on opcode type

Variants§

§

PushTrue = 1

Push true onto the stack.

§

PushFalse = 2

Push false onto the stack.

§

Contains = 16

Check if payload contains the string at index. Bytecode: [0x10, idx_lo, idx_hi]

§

StartsWith = 17

Check if payload starts with the string at index. Bytecode: [0x11, idx_lo, idx_hi]

§

EndsWith = 18

Check if payload ends with the string at index. Bytecode: [0x12, idx_lo, idx_hi]

§

Equals = 19

Check if payload equals the string at index. Bytecode: [0x13, idx_lo, idx_hi]

§

Matches = 32

Check if payload matches the regex at index. Bytecode: [0x20, idx_lo, idx_hi]

§

And = 48

Pop 2 booleans, push (a AND b). Bytecode: [0x30]

§

Or = 49

Pop 2 booleans, push (a OR b). Bytecode: [0x31]

§

Not = 50

Pop 1 boolean, push (NOT a). Bytecode: [0x32]

§

PartContains = 64

Check if parts[part_idx] contains string at index. Bytecode: [0x40, part_idx, str_idx_lo, str_idx_hi]

§

PartStartsWith = 65

Check if parts[part_idx] starts with string at index. Bytecode: [0x41, part_idx, str_idx_lo, str_idx_hi]

§

PartEndsWith = 66

Check if parts[part_idx] ends with string at index. Bytecode: [0x42, part_idx, str_idx_lo, str_idx_hi]

§

PartEquals = 67

Check if parts[part_idx] equals string at index. Bytecode: [0x43, part_idx, str_idx_lo, str_idx_hi]

§

PartMatches = 68

Check if parts[part_idx] matches regex at index. Bytecode: [0x44, part_idx, regex_idx_lo, regex_idx_hi]

§

PartIsEmpty = 69

Check if parts[part_idx] is empty. Bytecode: [0x45, part_idx]

§

PartNotEmpty = 70

Check if parts[part_idx] is not empty. Bytecode: [0x46, part_idx]

§

PartInSet = 71

Check if parts[part_idx] equals any string in a set. Bytecode: [0x47, part_idx, set_idx_lo, set_idx_hi]

§

PartIEquals = 72

Case-insensitive equality check for parts[part_idx]. Bytecode: [0x48, part_idx, str_idx_lo, str_idx_hi]

§

PartIContains = 73

Case-insensitive contains check for parts[part_idx]. Bytecode: [0x49, part_idx, str_idx_lo, str_idx_hi]

§

HeaderEquals = 80

Extract header from parts[part_idx], check exact equality. Bytecode: [0x50, part_idx, hdr_idx_lo, hdr_idx_hi, val_idx_lo, val_idx_hi]

§

HeaderIEquals = 81

Extract header from parts[part_idx], check case-insensitive equality. Bytecode: [0x51, part_idx, hdr_idx_lo, hdr_idx_hi, val_idx_lo, val_idx_hi]

§

HeaderContains = 82

Extract header from parts[part_idx], check if value contains string. Bytecode: [0x52, part_idx, hdr_idx_lo, hdr_idx_hi, val_idx_lo, val_idx_hi]

§

HeaderExists = 83

Check if header exists in parts[part_idx]. Bytecode: [0x53, part_idx, hdr_idx_lo, hdr_idx_hi]

§

JumpIfFalse = 112

If top of stack is false, jump by i16 offset (leave false on stack). If true, pop and continue to evaluate right operand. Bytecode: [0x70, offset_lo, offset_hi]

§

JumpIfTrue = 113

If top of stack is true, jump by i16 offset (leave true on stack). If false, pop and continue to evaluate right operand. Bytecode: [0x71, offset_lo, offset_hi]

§

Rand = 96

Returns true with probability 1/N. Bytecode: [0x60, n_lo, n_hi]

§

Return = 255

Return the top of the stack as the filter result. Bytecode: [0xFF]

Implementations§

Source§

impl Opcode

Source

pub fn from_byte(byte: u8) -> Option<Self>

Decode an opcode from a byte.

Source

pub fn instruction_size(&self) -> usize

Get the size of this instruction in bytes (opcode + operands).

Trait Implementations§

Source§

impl Clone for Opcode

Source§

fn clone(&self) -> Opcode

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Opcode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Opcode

Source§

fn eq(&self, other: &Opcode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Opcode

Source§

impl Eq for Opcode

Source§

impl StructuralPartialEq for Opcode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.