Module rspamd_text

This module provides access to opaque text structures used widely to prevent copying between Lua and C for various concerns: performance, security etc…

You can convert rspamd_text into string but it will copy data.

Brief content:

Methods:

Method Description
rspamd_text:len() Returns length of a string.
rspamd_text:str() Converts text to string by copying its content.
rspamd_text:ptr() Converts text to lightuserdata.
rspamd_text:save_in_file(fname[, mode]) Saves text in file.
rspamd_text:span(start[, len]) Returns a span for lua_text starting at pos [start] (1 indexed) and with.
rspamd_text:at(pos) Returns a byte at the position pos.
rspamd_text:bytes() Converts text to an array of bytes.

Methods

The module rspamd_text defines the following methods.

Method rspamd_text:len()

Returns length of a string

Parameters:

No parameters

Returns:

  • {number}: length of string in bytes

Back to module description.

Method rspamd_text:str()

Converts text to string by copying its content

Parameters:

No parameters

Returns:

  • {string}: copy of text as Lua string

Back to module description.

Method rspamd_text:ptr()

Converts text to lightuserdata

Parameters:

No parameters

Returns:

  • {lightuserdata}: pointer value of rspamd_text

Back to module description.

Method rspamd_text:save_in_file(fname[, mode])

Saves text in file

Parameters:

No parameters

Returns:

  • {boolean}: true if save has been completed

Back to module description.

Method rspamd_text:span(start[, len])

Returns a span for lua_text starting at pos [start] (1 indexed) and with length len (or to the end of the text)

Parameters:

  • start {integer}: start index
  • len {integer}: length of span

Returns:

  • {rspamd_text}: new rspamd_text with span (must be careful when using with owned texts…)

Back to module description.

Method rspamd_text:at(pos)

Returns a byte at the position pos

Parameters:

  • pos {integer}: index

Returns:

  • {integer}: byte at the position pos or nil if pos out of bound

Back to module description.

Method rspamd_text:bytes()

Converts text to an array of bytes

Parameters:

No parameters

Returns:

  • {table|integer}: bytes in the array (as unsigned char)

Back to module description.

Back to top.