Obtaining pointer from Bytes in Sway 0.60.0 error, compared to 0.49.2

Hi All,

I’m in the process of upgrading to Sway 0.60.0 and have a piece of code in Sway that obtains a pointer to some data bytes at an offset:

fn some_function(data: Bytes, ptr_start: u64,) {

    let src = data.buf.ptr().add_uint_offset(ptr_start);

}

In sway 0.49.2 this compiled without issue. In Sway 0.60.0 I get the following errors. There does not seem to be any difference with the definition of

pub struct Bytes {
    /// A barebones struct for the bytes.
    buf: RawBytes,
    /// The number of bytes being stored.
    len: u64,
}

in Sway 0.60.0 compared to 0.49.2: https://github.com/FuelLabs/sway/blob/9d03fbd352bb112bd637909b33967d01f1f979e6/sway-lib-std/src/bytes.sw#L84-L90

Compilation error:

296 |     let src = data.buf.ptr().add_uint_offset(ptr_start);
    |                    ^^^ Private field "buf" of the struct "Bytes" is inaccessible in this module.
    |                    --- help: Private fields can only be accessed within the module in which their struct is declared.
    |
   ::: /home/user/.forc/git/checkouts/std-9be0d6062747ea7/2f0392ee35a1e4dd80bd8034962d5b4083dfb8b6/sway-lib-std/src/bytes.sw:87:5
    |
...
 87 |     buf: RawBytes,
    |     --- info: Field "buf" is declared here as private.
    |
____

error
   --> /file.sw:296:24
    |
294 | 

296 |     let src = data.buf.ptr().add_uint_offset(ptr_start);
    |                        ^^^ No method named "ptr" found for type "{unknown}".
297 | 

    |
____

error
   --> /file.sw:296:30
    |
294 | 

296 |     let src = data.buf.ptr().add_uint_offset(ptr_start);
    |                              ^^^^^^^^^^^^^^^ No method named "add_uint_offset" found for type "{unknown}".
297 | 

...
 87 |     buf: RawBytes,
    |     --- info: Field "buf" is declared here as private.
    |
____

Any ideas how to obtain a pointer from Bytes at an integer offset with the latest Sway release?

Ok looks like the solution is to drop the “.buf”

let src = data.ptr().add_uint_offset(ptr_start);

SOLVED.

2 Likes