Giter Site home page Giter Site logo

char array about bytebuffer.js HOT 5 CLOSED

majimboo avatar majimboo commented on June 26, 2024
char array

from bytebuffer.js.

Comments (5)

dcodeIO avatar dcodeIO commented on June 26, 2024

Well, it's 32 bytes. You may either #slice(offset, offset+32) it or read it sequentially through calling #readUint8(offset++) successively.

You might also want to take a look at the API docs.

from bytebuffer.js.

majimboo avatar majimboo commented on June 26, 2024

Sorry, I still don't get it. I currently need to write it. It's actually a string. Let us say

UINT8 data[16]
UINT8 data[16]

Could be

42 75 66 66 65 72 00 00 00 00 00 00 00 00 00 00 4d 61 74 74 65 72 00 00 00 00 00 00 00 00 00 00

If I try to

writeString('Buffer', 16) // suggestion
writeString('Matter', 16) // suggestion

from bytebuffer.js.

dcodeIO avatar dcodeIO commented on June 26, 2024
  1. Remember the current offset
  2. Write the string
  3. While 16 bytes are not reached, write 0
var s = "Buffer",
    o = bb.offset;
bb.writeString(s);
while (bb.offset < o + 16)
    bb.writeUint8(0);
...

from bytebuffer.js.

majimboo avatar majimboo commented on June 26, 2024

Would love to see this get supported with bytebuffer. Cheers, great as always.

from bytebuffer.js.

dcodeIO avatar dcodeIO commented on June 26, 2024

You may also extend the prototype with your use case specific code for comfort and a bit of speed:

mybytebuffer.js

var ByteBuffer = require("bytebuffer");

ByteBuffer.prototype.writeStringPadded = function(s, len) {
    var end = this.offset + len;
    this.ensureCapacity(end);
    this.writeString(s);
    while (this.offset < end)
        this.writeUint8(0);
    return this;
};

module.exports = ByteBuffer;
var ByteBuffer = require("mybytebuffer.js");
var bb = new ByteBuffer();
bb.writeStringPadded("Buffer", 16);
...

from bytebuffer.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.