Skip to content

Commit

Permalink
Add missing ProtobufMessage conformance
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Oct 10, 2024
1 parent 71157c5 commit 4befb41
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 18 deletions.
44 changes: 39 additions & 5 deletions Sources/OpenSwiftUICore/Data/StrongHash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// OpenSwiftUICore
//
// Audited for RELEASE_2024
// Status: Blocked by OGTypeGetSignature
// Status: Blocked by OGTypeGetSignature and RBUUID

#if OPENSWIFTUI_SWIFT_CRYPTO
internal import Crypto
Expand Down Expand Up @@ -215,7 +215,41 @@ extension UUID: StronglyHashableByBitPattern {}
//extension RenderBox.RBUUID {
// package init(hash: StrongHash)
//}
//extension StrongHash: ProtobufMessage {
// package func encode(to encoder: inout ProtobufEncoder)
// package init(from decoder: inout ProtobufDecoder) throws
//}

extension StrongHash: ProtobufMessage {
package func encode(to encoder: inout ProtobufEncoder) {
encoder.packedField(1) { encoder in
encoder.encodeFixed32(words.0)
encoder.encodeFixed32(words.1)
encoder.encodeFixed32(words.2)
encoder.encodeFixed32(words.3)
encoder.encodeFixed32(words.4)

Check warning on line 226 in Sources/OpenSwiftUICore/Data/StrongHash.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/StrongHash.swift#L220-L226

Added lines #L220 - L226 were not covered by tests
}
}

package init(from decoder: inout ProtobufDecoder) throws {
var hash = StrongHash()
var count = 0
while count < 5 {
guard let field = try decoder.nextField() else {
self = hash
return

Check warning on line 236 in Sources/OpenSwiftUICore/Data/StrongHash.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/StrongHash.swift#L230-L236

Added lines #L230 - L236 were not covered by tests
}
if field.tag == 1 {
let result = try decoder.fixed32Field(field)
switch count {
case 0: hash.words.0 = result
case 1: hash.words.1 = result
case 2: hash.words.2 = result
case 3: hash.words.3 = result
case 4: hash.words.4 = result
default: break

Check warning on line 246 in Sources/OpenSwiftUICore/Data/StrongHash.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/StrongHash.swift#L238-L246

Added lines #L238 - L246 were not covered by tests
}
count += 1
} else {
try decoder.skipField(field)

Check warning on line 250 in Sources/OpenSwiftUICore/Data/StrongHash.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/StrongHash.swift#L248-L250

Added lines #L248 - L250 were not covered by tests
}
}
self = hash

Check warning on line 253 in Sources/OpenSwiftUICore/Data/StrongHash.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/StrongHash.swift#L253

Added line #L253 was not covered by tests
}
}
29 changes: 25 additions & 4 deletions Sources/OpenSwiftUICore/Graphic/Color/ColorResolved.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,31 @@ extension Color.Resolved: Codable {

// MARK: - Color.Resolved + ProtobufMessage

//extension Color.Resolved: ProtobufMessage {
// package func encode(to encoder: inout ProtobufEncoder)
// package init(from decoder: inout ProtobufDecoder) throws
//}
extension Color.Resolved: ProtobufMessage {
package func encode(to encoder: inout ProtobufEncoder) {
encoder.floatField(1, red)
encoder.floatField(2, green)
encoder.floatField(3, blue)
encoder.floatField(4, opacity)

Check warning on line 264 in Sources/OpenSwiftUICore/Graphic/Color/ColorResolved.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/ColorResolved.swift#L260-L264

Added lines #L260 - L264 were not covered by tests
}

package init(from decoder: inout ProtobufDecoder) throws {
var red: Float = .zero
var green: Float = .zero
var blue: Float = .zero
var opacity: Float = 1
while let field = try decoder.nextField() {
switch field.tag {
case 1: red = try decoder.floatField(field)
case 2: green = try decoder.floatField(field)
case 3: blue = try decoder.floatField(field)
case 4: opacity = try decoder.floatField(field)
default: try decoder.skipField(field)

Check warning on line 278 in Sources/OpenSwiftUICore/Graphic/Color/ColorResolved.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/ColorResolved.swift#L267-L278

Added lines #L267 - L278 were not covered by tests
}
}
self.init(red: red, green: green, blue: blue, opacity: opacity)

Check warning on line 281 in Sources/OpenSwiftUICore/Graphic/Color/ColorResolved.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Graphic/Color/ColorResolved.swift#L281

Added line #L281 was not covered by tests
}
}

// MARK: - Util method

Expand Down
29 changes: 20 additions & 9 deletions Sources/OpenSwiftUICore/Render/DisplayList_StableIdentity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,26 @@ package struct _DisplayList_StableIdentityScope: ViewInput, _ViewTraitKey {
}
}

// TODO: Blocked by ProtobufMessage
//extension _DisplayList_StableIdentity: ProtobufMessage {
// package func encode(to encoder: inout ProtobufEncoder) throws
// package init(from decoder: inout ProtobufDecoder) throws
//}
//extension _DisplayList_StableIdentityMap: ProtobufMessage {
// package func encode(to encoder: inout ProtobufEncoder) throws
// package init(from decoder: inout ProtobufDecoder) throws
//}
extension _DisplayList_StableIdentity: ProtobufMessage {
package func encode(to encoder: inout ProtobufEncoder) throws {
try encoder.messageField(1, hash)
encoder.uintField(2, UInt(serial))

Check warning on line 80 in Sources/OpenSwiftUICore/Render/DisplayList_StableIdentity.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList_StableIdentity.swift#L78-L80

Added lines #L78 - L80 were not covered by tests
}

package init(from decoder: inout ProtobufDecoder) throws {
fatalError("TODO")

Check warning on line 84 in Sources/OpenSwiftUICore/Render/DisplayList_StableIdentity.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList_StableIdentity.swift#L83-L84

Added lines #L83 - L84 were not covered by tests
}
}

extension _DisplayList_StableIdentityMap: ProtobufMessage {
package func encode(to encoder: inout ProtobufEncoder) throws {
fatalError("TODO")

Check warning on line 90 in Sources/OpenSwiftUICore/Render/DisplayList_StableIdentity.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList_StableIdentity.swift#L89-L90

Added lines #L89 - L90 were not covered by tests
}

package init(from decoder: inout ProtobufDecoder) throws {
fatalError("TODO")

Check warning on line 94 in Sources/OpenSwiftUICore/Render/DisplayList_StableIdentity.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/DisplayList_StableIdentity.swift#L93-L94

Added lines #L93 - L94 were not covered by tests
}
}

// TODO: Blocked by _ViewInputs
//extension _ViewInputs {
Expand Down

0 comments on commit 4befb41

Please sign in to comment.