Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Sources/SWONMacros/Decoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ struct SWONDecodeMacro: MemberMacro {
}
self = value
""")
case "Int", "UInt":
case "Int", "Int8", "Int16", "Int32", "Int64",
"UInt", "UInt8", "UInt16", "UInt32", "UInt64":
assignments.append("""
var num: Int32 = 0
try swon_get_integer(&num, root).check("\(enumType)")
Expand Down Expand Up @@ -196,12 +197,13 @@ private extension SWONDecodeMacro {
\(checkExpr)
return String(cString: str)
"""
case "Int":
case "Int", "Int8", "Int16", "Int32", "Int64",
"UInt", "UInt8", "UInt16", "UInt32", "UInt64":
return """
var num: Int32 = 0
let result = swon_get_integer(&num, \(varName))
\(checkExpr)
return Int(num)
return \(typeName)(num)
"""
case "Double":
return """
Expand Down
6 changes: 4 additions & 2 deletions Sources/SWONMacros/Encoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ struct SWONEncodeMacro: MemberMacro {
throw SWONError.invalid("\(enumType)(String)")
}
""")
case "Int", "UInt":
case "Int", "Int8", "Int16", "Int32", "Int64",
"UInt", "UInt8", "UInt16", "UInt32", "UInt64":
assignments.append("""
var root = swon_t()
guard swon_create_number(&root, Double(rawValue)) else {
Expand Down Expand Up @@ -399,7 +400,8 @@ private extension DecodedType {
switch description {
case "Bool":
stmts.append("guard swon_create_bool(&\(name), \(element)\(suffix)) else {")
case "Int":
case "Int", "Int8", "Int16", "Int32", "Int64",
"UInt", "UInt8", "UInt16", "UInt32", "UInt64":
stmts.append("guard swon_create_number(&\(name), Double(\(element)\(suffix))) else {")
case "Double":
stmts.append("guard swon_create_number(&\(name), \(element)\(suffix)) else {")
Expand Down
2 changes: 2 additions & 0 deletions Tests/SWONTests/ComplexStruct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ struct ComplexStruct: Equatable, Codable {
let stringToSubStruct: [String: SubStruct]
let optionalStringToSubStruct: [String: SubStruct]?
let optionalStringToSubStructArray: [String: [SubStruct]]?

let uint16: UInt16?
}

@SWON
Expand Down
3 changes: 2 additions & 1 deletion Tests/SWONTests/Resources/populated.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@
}
]
}]
}
},
"uint16": 60000
}