-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request