Code Monkey home page Code Monkey logo

Comments (2)

tamama avatar tamama commented on June 2, 2024

Greetings again!

Let me answer my own question above.

It turns out that the serialized protobuf contains a lot of '\0', which obviously would mess up your C-string.
(To confirm, you can verify using your-cxx-string.size() with std::strlen(your-c-string))

The following code would then circumvent this situation...

#[no_mangle]
pub unsafe fn Rust__plugin__input__http_poller__constructor(serialized__protobuf__plugin__configuration: *const u8,
                                                            sizeof__serialized__protobuf__plugin__configuration: usize)
        -> *mut SofiaPlugin__input__http_poller
{
    let protobuf__plugin__configuration: Option<::prost_types::Struct>
        = ::prost_types::Struct::decode(::std::slice::from_raw_parts(serialized__protobuf__plugin__configuration,
                                                                     sizeof__serialized__protobuf__plugin__configuration))
                .ok();

    info!("[constructor] protobuf__plugin__configuration: {:?}", protobuf__plugin__configuration);

    let mut ctx: Box<context::Context> = context::Background();
    match SofiaPlugin__input__http_poller::new(ctx.as_ref(), protobuf__plugin__configuration) {
        Err(_) => ::std::ptr::null_mut(),
        Ok(plugin) => Box::into_raw(plugin),
    }
}

You would then see that Prost (Rust) desearializing your C-serialized protocol-buffers correctly!

Cheers!
Tama MA

from prost.

caspermeijn avatar caspermeijn commented on June 2, 2024

@tamama I am glad to see you solved your own issue. Please close the issue when you have no further questions.

from prost.

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.