File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
swift/Sources/FlexBuffers Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 1414 * limitations under the License.
1515 */
1616
17+ import Common
1718import Foundation
1819
1920enum FlexBuffersErrors : Error {
@@ -23,6 +24,10 @@ enum FlexBuffersErrors: Error {
2324
2425@inline ( __always)
2526public func getRoot( buffer: ByteBuffer ) throws -> Reference ? {
27+ assert (
28+ isLitteEndian,
29+ " Swift FlexBuffers currently only supports little-endian systems " )
30+
2631 let end = buffer. count
2732 if buffer. count < 3 {
2833 throw FlexBuffersErrors . sizeOfBufferIsTooSmall
Original file line number Diff line number Diff line change @@ -37,12 +37,19 @@ public struct FlexBuffersWriter {
3737 private var hasDuplicatedKeys = false
3838 private var minBitWidth : BitWidth = . w8
3939 private var _bb : _InternalByteBuffer
40+ #if os(Wasm)
41+ private var stack : [ Value ] = [ ]
42+ #else
4043 private var stack : Stack = Stack ( )
44+ #endif
4145 private var keyPool : [ Int : UInt ] = [ : ]
4246 private var stringPool : [ Int : UInt ] = [ : ]
4347 private var flags : BuilderFlag
4448
4549 public init ( initialSize: Int = 1024 , flags: BuilderFlag = . shareKeys) {
50+ assert (
51+ isLitteEndian,
52+ " Swift FlexBuffers currently only supports little-endian systems " )
4653 _bb = _InternalByteBuffer ( initialSize: initialSize)
4754 self . flags = flags
4855 }
@@ -899,6 +906,22 @@ extension FlexBuffersWriter {
899906 }
900907}
901908
909+ extension Array where Element == Value {
910+ mutating func popLast( _ val: Int ) {
911+ self = Array ( self [ ..< val] )
912+ }
913+
914+ @discardableResult
915+ mutating func withUnsafeMutableBytes< R> (
916+ start: Int ,
917+ _ body: ( UnsafeMutableRawBufferPointer ) throws -> R ) rethrows -> R
918+ {
919+ try self [ start... ] . withUnsafeMutableBytes { buffer in
920+ try body ( buffer)
921+ }
922+ }
923+ }
924+
902925fileprivate struct Stack : RandomAccessCollection {
903926 typealias Element = Value
904927 typealias Index = Int
You can’t perform that action at this time.
0 commit comments