Fixed-length types not encoding as expected

未关闭
#33 0 条评论 5 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
javascript
领域
backend

调研方向

首先使用 r.EncodeStream、r.Struct、r.Buffer 和 r.String 复现示例,然后检查它们的编码路径如何处理固定长度。完成的标准是将两个三字节值都编码为带 null 填充的十字节缓冲区,并与预期输出匹配。

由索引模型根据 Issue 内容生成。

描述

Version: 1.0.0
Issue: I'm using restructure to unpack/pack objects for use in a binary protocol. Given "C-like structures" are a supported feature, I expected the "encode" function to align fields based on the spec provided.

If the spec states a string is 10 bytes long, shouldn't a 3-byte string be null-padded when encoded?

For example:

let stream = new r.EncodeStream();
stream.on('data', console.log);

let encoder = new r.Struct({
  foo: new r.Buffer(10),
  bar: new r.String(10)
});

encoder.encode(stream, {
  foo: Buffer.from('foo'),
  bar: 'bar'
});
stream.end();

Expected:

<Buffer 66 6f 6f 00 00 00 00 00 00 00>
<Buffer 62 61 72 00 00 00 00 00 00 00>

Actual:

<Buffer 66 6f 6f>
<Buffer 62 61 72>
主要语言
JavaScript
星标
146
派生
37
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

foliojs/restructure 的其他 Issue

查看 foliojs/restructure 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。