Giter VIP home page Giter VIP logo

Comments (7)

dwrensha avatar dwrensha commented on June 24, 2024 1

I removed the first parameter in 9738fed.

from capnproto-rust.

dwrensha avatar dwrensha commented on June 24, 2024 1

I opened a PR for adding public visibility tot he relevant items: #489.

from capnproto-rust.

dwrensha avatar dwrensha commented on June 24, 2024

What if we add public visibility to ReadSegmentTableResult, read_segment_table(), and NoAllocBufferSegments::from_segment_table()? (These things are currently at private or crate-only visibility.)

Then I think you would be able get the message length from ReadSegmentTableResult before constructing the BufferSegments.

from capnproto-rust.

hs-vc avatar hs-vc commented on June 24, 2024

What if we add public visibility to ReadSegmentTableResult, read_segment_table(), and NoAllocBufferSegments::from_segment_table()? (These things are currently at private or crate-only visibility.)

Then I think you would be able get the message length from ReadSegmentTableResult before constructing the BufferSegments.

In my case, I don't need to use read_segment_table() which requires a complete slice because I need to parse the header while reading from the socket to get complete messages.
So I am reading bytes partially from the socket and parsing the header directly to determine the total message length. In fact, exposing NoAllocBufferSegments::from_segment_table() to public seems sufficient.

BTW, is there a reason why NoAllocBufferSegmentType is defined as:

enum NoAllocBufferSegmentType {
    SingleSegment(usize, usize),
    MultipleSegments,
}

Instead of:

enum NoAllocBufferSegmentType {
    SingleSegment,
    MultipleSegments,
}

In the case of SingleSegment, segment_table_length_bytes must always be 8, and the message length is also inferred from the buffer. In fact, in version 0.17, NoAllocSliceSegments requires buffer only for both of SingleSegment and MultipleSegments

from capnproto-rust.

dwrensha avatar dwrensha commented on June 24, 2024

In the case of SingleSegment, segment_table_length_bytes must always be 8, and the message length is also inferred from the buffer.

Hm... I agree that it looks like the first parameter is not needed. The second parameter however might point to before the end of the buffer if from_buffer() is called on something that's longer than the message:

pub fn from_buffer(buffer: T, options: ReaderOptions) -> Result<Self> {
let segment_table_info = read_segment_table(buffer.as_ref(), options)?;
Ok(Self::from_segment_table(buffer, segment_table_info))
}

from capnproto-rust.

hs-vc avatar hs-vc commented on June 24, 2024

@dwrensha Thanks for your prompt help. I really appreciate it!

from capnproto-rust.

dwrensha avatar dwrensha commented on June 24, 2024

Closed by #489.

from capnproto-rust.

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.