Skip to content

Commit 04da255

Browse files
authored
Merge branch 'master' into feature/python-obj-api-decode-strings
2 parents f47dce8 + 31beb0f commit 04da255

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+4589
-1080
lines changed

.eslintrc.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ jobs:
394394
# Force Xcode 14.3 since Xcode 15 doesnt support older versions of
395395
# kotlin. For Xcode 15, kotlin should be bumpped to 1.9.10
396396
# https://stackoverflow.com/a/77150623
397-
# For now, run with macos-13 which has this 14.3 installed:
397+
# For now, run with macos-13 which has this 14.3 installed:
398398
# https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md#xcode
399399
- name: Set up Xcode version
400400
run: sudo xcode-select -s /Applications/Xcode_14.3.app/Contents/Developer
@@ -534,14 +534,15 @@ jobs:
534534
- name: flatc
535535
# FIXME: make test script not rely on flatc
536536
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
537+
- name: pnpm
538+
run: npm install -g pnpm esbuild
537539
- name: deps
538-
run: yarn
540+
run: pnpm i
539541
- name: compile
540-
run: yarn compile
542+
run: pnpm compile
541543
- name: test
542544
working-directory: tests/ts
543545
run: |
544-
yarn global add esbuild
545546
python3 TypeScriptTest.py
546547
547548
build-dart:
@@ -582,12 +583,12 @@ jobs:
582583
- uses: actions/checkout@v3
583584
- name: bazel build
584585
run: >
585-
bazel build
586+
bazel build
586587
//:flatc
587588
//:flatbuffers
588589
- name: bazel test
589590
run: >
590-
bazel test
591+
bazel test
591592
//tests:flatbuffers_test
592593
593594
release-digests:

MODULE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ bazel_dep(
1515
)
1616
bazel_dep(
1717
name = "aspect_rules_js",
18-
version = "2.1.3",
18+
version = "2.3.8",
1919
)
2020
bazel_dep(
2121
name = "aspect_rules_ts",
22-
version = "3.4.0",
22+
version = "3.6.0",
2323
)
2424
bazel_dep(
2525
name = "grpc",

Package.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,28 @@ import PackageDescription
2020
let package = Package(
2121
name: "FlatBuffers",
2222
platforms: [
23-
.iOS(.v11),
23+
.iOS(.v12),
2424
.macOS(.v10_14),
2525
],
2626
products: [
2727
.library(
2828
name: "FlatBuffers",
2929
targets: ["FlatBuffers"]),
30+
.library(
31+
name: "FlexBuffers",
32+
targets: ["FlexBuffers"]),
3033
],
3134
targets: [
3235
.target(
3336
name: "FlatBuffers",
37+
dependencies: ["Common"],
38+
path: "swift/Sources/FlatBuffers"),
39+
.target(
40+
name: "FlexBuffers",
41+
dependencies: ["Common"],
42+
path: "swift/Sources/FlexBuffers"),
43+
.target(
44+
name: "Common",
3445
dependencies: [],
35-
path: "swift/Sources"),
46+
path: "swift/Sources/Common"),
3647
])

docs/source/flatc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ list of `FILES...`.
131131
- `--gen-mutable` : Generate additional non-const accessors for mutating
132132
FlatBuffers in-place.
133133

134-
- `--gen-onefile` : Generate single output file for C#, Go, and Python.
134+
- `--gen-onefile` : Generate a single output file for C#, Go, Java, Kotlin and Python.
135135

136136
- `--gen-name-strings` : Generate type name functions for C++.
137137

eslint.config.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
3+
import tseslint from "typescript-eslint";
4+
5+
export default [
6+
{files: ["**/*.{js,mjs,cjs,ts}"]},
7+
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
8+
pluginJs.configs.recommended,
9+
...tseslint.configs.recommended,
10+
];
Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,54 @@
1-
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
1+
# Generated by the gRPC FlatBuffers compiler. DO NOT EDIT!
22

3+
import flatbuffers
34
import grpc
45

