@@ -59,21 +59,21 @@ public struct FlatBufferBuilder {
59
59
public var capacity : Int { _bb. capacity }
60
60
61
61
#if !os(WASI)
62
- /// Data representation of the buffer
63
- ///
64
- /// Should only be used after ``finish(offset:addPrefix:)`` is called
65
- public var data : Data {
66
- assert ( finished, " Data shouldn't be called before finish() " )
67
- return _bb. withUnsafeSlicedBytes { ptr in
68
- var data = Data ( )
69
- data. append (
70
- ptr. baseAddress!. bindMemory (
71
- to: UInt8 . self,
72
- capacity: _bb. capacity) ,
73
- count: _bb. capacity)
74
- return data
75
- }
62
+ /// Data representation of the buffer
63
+ ///
64
+ /// Should only be used after ``finish(offset:addPrefix:)`` is called
65
+ public var data : Data {
66
+ assert ( finished, " Data shouldn't be called before finish() " )
67
+ return _bb. withUnsafeSlicedBytes { ptr in
68
+ var data = Data ( )
69
+ data. append (
70
+ ptr. baseAddress!. bindMemory (
71
+ to: UInt8 . self,
72
+ capacity: _bb. capacity) ,
73
+ count: _bb. capacity)
74
+ return data
76
75
}
76
+ }
77
77
#endif
78
78
79
79
/// Returns the underlying bytes in the ``ByteBuffer``
@@ -110,7 +110,7 @@ public struct FlatBufferBuilder {
110
110
public var sizedBuffer : ByteBuffer {
111
111
assert ( finished, " Data shouldn't be called before finish() " )
112
112
return _bb. withUnsafeSlicedBytes { ptr in
113
- return ByteBuffer (
113
+ ByteBuffer (
114
114
copyingMemoryBound: ptr. baseAddress!,
115
115
capacity: ptr. count)
116
116
}
@@ -128,8 +128,8 @@ public struct FlatBufferBuilder {
128
128
/// however the builder can be force by passing true for `serializeDefaults`
129
129
public init (
130
130
initialSize: Int32 = 1024 ,
131
- serializeDefaults force: Bool = false
132
- ) {
131
+ serializeDefaults force: Bool = false )
132
+ {
133
133
assert ( initialSize > 0 , " Size should be greater than zero! " )
134
134
guard isLitteEndian else {
135
135
fatalError (
@@ -196,8 +196,8 @@ public struct FlatBufferBuilder {
196
196
mutating public func finish(
197
197
offset: Offset ,
198
198
fileId: String ,
199
- addPrefix prefix: Bool = false
200
- ) {
199
+ addPrefix prefix: Bool = false )
200
+ {
201
201
let size = MemoryLayout< UOffset> . size
202
202
preAlign (
203
203
len: size &+ ( prefix ? size : 0 ) &+ FileIdLength,
@@ -226,8 +226,8 @@ public struct FlatBufferBuilder {
226
226
/// include the size of the current buffer.
227
227
mutating public func finish(
228
228
offset: Offset ,
229
- addPrefix prefix: Bool = false
230
- ) {
229
+ addPrefix prefix: Bool = false )
230
+ {
231
231
notNested ( )
232
232
let size = MemoryLayout< UOffset> . size
233
233
preAlign ( len: size &+ ( prefix ? size : 0 ) , alignment: _minAlignment)
@@ -351,8 +351,8 @@ public struct FlatBufferBuilder {
351
351
@usableFromInline
352
352
mutating internal func padding(
353
353
bufSize: UInt32 ,
354
- elementSize: UInt32
355
- ) -> UInt32 {
354
+ elementSize: UInt32 ) -> UInt32
355
+ {
356
356
( ( ~ bufSize) &+ 1 ) & ( elementSize &- 1 )
357
357
}
358
358
@@ -479,29 +479,29 @@ public struct FlatBufferBuilder {
479
479
@inline ( __always)
480
480
mutating public func createVector< T: Scalar > (
481
481
_ elements: [ T ] ,
482
- size: Int
483
- ) -> Offset {
482
+ size: Int ) -> Offset
483
+ {
484
484
let size = size
485
485
startVector ( size, elementSize: MemoryLayout< T> . size)
486
486
_bb. push ( elements: elements)
487
487
return endVector ( len: size)
488
488
}
489
489
490
490
#if swift(>=5.0) && !os(WASI)
491
- @inline ( __always)
492
- /// Creates a vector of bytes in the buffer.
493
- ///
494
- /// Allows creating a vector from `Data` without copying to a `[UInt8]`
495
- ///
496
- /// - Parameter bytes: bytes to be written into the buffer
497
- /// - Returns: ``Offset`` of the vector
498
- mutating public func createVector( bytes: ContiguousBytes ) -> Offset {
499
- bytes. withUnsafeBytes {
500
- startVector ( $0. count, elementSize: MemoryLayout< UInt8> . size)
501
- _bb. push ( bytes: $0)
502
- return endVector ( len: $0. count)
503
- }
491
+ @inline ( __always)
492
+ /// Creates a vector of bytes in the buffer.
493
+ ///
494
+ /// Allows creating a vector from `Data` without copying to a `[UInt8]`
495
+ ///
496
+ /// - Parameter bytes: bytes to be written into the buffer
497
+ /// - Returns: ``Offset`` of the vector
498
+ mutating public func createVector( bytes: ContiguousBytes ) -> Offset {
499
+ bytes. withUnsafeBytes {
500
+ startVector ( $0. count, elementSize: MemoryLayout< UInt8> . size)
501
+ _bb. push ( bytes: $0)
502
+ return endVector ( len: $0. count)
504
503
}
504
+ }
505
505
#endif
506
506
507
507
/// Creates a vector of type ``Enum`` into the ``ByteBuffer``
@@ -539,8 +539,8 @@ public struct FlatBufferBuilder {
539
539
@inline ( __always)
540
540
mutating public func createVector< T: Enum > (
541
541
_ elements: [ T ] ,
542
- size: Int
543
- ) -> Offset {
542
+ size: Int ) -> Offset
543
+ {
544
544
let size = size
545
545
startVector ( size, elementSize: T . byteSize)
546
546
for index in stride ( from: elements. count, to: 0 , by: - 1 ) {
@@ -585,8 +585,8 @@ public struct FlatBufferBuilder {
585
585
@inline ( __always)
586
586
mutating public func createVector(
587
587
ofOffsets offsets: [ Offset ] ,
588
- len: Int
589
- ) -> Offset {
588
+ len: Int ) -> Offset
589
+ {
590
590
startVector ( len, elementSize: MemoryLayout< Offset> . size)
591
591
for index in stride ( from: offsets. count, to: 0 , by: - 1 ) {
592
592
push ( element: offsets [ index &- 1 ] )
@@ -662,8 +662,8 @@ public struct FlatBufferBuilder {
662
662
@inline ( __always)
663
663
@discardableResult
664
664
mutating public func create< T: NativeStruct > (
665
- struct s: T , position: VOffset
666
- ) -> Offset {
665
+ struct s: T , position: VOffset ) -> Offset
666
+ {
667
667
let offset = create ( struct: s)
668
668
_vtableStorage. add (
669
669
loc: ( offset: _bb. size, position: VOffset ( position) ) )
@@ -687,8 +687,8 @@ public struct FlatBufferBuilder {
687
687
@inline ( __always)
688
688
@discardableResult
689
689
mutating public func create< T: NativeStruct > (
690
- struct s: T
691
- ) -> Offset {
690
+ struct s: T ) -> Offset
691
+ {
692
692
let size = MemoryLayout< T> . size
693
693
preAlign ( len: size, alignment: MemoryLayout< T> . alignment)
694
694
_bb. push ( struct: s, size: size)
@@ -803,8 +803,8 @@ public struct FlatBufferBuilder {
803
803
mutating public func add< T: Scalar > (
804
804
element: T ,
805
805
def: T ,
806
- at position: VOffset
807
- ) {
806
+ at position: VOffset )
807
+ {
808
808
if element == def && !serializeDefaults { return }
809
809
track ( offset: push ( element: element) , at: position)
810
810
}
0 commit comments