-
Notifications
You must be signed in to change notification settings - Fork 18
Support Embedded Swift #72
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
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
public enum JSONValue { | ||
public enum JSONValue: Sendable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realised just before submitting this PR that this is not strictly necessary. But given that all of the enum cases themselves are Sendable, I think this is correct and desirable. Let me know if you'd like me to revert the change
throw JSONError.couldNotCreateUnicodeScalarFromUInt32( | ||
in: output!, index: failureIndex, unicodeScalarValue: unicodeScalarValue | ||
) | ||
switch error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving this to a single switch statement rather than multiple catch statements cleans up the code somewhat by removing repetition. More importantly, Swift didn't seem to recognise that all cases are satisfied without this change
case expectedLowSurrogateUTF8SequenceAfterHighSurrogate(index: Int) | ||
case unexpectedEscapedCharacter(ascii: UInt8, index: Int) | ||
case couldNotCreateUnicodeScalarFromUInt32(index: Int, unicodeScalarValue: UInt32) | ||
case jsonError(JSONError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is arguably the biggest "functional change" of the PR, and I'm not extremely happy about it, but I couldn't find a better way of keeping to a single error type per function (noting that some of these functions throw JSONError
or EscapedSequenceError
)
I think it's fine though, especially given that EscapedSequenceError
is internal to the library.
Hallo aus Berlin @fabianfett,
We're interested in using
JSONValue
with Embedded Swift to manually encode and decode values like in your example here. We could just "rip out" the bits we need, but I thought this functionality might be useful for some of your audience as well.Note that
Codable
and co are not available on Embedded at all, so the library without these changes does not compile.With this change, users have a minimal but totally usable JSON implementation for Embedded platforms and devices.
Note that the resulting Embedded Swift binary must be compiled with
-l swiftUnicodeDataTables
, found in the respective embedded library directory of the Swift toolchain, for example:With this, I'm able to build a test file via Embedded Swift:
What do you think?