Class: NodejsBufferTextEncoder

bre/lib/text-encoders.NodejsBufferTextEncoder

The text encoder which uses only Nodejs's Buffer.

The list of supported encodings is here.

It needs to set a text encoder before you define string fields of records.

const bre = require("bre")
bre.setTextEncoder(require("bre/lib/text-encoders/buffer"))

const ExampleRecord = bre.defineObjectRecord("ExampleRecord", [
    {type: "string(15)", name: "s"},
    {type: "utf8(32)", name: "utf8"},
])

Note: This encoder depends on Node.js Buffer, so does not fit to browsers.

Constructor

new NodejsBufferTextEncoder()

Source:

Methods

decode(data, byteOffset, byteLength, encoding) → {string}

Converts the given binary data to the string of the binary data.

Parameters:
Name Type Description
data DataView

the binary data to decode.

byteOffset number

The start index of text data in the data.

byteLength number

The length of text data in the data.

encoding string

The encoding type.

Source:
Returns:

Decoded string data.

Type
string

encode(text, encoding) → {DataView}

Converts the given string to the binary data of the string.

Parameters:
Name Type Description
text string

The text to encode.

encoding string

The encoding type to encode.

Source:
Returns:

Encoded binary data.

Type
DataView

encodingExists(value) → {boolean}

Checks whether the given string is a valid encoding type or not.

Parameters:
Name Type Description
value any

The value to check.

Source:
Returns:

true if the value is a valid encoding type.

Type
boolean