mirror of
https://github.com/Dev1an/MsgPack.git
synced 2026-04-27 14:57:46 +00:00
Fix Float decoding bug
This commit is contained in:
parent
068bbe87dc
commit
101abe3e46
2 changed files with 8 additions and 3 deletions
|
|
@ -135,7 +135,8 @@ struct MsgPckSingleValueDecodingContainer: SingleValueDecodingContainer {
|
||||||
guard decoder.storage[base] == FormatID.float32.rawValue else {
|
guard decoder.storage[base] == FormatID.float32.rawValue else {
|
||||||
throw Error.invalidFormat(decoder.storage[base])
|
throw Error.invalidFormat(decoder.storage[base])
|
||||||
}
|
}
|
||||||
return decoder.storage.read(at: base + 1)
|
let bitPattern: UInt32 = decoder.storage.bigEndianInteger(at: base + 1)
|
||||||
|
return .init(bitPattern: bitPattern)
|
||||||
}
|
}
|
||||||
|
|
||||||
func decode(_ type: Double.Type) throws -> Double {
|
func decode(_ type: Double.Type) throws -> Double {
|
||||||
|
|
|
||||||
|
|
@ -40,5 +40,9 @@ for byte in encodedGraph {
|
||||||
|
|
||||||
let decoder = Decoder()
|
let decoder = Decoder()
|
||||||
|
|
||||||
let int8 = try encoder.encode(Double(-10))
|
func roundtrip<T: Codable>(value: T) throws -> T {
|
||||||
try decoder.decode(Double.self, from: int8)
|
return try decoder.decode(T.self, from: encoder.encode(value))
|
||||||
|
}
|
||||||
|
|
||||||
|
var x: UInt64? = nil
|
||||||
|
try roundtrip(value: false)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue