Skip to content

Commit 4955ab5

Browse files
committed
Added fixed size arrays and their generator, generated sizes from 1 to 256
1 parent d5394f8 commit 4955ab5

File tree

260 files changed

+11021
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

260 files changed

+11021
-0
lines changed

Example/ScaleCodecSwift.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
3535
A6AD4409798F9F0A3122ADBB /* Pods_ScaleCodecSwift_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D6C2341B483543A11ED7D71 /* Pods_ScaleCodecSwift_Example.framework */; };
3636
C7542D55296FD3A500D4606D /* AdapterProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7542D54296FD3A500D4606D /* AdapterProtocolTests.swift */; };
37+
C7B811212972809400BAE319 /* FixedSizeArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7B811202972809400BAE319 /* FixedSizeArrayTests.swift */; };
3738
/* End PBXBuildFile section */
3839

3940
/* Begin PBXContainerItemProxy section */
@@ -83,6 +84,7 @@
8384
94D9D7D0A540F3DBB2DB56D2 /* Pods-ScaleCodecSwift_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ScaleCodecSwift_Tests.debug.xcconfig"; path = "Target Support Files/Pods-ScaleCodecSwift_Tests/Pods-ScaleCodecSwift_Tests.debug.xcconfig"; sourceTree = "<group>"; };
8485
B9F5545EEDDF89E927CBD079 /* Pods-ScaleCodecSwift_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ScaleCodecSwift_Example.debug.xcconfig"; path = "Target Support Files/Pods-ScaleCodecSwift_Example/Pods-ScaleCodecSwift_Example.debug.xcconfig"; sourceTree = "<group>"; };
8586
C7542D54296FD3A500D4606D /* AdapterProtocolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdapterProtocolTests.swift; sourceTree = "<group>"; };
87+
C7B811202972809400BAE319 /* FixedSizeArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FixedSizeArrayTests.swift; sourceTree = "<group>"; };
8688
D51B06D7123C18EF5AC22025 /* Pods-ScaleCodecSwift_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ScaleCodecSwift_Example.release.xcconfig"; path = "Target Support Files/Pods-ScaleCodecSwift_Example/Pods-ScaleCodecSwift_Example.release.xcconfig"; sourceTree = "<group>"; };
8789
D91F409B4E55A15F4F873D03 /* ScaleCodecSwift.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = ScaleCodecSwift.podspec; path = ../ScaleCodecSwift.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
8890
/* End PBXFileReference section */
@@ -172,6 +174,7 @@
172174
607FACE81AFB9204008FA782 /* Tests */ = {
173175
isa = PBXGroup;
174176
children = (
177+
C7B811202972809400BAE319 /* FixedSizeArrayTests.swift */,
175178
1111B34128FDDFF70019844F /* Types */,
176179
1111B34628FDDFF70019844F /* Base */,
177180
C7542D54296FD3A500D4606D /* AdapterProtocolTests.swift */,
@@ -424,6 +427,7 @@
424427
11882BFF28FDE5E30029E4BD /* BoolTests.swift in Sources */,
425428
11882C0528FDE5E80029E4BD /* BaseTest.swift in Sources */,
426429
11882C0128FDE5E30029E4BD /* BigUIntTests.swift in Sources */,
430+
C7B811212972809400BAE319 /* FixedSizeArrayTests.swift in Sources */,
427431
C7542D55296FD3A500D4606D /* AdapterProtocolTests.swift in Sources */,
428432
11353EA729397E1B00744B0B /* Int256Tests.swift in Sources */,
429433
11882C0228FDE5E30029E4BD /* StringTests.swift in Sources */,

Example/Tests/FixedSizeArrayTests.swift

+3,588
Large diffs are not rendered by default.

ScaleCodecFixedArrayGenerator

186 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
3+
// MARK: - Array1 + Encodable
4+
5+
@propertyWrapper public struct Array1<Element> {
6+
public var wrappedValue: [Element]
7+
public init(wrappedValue: [Element]) {
8+
self.wrappedValue = wrappedValue
9+
}
10+
}
11+
12+
// MARK: - Array1 + Encodable
13+
14+
extension Array1: Encodable where Element : Encodable {
15+
public func encode(to encoder: Encoder) throws {
16+
guard wrappedValue.count == 1 else { throw FixedArrayError.invalidSize }
17+
var container = encoder.unkeyedContainer()
18+
try wrappedValue.forEach { try container.encode($0) }
19+
}
20+
}
21+
22+
// MARK: - Array1 + Decodable
23+
24+
extension Array1: Decodable where Element : Decodable {
25+
public init(from decoder: Decoder) throws {
26+
var container = try decoder.unkeyedContainer()
27+
wrappedValue = try (0..<1).map { _ in try container.decode(Element.self) }
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
3+
// MARK: - Array10 + Encodable
4+
5+
@propertyWrapper public struct Array10<Element> {
6+
public var wrappedValue: [Element]
7+
public init(wrappedValue: [Element]) {
8+
self.wrappedValue = wrappedValue
9+
}
10+
}
11+
12+
// MARK: - Array10 + Encodable
13+
14+
extension Array10: Encodable where Element : Encodable {
15+
public func encode(to encoder: Encoder) throws {
16+
guard wrappedValue.count == 10 else { throw FixedArrayError.invalidSize }
17+
var container = encoder.unkeyedContainer()
18+
try wrappedValue.forEach { try container.encode($0) }
19+
}
20+
}
21+
22+
// MARK: - Array10 + Decodable
23+
24+
extension Array10: Decodable where Element : Decodable {
25+
public init(from decoder: Decoder) throws {
26+
var container = try decoder.unkeyedContainer()
27+
wrappedValue = try (0..<10).map { _ in try container.decode(Element.self) }
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
3+
// MARK: - Array100 + Encodable
4+
5+
@propertyWrapper public struct Array100<Element> {
6+
public var wrappedValue: [Element]
7+
public init(wrappedValue: [Element]) {
8+
self.wrappedValue = wrappedValue
9+
}
10+
}
11+
12+
// MARK: - Array100 + Encodable
13+
14+
extension Array100: Encodable where Element : Encodable {
15+
public func encode(to encoder: Encoder) throws {
16+
guard wrappedValue.count == 100 else { throw FixedArrayError.invalidSize }
17+
var container = encoder.unkeyedContainer()
18+
try wrappedValue.forEach { try container.encode($0) }
19+
}
20+
}
21+
22+
// MARK: - Array100 + Decodable
23+
24+
extension Array100: Decodable where Element : Decodable {
25+
public init(from decoder: Decoder) throws {
26+
var container = try decoder.unkeyedContainer()
27+
wrappedValue = try (0..<100).map { _ in try container.decode(Element.self) }
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
3+
// MARK: - Array101 + Encodable
4+
5+
@propertyWrapper public struct Array101<Element> {
6+
public var wrappedValue: [Element]
7+
public init(wrappedValue: [Element]) {
8+
self.wrappedValue = wrappedValue
9+
}
10+
}
11+
12+
// MARK: - Array101 + Encodable
13+
14+
extension Array101: Encodable where Element : Encodable {
15+
public func encode(to encoder: Encoder) throws {
16+
guard wrappedValue.count == 101 else { throw FixedArrayError.invalidSize }
17+
var container = encoder.unkeyedContainer()
18+
try wrappedValue.forEach { try container.encode($0) }
19+
}
20+
}
21+
22+
// MARK: - Array101 + Decodable
23+
24+
extension Array101: Decodable where Element : Decodable {
25+
public init(from decoder: Decoder) throws {
26+
var container = try decoder.unkeyedContainer()
27+
wrappedValue = try (0..<101).map { _ in try container.decode(Element.self) }
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
3+
// MARK: - Array102 + Encodable
4+
5+
@propertyWrapper public struct Array102<Element> {
6+
public var wrappedValue: [Element]
7+
public init(wrappedValue: [Element]) {
8+
self.wrappedValue = wrappedValue
9+
}
10+
}
11+
12+
// MARK: - Array102 + Encodable
13+
14+
extension Array102: Encodable where Element : Encodable {
15+
public func encode(to encoder: Encoder) throws {
16+
guard wrappedValue.count == 102 else { throw FixedArrayError.invalidSize }
17+
var container = encoder.unkeyedContainer()
18+
try wrappedValue.forEach { try container.encode($0) }
19+
}
20+
}
21+
22+
// MARK: - Array102 + Decodable
23+
24+
extension Array102: Decodable where Element : Decodable {
25+
public init(from decoder: Decoder) throws {
26+
var container = try decoder.unkeyedContainer()
27+
wrappedValue = try (0..<102).map { _ in try container.decode(Element.self) }
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
3+
// MARK: - Array103 + Encodable
4+
5+
@propertyWrapper public struct Array103<Element> {
6+
public var wrappedValue: [Element]
7+
public init(wrappedValue: [Element]) {
8+
self.wrappedValue = wrappedValue
9+
}
10+
}
11+
12+
// MARK: - Array103 + Encodable
13+
14+
extension Array103: Encodable where Element : Encodable {
15+
public func encode(to encoder: Encoder) throws {
16+
guard wrappedValue.count == 103 else { throw FixedArrayError.invalidSize }
17+
var container = encoder.unkeyedContainer()
18+
try wrappedValue.forEach { try container.encode($0) }
19+
}
20+
}
21+
22+
// MARK: - Array103 + Decodable
23+
24+
extension Array103: Decodable where Element : Decodable {
25+
public init(from decoder: Decoder) throws {
26+
var container = try decoder.unkeyedContainer()
27+
wrappedValue = try (0..<103).map { _ in try container.decode(Element.self) }
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
3+
// MARK: - Array104 + Encodable
4+
5+
@propertyWrapper public struct Array104<Element> {
6+
public var wrappedValue: [Element]
7+
public init(wrappedValue: [Element]) {
8+
self.wrappedValue = wrappedValue
9+
}
10+
}
11+
12+
// MARK: - Array104 + Encodable
13+
14+
extension Array104: Encodable where Element : Encodable {
15+
public func encode(to encoder: Encoder) throws {
16+
guard wrappedValue.count == 104 else { throw FixedArrayError.invalidSize }
17+
var container = encoder.unkeyedContainer()
18+
try wrappedValue.forEach { try container.encode($0) }
19+
}
20+
}
21+
22+
// MARK: - Array104 + Decodable
23+
24+
extension Array104: Decodable where Element : Decodable {
25+
public init(from decoder: Decoder) throws {
26+
var container = try decoder.unkeyedContainer()
27+
wrappedValue = try (0..<104).map { _ in try container.decode(Element.self) }
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
3+
// MARK: - Array105 + Encodable
4+
5+
@propertyWrapper public struct Array105<Element> {
6+
public var wrappedValue: [Element]
7+
public init(wrappedValue: [Element]) {
8+
self.wrappedValue = wrappedValue
9+
}
10+
}
11+
12+
// MARK: - Array105 + Encodable
13+
14+
extension Array105: Encodable where Element : Encodable {
15+
public func encode(to encoder: Encoder) throws {
16+
guard wrappedValue.count == 105 else { throw FixedArrayError.invalidSize }
17+
var container = encoder.unkeyedContainer()
18+
try wrappedValue.forEach { try container.encode($0) }
19+
}
20+
}
21+
22+
// MARK: - Array105 + Decodable
23+
24+
extension Array105: Decodable where Element : Decodable {
25+
public init(from decoder: Decoder) throws {
26+
var container = try decoder.unkeyedContainer()
27+
wrappedValue = try (0..<105).map { _ in try container.decode(Element.self) }
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
3+
// MARK: - Array106 + Encodable
4+
5+
@propertyWrapper public struct Array106<Element> {
6+
public var wrappedValue: [Element]
7+
public init(wrappedValue: [Element]) {
8+
self.wrappedValue = wrappedValue
9+
}
10+
}
11+
12+
// MARK: - Array106 + Encodable
13+
14+
extension Array106: Encodable where Element : Encodable {
15+
public func encode(to encoder: Encoder) throws {
16+
guard wrappedValue.count == 106 else { throw FixedArrayError.invalidSize }
17+
var container = encoder.unkeyedContainer()
18+
try wrappedValue.forEach { try container.encode($0) }
19+
}
20+
}
21+
22+
// MARK: - Array106 + Decodable
23+
24+
extension Array106: Decodable where Element : Decodable {
25+
public init(from decoder: Decoder) throws {
26+
var container = try decoder.unkeyedContainer()
27+
wrappedValue = try (0..<106).map { _ in try container.decode(Element.self) }
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
3+
// MARK: - Array107 + Encodable
4+
5+
@propertyWrapper public struct Array107<Element> {
6+
public var wrappedValue: [Element]
7+
public init(wrappedValue: [Element]) {
8+
self.wrappedValue = wrappedValue
9+
}
10+
}
11+
12+
// MARK: - Array107 + Encodable
13+
14+
extension Array107: Encodable where Element : Encodable {
15+
public func encode(to encoder: Encoder) throws {
16+
guard wrappedValue.count == 107 else { throw FixedArrayError.invalidSize }
17+
var container = encoder.unkeyedContainer()
18+
try wrappedValue.forEach { try container.encode($0) }
19+
}
20+
}
21+
22+
// MARK: - Array107 + Decodable
23+
24+
extension Array107: Decodable where Element : Decodable {
25+
public init(from decoder: Decoder) throws {
26+
var container = try decoder.unkeyedContainer()
27+
wrappedValue = try (0..<107).map { _ in try container.decode(Element.self) }
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
3+
// MARK: - Array108 + Encodable
4+
5+
@propertyWrapper public struct Array108<Element> {
6+
public var wrappedValue: [Element]
7+
public init(wrappedValue: [Element]) {
8+
self.wrappedValue = wrappedValue
9+
}
10+
}
11+
12+
// MARK: - Array108 + Encodable
13+
14+
extension Array108: Encodable where Element : Encodable {
15+
public func encode(to encoder: Encoder) throws {
16+
guard wrappedValue.count == 108 else { throw FixedArrayError.invalidSize }
17+
var container = encoder.unkeyedContainer()
18+
try wrappedValue.forEach { try container.encode($0) }
19+
}
20+
}
21+
22+
// MARK: - Array108 + Decodable
23+
24+
extension Array108: Decodable where Element : Decodable {
25+
public init(from decoder: Decoder) throws {
26+
var container = try decoder.unkeyedContainer()
27+
wrappedValue = try (0..<108).map { _ in try container.decode(Element.self) }
28+
}
29+
}

0 commit comments

Comments
 (0)