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

Take parsing functions as parameters to avoid need to change library #9

Open
mangalaman93 opened this issue Oct 14, 2018 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@mangalaman93
Copy link
Member

Currently we have two functions (ReadUint64 and WriteUint64) that are available to convert array of bytes into Uint64. Adding more function requires changes in the library in case of a need of different and more customized conversions.

Given that we do not want to expose the mmaped slice outside the library, this can be solved by taking conversion functions as arguments. This can clearly scope the mmaped array within the library itself.

For examples, consider following piece of code -

type RUint64 func([]byte) (uint64, error)
type WUint64 func([]byte, uint64) error

func (m *Mmap) ReadUint64(offset int, f RUint64) (uint64, error) {
        return f(m.data[offset : offset+8])
}

func (m *Mmap) WriteUint64(offset int, num uint64, f WUint64) {
	return f(m.data[offset:offset+8], num)
}

This is still not extensible to new types without changes to the library though provides customized conversion (such as for little endian architecture, big endian architecture). We can also provide default implementation for these types for direct usability.

@mangalaman93 mangalaman93 added the enhancement New feature or request label Oct 14, 2018
@mangalaman93 mangalaman93 added this to the v0.2.0 milestone Oct 14, 2018
@mangalaman93 mangalaman93 self-assigned this Oct 14, 2018
@mangalaman93 mangalaman93 modified the milestones: v0.2.0, v0.3.0 Nov 27, 2018
@mangalaman93 mangalaman93 modified the milestones: v0.2.0, v0.3.0 Dec 16, 2018
@mangalaman93 mangalaman93 modified the milestones: v0.3.0, future Mar 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant