mirror of
https://github.com/google/flatbuffers.git
synced 2026-11-13 07:26:23 +00:00
Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90d269a7e2 | ||
|
|
f58d5768f1 | ||
|
|
7af1efe4b2 | ||
|
|
6dda43bbaa | ||
|
|
9a8a511b52 | ||
|
|
b8431fbcd7 | ||
|
|
5761d6e67a | ||
|
|
81edeb17d9 | ||
|
|
5982eb6495 | ||
|
|
38df29380a | ||
|
|
1f438bd40f |
@@ -545,7 +545,7 @@ jobs:
|
||||
# FIXME: make test script not rely on flatc
|
||||
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j
|
||||
- name: pnpm
|
||||
run: npm install -g pnpm
|
||||
run: npm install -g pnpm@10
|
||||
- name: deps
|
||||
run: pnpm i
|
||||
- name: compile
|
||||
|
||||
@@ -75,6 +75,17 @@ extension Array where Element == Package.Dependency {
|
||||
.package(
|
||||
url: "https://github.com/grpc/grpc-swift-nio-transport.git",
|
||||
from: "2.0.0"),
|
||||
// swift-crypto arrives through grpc-swift-nio-transport -> swift-nio-ssl
|
||||
// and is otherwise resolved afresh on every build, because this package
|
||||
// ships no Package.resolved. 5.x asks for swift-tools-version 6.2, so only
|
||||
// the 6.2 CI job selects it - and then fails to compile it, because 5.x
|
||||
// uses `@nonexhaustive`, which the 6.2.x toolchains do not accept yet.
|
||||
// Stay on the last 4.x release that still builds with every toolchain in
|
||||
// the Swift CI matrix (4.3.0 declares swift-tools-version 6.0; 4.4+ asks
|
||||
// for 6.1 and would drop the 6.0 job).
|
||||
.package(
|
||||
url: "https://github.com/apple/swift-crypto.git",
|
||||
"4.0.0" ..< "4.4.0"),
|
||||
]
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ let benchmarks = {
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(ByteBuffer(assumingMemoryBound: memory, capacity: Int(oneGB)))
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark("Clearing 1GB", configuration: singleConfiguration) { benchmark in
|
||||
@@ -105,6 +106,7 @@ let benchmarks = {
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.clear())
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark("Strings 10") { benchmark in
|
||||
@@ -113,6 +115,7 @@ let benchmarks = {
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.create(string: str10))
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark("Strings 100") { benchmark in
|
||||
@@ -121,6 +124,7 @@ let benchmarks = {
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.create(string: str100))
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark("Vector 1 Bytes") { benchmark in
|
||||
@@ -129,6 +133,7 @@ let benchmarks = {
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.createVector(bytes: bytes))
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark("Vector 1 Ints") { benchmark in
|
||||
@@ -137,6 +142,7 @@ let benchmarks = {
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.createVector(ints))
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark("Vector 100 Ints") { benchmark in
|
||||
@@ -145,6 +151,7 @@ let benchmarks = {
|
||||
for i in benchmark.scaledIterations {
|
||||
blackHole(fb.createVector(ints))
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark("Vector 100 Bytes") { benchmark in
|
||||
@@ -153,6 +160,7 @@ let benchmarks = {
|
||||
for i in benchmark.scaledIterations {
|
||||
blackHole(fb.createVector(bytes))
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark("Vector 100 ContiguousBytes") { benchmark in
|
||||
@@ -161,6 +169,7 @@ let benchmarks = {
|
||||
for i in benchmark.scaledIterations {
|
||||
blackHole(fb.createVector(bytes: bytes))
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark(
|
||||
@@ -178,6 +187,7 @@ let benchmarks = {
|
||||
fb.add(offset: off, at: 8)
|
||||
blackHole(fb.endTable(at: s))
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark(
|
||||
@@ -190,6 +200,7 @@ let benchmarks = {
|
||||
let s = fb.startTable(with: 4)
|
||||
blackHole(fb.endTable(at: s))
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark("Struct") { benchmark in
|
||||
@@ -198,6 +209,7 @@ let benchmarks = {
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.create(struct: array.first!))
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark("Structs") { benchmark in
|
||||
@@ -219,6 +231,7 @@ let benchmarks = {
|
||||
fb.add(offset: vector, at: 4)
|
||||
let root = Offset(offset: fb.endTable(at: start))
|
||||
blackHole(fb.finish(offset: root))
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark("Vector of Offsets") { benchmark in
|
||||
@@ -239,12 +252,15 @@ let benchmarks = {
|
||||
fb.add(offset: off, at: 2)
|
||||
blackHole(fb.endTable(at: s))
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark("Reading Doubles") { benchmark in
|
||||
let byteBuffer = ByteBuffer(data: data)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(byteBuffer.read(def: Double.self, position: 0))
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright 2024 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Benchmark
|
||||
import FlexBuffers
|
||||
import Foundation
|
||||
|
||||
let benchmarks = {
|
||||
let data = {
|
||||
var array = [8888.88, 8888.88]
|
||||
var data = Data()
|
||||
array.withUnsafeBytes { ptr in
|
||||
data.append(contentsOf: ptr)
|
||||
}
|
||||
return data
|
||||
}()
|
||||
let ints: [Int32] = Array(repeating: 42, count: 100)
|
||||
let str10 = (0...9).map { _ -> String in "x" }.joined()
|
||||
let str100 = (0...99).map { _ -> String in "x" }.joined()
|
||||
|
||||
// A representative map: 50 keyed scalars, a keyed string and a keyed vector
|
||||
// of 100 scalars. Used for the realistic decode benchmarks.
|
||||
let mapBuffer: ByteBuffer = {
|
||||
var fbx = FlexBuffersWriter(initialSize: 1 << 16)
|
||||
fbx.map {
|
||||
for i in 0..<50 { $0.add(int: i, key: "i\(i)") }
|
||||
$0.add(string: "hello world", key: "s")
|
||||
$0.vector(key: "v") { v in
|
||||
for x in 0..<100 { v.add(int: x) }
|
||||
}
|
||||
}
|
||||
fbx.finish()
|
||||
return fbx.sizedByteBuffer
|
||||
}()
|
||||
|
||||
let metrics: [BenchmarkMetric] = [
|
||||
.cpuTotal,
|
||||
.wallClock,
|
||||
.mallocCountTotal,
|
||||
.releaseCount,
|
||||
.peakMemoryResident,
|
||||
]
|
||||
let maxIterations = 1_000_000
|
||||
let maxDuration: Duration = .seconds(3)
|
||||
let megaConfiguration: Benchmark.Configuration = .init(
|
||||
metrics: metrics,
|
||||
warmupIterations: 1,
|
||||
scalingFactor: .mega,
|
||||
maxDuration: maxDuration,
|
||||
maxIterations: maxIterations)
|
||||
|
||||
Benchmark.defaultConfiguration = megaConfiguration
|
||||
|
||||
// Decode (read path)
|
||||
|
||||
// Raw scalar read: isolates `read<T: BitwiseCopyable>` and the `let` blob.
|
||||
Benchmark("Reading Doubles") { benchmark in
|
||||
let byteBuffer = ByteBuffer(data: data)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(byteBuffer.read(def: Double.self, position: 0))
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
// Realistic decode: resolve root map and read a keyed scalar.
|
||||
Benchmark("Decode Map Scalar") { benchmark in
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
let map = try! getRoot(buffer: mapBuffer)!.map!
|
||||
blackHole(map["i25"]?.int)
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
// Realistic decode: resolve root map and read a keyed string.
|
||||
Benchmark("Decode Map String") { benchmark in
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
let map = try! getRoot(buffer: mapBuffer)!.map!
|
||||
blackHole(map["s"]?.string())
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
// Realistic decode: resolve a nested vector and sum its scalars.
|
||||
Benchmark("Decode Vector") { benchmark in
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
let map = try! getRoot(buffer: mapBuffer)!.map!
|
||||
let vector = map["v"]!.vector!
|
||||
var sum: Int64 = 0
|
||||
for i in 0..<vector.count {
|
||||
sum &+= vector[i]?.int ?? 0
|
||||
}
|
||||
blackHole(sum)
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
// Encode (write path)
|
||||
// Writers are reused with `reset(keepingCapacity:)` so per-iteration
|
||||
// allocation does not dominate and mask the write-path cost (which is what
|
||||
// the `@exclusivity(unchecked)` storage pointer affects).
|
||||
|
||||
Benchmark("Strings 10") { benchmark in
|
||||
var fbx = FlexBuffersWriter(initialSize: 1 << 20)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
fbx.add(string: str10)
|
||||
fbx.finish()
|
||||
blackHole(fbx.sizedByteBuffer)
|
||||
fbx.reset(keepingCapacity: true)
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark("Strings 100") { benchmark in
|
||||
var fbx = FlexBuffersWriter(initialSize: 1 << 20)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
fbx.add(string: str100)
|
||||
fbx.finish()
|
||||
blackHole(fbx.sizedByteBuffer)
|
||||
fbx.reset(keepingCapacity: true)
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark("Encoding Vector Of Ints") { benchmark in
|
||||
var fbx = FlexBuffersWriter(initialSize: 1 << 20)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
fbx.vector {
|
||||
$0.create(vector: ints)
|
||||
}
|
||||
fbx.finish()
|
||||
blackHole(fbx.sizedByteBuffer)
|
||||
fbx.reset(keepingCapacity: true)
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
|
||||
Benchmark("Encoding Map") { benchmark in
|
||||
var fbx = FlexBuffersWriter(initialSize: 1 << 20)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
fbx.map {
|
||||
for i in 0..<50 { $0.add(int: i, key: "i\(i)") }
|
||||
$0.add(string: "hello world", key: "s")
|
||||
$0.vector(key: "v") { v in
|
||||
for x in 0..<100 { v.add(int: x) }
|
||||
}
|
||||
}
|
||||
fbx.finish()
|
||||
blackHole(fbx.sizedByteBuffer)
|
||||
fbx.reset(keepingCapacity: true)
|
||||
}
|
||||
benchmark.stopMeasurement()
|
||||
}
|
||||
}
|
||||
@@ -39,4 +39,14 @@ let package = Package(
|
||||
plugins: [
|
||||
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
|
||||
]),
|
||||
.executableTarget(
|
||||
name: "FlexBuffersBenchmarks",
|
||||
dependencies: [
|
||||
.product(name: "FlexBuffers", package: "flatbuffers"),
|
||||
.product(name: "Benchmark", package: "package-benchmark"),
|
||||
],
|
||||
path: "Benchmarks/FlexBuffersBenchmarks",
|
||||
plugins: [
|
||||
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
|
||||
]),
|
||||
])
|
||||
|
||||
@@ -271,7 +271,7 @@ namespace flatbuffers {
|
||||
#if (defined(_MSC_VER) && _MSC_VER >= 1800) || \
|
||||
(defined(__ANDROID__) && defined(__ANDROID_API__) && __ANDROID_API__>= 26) || \
|
||||
(defined(_XOPEN_VERSION) && (_XOPEN_VERSION >= 700)) && \
|
||||
!defined(__Fuchsia__)
|
||||
!defined(__Fuchsia__) && (!defined(__linux__) || defined(__GLIBC__))
|
||||
#define FLATBUFFERS_LOCALE_INDEPENDENT 1
|
||||
#else
|
||||
#define FLATBUFFERS_LOCALE_INDEPENDENT 0
|
||||
|
||||
@@ -24,15 +24,14 @@ class handle:
|
||||
struct offset:
|
||||
o:int
|
||||
|
||||
enum sizeof:
|
||||
sz_8 = 1
|
||||
sz_16 = 2
|
||||
sz_32 = 4
|
||||
sz_64 = 8
|
||||
sz_voffset = 2
|
||||
sz_uoffset = 4
|
||||
sz_soffset = 4
|
||||
sz_metadata_fields = 2
|
||||
let sz_8 = 1
|
||||
let sz_16 = 2
|
||||
let sz_32 = 4
|
||||
let sz_64 = 8
|
||||
let sz_voffset = 2
|
||||
let sz_uoffset = 4
|
||||
let sz_soffset = 4
|
||||
let sz_metadata_fields = 2
|
||||
|
||||
class builder:
|
||||
buf = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
|
||||
Generated
+84
-78
@@ -16,22 +16,22 @@ importers:
|
||||
version: 24.0.3
|
||||
'@typescript-eslint/eslint-plugin':
|
||||
specifier: ^8.34.1
|
||||
version: 8.34.1(@typescript-eslint/parser@8.34.1(eslint@9.29.0)(typescript@5.8.3))(eslint@9.29.0)(typescript@5.8.3)
|
||||
version: 8.34.1(@typescript-eslint/parser@8.34.1(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3))(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3)
|
||||
'@typescript-eslint/parser':
|
||||
specifier: ^8.34.1
|
||||
version: 8.34.1(eslint@9.29.0)(typescript@5.8.3)
|
||||
version: 8.34.1(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3)
|
||||
esbuild:
|
||||
specifier: ^0.25.5
|
||||
version: 0.25.5
|
||||
eslint:
|
||||
specifier: ^9.29.0
|
||||
version: 9.29.0
|
||||
version: 9.29.0(supports-color@7.2.0)
|
||||
typescript:
|
||||
specifier: 5.8.3
|
||||
version: 5.8.3
|
||||
typescript-eslint:
|
||||
specifier: ^8.34.1
|
||||
version: 8.34.1(eslint@9.29.0)(typescript@5.8.3)
|
||||
version: 8.34.1(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3)
|
||||
|
||||
tests/ts:
|
||||
dependencies:
|
||||
@@ -239,22 +239,22 @@ packages:
|
||||
resolution: {integrity: sha512-Z5kJ+wU3oA7MMIqVR9tyZRtjYPr4OC004Q4Rw7pgOKUOKkJfZ3O24nz3WYfGRpMDNmcOi3TwQOmgm7B7Tpii0w==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
|
||||
'@humanfs/core@0.19.1':
|
||||
resolution: {integrity: sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA==}
|
||||
'@humanfs/core@0.19.2':
|
||||
resolution: {integrity: sha512-UhXNm+CFMWcbChXywFwkmhqjs3PRCmcSa/hfBgLIb7oQ5HNb1wS0icWsGtSAUNgefHeI+eBrA8I1fxmbHsGdvA==}
|
||||
engines: {node: '>=18.18.0'}
|
||||
|
||||
'@humanfs/node@0.16.6':
|
||||
resolution: {integrity: sha512-YuI2ZHQL78Q5HbhDiBA1X4LmYdXCKCMQIfw0pw7piHJwyREFebJUvrQN4cMssyES6x+vfUbx1CIpaQUKYdQZOw==}
|
||||
'@humanfs/node@0.16.8':
|
||||
resolution: {integrity: sha512-gE1eQNZ3R++kTzFUpdGlpmy8kDZD/MLyHqDwqjkVQI0JMdI1D51sy1H958PNXYkM2rAac7e5/CnIKZrHtPh3BQ==}
|
||||
engines: {node: '>=18.18.0'}
|
||||
|
||||
'@humanfs/types@0.15.0':
|
||||
resolution: {integrity: sha512-ZZ1w0aoQkwuUuC7Yf+7sdeaNfqQiiLcSRbfI08oAxqLtpXQr9AIVX7Ay7HLDuiLYAaFPu8oBYNq/QIi9URHJ3Q==}
|
||||
engines: {node: '>=18.18.0'}
|
||||
|
||||
'@humanwhocodes/module-importer@1.0.1':
|
||||
resolution: {integrity: sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==}
|
||||
engines: {node: '>=12.22'}
|
||||
|
||||
'@humanwhocodes/retry@0.3.1':
|
||||
resolution: {integrity: sha512-JBxkERygn7Bv/GbN5Rv8Ul6LVknS+5Bp6RgDC/O8gEBU/yeH5Ui5C/OlWrTb6qct7LjjfT6Re2NxB0ln0yYybA==}
|
||||
engines: {node: '>=18.18'}
|
||||
|
||||
'@humanwhocodes/retry@0.4.3':
|
||||
resolution: {integrity: sha512-bV0Tgo9K4hfPCek+aMAn81RppFKv2ySDQeMoSZuvTASywNTnVJCArCZE2FWqpvIatKu7VMRLWlR1EazvVhDyhQ==}
|
||||
engines: {node: '>=18.18'}
|
||||
@@ -362,11 +362,11 @@ packages:
|
||||
balanced-match@1.0.2:
|
||||
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
|
||||
|
||||
brace-expansion@1.1.12:
|
||||
resolution: {integrity: sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==}
|
||||
brace-expansion@1.1.21:
|
||||
resolution: {integrity: sha512-9zeA+KLZNNzglF2TPKRQEDyx6Yby7daAkuy8MiPzpXPsYDWi/DRM8jmwUDxokQjYqBpv5DgPiwD4h4ZZSy1Ujw==}
|
||||
|
||||
brace-expansion@2.0.2:
|
||||
resolution: {integrity: sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==}
|
||||
brace-expansion@2.1.7:
|
||||
resolution: {integrity: sha512-uZbew1NqdmPDTMJ8ah1y+b+9QEJrfkXFk3RcTQw3X0jW/xRUvFKsg1CfQdSYGdTbXZWExtU3J3ccxtnfw1Fi0g==}
|
||||
|
||||
braces@3.0.3:
|
||||
resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==}
|
||||
@@ -430,6 +430,7 @@ packages:
|
||||
eslint@9.29.0:
|
||||
resolution: {integrity: sha512-GsGizj2Y1rCWDu6XoEekL3RLilp0voSePurjZIkxL3wlm5o5EC9VpgaP7lrCvjnkuLvzFBQWB3vWB3K5KQTveQ==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
deprecated: This version is no longer supported. Please see https://eslint.org/version-support for other options.
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
jiti: '*'
|
||||
@@ -542,8 +543,8 @@ packages:
|
||||
isexe@2.0.0:
|
||||
resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}
|
||||
|
||||
js-yaml@4.1.1:
|
||||
resolution: {integrity: sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==}
|
||||
js-yaml@4.3.2:
|
||||
resolution: {integrity: sha512-SFNOvSJ+Dgf/9An904Yx+CgSlIPCkIpao4qo51lpee25TIRejdH3rhR4EZMGoNx3/TP3O+wzWuiTFl4sqbltzA==}
|
||||
hasBin: true
|
||||
|
||||
json-buffer@3.0.1:
|
||||
@@ -614,8 +615,8 @@ packages:
|
||||
resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
picomatch@2.3.1:
|
||||
resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
|
||||
picomatch@2.3.2:
|
||||
resolution: {integrity: sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==}
|
||||
engines: {node: '>=8.6'}
|
||||
|
||||
prelude-ls@1.2.1:
|
||||
@@ -783,22 +784,22 @@ snapshots:
|
||||
'@esbuild/win32-x64@0.25.5':
|
||||
optional: true
|
||||
|
||||
'@eslint-community/eslint-utils@4.4.0(eslint@9.29.0)':
|
||||
'@eslint-community/eslint-utils@4.4.0(eslint@9.29.0(supports-color@7.2.0))':
|
||||
dependencies:
|
||||
eslint: 9.29.0
|
||||
eslint: 9.29.0(supports-color@7.2.0)
|
||||
eslint-visitor-keys: 3.4.3
|
||||
|
||||
'@eslint-community/eslint-utils@4.7.0(eslint@9.29.0)':
|
||||
'@eslint-community/eslint-utils@4.7.0(eslint@9.29.0(supports-color@7.2.0))':
|
||||
dependencies:
|
||||
eslint: 9.29.0
|
||||
eslint: 9.29.0(supports-color@7.2.0)
|
||||
eslint-visitor-keys: 3.4.3
|
||||
|
||||
'@eslint-community/regexpp@4.12.1': {}
|
||||
|
||||
'@eslint/config-array@0.20.1':
|
||||
'@eslint/config-array@0.20.1(supports-color@7.2.0)':
|
||||
dependencies:
|
||||
'@eslint/object-schema': 2.1.6
|
||||
debug: 4.3.7
|
||||
debug: 4.3.7(supports-color@7.2.0)
|
||||
minimatch: 3.1.5
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
@@ -813,15 +814,15 @@ snapshots:
|
||||
dependencies:
|
||||
'@types/json-schema': 7.0.15
|
||||
|
||||
'@eslint/eslintrc@3.3.1':
|
||||
'@eslint/eslintrc@3.3.1(supports-color@7.2.0)':
|
||||
dependencies:
|
||||
ajv: 6.14.0
|
||||
debug: 4.3.7
|
||||
debug: 4.3.7(supports-color@7.2.0)
|
||||
espree: 10.4.0
|
||||
globals: 14.0.0
|
||||
ignore: 5.3.2
|
||||
import-fresh: 3.3.0
|
||||
js-yaml: 4.1.1
|
||||
js-yaml: 4.3.2
|
||||
minimatch: 3.1.5
|
||||
strip-json-comments: 3.1.1
|
||||
transitivePeerDependencies:
|
||||
@@ -836,17 +837,20 @@ snapshots:
|
||||
'@eslint/core': 0.15.2
|
||||
levn: 0.4.1
|
||||
|
||||
'@humanfs/core@0.19.1': {}
|
||||
|
||||
'@humanfs/node@0.16.6':
|
||||
'@humanfs/core@0.19.2':
|
||||
dependencies:
|
||||
'@humanfs/core': 0.19.1
|
||||
'@humanwhocodes/retry': 0.3.1
|
||||
'@humanfs/types': 0.15.0
|
||||
|
||||
'@humanfs/node@0.16.8':
|
||||
dependencies:
|
||||
'@humanfs/core': 0.19.2
|
||||
'@humanfs/types': 0.15.0
|
||||
'@humanwhocodes/retry': 0.4.3
|
||||
|
||||
'@humanfs/types@0.15.0': {}
|
||||
|
||||
'@humanwhocodes/module-importer@1.0.1': {}
|
||||
|
||||
'@humanwhocodes/retry@0.3.1': {}
|
||||
|
||||
'@humanwhocodes/retry@0.4.3': {}
|
||||
|
||||
'@nodelib/fs.scandir@2.1.5':
|
||||
@@ -869,15 +873,15 @@ snapshots:
|
||||
dependencies:
|
||||
undici-types: 7.8.0
|
||||
|
||||
'@typescript-eslint/eslint-plugin@8.34.1(@typescript-eslint/parser@8.34.1(eslint@9.29.0)(typescript@5.8.3))(eslint@9.29.0)(typescript@5.8.3)':
|
||||
'@typescript-eslint/eslint-plugin@8.34.1(@typescript-eslint/parser@8.34.1(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3))(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3)':
|
||||
dependencies:
|
||||
'@eslint-community/regexpp': 4.12.1
|
||||
'@typescript-eslint/parser': 8.34.1(eslint@9.29.0)(typescript@5.8.3)
|
||||
'@typescript-eslint/parser': 8.34.1(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3)
|
||||
'@typescript-eslint/scope-manager': 8.34.1
|
||||
'@typescript-eslint/type-utils': 8.34.1(eslint@9.29.0)(typescript@5.8.3)
|
||||
'@typescript-eslint/utils': 8.34.1(eslint@9.29.0)(typescript@5.8.3)
|
||||
'@typescript-eslint/type-utils': 8.34.1(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3)
|
||||
'@typescript-eslint/utils': 8.34.1(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3)
|
||||
'@typescript-eslint/visitor-keys': 8.34.1
|
||||
eslint: 9.29.0
|
||||
eslint: 9.29.0(supports-color@7.2.0)
|
||||
graphemer: 1.4.0
|
||||
ignore: 7.0.5
|
||||
natural-compare: 1.4.0
|
||||
@@ -886,23 +890,23 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@typescript-eslint/parser@8.34.1(eslint@9.29.0)(typescript@5.8.3)':
|
||||
'@typescript-eslint/parser@8.34.1(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3)':
|
||||
dependencies:
|
||||
'@typescript-eslint/scope-manager': 8.34.1
|
||||
'@typescript-eslint/types': 8.34.1
|
||||
'@typescript-eslint/typescript-estree': 8.34.1(typescript@5.8.3)
|
||||
'@typescript-eslint/typescript-estree': 8.34.1(supports-color@7.2.0)(typescript@5.8.3)
|
||||
'@typescript-eslint/visitor-keys': 8.34.1
|
||||
debug: 4.3.7
|
||||
eslint: 9.29.0
|
||||
debug: 4.3.7(supports-color@7.2.0)
|
||||
eslint: 9.29.0(supports-color@7.2.0)
|
||||
typescript: 5.8.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@typescript-eslint/project-service@8.34.1(typescript@5.8.3)':
|
||||
'@typescript-eslint/project-service@8.34.1(supports-color@7.2.0)(typescript@5.8.3)':
|
||||
dependencies:
|
||||
'@typescript-eslint/tsconfig-utils': 8.34.1(typescript@5.8.3)
|
||||
'@typescript-eslint/types': 8.34.1
|
||||
debug: 4.3.7
|
||||
debug: 4.3.7(supports-color@7.2.0)
|
||||
typescript: 5.8.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
@@ -916,12 +920,12 @@ snapshots:
|
||||
dependencies:
|
||||
typescript: 5.8.3
|
||||
|
||||
'@typescript-eslint/type-utils@8.34.1(eslint@9.29.0)(typescript@5.8.3)':
|
||||
'@typescript-eslint/type-utils@8.34.1(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3)':
|
||||
dependencies:
|
||||
'@typescript-eslint/typescript-estree': 8.34.1(typescript@5.8.3)
|
||||
'@typescript-eslint/utils': 8.34.1(eslint@9.29.0)(typescript@5.8.3)
|
||||
debug: 4.3.7
|
||||
eslint: 9.29.0
|
||||
'@typescript-eslint/typescript-estree': 8.34.1(supports-color@7.2.0)(typescript@5.8.3)
|
||||
'@typescript-eslint/utils': 8.34.1(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3)
|
||||
debug: 4.3.7(supports-color@7.2.0)
|
||||
eslint: 9.29.0(supports-color@7.2.0)
|
||||
ts-api-utils: 2.1.0(typescript@5.8.3)
|
||||
typescript: 5.8.3
|
||||
transitivePeerDependencies:
|
||||
@@ -929,13 +933,13 @@ snapshots:
|
||||
|
||||
'@typescript-eslint/types@8.34.1': {}
|
||||
|
||||
'@typescript-eslint/typescript-estree@8.34.1(typescript@5.8.3)':
|
||||
'@typescript-eslint/typescript-estree@8.34.1(supports-color@7.2.0)(typescript@5.8.3)':
|
||||
dependencies:
|
||||
'@typescript-eslint/project-service': 8.34.1(typescript@5.8.3)
|
||||
'@typescript-eslint/project-service': 8.34.1(supports-color@7.2.0)(typescript@5.8.3)
|
||||
'@typescript-eslint/tsconfig-utils': 8.34.1(typescript@5.8.3)
|
||||
'@typescript-eslint/types': 8.34.1
|
||||
'@typescript-eslint/visitor-keys': 8.34.1
|
||||
debug: 4.3.7
|
||||
debug: 4.3.7(supports-color@7.2.0)
|
||||
fast-glob: 3.3.2
|
||||
is-glob: 4.0.3
|
||||
minimatch: 9.0.9
|
||||
@@ -945,13 +949,13 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@typescript-eslint/utils@8.34.1(eslint@9.29.0)(typescript@5.8.3)':
|
||||
'@typescript-eslint/utils@8.34.1(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3)':
|
||||
dependencies:
|
||||
'@eslint-community/eslint-utils': 4.7.0(eslint@9.29.0)
|
||||
'@eslint-community/eslint-utils': 4.7.0(eslint@9.29.0(supports-color@7.2.0))
|
||||
'@typescript-eslint/scope-manager': 8.34.1
|
||||
'@typescript-eslint/types': 8.34.1
|
||||
'@typescript-eslint/typescript-estree': 8.34.1(typescript@5.8.3)
|
||||
eslint: 9.29.0
|
||||
'@typescript-eslint/typescript-estree': 8.34.1(supports-color@7.2.0)(typescript@5.8.3)
|
||||
eslint: 9.29.0(supports-color@7.2.0)
|
||||
typescript: 5.8.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
@@ -982,12 +986,12 @@ snapshots:
|
||||
|
||||
balanced-match@1.0.2: {}
|
||||
|
||||
brace-expansion@1.1.12:
|
||||
brace-expansion@1.1.21:
|
||||
dependencies:
|
||||
balanced-match: 1.0.2
|
||||
concat-map: 0.0.1
|
||||
|
||||
brace-expansion@2.0.2:
|
||||
brace-expansion@2.1.7:
|
||||
dependencies:
|
||||
balanced-match: 1.0.2
|
||||
|
||||
@@ -1016,9 +1020,11 @@ snapshots:
|
||||
shebang-command: 2.0.0
|
||||
which: 2.0.2
|
||||
|
||||
debug@4.3.7:
|
||||
debug@4.3.7(supports-color@7.2.0):
|
||||
dependencies:
|
||||
ms: 2.1.3
|
||||
optionalDependencies:
|
||||
supports-color: 7.2.0
|
||||
|
||||
deep-is@0.1.4: {}
|
||||
|
||||
@@ -1061,17 +1067,17 @@ snapshots:
|
||||
|
||||
eslint-visitor-keys@4.2.1: {}
|
||||
|
||||
eslint@9.29.0:
|
||||
eslint@9.29.0(supports-color@7.2.0):
|
||||
dependencies:
|
||||
'@eslint-community/eslint-utils': 4.4.0(eslint@9.29.0)
|
||||
'@eslint-community/eslint-utils': 4.4.0(eslint@9.29.0(supports-color@7.2.0))
|
||||
'@eslint-community/regexpp': 4.12.1
|
||||
'@eslint/config-array': 0.20.1
|
||||
'@eslint/config-array': 0.20.1(supports-color@7.2.0)
|
||||
'@eslint/config-helpers': 0.2.3
|
||||
'@eslint/core': 0.14.0
|
||||
'@eslint/eslintrc': 3.3.1
|
||||
'@eslint/eslintrc': 3.3.1(supports-color@7.2.0)
|
||||
'@eslint/js': 9.29.0
|
||||
'@eslint/plugin-kit': 0.3.5
|
||||
'@humanfs/node': 0.16.6
|
||||
'@humanfs/node': 0.16.8
|
||||
'@humanwhocodes/module-importer': 1.0.1
|
||||
'@humanwhocodes/retry': 0.4.3
|
||||
'@types/estree': 1.0.8
|
||||
@@ -1079,7 +1085,7 @@ snapshots:
|
||||
ajv: 6.14.0
|
||||
chalk: 4.1.2
|
||||
cross-spawn: 7.0.6
|
||||
debug: 4.3.7
|
||||
debug: 4.3.7(supports-color@7.2.0)
|
||||
escape-string-regexp: 4.0.0
|
||||
eslint-scope: 8.4.0
|
||||
eslint-visitor-keys: 4.2.1
|
||||
@@ -1192,7 +1198,7 @@ snapshots:
|
||||
|
||||
isexe@2.0.0: {}
|
||||
|
||||
js-yaml@4.1.1:
|
||||
js-yaml@4.3.2:
|
||||
dependencies:
|
||||
argparse: 2.0.1
|
||||
|
||||
@@ -1222,15 +1228,15 @@ snapshots:
|
||||
micromatch@4.0.8:
|
||||
dependencies:
|
||||
braces: 3.0.3
|
||||
picomatch: 2.3.1
|
||||
picomatch: 2.3.2
|
||||
|
||||
minimatch@3.1.5:
|
||||
dependencies:
|
||||
brace-expansion: 1.1.12
|
||||
brace-expansion: 1.1.21
|
||||
|
||||
minimatch@9.0.9:
|
||||
dependencies:
|
||||
brace-expansion: 2.0.2
|
||||
brace-expansion: 2.1.7
|
||||
|
||||
ms@2.1.3: {}
|
||||
|
||||
@@ -1261,7 +1267,7 @@ snapshots:
|
||||
|
||||
path-key@3.1.1: {}
|
||||
|
||||
picomatch@2.3.1: {}
|
||||
picomatch@2.3.2: {}
|
||||
|
||||
prelude-ls@1.2.1: {}
|
||||
|
||||
@@ -1303,12 +1309,12 @@ snapshots:
|
||||
dependencies:
|
||||
prelude-ls: 1.2.1
|
||||
|
||||
typescript-eslint@8.34.1(eslint@9.29.0)(typescript@5.8.3):
|
||||
typescript-eslint@8.34.1(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3):
|
||||
dependencies:
|
||||
'@typescript-eslint/eslint-plugin': 8.34.1(@typescript-eslint/parser@8.34.1(eslint@9.29.0)(typescript@5.8.3))(eslint@9.29.0)(typescript@5.8.3)
|
||||
'@typescript-eslint/parser': 8.34.1(eslint@9.29.0)(typescript@5.8.3)
|
||||
'@typescript-eslint/utils': 8.34.1(eslint@9.29.0)(typescript@5.8.3)
|
||||
eslint: 9.29.0
|
||||
'@typescript-eslint/eslint-plugin': 8.34.1(@typescript-eslint/parser@8.34.1(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3))(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3)
|
||||
'@typescript-eslint/parser': 8.34.1(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3)
|
||||
'@typescript-eslint/utils': 8.34.1(eslint@9.29.0(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.8.3)
|
||||
eslint: 9.29.0(supports-color@7.2.0)
|
||||
typescript: 5.8.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
+1
-1
@@ -404,7 +404,7 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ += "struct {{STRUCT_NAME}}BinarySchema {";
|
||||
code_ += " static const uint8_t *data() {";
|
||||
code_ += " // Buffer containing the binary schema.";
|
||||
code_ += " static const uint8_t bfbsData[" +
|
||||
code_ += " alignas(uint64_t) static const uint8_t bfbsData[" +
|
||||
NumToString(parser_.builder_.GetSize()) + "] = {";
|
||||
code_ += binary_schema_hex_text;
|
||||
code_ += " };";
|
||||
|
||||
+6
-25
@@ -654,34 +654,15 @@ class DartGenerator : public BaseGenerator {
|
||||
|
||||
std::string NamespaceAliasFromUnionType(Namespace* root_namespace,
|
||||
const Type& type) {
|
||||
const std::vector<std::string> qualified_name_parts =
|
||||
type.struct_def->defined_namespace->components;
|
||||
if (std::equal(root_namespace->components.begin(),
|
||||
root_namespace->components.end(),
|
||||
qualified_name_parts.begin())) {
|
||||
const Namespace& type_namespace = *type.struct_def->defined_namespace;
|
||||
if (root_namespace->components == type_namespace.components) {
|
||||
return namer_.Type(*type.struct_def);
|
||||
}
|
||||
|
||||
std::string ns;
|
||||
|
||||
for (auto it = qualified_name_parts.begin();
|
||||
it != qualified_name_parts.end(); ++it) {
|
||||
auto& part = *it;
|
||||
|
||||
for (size_t i = 0; i < part.length(); i++) {
|
||||
if (i && !isdigit(part[i]) && part[i] == CharToUpper(part[i])) {
|
||||
ns += "_";
|
||||
ns += CharToLower(part[i]);
|
||||
} else {
|
||||
ns += CharToLower(part[i]);
|
||||
}
|
||||
}
|
||||
if (it != qualified_name_parts.end() - 1) {
|
||||
ns += "_";
|
||||
}
|
||||
}
|
||||
|
||||
return ns + "." + namer_.Type(*type.struct_def);
|
||||
const std::string ns = namer_.Namespace(type_namespace);
|
||||
return ns.empty()
|
||||
? namer_.Type(*type.struct_def)
|
||||
: ImportAliasName(ns) + "." + namer_.Type(*type.struct_def);
|
||||
}
|
||||
|
||||
void GenImplementationGetters(
|
||||
|
||||
@@ -28,7 +28,7 @@ public let FileIdLength = 4
|
||||
/// Protocol that All Scalars should conform to
|
||||
///
|
||||
/// Scalar is used to conform all the numbers that can be represented in a FlatBuffer. It's used to write/read from the buffer.
|
||||
public protocol Scalar: Equatable {
|
||||
public protocol Scalar: Equatable, BitwiseCopyable {
|
||||
associatedtype NumericValue
|
||||
var convertedEndian: NumericValue { get }
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public struct ByteBuffer: @unchecked Sendable {
|
||||
@usableFromInline
|
||||
final class Storage {
|
||||
@usableFromInline
|
||||
enum Blob {
|
||||
@frozen enum Blob: ~Copyable {
|
||||
#if !os(WASI)
|
||||
case data(Data)
|
||||
case bytes(any ContiguousBytes)
|
||||
@@ -36,6 +36,40 @@ public struct ByteBuffer: @unchecked Sendable {
|
||||
case byteBuffer(_InternalByteBuffer)
|
||||
case array([UInt8])
|
||||
case pointer(UnsafeMutableRawPointer)
|
||||
|
||||
init(_ other: borrowing Blob) {
|
||||
switch other {
|
||||
#if !os(WASI)
|
||||
case .data(let data):
|
||||
self = .data(data)
|
||||
case .bytes(let contiguousBytes):
|
||||
self = .bytes(contiguousBytes)
|
||||
#endif
|
||||
case .byteBuffer(let internalByteBuffer):
|
||||
self = .byteBuffer(internalByteBuffer)
|
||||
case .array(let array):
|
||||
self = .array(array)
|
||||
case .pointer(let unsafeMutableRawPointer):
|
||||
self = .pointer(unsafeMutableRawPointer)
|
||||
}
|
||||
}
|
||||
|
||||
var description: String {
|
||||
switch self {
|
||||
#if !os(WASI)
|
||||
case .data(let data):
|
||||
"data: \(data)"
|
||||
case .bytes(let contiguousBytes):
|
||||
"bytes: \(contiguousBytes)"
|
||||
#endif
|
||||
case .byteBuffer(let internalByteBuffer):
|
||||
"byteBuffer: \(internalByteBuffer)"
|
||||
case .array(let array):
|
||||
"array: \(array)"
|
||||
case .pointer(let unsafeMutableRawPointer):
|
||||
"pointer: \(unsafeMutableRawPointer)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This storage doesn't own the memory, therefore, we won't deallocate on deinit.
|
||||
@@ -44,7 +78,7 @@ public struct ByteBuffer: @unchecked Sendable {
|
||||
private let capacity: Int
|
||||
/// Retained blob of data that requires the storage to retain a pointer to.
|
||||
@usableFromInline
|
||||
var retainedBlob: Blob
|
||||
let retainedBlob: Blob
|
||||
|
||||
@usableFromInline
|
||||
init(count: Int) {
|
||||
@@ -57,9 +91,9 @@ public struct ByteBuffer: @unchecked Sendable {
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
init(blob: Blob, capacity count: Int) {
|
||||
init(blob: borrowing Blob, capacity count: Int) {
|
||||
capacity = count
|
||||
retainedBlob = blob
|
||||
retainedBlob = .init(blob)
|
||||
isOwned = false
|
||||
}
|
||||
|
||||
@@ -150,6 +184,7 @@ public struct ByteBuffer: @unchecked Sendable {
|
||||
|
||||
@discardableResult
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
func readWithUnsafeRawPointer<T>(
|
||||
position: Int,
|
||||
_ body: (UnsafeRawPointer) throws -> T) rethrows -> T
|
||||
@@ -278,7 +313,7 @@ public struct ByteBuffer: @unchecked Sendable {
|
||||
/// - removeBytes: Removes a number of bytes from the current size
|
||||
@inline(__always)
|
||||
init(
|
||||
blob: Storage.Blob,
|
||||
blob: borrowing Storage.Blob,
|
||||
count: Int,
|
||||
removing removeBytes: Int)
|
||||
{
|
||||
@@ -318,7 +353,8 @@ public struct ByteBuffer: @unchecked Sendable {
|
||||
/// - def: Type of the object
|
||||
/// - position: the index of the object in the buffer
|
||||
@inline(__always)
|
||||
public func read<T>(def: T.Type, position: Int) -> T {
|
||||
@inlinable
|
||||
public func read<T: BitwiseCopyable>(def: T.Type, position: Int) -> T {
|
||||
_storage.readWithUnsafeRawPointer(position: position) {
|
||||
$0.bindMemory(to: T.self, capacity: 1)
|
||||
.pointee
|
||||
@@ -412,7 +448,7 @@ public struct ByteBuffer: @unchecked Sendable {
|
||||
/// - Parameter removeBytes: the amount of bytes to remove from the current Size
|
||||
@inline(__always)
|
||||
public func duplicate(removing removeBytes: Int = 0) -> ByteBuffer {
|
||||
assert(removeBytes > 0, "Can NOT remove negative bytes")
|
||||
assert(removeBytes >= 0, "Can NOT remove negative bytes")
|
||||
assert(
|
||||
removeBytes < capacity,
|
||||
"Can NOT remove more bytes than the ones allocated")
|
||||
@@ -464,8 +500,9 @@ public struct ByteBuffer: @unchecked Sendable {
|
||||
extension ByteBuffer: CustomDebugStringConvertible {
|
||||
|
||||
public var debugDescription: String {
|
||||
"""
|
||||
buffer located at: \(_storage.retainedBlob),
|
||||
let blobDescription = _storage.retainedBlob.description
|
||||
return """
|
||||
buffer located at: \(blobDescription),
|
||||
with capacity of \(capacity),
|
||||
{ writtenSize: \(_readerIndex), readerSize: \(reader),
|
||||
size: \(size) }
|
||||
|
||||
@@ -47,7 +47,8 @@ public struct FlatBufferBuilder {
|
||||
/// A check to see if finish(::) was ever called to retreive data object
|
||||
private(set) var finished = false
|
||||
/// A check to see if the buffer should serialize Default values
|
||||
private var serializeDefaults: Bool
|
||||
@usableFromInline
|
||||
let serializeDefaults: Bool
|
||||
|
||||
/// Current alignment for the buffer
|
||||
var _minAlignment: Int = 0 {
|
||||
@@ -756,6 +757,7 @@ public struct FlatBufferBuilder {
|
||||
/// - offset: ``Offset`` of another object to be written
|
||||
/// - position: The predefined position of the object
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
mutating public func add(offset: Offset, at position: VOffset) {
|
||||
if offset.isEmpty { return }
|
||||
add(element: refer(to: offset.o), def: 0, at: position)
|
||||
@@ -794,6 +796,7 @@ public struct FlatBufferBuilder {
|
||||
/// - def: Default value for that element
|
||||
/// - position: The predefined position of the element
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
mutating public func add<T: Scalar>(
|
||||
element: T,
|
||||
def: T,
|
||||
@@ -813,6 +816,7 @@ public struct FlatBufferBuilder {
|
||||
/// - element: Optional element of type scalar
|
||||
/// - position: The predefined position of the element
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
mutating public func add<T: Scalar>(element: T?, at position: VOffset) {
|
||||
guard let element = element else { return }
|
||||
track(offset: push(element: element), at: position)
|
||||
@@ -825,6 +829,7 @@ public struct FlatBufferBuilder {
|
||||
/// - Parameter element: Element to insert
|
||||
/// - returns: position of the Element
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
@discardableResult
|
||||
mutating public func push<T: Scalar>(element: T) -> UOffset {
|
||||
let size = MemoryLayout<T>.size
|
||||
@@ -836,7 +841,8 @@ public struct FlatBufferBuilder {
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func read<T>(def: T.Type, position: Int) -> T {
|
||||
@inlinable
|
||||
public func read<T: BitwiseCopyable>(def: T.Type, position: Int) -> T {
|
||||
_bb.read(def: def, position: position)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import Foundation
|
||||
|
||||
/// NativeStruct is a protocol that indicates if the struct is a native `swift` struct
|
||||
/// since now we will be serializing native structs into the buffer.
|
||||
public protocol NativeStruct {}
|
||||
public protocol NativeStruct: BitwiseCopyable {}
|
||||
|
||||
public protocol FlatBufferVerifiableNativeStruct: NativeStruct, Verifiable {}
|
||||
|
||||
|
||||
@@ -16,6 +16,30 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
@inline(__always)
|
||||
private func verifySizePrefix(
|
||||
byteBuffer: inout ByteBuffer,
|
||||
requireExactSize: Bool,
|
||||
options: VerifierOptions) throws
|
||||
{
|
||||
let verifier = try Verifier(buffer: &byteBuffer, options: options)
|
||||
let prefixPosition = byteBuffer.reader
|
||||
let prefix: UOffset = try verifier.getValue(at: prefixPosition)
|
||||
let availableSize = byteBuffer.size &- UOffset(MemoryLayout<UOffset>.size)
|
||||
|
||||
if requireExactSize {
|
||||
guard prefix == availableSize else {
|
||||
throw FlatbuffersErrors.prefixedSizeNotEqualToBufferSize
|
||||
}
|
||||
} else if prefix > availableSize {
|
||||
throw FlatbuffersErrors.outOfBounds(
|
||||
position: UInt(prefixPosition)
|
||||
&+ UInt(MemoryLayout<UOffset>.size)
|
||||
&+ UInt(prefix),
|
||||
end: byteBuffer.capacity)
|
||||
}
|
||||
}
|
||||
|
||||
/// Takes in a prefixed sized buffer, where the prefixed size would be skipped.
|
||||
/// And would verify that the buffer passed is a valid `Flatbuffers` Object.
|
||||
/// - Parameters:
|
||||
@@ -31,6 +55,10 @@ public func getPrefixedSizeCheckedRoot<T: FlatBufferTable & Verifiable>(
|
||||
fileId: String? = nil,
|
||||
options: VerifierOptions = .init()) throws -> T
|
||||
{
|
||||
try verifySizePrefix(
|
||||
byteBuffer: &byteBuffer,
|
||||
requireExactSize: false,
|
||||
options: options)
|
||||
byteBuffer.skipPrefix()
|
||||
return try getCheckedRoot(
|
||||
byteBuffer: &byteBuffer,
|
||||
@@ -53,10 +81,11 @@ public func getCheckedPrefixedSizeRoot<T: FlatBufferTable & Verifiable>(
|
||||
fileId: String? = nil,
|
||||
options: VerifierOptions = .init()) throws -> T
|
||||
{
|
||||
let prefix = byteBuffer.skipPrefix()
|
||||
if prefix != byteBuffer.size {
|
||||
throw FlatbuffersErrors.prefixedSizeNotEqualToBufferSize
|
||||
}
|
||||
try verifySizePrefix(
|
||||
byteBuffer: &byteBuffer,
|
||||
requireExactSize: true,
|
||||
options: options)
|
||||
byteBuffer.skipPrefix()
|
||||
return try getCheckedRoot(
|
||||
byteBuffer: &byteBuffer,
|
||||
fileId: fileId,
|
||||
@@ -95,14 +124,15 @@ public func getCheckedRoot<T: FlatBufferTable & Verifiable>(
|
||||
options: VerifierOptions = .init()) throws -> T
|
||||
{
|
||||
var verifier = try Verifier(buffer: &byteBuffer, options: options)
|
||||
let rootPosition = byteBuffer.reader
|
||||
if let fileId = fileId {
|
||||
try verifier.verify(id: fileId)
|
||||
try verifier.verify(id: fileId, at: rootPosition)
|
||||
}
|
||||
try ForwardOffset<T>.verify(&verifier, at: 0, of: T.self)
|
||||
try ForwardOffset<T>.verify(&verifier, at: rootPosition, of: T.self)
|
||||
return T.init(
|
||||
byteBuffer,
|
||||
o: Int32(byteBuffer.read(def: UOffset.self, position: byteBuffer.reader))
|
||||
&+ Int32(byteBuffer.reader))
|
||||
o: Int32(byteBuffer.read(def: UOffset.self, position: rootPosition))
|
||||
&+ Int32(rootPosition))
|
||||
}
|
||||
|
||||
/// Returns a `NON-Checked` flatbuffers object
|
||||
|
||||
@@ -82,7 +82,7 @@ public struct Table {
|
||||
/// - Parameters:
|
||||
/// - type: Type of Element that needs to be read from the buffer
|
||||
/// - o: Offset of the Element
|
||||
public func readBuffer<T>(of type: T.Type, at o: Int32) -> T {
|
||||
public func readBuffer<T: BitwiseCopyable>(of type: T.Type, at o: Int32) -> T {
|
||||
bb.read(def: T.self, position: Int(o &+ position))
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,15 @@ extension Verifiable {
|
||||
let len: UOffset = try verifier.getValue(at: position)
|
||||
let intLen = Int(len)
|
||||
let start = Int(clamping: (position &+ MemoryLayout<Int32>.size).magnitude)
|
||||
let byteCount = intLen.multipliedReportingOverflow(
|
||||
by: MemoryLayout<T>.size)
|
||||
guard !byteCount.overflow else {
|
||||
throw FlatbuffersErrors.outOfBounds(
|
||||
position: UInt.max,
|
||||
end: verifier.capacity)
|
||||
}
|
||||
try verifier.isAligned(position: start, type: type.self)
|
||||
try verifier.rangeInBuffer(position: start, size: intLen)
|
||||
try verifier.rangeInBuffer(position: start, size: byteCount.partialValue)
|
||||
return (start, intLen)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public struct Verifier {
|
||||
/// - Parameter position: Current position to be read
|
||||
/// - Throws: `inBuffer` errors
|
||||
/// - Returns: a value of type `T` usually a `VTable` or a table offset
|
||||
internal func getValue<T>(at position: Int) throws -> T {
|
||||
internal func getValue<T: BitwiseCopyable>(at position: Int) throws -> T {
|
||||
try inBuffer(position: position, of: T.self)
|
||||
return _buffer.read(def: T.self, position: position)
|
||||
}
|
||||
@@ -215,12 +215,16 @@ public struct Verifier {
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
func verify(id: String) throws {
|
||||
func verify(id: String, at position: Int) throws {
|
||||
let size = MemoryLayout<Int32>.size
|
||||
guard storage.capacity >= (size &* 2) else {
|
||||
guard
|
||||
position >= 0,
|
||||
position <= storage.capacity,
|
||||
storage.capacity - position >= size &* 2
|
||||
else {
|
||||
throw FlatbuffersErrors.bufferDoesntContainID
|
||||
}
|
||||
let str = _buffer.readString(at: size, count: size)
|
||||
let str = _buffer.readString(at: position &+ size, count: size)
|
||||
if id == str {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ struct _InternalByteBuffer {
|
||||
@usableFromInline
|
||||
final class Storage {
|
||||
/// pointer to the start of the buffer object in memory
|
||||
private(set) var memory: UnsafeMutableRawPointer
|
||||
@exclusivity(unchecked) private(set) var memory: UnsafeMutableRawPointer
|
||||
|
||||
@usableFromInline
|
||||
init(count: Int, alignment: Int) {
|
||||
@@ -333,6 +333,7 @@ struct _InternalByteBuffer {
|
||||
|
||||
@discardableResult
|
||||
@inline(__always)
|
||||
@usableFromInline
|
||||
func readWithUnsafeRawPointer<T>(
|
||||
position: Int,
|
||||
_ body: (UnsafeRawPointer) throws -> T) rethrows -> T
|
||||
|
||||
@@ -27,7 +27,7 @@ public struct ByteBuffer {
|
||||
@usableFromInline
|
||||
final class Storage {
|
||||
@usableFromInline
|
||||
enum Blob {
|
||||
@frozen enum Blob: ~Copyable {
|
||||
#if !os(WASI)
|
||||
case data(Data)
|
||||
case bytes(any ContiguousBytes)
|
||||
@@ -36,6 +36,23 @@ public struct ByteBuffer {
|
||||
case byteBuffer(_InternalByteBuffer)
|
||||
case array([UInt8])
|
||||
case pointer(UnsafeMutableRawPointer)
|
||||
|
||||
init(_ other: borrowing Blob) {
|
||||
switch other {
|
||||
#if !os(WASI)
|
||||
case .data(let data):
|
||||
self = .data(data)
|
||||
case .bytes(let contiguousBytes):
|
||||
self = .bytes(contiguousBytes)
|
||||
#endif
|
||||
case .byteBuffer(let internalByteBuffer):
|
||||
self = .byteBuffer(internalByteBuffer)
|
||||
case .array(let array):
|
||||
self = .array(array)
|
||||
case .pointer(let unsafeMutableRawPointer):
|
||||
self = .pointer(unsafeMutableRawPointer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This storage doesn't own the memory, therefore, we won't deallocate on deinit.
|
||||
@@ -44,7 +61,7 @@ public struct ByteBuffer {
|
||||
private let capacity: Int
|
||||
/// Retained blob of data that requires the storage to retain a pointer to.
|
||||
@usableFromInline
|
||||
var retainedBlob: Blob
|
||||
let retainedBlob: Blob
|
||||
|
||||
@usableFromInline
|
||||
init(count: Int) {
|
||||
@@ -57,9 +74,9 @@ public struct ByteBuffer {
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
init(blob: Blob, capacity count: Int) {
|
||||
init(blob: borrowing Blob, capacity count: Int) {
|
||||
capacity = count
|
||||
retainedBlob = blob
|
||||
retainedBlob = .init(blob)
|
||||
isOwned = false
|
||||
}
|
||||
|
||||
@@ -276,7 +293,7 @@ public struct ByteBuffer {
|
||||
/// - removeBytes: Removes a number of bytes from the current size
|
||||
@inline(__always)
|
||||
init(
|
||||
blob: Storage.Blob,
|
||||
blob: borrowing Storage.Blob,
|
||||
count: Int,
|
||||
removing removeBytes: Int)
|
||||
{
|
||||
@@ -316,7 +333,7 @@ public struct ByteBuffer {
|
||||
/// - def: Type of the object
|
||||
/// - position: the index of the object in the buffer
|
||||
@inline(__always)
|
||||
public func read<T>(def: T.Type, position: Int) -> T {
|
||||
public func read<T: BitwiseCopyable>(def: T.Type, position: Int) -> T {
|
||||
_storage.readWithUnsafeRawPointer(position: position) {
|
||||
$0.bindMemory(to: T.self, capacity: 1)
|
||||
.pointee
|
||||
@@ -360,10 +377,10 @@ public struct ByteBuffer {
|
||||
@inline(__always)
|
||||
func readSizedScalar<
|
||||
T: BinaryInteger,
|
||||
T1: BinaryInteger,
|
||||
T2: BinaryInteger,
|
||||
T3: BinaryInteger,
|
||||
T4: BinaryInteger
|
||||
T1: BinaryInteger & BitwiseCopyable,
|
||||
T2: BinaryInteger & BitwiseCopyable,
|
||||
T3: BinaryInteger & BitwiseCopyable,
|
||||
T4: BinaryInteger & BitwiseCopyable
|
||||
>(
|
||||
def: T.Type,
|
||||
t1: T1.Type,
|
||||
|
||||
@@ -31,7 +31,7 @@ struct _InternalByteBuffer {
|
||||
@usableFromInline
|
||||
final class Storage {
|
||||
/// pointer to the start of the buffer object in memory
|
||||
var memory: UnsafeMutableRawPointer
|
||||
@exclusivity(unchecked) private(set) var memory: UnsafeMutableRawPointer
|
||||
|
||||
@usableFromInline
|
||||
init(count: Int, alignment: Int) {
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Example {
|
||||
struct MonsterBinarySchema {
|
||||
static const uint8_t *data() {
|
||||
// Buffer containing the binary schema.
|
||||
static const uint8_t bfbsData[14520] = {
|
||||
alignas(uint64_t) static const uint8_t bfbsData[14520] = {
|
||||
0x20,0x00,0x00,0x00,0x42,0x46,0x42,0x53,0x00,0x00,0x00,0x00,0x14,0x00,0x20,0x00,0x04,0x00,0x08,0x00,
|
||||
0x0C,0x00,0x10,0x00,0x14,0x00,0x18,0x00,0x00,0x00,0x1C,0x00,0x14,0x00,0x00,0x00,0x58,0x00,0x00,0x00,
|
||||
0x34,0x00,0x00,0x00,0x24,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x70,0x0D,0x00,0x00,0x08,0x00,0x00,0x00,
|
||||
|
||||
@@ -373,6 +373,58 @@ final class FlatbuffersVerifierTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func testSizePrefixedVerifierUsesPostPrefixRoot() throws {
|
||||
// The size prefix points to a valid empty decoy table at byte 44. The real
|
||||
// root at byte 4 points to a truncated UInt64 vector that must be rejected.
|
||||
let bytes: [UInt8] = [
|
||||
44, 0, 0, 0,
|
||||
16, 0, 0, 0,
|
||||
6, 0, 8, 0, 4, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
12, 0, 0, 0,
|
||||
8, 0, 0, 0, 0, 0, 0, 0,
|
||||
2, 0, 0, 0, 65, 66,
|
||||
0, 0,
|
||||
4, 0, 4, 0,
|
||||
4, 0, 0, 0,
|
||||
]
|
||||
|
||||
var strictBuffer = ByteBuffer(bytes: bytes)
|
||||
#expect(throws: FlatbuffersErrors.self) {
|
||||
try getCheckedPrefixedSizeRoot(
|
||||
byteBuffer: &strictBuffer) as Swift_Tests_Vectors
|
||||
}
|
||||
|
||||
var prefixedBuffer = ByteBuffer(bytes: bytes)
|
||||
#expect(throws: FlatbuffersErrors.self) {
|
||||
try getPrefixedSizeCheckedRoot(
|
||||
byteBuffer: &prefixedBuffer) as Swift_Tests_Vectors
|
||||
}
|
||||
|
||||
var builder = FlatBufferBuilder()
|
||||
let movie = Movie.createMovie(&builder)
|
||||
Movie.finish(&builder, end: movie, prefix: true)
|
||||
var validBuffer = builder.sizedBuffer
|
||||
let _: Movie = try getCheckedPrefixedSizeRoot(
|
||||
byteBuffer: &validBuffer,
|
||||
fileId: Movie.id)
|
||||
|
||||
var shortBuffer = ByteBuffer(bytes: [0, 0, 0, 0])
|
||||
#expect(throws: FlatbuffersErrors.bufferDoesntContainID) {
|
||||
try getCheckedRoot(
|
||||
byteBuffer: &shortBuffer,
|
||||
fileId: Movie.id) as Movie
|
||||
}
|
||||
|
||||
var oversizedPrefix = ByteBuffer(bytes: [5, 0, 0, 0, 0, 0, 0, 0])
|
||||
#expect(throws: FlatbuffersErrors.outOfBounds(position: 9, end: 8)) {
|
||||
try getPrefixedSizeCheckedRoot(
|
||||
byteBuffer: &oversizedPrefix) as Movie
|
||||
}
|
||||
#expect(oversizedPrefix.reader == 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
func testFullVerifier() throws {
|
||||
_ =
|
||||
@@ -411,6 +463,27 @@ final class FlatbuffersVerifierTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(.bug("https://github.com/google/flatbuffers/issues/9082"))
|
||||
func testRejectsTruncatedScalarVector() {
|
||||
// swiftformat:disable all
|
||||
var byteBuffer = ByteBuffer(bytes: [
|
||||
16, 0, 0, 0,
|
||||
6, 0, 8, 0,
|
||||
4, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
12, 0, 0, 0,
|
||||
8, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
2, 0, 0, 0,
|
||||
65, 66,
|
||||
])
|
||||
// swiftformat:enable all
|
||||
|
||||
#expect(throws: FlatbuffersErrors.self) {
|
||||
try getCheckedRoot(byteBuffer: &byteBuffer) as Swift_Tests_Vectors
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func testValidUnionBuffer() {
|
||||
let string = "Awesome \\\\t\t\nstring!"
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"lodash": "4.17.23"
|
||||
"lodash": "4.18.1"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user