6+
from models.HelloReply import HelloReply
7+
from models.HelloRequest import HelloRequest
8+
9+
510
class GreeterStub(object):
6-
""" Interface exported by the server. """
7-
11+
'''Interface exported by the server.'''
12+
813
def __init__(self, channel):
9-
""" Constructor.
10-
11-
Args:
12-
channel: A grpc.Channel.
13-
"""
14-
14+
'''Constructor.
15+
16+
Args:
17+
channel: A grpc.Channel.
18+
'''
19+
1520
self.SayHello = channel.unary_unary(
16-
"/models.Greeter/SayHello"
17-
)
18-
21+
method='/models.Greeter/SayHello')
22+
1923
self.SayManyHellos = channel.unary_stream(
20-
"/models.Greeter/SayManyHellos"
21-
)
22-
24+
method='/models.Greeter/SayManyHellos')
25+
2326

2427
class GreeterServicer(object):
25-
""" Interface exported by the server. """
26-
28+
'''Interface exported by the server.'''
29+
2730
def SayHello(self, request, context):
2831
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
2932
context.set_details('Method not implemented!')
3033
raise NotImplementedError('Method not implemented!')
31-
32-
34+
3335
def SayManyHellos(self, request, context):
3436
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
3537
context.set_details('Method not implemented!')
3638
raise NotImplementedError('Method not implemented!')
37-
38-
39+
3940

4041
def add_GreeterServicer_to_server(servicer, server):
4142
rpc_method_handlers = {
4243
'SayHello': grpc.unary_unary_rpc_method_handler(
43-
servicer.SayHello
44-
),
44+
servicer.SayHello),
4545
'SayManyHellos': grpc.unary_stream_rpc_method_handler(
46-
servicer.SayManyHellos
47-
),
46+
servicer.SayManyHellos),
4847
}
48+
4949
generic_handler = grpc.method_handlers_generic_handler(
5050
'models.Greeter', rpc_method_handlers)
51+
5152
server.add_generic_rpc_handlers((generic_handler,))
5253

54+

