RedBencode:
Filter:
redSys/Classes (extension) | Red > redTools

RedBencode
ExtensionExtension

Bencode encoder and decoder

Description

Read about this format here... http://en.wikipedia.org/wiki/Bencode

Class Methods

.encode

Encodes an array of items as a bencoded string.

Arguments:

array

Expects an Array with items of the following kind...

For example here is a valid argument with different items...

Returns:

A String containing the encoded data. For example...

.encodeBytes

Same as *encode but returns an array with 8bit bytes suitable for sending over serial port.

Returns:

An Int8Array containing the encoded data as 8bit bytes. For example...

.decodeBytes

Same as *decode but useful when decoding data received from the serial port.

Arguments:

array

An Int8Array with 8bit values.

.decodeString

Same as *decode but takes a String as argument. This is the more common method for decoding (compare *decode and *decodeBytes).

Arguments:

string

A bencoded String

.decode

Decodes a bencoded stream of characters in to an array of items (Integer, String, Array, Dictionary). Usually it is easier to use the *decodeString method as it will automatically create a CollStream out of the argument string.

NOTE: Event will become Dictionary and List will become Array.

Arguments:

stream

A CollStream.

Examples