You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Currently we have two functions (
ReadUint64
andWriteUint64
) 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 -
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.
The text was updated successfully, but these errors were encountered: