Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepend does not include the zero bytes #94

Open
courteous opened this issue Jul 1, 2018 · 0 comments
Open

Prepend does not include the zero bytes #94

courteous opened this issue Jul 1, 2018 · 0 comments

Comments

@courteous
Copy link

I have noticed a behaviour that i can not explain thus i am asking this question. To me it seems that the behaviour of append and prepend differs. I would like to explain.

Lets say that i would like to append a buffer of 5 bytes !!!that has zero bytes in it!!! to another one that has a capasity of 20 then it all works as expected i.e. the capasity is not increased and the zero bytes included in the buffer that had the capacity of 5 are also appended correctly.
However if i try to do the same trick with prepend then the capsity is increased but not to the expected one i.e. it is 24 instead of 25 and to me it seems like the zero byte is not prepended correctly.

here is an simple test in type script


import { expect } from 'chai';
import ByteBuffer  = require("bytebuffer");

import { PrintUtils } from '../ts/utility/PrintUtils';

describe('Prepends to an existing ByteBuffer some other buffer', () => {

  it('should prepends another buffer to an existing one ', () => {
    

    var buffer = new ByteBuffer(20);
    

    PrintUtils.printBuffer(buffer);
    var testAppend5bytes = new ByteBuffer(5);
    testAppend5bytes.writeInt32(34124356);
    // need to flip the buffer before it can be used
    testAppend5bytes.flip(); 
    PrintUtils.printBuffer(testAppend5bytes);
    buffer.prepend(testAppend5bytes, "binary", 0);

    PrintUtils.printBuffer(buffer);
    
    expect(25).to.equal(buffer.capacity());



  });

});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant