Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SwiftProtobuf/BinaryEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ internal struct BinaryEncoder {
}
}

// Higher-level serialization methods shared by both `_MessageStorage` and `ExtensionStorage`.
// Higher-level serialization methods shared by both `MessageStorage` and `ExtensionStorage`.
extension BinaryEncoder {
/// Serializes the field tag and value for a singular or unpacked `bool` field.
@inline(__always)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftProtobuf/ExtensionSchema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public struct ExtensionSchema: @unchecked Sendable {
_ ext: ExtensionSchema,
_ storage: ExtensionStorage,
_ operation: TrampolineFieldOperation,
_ perform: (_MessageStorage) throws -> Bool
_ perform: (MessageStorage) throws -> Bool
) throws -> Bool

/// The function type for the generated function that is called to perform an arbitrary
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftProtobuf/ExtensionStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ extension ExtensionStorage {
of ext: ExtensionSchema,
operation: TrampolineFieldOperation,
type: T.Type,
perform: (_MessageStorage) throws -> Bool
perform: (MessageStorage) throws -> Bool
) rethrows -> Bool {
let field = ext.field

Expand Down Expand Up @@ -312,7 +312,7 @@ extension ExtensionStorage {
of ext: ExtensionSchema,
operation: TrampolineFieldOperation,
type: [T].Type,
perform: (_MessageStorage) throws -> Bool
perform: (MessageStorage) throws -> Bool
) rethrows -> Bool {
let field = ext.field

Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftProtobuf/ExtensionValueStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

/// The storage for a single extension field in a message.
///
/// This can be thought of as a miniature version of `_MessageStorage`, but which only holds the
/// value for a single field. Just as `_MessageStorage` is self-describing (it contains its own
/// This can be thought of as a miniature version of `MessageStorage`, but which only holds the
/// value for a single field. Just as `MessageStorage` is self-describing (it contains its own
/// `_MessageLayout`), each extension value is self-describing (it contains its own
/// `_MessageExtension`).
///
Expand Down Expand Up @@ -114,7 +114,7 @@
as type: Value.Type,
) -> UnsafeMutablePointer<Value> {
let pointer = UnsafeMutablePointer<Value>(bitPattern: Int(truncatingIfNeeded: Int64(bitPattern: storage)))!
pointer.pointee._protobuf_ensureUniqueStorage(accessToken: _MessageStorageToken())
pointer.pointee._protobuf_ensureUniqueStorage(accessToken: MessageStorageToken())
return pointer
}
}
12 changes: 6 additions & 6 deletions Sources/SwiftProtobuf/MapEntryWorkingSpace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,31 @@
/// representation is only used when encoding/decoding.
///
/// To minimize unnecessary allocations, the encode/decode loop for a message creates an instance
/// of this type to maintain a cache of `_MessageStorage` objects that it uses as temporary
/// of this type to maintain a cache of `MessageStorage` objects that it uses as temporary
/// workspace before/after transferring the key and value into/out of the dictionary. This allows
/// map entry serialization to be implemented in essentially the same fashion as other types.
struct MapEntryWorkingSpace {
/// The schema of the message that contains the map field being encoded/decoded.
private let ownerSchema: MessageSchema

/// The cache of `_MessageStorage` objects used for the map entries in this message.
private var entryStorage: [Int: _MessageStorage]
/// The cache of `MessageStorage` objects used for the map entries in this message.
private var entryStorage: [Int: MessageStorage]

/// Creates a new map entry working space for the message with the given schema.
init(ownerSchema: MessageSchema) {
self.ownerSchema = ownerSchema
self.entryStorage = [:]
}

/// Returns the `_MessageStorage` used to encode/decode map entries with the given trampoline
/// Returns the `MessageStorage` used to encode/decode map entries with the given trampoline
/// index, creating it if necessary.
mutating func storage(for trampolineIndex: Int) -> _MessageStorage {
mutating func storage(for trampolineIndex: Int) -> MessageStorage {
if let storage = entryStorage[trampolineIndex] {
return storage
}

// It didn't already exist, so create it and cache it.
let storage = _MessageStorage(
let storage = MessageStorage(
schema: ownerSchema.mapEntrySchema(MessageSchema.TrampolineToken(index: trampolineIndex))
)
entryStorage[trampolineIndex] = storage
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftProtobuf/Message+BinaryAdditions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ extension Message {
partial: Bool,
options: BinaryDecodingOptions
) throws {
_protobuf_ensureUniqueStorage(accessToken: _MessageStorageToken())
_protobuf_ensureUniqueStorage(accessToken: MessageStorageToken())
try storageForRuntime.merge(byReadingFrom: body, extensions: extensions, partial: partial, options: options)
}
}
8 changes: 4 additions & 4 deletions Sources/SwiftProtobuf/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public protocol Message: Sendable, Equatable, Hashable, CustomDebugStringConvert
/// This is an implementation detail of the runtime; users should not call it. The return type
/// is a class-bound existential because the true SPI type cannot be used in a protocol
/// requirement.
func _protobuf_messageStorage(accessToken: _MessageStorageToken) -> AnyObject
func _protobuf_messageStorage(accessToken: MessageStorageToken) -> AnyObject

/// This is an implementation detail of the runtime; users should not call it.
mutating func _protobuf_ensureUniqueStorage(accessToken: _MessageStorageToken)
mutating func _protobuf_ensureUniqueStorage(accessToken: MessageStorageToken)

/// This is an implementation detail of the runtime; users should not call it. The return type
/// is a class-bound existential because the true SPI type cannot be used in a protocol
Expand Down Expand Up @@ -162,8 +162,8 @@ extension Message {
extension Message {
/// Convenience property for the runtime to retrieve the underlying storage for a concretely
/// typed message.
internal var storageForRuntime: _MessageStorage {
unsafeDowncast(_protobuf_messageStorage(accessToken: _MessageStorageToken()), to: _MessageStorage.self)
internal var storageForRuntime: MessageStorage {
unsafeDowncast(_protobuf_messageStorage(accessToken: MessageStorageToken()), to: MessageStorage.self)
}

/// Convenience method for generated code to retrieve the underlying storage for the extensions
Expand Down
16 changes: 8 additions & 8 deletions Sources/SwiftProtobuf/MessageSchema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public struct MessageSchema: @unchecked Sendable {
_ token: TrampolineToken,
_ operation: NontrivialFieldOperation,
_ field: FieldSchema,
_ storage: _MessageStorage
_ storage: MessageStorage
) -> Bool

/// The function type for the generated function that is called to perform an arbitrary
Expand All @@ -115,9 +115,9 @@ public struct MessageSchema: @unchecked Sendable {
public typealias SubmessageStoragePerformer = (
_ token: TrampolineToken,
_ field: FieldSchema,
_ storage: _MessageStorage,
_ storage: MessageStorage,
_ operation: TrampolineFieldOperation,
_ perform: (_MessageStorage) throws -> Bool
_ perform: (MessageStorage) throws -> Bool
) throws -> Bool

/// The function type for the generated function that is called to perform an arbitrary
Expand All @@ -126,7 +126,7 @@ public struct MessageSchema: @unchecked Sendable {
public typealias RawEnumValuesPerformer = (
_ token: TrampolineToken,
_ field: FieldSchema,
_ storage: _MessageStorage,
_ storage: MessageStorage,
_ operation: TrampolineFieldOperation,
_ perform: (EnumSchema, inout Int32) throws -> Bool,
_ onInvalidValue: (Int32) throws -> Void
Expand All @@ -143,11 +143,11 @@ public struct MessageSchema: @unchecked Sendable {
public typealias MapEntryPerformer = (
_ token: TrampolineToken,
_ field: FieldSchema,
_ storage: _MessageStorage,
_ workingSpace: _MessageStorage,
_ storage: MessageStorage,
_ workingSpace: MessageStorage,
_ operation: TrampolineFieldOperation,
_ deterministicOrdering: Bool,
_ perform: (_MessageStorage) throws -> Bool
_ perform: (MessageStorage) throws -> Bool
) throws -> Bool

/// The function that is called to deinitialize a field whose type is a message (singular or
Expand Down Expand Up @@ -689,7 +689,7 @@ public struct FieldSchema {
case .fixed32, .uint32: return MemoryLayout<UInt32>.stride
case .bool: return MemoryLayout<Bool>.stride
case .string: return MemoryLayout<String>.stride
case .group, .message: return MemoryLayout<_MessageStorage>.stride
case .group, .message: return MemoryLayout<MessageStorage>.stride
case .bytes: return MemoryLayout<Data>.stride
default: preconditionFailure("Unreachable")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Sources/SwiftProtobuf/_MessageStorage+BinaryDecoding.swift - Binary decoding for messages
// Sources/SwiftProtobuf/MessageStorage+BinaryDecoding.swift - Binary decoding for messages
//
// Copyright (c) 2014 - 2025 Apple Inc. and the project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
Expand All @@ -8,13 +8,13 @@
//
// -----------------------------------------------------------------------------
///
/// Binary decoding support for `_MessageStorage.`
/// Binary decoding support for `MessageStorage.`
///
// -----------------------------------------------------------------------------

import Foundation

extension _MessageStorage {
extension MessageStorage {
/// Decodes field values from the given binary-encoded buffer into this storage class.
///
/// - Parameters:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Sources/SwiftProtobuf/_MessageStorage+BinaryEncoding.swift - Binary encoding for messages
// Sources/SwiftProtobuf/MessageStorage+BinaryEncoding.swift - Binary encoding for messages
//
// Copyright (c) 2014 - 2025 Apple Inc. and the project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
Expand All @@ -8,13 +8,13 @@
//
// -----------------------------------------------------------------------------
///
/// Binary encoding support for `_MessageStorage.`
/// Binary encoding support for `MessageStorage.`
///
// -----------------------------------------------------------------------------

import Foundation

extension _MessageStorage {
extension MessageStorage {
/// Serializes the message represented by this storage into binary format and returns the
/// corresponding bytes.
public func serializedBytes<Bytes: SwiftProtobufContiguousBytes>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Sources/SwiftProtobuf/_MessageStorage+BinarySize.swift - Binary size calculation for messages
// Sources/SwiftProtobuf/MessageStorage+BinarySize.swift - Binary size calculation for messages
//
// Copyright (c) 2014 - 2025 Apple Inc. and the project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
Expand All @@ -8,13 +8,13 @@
//
// -----------------------------------------------------------------------------
///
/// Computes the binary-encoded size of `_MessageStorage.`
/// Computes the binary-encoded size of `MessageStorage.`
///
// -----------------------------------------------------------------------------

import Foundation

extension _MessageStorage {
extension MessageStorage {
/// Computes and returns the size in bytes required to serialize this message.
public func serializedBytesSize() -> Int {
var serializedSize = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Sources/SwiftProtobuf/_MessageStorage+Equality.swift - Table-driven message storage equality
// Sources/SwiftProtobuf/MessageStorage+Equality.swift - Table-driven message storage equality
//
// Copyright (c) 2014 - 2026 Apple Inc. and the project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
Expand All @@ -8,13 +8,13 @@
//
// -----------------------------------------------------------------------------
///
/// Implementation of equality for `_MessageStorage`.
/// Implementation of equality for `MessageStorage`.
///
// -----------------------------------------------------------------------------

import Foundation

extension _MessageStorage {
extension MessageStorage {
/// Tests this message storage for equality with the other storage.
///
/// Precondition: Both instances of storage are assumed to be represented by the same message
Expand All @@ -24,7 +24,7 @@ extension _MessageStorage {
/// field set to 100 is not considered equal to one where that field is not present but has a
/// default defined to be 100.
@inline(never)
public func isEqual(to other: _MessageStorage) -> Bool {
public func isEqual(to other: MessageStorage) -> Bool {
if self === other {
/// Identical message storage means they must be equal.
return true
Expand Down Expand Up @@ -144,7 +144,7 @@ extension _MessageStorage {
/// storage, given the expected type of that field.
func isField<T: Equatable>(
_ field: FieldSchema,
equalToSameFieldIn other: _MessageStorage,
equalToSameFieldIn other: MessageStorage,
type: T.Type
) -> Bool {
let isSelfPresent = isPresent(field)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Sources/SwiftProtobuf/_MessageStorage+Hashing.swift - Table-driven message storage hashing
// Sources/SwiftProtobuf/MessageStorage+Hashing.swift - Table-driven message storage hashing
//
// Copyright (c) 2014 - 2026 Apple Inc. and the project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
Expand All @@ -8,13 +8,13 @@
//
// -----------------------------------------------------------------------------
///
/// Implementation of hashing for `_MessageStorage`.
/// Implementation of hashing for `MessageStorage`.
///
// -----------------------------------------------------------------------------

import Foundation

extension _MessageStorage {
extension MessageStorage {
/// Hashes the values of this storage object's fields into the given hasher.
///
/// As required by the definitions of those operations, hashing -- like equality -- considers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Sources/SwiftProtobuf/_MessageStorage+JSONDecoding.swift - JSON decoding for messages
// Sources/SwiftProtobuf/MessageStorage+JSONDecoding.swift - JSON decoding for messages
//
// Copyright (c) 2014 - 2026 Apple Inc. and the project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
Expand All @@ -8,13 +8,13 @@
//
// -----------------------------------------------------------------------------
///
/// JSON decoding support for `_MessageStorage.`
/// JSON decoding support for `MessageStorage.`
///
// -----------------------------------------------------------------------------

import Foundation

extension _MessageStorage {
extension MessageStorage {
/// Decodes field values from the given UTF-8-encoded JSON buffer into this storage class.
///
/// - Parameters:
Expand Down Expand Up @@ -558,7 +558,7 @@ extension _MessageStorage {
throw SwiftProtobufError.JSONDecoding.unknownAnyTypeURL(type_url: typeURL)
}

let messageStorage = _MessageStorage(schema: messageSchema)
let messageStorage = MessageStorage(schema: messageSchema)
func parseJSONBuffer(_ buffer: UnsafeRawBufferPointer) throws {
var subReader = JSONReader(
buffer: buffer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Sources/SwiftProtobuf/_MessageStorage+JSONEncoding.swift - JSON format encoding for messages
// Sources/SwiftProtobuf/MessageStorage+JSONEncoding.swift - JSON format encoding for messages
//
// Copyright (c) 2014 - 2026 Apple Inc. and the project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
Expand All @@ -8,13 +8,13 @@
//
// -----------------------------------------------------------------------------
///
/// JSON format encoding support for `_MessageStorage.`
/// JSON format encoding support for `MessageStorage.`
///
// -----------------------------------------------------------------------------

import Foundation

extension _MessageStorage {
extension MessageStorage {
/// Returns the Protocol Buffer JSON serialization of the message.
///
/// - Parameter options: The options to use when encoding the message.
Expand Down Expand Up @@ -434,7 +434,7 @@ extension _MessageStorage {
}
let bytes = assumedPresentValue(at: valueField.offset) as Data
try bytes.withUnsafeBytes { buffer in
let messageStorage = _MessageStorage(schema: messageSchema)
let messageStorage = MessageStorage(schema: messageSchema)
try messageStorage.merge(byReadingFrom: buffer, extensions: options.extensions, partial: false, options: BinaryDecodingOptions())
try messageStorage.serializeJSON(into: &encoder, options: options, shouldInlineFields: !isWKT)
}
Expand Down
Loading
Loading