lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi Tobias

It seems strange to me that the Segment does not refer to the buffer. Would'nt you need to provide the buffer? Something like:

b = Buffer (1024)
s1 = b:Segment (128, 256) -- from 128 to 384
s2 = b:Segment (439) -- from 439 to 1024 (which is the end of the buffer)

IMHO, since the offset is the first argument, it seems to me that it should be more important than the length, thus the above interpretation.


On 2017-09-18 15:18, wrote:
Hi there,

I'm designing a library which has a Buffer module that allows to
contain binary data.  Think of it as a string just with less features
:-P ... except it is mutable.  Now I'm writing a companion module
called Buffer.Segment that allows access to just a limited part of the
 buffer which is defined by an offset and a length.  I'd plan the API
look like this:

b  = Buffer( 1024 )      -- buffer with 124 bytes
s  = Segment( b )        -- creates a segment starting at the first
byte of the buffer as long as the buffer itself
s1 = Segment( 128, 256 ) -- Segment with 128 byte offset and 256 bytes length
s2 = Segment( 439 )      -- this is the question, shall this be:

                     - a segment starting at byte 439 and have a
length to the end of the buffer, or
- a segment starting at first byte being 439 bytes long

I don't think there is a 'right' answer, but to all those people who
work with this kind of stuff, what would feel more natural to you?
Also, does Segment( offset, length ) makes more sense than Segment(
length, offset ) ?

Thanks for the input,

 - Tobias