@@ -118,6 +118,11 @@ public struct OcaPropertyID: Codable, Hashable, Equatable, Comparable, Sendable,
118118 let defLevel : OcaUint16
119119 let propertyIndex : OcaUint16
120120
121+ public init ( defLevel: OcaUint16 , propertyIndex: OcaUint16 ) {
122+ self . defLevel = defLevel
123+ self . propertyIndex = propertyIndex
124+ }
125+
121126 public init ( _ string: OcaString ) {
122127 let s = string. split ( separator: " . " , maxSplits: 1 ) . map { OcaUint16 ( $0) ! }
123128 defLevel = s [ 0 ]
@@ -139,6 +144,33 @@ public struct OcaPropertyID: Codable, Hashable, Equatable, Comparable, Sendable,
139144 lhs. defLevel < rhs. defLevel
140145 }
141146 }
147+
148+ @_spi ( SwiftOCAPrivate)
149+ public init ? ( data: Data ) {
150+ precondition ( MemoryLayout< Self> . size == 4 )
151+ guard data. count >= 4 else { return nil }
152+
153+ let encodedSelf = data. withUnsafeBytes {
154+ $0. withMemoryRebound ( to: Self . self) {
155+ $0. baseAddress!. pointee
156+ }
157+ }
158+
159+ self . init (
160+ defLevel: UInt16 ( bigEndian: encodedSelf. defLevel) ,
161+ propertyIndex: UInt16 ( bigEndian: encodedSelf. propertyIndex)
162+ )
163+ }
164+
165+ @_spi ( SwiftOCAPrivate)
166+ public var data : Data {
167+ withUnsafeBytes ( of: Self (
168+ defLevel: defLevel. bigEndian,
169+ propertyIndex: propertyIndex. bigEndian
170+ ) ) {
171+ Data ( $0)
172+ }
173+ }
142174}
143175
144176public enum OcaIODirection : OcaUint8 , Codable , Sendable , CaseIterable {
@@ -363,6 +395,11 @@ public struct OcaMethodID: Codable, Hashable, Sendable, CustomStringConvertible,
363395 public let defLevel : OcaUint16
364396 public let methodIndex : OcaUint16
365397
398+ public init ( defLevel: OcaUint16 , methodIndex: OcaUint16 ) {
399+ self . defLevel = defLevel
400+ self . methodIndex = methodIndex
401+ }
402+
366403 public init ( _ string: OcaString ) {
367404 let s = string. split ( separator: " . " , maxSplits: 1 ) . map { OcaUint16 ( $0) ! }
368405 defLevel = s [ 0 ]
@@ -388,6 +425,33 @@ public struct OcaMethodID: Codable, Hashable, Sendable, CustomStringConvertible,
388425 self . init ( value)
389426 }
390427
428+ @_spi ( SwiftOCAPrivate)
429+ public init ? ( data: Data ) {
430+ precondition ( MemoryLayout< Self> . size == 4 )
431+ guard data. count >= 4 else { return nil }
432+
433+ let encodedSelf = data. withUnsafeBytes {
434+ $0. withMemoryRebound ( to: Self . self) {
435+ $0. baseAddress!. pointee
436+ }
437+ }
438+
439+ self . init (
440+ defLevel: UInt16 ( bigEndian: encodedSelf. defLevel) ,
441+ methodIndex: UInt16 ( bigEndian: encodedSelf. methodIndex)
442+ )
443+ }
444+
445+ @_spi ( SwiftOCAPrivate)
446+ public var data : Data {
447+ withUnsafeBytes ( of: Self (
448+ defLevel: defLevel. bigEndian,
449+ methodIndex: methodIndex. bigEndian
450+ ) ) {
451+ Data ( $0)
452+ }
453+ }
454+
391455 public var description : String {
392456 " \( defLevel) . \( methodIndex) "
393457 }
0 commit comments