1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2024 Google Inc. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 /// Swift specific additions to simplify usage. 9 extension GPBUnknownField { 10 11 /// The value of the field in a type-safe manner. 12 public enum Value: Equatable { 13 case varint(UInt64) 14 case fixed32(UInt32) 15 case fixed64(UInt64) 16 case lengthDelimited(Data) // length prefixed 17 case group(GPBUnknownFields) // tag delimited 18 } 19 20 /// The value of the field in a type-safe manner. 21 /// 22 /// - Note: This is only valid for non-legacy fields. 23 public var value: Value { 24 switch type { 25 case .varint: 26 return .varint(varint) 27 case .fixed32: 28 return .fixed32(fixed32) 29 case .fixed64: 30 return .fixed64(fixed64) 31 case .lengthDelimited: 32 return .lengthDelimited(lengthDelimited) 33 case .group: 34 return .group(group) 35 case .legacy: 36 fatalError("`value` not valid for Legacy fields.") 37 @unknown default: 38 fatalError("Internal error: Unknown field type: \(type)") 39 } 40 } 41 42 } 43