diff --git a/Sources/OpenSwiftUICore/Data/StrongHash.swift b/Sources/OpenSwiftUICore/Data/StrongHash.swift index a318266a..080e234e 100644 --- a/Sources/OpenSwiftUICore/Data/StrongHash.swift +++ b/Sources/OpenSwiftUICore/Data/StrongHash.swift @@ -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 @@ -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) + } + } + + 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 + } + 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 + } + count += 1 + } else { + try decoder.skipField(field) + } + } + self = hash + } +} diff --git a/Sources/OpenSwiftUICore/Graphic/Color/ColorResolved.swift b/Sources/OpenSwiftUICore/Graphic/Color/ColorResolved.swift index e50e622d..3067142a 100644 --- a/Sources/OpenSwiftUICore/Graphic/Color/ColorResolved.swift +++ b/Sources/OpenSwiftUICore/Graphic/Color/ColorResolved.swift @@ -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) + } + + 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) + } + } + self.init(red: red, green: green, blue: blue, opacity: opacity) + } +} // MARK: - Util method diff --git a/Sources/OpenSwiftUICore/Render/DisplayList_StableIdentity.swift b/Sources/OpenSwiftUICore/Render/DisplayList_StableIdentity.swift index 47f62475..53d7dd89 100644 --- a/Sources/OpenSwiftUICore/Render/DisplayList_StableIdentity.swift +++ b/Sources/OpenSwiftUICore/Render/DisplayList_StableIdentity.swift @@ -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)) + } + + package init(from decoder: inout ProtobufDecoder) throws { + fatalError("TODO") + } +} + +extension _DisplayList_StableIdentityMap: ProtobufMessage { + package func encode(to encoder: inout ProtobufEncoder) throws { + fatalError("TODO") + } + + package init(from decoder: inout ProtobufDecoder) throws { + fatalError("TODO") + } +} // TODO: Blocked by _ViewInputs //extension _ViewInputs {