模极社社区 - 制造业全产业链交流平台

    • 登录
    • 版块
    • 最新
    • 话题
    • 热门
    • 用户
    • 群组

    BSER Binary Serialization

    社区公告
    1
    1
    0
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • S
      system 2 最后由 编辑

      <h2>BSER Binary Serialization</h2>

      <p>BSER is a binary serialization scheme that can be used as an alternative to JSON.</p>
      <p>BSER uses a framed encoding that makes it simpler to use to stream a sequence of</p>
      <p>encoded values.</p>

      <p>It is intended to be used for local-IPC only and strings are represented as binary</p>
      <p>with no specific encoding; this matches the convention employed by most operating</p>
      <p>system filename storage.</p>

      <p>For more details about the serialization scheme see</p>
      <p><a href="https://facebook.github.io/watchman/docs/bser.html">Watchman's docs</a>.</p>

      <h3>API</h3>

      <pre><code>
      var bser = require('bser');
      </code></pre>

      <h4>bser.loadFromBuffer</h4>

      <p>The is the synchronous decoder; given an input string or buffer,</p>
      <p>decodes a single value and returns it. Throws an error if the</p>
      <p>input is invalid.</p>

      <pre><code>
      var obj = bser.loadFromBuffer(buf);
      </code></pre>

      <h4>bser.dumpToBuffer</h4>

      <p>Synchronously encodes a value as BSER.</p>

      <pre><code>
      var encoded = bser.dumpToBuffer(['hello']);
      console.log(bser.loadFromBuffer(encoded)); // ['hello']
      </code></pre>

      <h4>BunserBuf</h4>

      <p>The asynchronous decoder API is implemented in the BunserBuf object.</p>
      <p>You may incrementally append data to this object and it will emit the</p>
      <p>decoded values via its <code>value</code> event.</p>

      <pre><code>
      var bunser = new bser.BunserBuf();

      bunser.on('value', function(obj) {
      console.log(obj);
      });
      </code></pre>

      <p>Then in your socket <code>data</code> event:</p>

      <pre><code>
      bunser.append(buf);
      </code></pre>

      <h3>Example</h3>

      <p>Read BSER from socket:</p>

      <pre><code>
      var bunser = new bser.BunserBuf();

      bunser.on('value', function(obj) {
      console.log('data from socket', obj);
      });

      var socket = net.connect('/socket');

      socket.on('data', function(buf) {
      bunser.append(buf);
      });
      </code></pre>

      <p>Write BSER to socket:</p>

      <pre><code>
      socket.write(bser.dumpToBuffer(obj));
      </code></pre>

      <hr>

      <p>本文由模极社发布</p>

      <h4>📋 内容概览</h4>

      <table>
      <tr><td>分类</td><td>要点</td><td>建议/说明</td></tr>
      <tr><td>核心概念</td><td>BSER Binary Serializ</td><td>详见正文</td></tr>
      <tr><td>操作步骤</td><td>BSER Binary Serializ</td><td>详见正文</td></tr>
      <tr><td>注意事项</td><td>BSER Binary Serializ</td><td>详见正文</td></tr>
      <tr><td>适用场景</td><td>BSER Binary Serializ</td><td>详见正文</td></tr>
      <tr><td>常见问题</td><td>BSER Binary Serializ</td><td>详见正文</td></tr>
      </table>

      <hr>
      <h4>🔗 你可能还感兴趣</h4>
      <ul>
      <li><a href="/t/3750/3750">典型卫浴产品模具选型案例集</a></li>
      <li><a href="/t/3828/3828">Amaplast(意大利塑料橡胶加工机械和模具制造行业组织)</a></li>
      <li><a href="/t/4361/4361">inflight</a></li>
      </ul>

      <hr>
      <p><strong>相关推荐:</strong></p>
      <ul>
      <li><a href="https://www.mj7.cn/t/4836-4836">北京模具产业 — 科技研发驱动型模具基地</a></li>
      <li><a href="https://www.mj7.cn/t/4835-4835">上海模具产业 — 高端精密模具研发中心</a></li>
      <li><a href="https://www.mj7.cn/t/4834-4834">产业集群与模具产业发展的关系</a></li>
      </ul>

      <hr>
      <p>各位师傅觉得这个方案怎么样?有更好的做法吗?</p>

      1 条回复 最后回复 回复 引用 0
      • First post
        Last post
      Powered by NodeBB | Contributors