grpc/examples/swift/Greeter/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import PackageDescription
2020
let package = Package(
2121
name: "Greeter",
2222
platforms: [
23-
.iOS(.v11),
23+
.iOS(.v12),
2424
.macOS(.v10_14),
2525
],
2626
dependencies: [

grpc/src/compiler/python_generator.cc

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ namespace grpc {
3737
namespace {
3838
bool ClientStreaming(const RPCCall *method) {
3939
const Value *val = method->attributes.Lookup("streaming");
40-
return val != nullptr && (val->constant == "client" || val->constant == "bidi");
40+
return val != nullptr &&
41+
(val->constant == "client" || val->constant == "bidi");
4142
}
4243

4344
bool ServerStreaming(const RPCCall *method) {
4445
const Value *val = method->attributes.Lookup("streaming");
45-
return val != nullptr && (val->constant == "server" || val->constant == "bidi");
46+
return val != nullptr &&
47+
(val->constant == "server" || val->constant == "bidi");
4648
}
4749

4850
void FormatImports(std::stringstream &ss, const Imports &imports) {
@@ -103,9 +105,10 @@ class BaseGenerator {
103105
protected:
104106
BaseGenerator(const Parser &parser, const Namer::Config &config,
105107
const std::string &path, const Version &version)
106-
: parser_{parser},
107-
namer_{WithFlagOptions(config, parser.opts, path), Keywords(version)},
108-
version_{version} {}
108+
: parser_{ parser },
109+
namer_{ WithFlagOptions(config, parser.opts, path), Keywords(version) },
110+
version_{ version },
111+
path_(path) {}
109112

110113
protected:
111114
std::string ModuleForFile(const std::string &file) const {
@@ -115,15 +118,34 @@ class BaseGenerator {
115118
return module;
116119
}
117120

118-
template <typename T>
119-
std::string ModuleFor(const T *def) const {
121+
template<typename T> std::string ModuleFor(const T *def) const {
120122
if (parser_.opts.one_file) return ModuleForFile(def->file);
121123
return namer_.NamespacedType(*def);
122124
}
123125

126+
std::string NamespaceDir(const Parser &parser, const std::string &path,
127+
const Namespace &ns, const bool dasherize) {
128+
EnsureDirExists(path);
129+
if (parser.opts.one_file) return path;
130+
std::string namespace_dir = path; // Either empty or ends in separator.
131+
auto &namespaces = ns.components;
132+
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
133+
namespace_dir +=
134+
!dasherize ? *it : ConvertCase(*it, Case::kDasher, Case::kUpperCamel);
135+
namespace_dir += kPathSeparator;
136+
EnsureDirExists(namespace_dir);
137+
}
138+
return namespace_dir;
139+
}
140+
141+
std::string NamespaceDir(const Namespace &ns, const bool dasherize) {
142+
return NamespaceDir(parser_, path_, ns, dasherize);
143+
}
144+
124145
const Parser &parser_;
125146
const IdlNamer namer_;
126147
const Version version_;
148+
const std::string &path_;
127149
};
128150

129151
class StubGenerator : public BaseGenerator {
@@ -135,14 +157,18 @@ class StubGenerator : public BaseGenerator {
135157
bool Generate() {
136158
Imports imports;
137159
std::stringstream stub;
160+
std::string ns_name{};
138161
for (const ServiceDef *service : parser_.services_.vec) {
139162
Generate(stub, service, &imports);
163+
ns_name = NamespaceDir(*service->defined_namespace, false);
140164
}
141165

166+
std::string sanitized_suffix{ parser_.opts.grpc_filename_suffix };
167+
std::replace(sanitized_suffix.begin(), sanitized_suffix.end(), '.', '_');
142168
std::string filename =
143-
namer_.config_.output_path +
169+
ns_name + kPathSeparator +
144170
StripPath(StripExtension(parser_.file_being_parsed_)) + "_grpc" +
145-
parser_.opts.grpc_filename_suffix + namer_.config_.filename_extension;
171+
sanitized_suffix + namer_.config_.filename_extension;
146172

147173
return SaveStub(filename, imports, stub.str());
148174
}
@@ -247,16 +273,20 @@ class ServiceGenerator : public BaseGenerator {
247273
<< '\n';
248274
}
249275

276+
std::string ns_name{};
250277
for (const ServiceDef *service : parser_.services_.vec) {
251278
GenerateStub(ss, service, &imports);
252279
GenerateServicer(ss, service, &imports);
253280
GenerateRegister(ss, service, &imports);
281+
ns_name = NamespaceDir(*service->defined_namespace, false);
254282
}
255283

284+
std::string sanitized_suffix{ parser_.opts.grpc_filename_suffix };
285+
std::replace(sanitized_suffix.begin(), sanitized_suffix.end(), '.', '_');
256286
std::string filename =
257-
namer_.config_.output_path +
287+
ns_name + kPathSeparator +
258288
StripPath(StripExtension(parser_.file_being_parsed_)) + "_grpc" +
259-
parser_.opts.grpc_filename_suffix + namer_.config_.filename_extension;
289+
sanitized_suffix + namer_.config_.filename_extension;
260290

261291
return SaveService(filename, imports, ss.str());
262292
}
@@ -365,13 +395,13 @@ class ServiceGenerator : public BaseGenerator {
365395

366396
bool Generate(const Parser &parser, const std::string &path,
367397
const Version &version) {
368-
ServiceGenerator generator{parser, path, version};
398+
ServiceGenerator generator{ parser, path, version };
369399
return generator.Generate();
370400
}
371401

372402
bool GenerateStub(const Parser &parser, const std::string &path,
373403
const Version &version) {
374-
StubGenerator generator{parser, path, version};
404+
StubGenerator generator{ parser, path, version };
375405
return generator.Generate();
376406
}
377407

include/flatbuffers/array.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,10 @@ template<typename T, uint16_t length> class Array {
3131
// Array<T> can carry only POD data types (scalars or structs).
3232
typedef typename flatbuffers::bool_constant<flatbuffers::is_scalar<T>::value>
3333
scalar_tag;
34-
typedef
35-
typename flatbuffers::conditional<scalar_tag::value, T, const T *>::type
36-
IndirectHelperType;
3734

3835
public:
3936
typedef uint16_t size_type;
40-
typedef typename IndirectHelper<IndirectHelperType>::return_type return_type;
37+
typedef typename IndirectHelper<T>::return_type return_type;
4138
typedef VectorConstIterator<T, return_type, uoffset_t> const_iterator;
4239
typedef VectorReverseIterator<const_iterator> const_reverse_iterator;
4340

@@ -50,7 +47,7 @@ template<typename T, uint16_t length> class Array {
5047

5148
return_type Get(uoffset_t i) const {
5249
FLATBUFFERS_ASSERT(i < size());
53-
return IndirectHelper<IndirectHelperType>::Read(Data(), i);
50+
return IndirectHelper<T>::Read(Data(), i);
5451
}
5552

5653
return_type operator[](uoffset_t i) const { return Get(i); }

0 commit comments

Comments
 (0)