Skip to content

Prepend does not include the zero bytes #94

Open
@courteous

Description

@courteous

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());



  });

});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions