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

Feature/unsigned int #1091

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

adamwulf
Copy link
Contributor

Adds support for UInt32 and UInt64. For the 64 bit versions, the 8 bytes are stored as a BLOB in big endian format. UInt32 are stored in a normal INTEGER column

@jberkel
Copy link
Collaborator

jberkel commented Oct 21, 2021

thanks for the PR, the build currently fails on linting

@adamwulf
Copy link
Contributor Author

Just pushed up a commit to fix the linting error

public var datatypeValue: Blob {
var bytes: [UInt8] = []
withUnsafeBytes(of: self) { pointer in
// little endian by default on iOS/macOS, so reverse to get bigEndian
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about Linux? Will this work everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah you're right, this would likely fail on non-macOS. i'll look for the right way to get defined bit order regardless of system.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the simplest way here would be

withUnsafeBytes(of: bigEndian) { pointer in
   bytes.append(contentsOf: pointer)
}

however, why is it stored as big endian by default? given that it implies a conversion in most cases.

let lBytes: [UInt8] = lhs.bytes.reversed()
let rBytes: [UInt8] = rhs.bytes.reversed()

for byteIndex in stride(from: max(lhs.bytes.count, rhs.bytes.count) - 1, to: 0, by: -1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be easier to change the iteration from 0 to bytes.count to avoid having to do reversed in the first place?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants