@@ -297,9 +297,9 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
297
297
}
298
298
299
299
/// Returns a new instance of the given type, read from the
300
- /// buffer pointer slice's raw memory.
300
+ /// specified offset into the buffer pointer slice's raw memory.
301
301
///
302
- /// The memory at the beginning of this buffer pointer slice
302
+ /// The memory at `offset` bytes into this buffer pointer slice
303
303
/// must be properly aligned for accessing `T` and initialized to `T` or
304
304
/// another type that is layout compatible with `T`.
305
305
///
@@ -314,28 +314,31 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
314
314
///
315
315
/// The memory to read for the new instance must not extend beyond the
316
316
/// memory region represented by the buffer pointer slice---that is,
317
- /// `MemoryLayout<T>.size` must be less than or equal to the slice's `count`.
317
+ /// `offset + MemoryLayout<T>.size` must be less than or equal
318
+ /// to the slice's `count`.
318
319
///
319
320
/// - Parameters:
321
+ /// - offset: The offset into the slice's memory, in bytes, at
322
+ /// which to begin reading data for the new instance. The default is zero.
320
323
/// - type: The type to use for the newly constructed instance. The memory
321
324
/// must be initialized to a value of a type that is layout compatible
322
325
/// with `type`.
323
326
/// - Returns: A new instance of type `T`, copied from the buffer pointer
324
327
/// slice's memory.
325
328
@inlinable
326
329
@_alwaysEmitIntoClient
327
- public func load< T> ( as type: T . Type ) -> T {
330
+ public func load< T> ( fromByteOffset offset : Int = 0 , as type: T . Type ) -> T {
328
331
let buffer = Base ( rebasing: self )
329
- return buffer. load ( fromByteOffset: 0 , as: T . self)
332
+ return buffer. load ( fromByteOffset: offset , as: T . self)
330
333
}
331
334
332
335
/// Returns a new instance of the given type, read from the
333
- /// buffer pointer slice's raw memory.
336
+ /// specified offset into the buffer pointer slice's raw memory.
334
337
///
335
338
/// This function only supports loading trivial types.
336
339
/// A trivial type does not contain any reference-counted property
337
340
/// within its in-memory stored representation.
338
- /// The memory at `offset` bytes into the buffer must be laid out
341
+ /// The memory at `offset` bytes into the buffer slice must be laid out
339
342
/// identically to the in-memory representation of `T`.
340
343
///
341
344
/// You can use this method to create new values from the buffer pointer's
@@ -349,32 +352,40 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
349
352
///
350
353
/// The memory to read for the new instance must not extend beyond the
351
354
/// memory region represented by the buffer pointer slice---that is,
352
- /// `MemoryLayout<T>.size` must be less than or equal to the slice's `count`.
355
+ /// `offset + MemoryLayout<T>.size` must be less than or equal
356
+ /// to the slice's `count`.
353
357
///
354
358
/// - Parameters:
359
+ /// - offset: The offset into the slice's memory, in bytes, at
360
+ /// which to begin reading data for the new instance. The default is zero.
355
361
/// - type: The type to use for the newly constructed instance. The memory
356
362
/// must be initialized to a value of a type that is layout compatible
357
363
/// with `type`.
358
364
/// - Returns: A new instance of type `T`, copied from the buffer pointer's
359
365
/// memory.
360
366
@inlinable
361
367
@_alwaysEmitIntoClient
362
- public func loadUnaligned< T> ( as type: T . Type ) -> T {
368
+ public func loadUnaligned< T> (
369
+ fromByteOffset offset: Int = 0 ,
370
+ as type: T . Type
371
+ ) -> T {
363
372
let buffer = Base ( rebasing: self )
364
- return buffer. loadUnaligned ( fromByteOffset: 0 , as: T . self)
373
+ return buffer. loadUnaligned ( fromByteOffset: offset , as: T . self)
365
374
}
366
375
367
- /// Stores a value's bytes into the buffer pointer slice's raw memory.
376
+ /// Stores a value's bytes into the buffer pointer slice's raw memory at the
377
+ /// specified byte offset.
368
378
///
369
379
/// The type `T` to be stored must be a trivial type. The memory must also be
370
380
/// uninitialized, initialized to `T`, or initialized to another trivial
371
381
/// type that is layout compatible with `T`.
372
382
///
373
383
/// The memory written to must not extend beyond
374
384
/// the memory region represented by the buffer pointer slice---that is,
375
- /// `MemoryLayout<T>.size` must be less than or equal to the slice's `count`.
385
+ /// `offset + MemoryLayout<T>.size` must be less than or equal
386
+ /// to the slice's `count`.
376
387
///
377
- /// After calling `storeBytes(of:as:)`, the memory is
388
+ /// After calling `storeBytes(of:toByteOffset: as:)`, the memory is
378
389
/// initialized to the raw bytes of `value`. If the memory is bound to a
379
390
/// type `U` that is layout compatible with `T`, then it contains a value of
380
391
/// type `U`. Calling `storeBytes(of:toByteOffset:as:)` does not change the
@@ -386,12 +397,14 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
386
397
/// forms of indirection are trivial, as are imported C structs and enums.
387
398
///
388
399
/// If you need to store into memory a copy of a value of a type that isn't
389
- /// trivial, you cannot use the `storeBytes(of:as:)` method.
400
+ /// trivial, you cannot use the `storeBytes(of:toByteOffset: as:)` method.
390
401
/// Instead, you must know either initialize the memory or,
391
402
/// if you know the memory was already bound to `type`, assign to the memory.
392
403
///
393
404
/// - Parameters:
394
405
/// - value: The value to store as raw bytes.
406
+ /// - offset: The offset in bytes into the buffer pointer slice's memory
407
+ /// to begin writing bytes from the value. The default is zero.
395
408
/// - type: The type to use for the newly constructed instance. The memory
396
409
/// must be initialized to a value of a type that is layout compatible
397
410
/// with `type`.
@@ -509,9 +522,9 @@ extension Slice where Base == UnsafeRawBufferPointer {
509
522
}
510
523
511
524
/// Returns a new instance of the given type, read from the
512
- /// buffer pointer slice's raw memory.
525
+ /// specified offset into the buffer pointer slice's raw memory.
513
526
///
514
- /// The memory at the beginning of this buffer pointer slice
527
+ /// The memory at `offset` bytes into this buffer pointer slice
515
528
/// must be properly aligned for accessing `T` and initialized to `T` or
516
529
/// another type that is layout compatible with `T`.
517
530
///
@@ -526,28 +539,31 @@ extension Slice where Base == UnsafeRawBufferPointer {
526
539
///
527
540
/// The memory to read for the new instance must not extend beyond the
528
541
/// memory region represented by the buffer pointer slice---that is,
529
- /// `MemoryLayout<T>.size` must be less than or equal to the slice's `count`.
542
+ /// `offset + MemoryLayout<T>.size` must be less than or equal
543
+ /// to the slice's `count`.
530
544
///
531
545
/// - Parameters:
546
+ /// - offset: The offset into the slice's memory, in bytes, at
547
+ /// which to begin reading data for the new instance. The default is zero.
532
548
/// - type: The type to use for the newly constructed instance. The memory
533
549
/// must be initialized to a value of a type that is layout compatible
534
550
/// with `type`.
535
551
/// - Returns: A new instance of type `T`, copied from the buffer pointer
536
552
/// slice's memory.
537
553
@inlinable
538
554
@_alwaysEmitIntoClient
539
- public func load< T> ( as type: T . Type ) -> T {
555
+ public func load< T> ( fromByteOffset offset : Int = 0 , as type: T . Type ) -> T {
540
556
let buffer = Base ( rebasing: self )
541
- return buffer. load ( fromByteOffset: 0 , as: T . self)
557
+ return buffer. load ( fromByteOffset: offset , as: T . self)
542
558
}
543
559
544
560
/// Returns a new instance of the given type, read from the
545
- /// buffer pointer slice's raw memory.
561
+ /// specified offset into the buffer pointer slice's raw memory.
546
562
///
547
563
/// This function only supports loading trivial types.
548
564
/// A trivial type does not contain any reference-counted property
549
565
/// within its in-memory stored representation.
550
- /// The memory at `offset` bytes into the buffer must be laid out
566
+ /// The memory at `offset` bytes into the buffer slice must be laid out
551
567
/// identically to the in-memory representation of `T`.
552
568
///
553
569
/// You can use this method to create new values from the buffer pointer's
@@ -561,19 +577,25 @@ extension Slice where Base == UnsafeRawBufferPointer {
561
577
///
562
578
/// The memory to read for the new instance must not extend beyond the
563
579
/// memory region represented by the buffer pointer slice---that is,
564
- /// `MemoryLayout<T>.size` must be less than or equal to the slice's `count`.
580
+ /// `offset + MemoryLayout<T>.size` must be less than or equal
581
+ /// to the slice's `count`.
565
582
///
566
583
/// - Parameters:
584
+ /// - offset: The offset into the slice's memory, in bytes, at
585
+ /// which to begin reading data for the new instance. The default is zero.
567
586
/// - type: The type to use for the newly constructed instance. The memory
568
587
/// must be initialized to a value of a type that is layout compatible
569
588
/// with `type`.
570
589
/// - Returns: A new instance of type `T`, copied from the buffer pointer's
571
590
/// memory.
572
591
@inlinable
573
592
@_alwaysEmitIntoClient
574
- public func loadUnaligned< T> ( as type: T . Type ) -> T {
593
+ public func loadUnaligned< T> (
594
+ fromByteOffset offset: Int = 0 ,
595
+ as type: T . Type
596
+ ) -> T {
575
597
let buffer = Base ( rebasing: self )
576
- return buffer. loadUnaligned ( fromByteOffset: 0 , as: T . self)
598
+ return buffer. loadUnaligned ( fromByteOffset: offset , as: T . self)
577
599
}
578
600
}
579
601
0 commit comments