You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
819 B
JavaScript

"use strict";
const bytesCoder = require("./bytes");
module.exports = {
encode: function (value, asIndexKey) {
if (asIndexKey) {
throw new Error(`Not implemented yet`);
} else {
let binaryValue = Buffer.from(value, "utf8");
return bytesCoder.encode(binaryValue);
}
},
decode: function (buffer, offset) {
let result = bytesCoder.decode(buffer, offset);
if (result.auxiliaryBlob === undefined) {
// Internal blob
return {
bytesRead: result.bytesRead,
value: result.value.toString("utf8"),
auxiliaryBlob: undefined
};
} else {
// External blob
return {
bytesRead: result.bytesRead,
value: undefined,
auxiliaryBlob: {
key: result.auxiliaryBlob.key,
transform: (blob) => result.auxiliaryBlob.transform(blob).toString("utf8")
}
};
}
}
};