node.js - 库 cbor 在转换中引入了一个新值
问题描述
我在node.js上做的这个程序,有异常。当我进行 decodeAllSync 时,我得到一个十进制数字的向量,它的数字比通过使用 encodeAsync 重新转换向量得到的数字少一个。为什么我没有得到相同的向量?谢谢
const cbor = require('cbor');
...
const results = cbor.decodeAllSync(output);
const input = cbor.encodeAsync(results);
console.log(output);
input.then(
function (x) {
var v=new Uint8Array(x);
console.log(v);
},
function () {
console.log("fail ");
});
我收到输入的打印输出:
Uint8Array [
129,
210,
132,
77,
...
我收到输出的打印输出:
Uint8Array [
210,
132,
77,
...
解决方案
cbor.decodeAllSync
使用 n 个参数返回一个包含 n 个条目的数组。所以你编码的东西[]
周围有一对额外的。
> cbor.decodeAllSync(cbor.encode(1))
[ 1 ]
> cbor.decode(cbor.encode(1))
1
推荐阅读
- r - 如何使用 R 将一个向量中的多个数据组合成一个数据?
- sql - 基于朋友去的事件的数据库查询
- javascript - React 功能组件 - 说它不是功能
- javascript - 如果找不到元素,将变量设置为 getElementById 的值或默认值的最简洁方法是什么?
- python - 从python中的类访问布尔值
- internet-explorer - 维基媒体地图在 Internet Explorer 上返回错误 429
- python - 阅读熊猫时如何克服Mac中的操作系统错误
- c# - 如何在设计模式下在 Windows 窗体组合框中添加多个项目?
- python - 我应该如何基于公共列组合表格?
- selenium-webdriver - 如何切换到 doctype html 中的元素?我使用切换到 iframe 并且不起作用