mirror of
https://github.com/apple/swift-nio-imap
synced 2026-11-30 05:28:46 +00:00
IMAPBuffer / IMAPByteStorage (owner + range, no pointer), IMAPBufferList, OutputSegment, the EncoderOutputBuffer sink protocol and its two conformers: IMAPOutputBuffer (core, donates to DispatchData) and ByteBufferOutput (NIOIMAP, fills a ByteBuffer in place). StableAddressByteRegion is the public opt-in for a foreign region to be donated by makeDispatchData() rather than copied: arrays conform, and NIOIMAP conforms ByteBuffer with public API only (CoW keeps a held copy's readable bytes in place). makeDispatchData() donates only regions of at least IMAPBuffer.dispatchDonationThreshold (512) bytes; each run of shorter or unstable regions is copied into one malloc'd region freed inline (.free). Measured: a donated region costs ~4 mallocs, 300-500 B and ~400 ns plus an async deallocator block; a copy costs a memcpy. The deallocator captures the owner's concrete type, not an existential. Public API for adapting a buffer type, so NIOIMAP's ByteBuffer support needs no SPI and a third-party type can do the same: IMAPBuffer.copyThreshold and dispatchDonationThreshold; backingRegion(as:), which recovers the backing region and range without copying; withUnsafeBytesAndOwner(_:), which hands out bytes with a fixed address and their owner, under the same rule makeDispatchData() uses. IMAPByteStorage.init(_:) has an overload for a StableAddressByteRegion, which records the fixed address statically: the generic init isn't specialized across modules, so its dynamic cast would run once per wrapped ByteBuffer. Additive; nothing uses them yet. Review focus: OutputSegment's @unchecked Sendable (handed-out ranges never overlap the write tail), IMAPOutputBuffer's copy-on-write state box and its @exclusivity(unchecked) properties, and makeDispatchData()'s copy runs.
1.4 KiB
1.4 KiB
Parsing and Encoding
Parse IMAP server responses and encode client commands using these streaming parsers and encode buffers.
Overview
NIOIMAPCore provides comprehensive parsing and encoding capabilities. These types handle the conversion between the IMAP wire format and strongly-typed Swift structures, including error handling and advanced features like pipelining.
Topics
Parsers
Streaming parsers for different contexts.
ResponseParserCommandParserSynchronizingLiteralParser
Encoders
Buffers for encoding protocol elements back to wire format.
CommandEncodeBufferResponseEncodeBufferCommandEncodingOptionsResponseEncodingOptions
Bytes
Types for carrying raw message payloads without copying them.
IMAPBufferIMAPBufferListIMAPByteStorageByteRegionStableAddressByteRegion
Encoder output
Where encoded bytes go.
EncoderOutputBufferIMAPOutputBuffer
Pipelining
Types related to command pipelining behavior.
PipeliningRequirementPipeliningBehavior
Errors
Parsing and encoding errors that may occur.
BadCommandParserErrorTooMuchRecursionExceededMaximumMessageAttributesErrorExceededMaximumBodySizeErrorExceededLiteralSizeLimitError
Utilities
Utility types and protocol defaults.
ModifiedUTF7IMAPDefaults