Skip to content

Commit 7967475

Browse files
authored
Merge pull request #24 from jgr-gh/fix_codable_encoding
Switch Codable encoding scheme from a base64-encoded string wrapped in an array to just a single base64-encoded string
2 parents 7c89e04 + ee037c1 commit 7967475

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Sources/SwiftRoaring/RoaringBitmap.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ public final class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
753753
/// Encodable conformance
754754
///
755755
public func encode(to encoder: Encoder) throws {
756-
var container = encoder.unkeyedContainer()
756+
var container = encoder.singleValueContainer()
757757
let count = self.sizeInBytes()
758758
var data = Data(count: count)
759759

@@ -768,7 +768,7 @@ public final class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
768768
/// Decodable conformance
769769
///
770770
public init(from decoder: Decoder) throws {
771-
var container = try decoder.unkeyedContainer()
771+
let container = try decoder.singleValueContainer()
772772

773773
let buffer = try container.decode(String.self)
774774
let data = Data(base64Encoded: buffer)

Tests/swiftRoaringTests/swiftRoaringTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ class swiftRoaringTests: XCTestCase {
332332
let s = String(data: a, encoding: .utf8)!
333333
print(s.count)
334334
let b = try! dec.decode(RoaringBitmap.self, from: a)
335-
let expected = "[\"AjowAAABAAAAAAAxABAAAAAAAAIABAAGAAgACgAMAA4AEAASABQAFgAYABoAHAAeACAAIgAkACYAKAAqACwALgAwADIANAA2ADgAOgA8AD4AQABCAEQARgBIAEoATABOAFAAUgBUAFYAWABaAFwAXgBgAGIA\"]"
335+
let expected = "\"AjowAAABAAAAAAAxABAAAAAAAAIABAAGAAgACgAMAA4AEAASABQAFgAYABoAHAAeACAAIgAkACYAKAAqACwALgAwADIANAA2ADgAOgA8AD4AQABCAEQARgBIAEoATABOAFAAUgBUAFYAWABaAFwAXgBgAGIA\""
336336

337337
XCTAssert(s == expected)
338338

0 commit comments

Comments
 (0)