Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast slice to bytesn #2

Open
rainbreak opened this issue May 11, 2016 · 2 comments
Open

Cast slice to bytesn #2

rainbreak opened this issue May 11, 2016 · 2 comments
Assignees

Comments

@rainbreak
Copy link

Thanks for your work on this - I'm looking forward to using it when it's stable.

Is it possible to enable functions like this:

function extract (bytes data, uint offset) returns (bytes4) {
    return bytes4(data.slice(offset, offset + 4))
}

i.e. returning a bytesn value type from a slice of bytes?

My current workaround feels clunky:

function extract (bytes data, uint offset) returns (bytes4) {
    uint32 ret = 0;
    for (uint32 i = 0; i < 4; i++) {
        ret += uint32(data[i + offset]) * 2 ** ((3 - i) * 8);
    }
    return (bytes4(ret));
} 
@androlo
Copy link
Owner

androlo commented Jun 2, 2016

it requires 32 functions since it is 32 bytes types. There is one for byte, and one for bytes32 and some other types in the works (same as the RLP contract has).

Very sorry for the late reply, announcements were off for some reason.

@androlo androlo self-assigned this Jun 2, 2016
@rainbreak
Copy link
Author

No worries. Makes sense. Thanks!

Repository owner deleted a comment from akashakki Mar 1, 2024
Repository owner deleted a comment from huzhen-v5 Mar 4, 2024
@github-staff github-staff deleted a comment Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants