Giter Club home page Giter Club logo

Comments (1)

fraillt avatar fraillt commented on August 18, 2024

Hello,
Good question and it certainly is not obvious how to make it work.
Writing to output buffer happens through OutputBufferAdapter class, and it has a currentWritePos method, which does what you need.
IMPORTANT: keep in mind that writtenBytesCount will return the final position in the buffer.
Example: if you set currentWritePos to 10 and write 4 bytes, writtenBytesCount will return 14, not 4.
Here, is a modified main function of basic_usage example.

int main() {
    //set some random data
    MyStruct data{8941, MyEnum::V2, {15.0f, -8.5f, 0.045f}};
    MyStruct res{};
    data.tmp.push_back(data);

    //create buffer to store data
    Buffer buffer;

    size_t my_offset = 10;
    // create adapter manually, that later will be moved into serialized (serialized/deserializer always owns adapter)
    OutputAdapter adapter{buffer};
    // set offset (which in turn resizes buffer is necessary)
    adapter.currentWritePos(my_offset);
    // minus my_offset from actual returned value
    auto writtenSize = bitsery::quickSerialization<OutputAdapter>(std::move(adapter), data) - my_offset;
    // add our offset
    auto beginIt = buffer.begin() + my_offset;

    auto state = bitsery::quickDeserialization<InputAdapter>({beginIt, writtenSize}, res);

    assert(state.first == bitsery::ReaderError::NoError && state.second);
    assert(data.fs == res.fs && data.i == res.i && data.e == res.e);
}

Btw, I'm glad you find this library useful!
Happy coding ;)

from bitsery.

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.