snowflake-connector-python 3.16.0__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- snowflake/connector/__init__.py +96 -0
- snowflake/connector/_query_context_cache.py +276 -0
- snowflake/connector/_sql_util.py +48 -0
- snowflake/connector/_utils.py +70 -0
- snowflake/connector/arrow_context.py +203 -0
- snowflake/connector/auth/__init__.py +53 -0
- snowflake/connector/auth/_auth.py +586 -0
- snowflake/connector/auth/_http_server.py +220 -0
- snowflake/connector/auth/_oauth_base.py +400 -0
- snowflake/connector/auth/by_plugin.py +219 -0
- snowflake/connector/auth/default.py +36 -0
- snowflake/connector/auth/idtoken.py +72 -0
- snowflake/connector/auth/keypair.py +222 -0
- snowflake/connector/auth/no_auth.py +39 -0
- snowflake/connector/auth/oauth.py +49 -0
- snowflake/connector/auth/oauth_code.py +479 -0
- snowflake/connector/auth/oauth_credentials.py +66 -0
- snowflake/connector/auth/okta.py +335 -0
- snowflake/connector/auth/pat.py +39 -0
- snowflake/connector/auth/usrpwdmfa.py +69 -0
- snowflake/connector/auth/webbrowser.py +502 -0
- snowflake/connector/auth/workload_identity.py +94 -0
- snowflake/connector/azure_storage_client.py +276 -0
- snowflake/connector/backoff_policies.py +141 -0
- snowflake/connector/bind_upload_agent.py +89 -0
- snowflake/connector/cache.py +696 -0
- snowflake/connector/compat.py +127 -0
- snowflake/connector/config_manager.py +496 -0
- snowflake/connector/connection.py +2273 -0
- snowflake/connector/connection_diagnostic.py +776 -0
- snowflake/connector/constants.py +442 -0
- snowflake/connector/converter.py +785 -0
- snowflake/connector/converter_issue23517.py +87 -0
- snowflake/connector/converter_null.py +14 -0
- snowflake/connector/converter_snowsql.py +205 -0
- snowflake/connector/cursor.py +1951 -0
- snowflake/connector/dbapi.py +53 -0
- snowflake/connector/description.py +19 -0
- snowflake/connector/direct_file_operation_utils.py +88 -0
- snowflake/connector/encryption_util.py +220 -0
- snowflake/connector/errorcode.py +91 -0
- snowflake/connector/errors.py +615 -0
- snowflake/connector/externals_utils/__init__.py +0 -0
- snowflake/connector/externals_utils/externals_setup.py +27 -0
- snowflake/connector/feature.py +4 -0
- snowflake/connector/file_compression_type.py +118 -0
- snowflake/connector/file_lock.py +72 -0
- snowflake/connector/file_transfer_agent.py +1215 -0
- snowflake/connector/file_util.py +153 -0
- snowflake/connector/gcs_storage_client.py +474 -0
- snowflake/connector/gzip_decoder.py +85 -0
- snowflake/connector/local_storage_client.py +90 -0
- snowflake/connector/log_configuration.py +60 -0
- snowflake/connector/logging_utils/__init__.py +0 -0
- snowflake/connector/logging_utils/filters.py +72 -0
- snowflake/connector/nanoarrow_arrow_iterator.cp313-win_amd64.pyd +0 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ArrayConverter.cpp +60 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ArrayConverter.hpp +29 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BinaryConverter.cpp +19 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BinaryConverter.hpp +26 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BooleanConverter.cpp +21 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BooleanConverter.hpp +23 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowChunkIterator.cpp +557 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowChunkIterator.hpp +98 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowIterator.cpp +125 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowIterator.hpp +115 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowTableIterator.cpp +1005 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowTableIterator.hpp +127 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DateConverter.cpp +47 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DateConverter.hpp +46 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecFloatConverter.cpp +83 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecFloatConverter.hpp +35 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecimalConverter.cpp +97 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecimalConverter.hpp +72 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.cpp +73 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.hpp +28 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FloatConverter.cpp +30 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FloatConverter.hpp +35 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IColumnConverter.hpp +17 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntConverter.cpp +23 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntConverter.hpp +45 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntervalConverter.cpp +71 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntervalConverter.hpp +56 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/LICENSE.txt +209 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/MapConverter.cpp +75 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/MapConverter.hpp +30 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ObjectConverter.cpp +46 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ObjectConverter.hpp +29 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Common.cpp +8 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Common.hpp +95 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Helpers.cpp +57 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Helpers.hpp +36 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/SnowflakeType.cpp +34 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/SnowflakeType.hpp +48 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/StringConverter.cpp +19 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/StringConverter.hpp +26 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeConverter.cpp +36 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeConverter.hpp +31 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeStampConverter.cpp +346 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeStampConverter.hpp +145 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/macros.hpp +14 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/time.cpp +65 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/time.hpp +68 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_accessors.h +101 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_alloc.h +127 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_assert.h +45 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_builder.h +1908 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_emitter.h +215 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_endian.h +125 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_epilogue.h +7 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_flatbuffers.h +55 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_identifier.h +148 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_iov.h +31 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_prologue.h +8 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_refmap.h +144 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_rtconfig.h +162 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_types.h +97 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_verifier.h +239 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/flatcc_portable.h +14 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/paligned_alloc.h +210 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pattributes.h +84 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic.h +84 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_pop.h +20 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_push.h +51 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian.h +206 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian_detect.h +118 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinline.h +19 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinttypes.h +52 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable.h +2 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable_basic.h +25 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstatic_assert.h +67 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdalign.h +162 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdint.h +898 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/punaligned.h +190 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pversion.h +6 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pwarnings.h +52 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc.c +3204 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.c +3217 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.h +3618 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.hpp +379 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_arrow_iterator.pyx +256 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_device.c +512 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_device.h +350 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.c +33273 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.h +397 -0
- snowflake/connector/nanoarrow_cpp/Logging/logging.cpp +100 -0
- snowflake/connector/nanoarrow_cpp/Logging/logging.hpp +49 -0
- snowflake/connector/network.py +1297 -0
- snowflake/connector/ocsp_asn1crypto.py +447 -0
- snowflake/connector/ocsp_snowflake.py +1883 -0
- snowflake/connector/options.py +131 -0
- snowflake/connector/pandas_tools.py +732 -0
- snowflake/connector/proxy.py +43 -0
- snowflake/connector/py.typed +0 -0
- snowflake/connector/result_batch.py +786 -0
- snowflake/connector/result_set.py +319 -0
- snowflake/connector/s3_storage_client.py +605 -0
- snowflake/connector/secret_detector.py +181 -0
- snowflake/connector/sf_dirs.py +64 -0
- snowflake/connector/sfbinaryformat.py +35 -0
- snowflake/connector/sfdatetime.py +345 -0
- snowflake/connector/snow_logging.py +144 -0
- snowflake/connector/sqlstate.py +9 -0
- snowflake/connector/ssd_internal_keys.py +30 -0
- snowflake/connector/ssl_wrap_socket.py +134 -0
- snowflake/connector/storage_client.py +478 -0
- snowflake/connector/telemetry.py +249 -0
- snowflake/connector/telemetry_oob.py +543 -0
- snowflake/connector/test_util.py +30 -0
- snowflake/connector/time_util.py +159 -0
- snowflake/connector/token_cache.py +402 -0
- snowflake/connector/tool/__init__.py +0 -0
- snowflake/connector/tool/dump_certs.py +57 -0
- snowflake/connector/tool/dump_ocsp_response.py +139 -0
- snowflake/connector/tool/dump_ocsp_response_cache.py +194 -0
- snowflake/connector/tool/probe_connection.py +69 -0
- snowflake/connector/url_util.py +49 -0
- snowflake/connector/util_text.py +301 -0
- snowflake/connector/vendored/__init__.py +3 -0
- snowflake/connector/vendored/requests/LICENSE +175 -0
- snowflake/connector/vendored/requests/__init__.py +169 -0
- snowflake/connector/vendored/requests/__version__.py +14 -0
- snowflake/connector/vendored/requests/_internal_utils.py +50 -0
- snowflake/connector/vendored/requests/adapters.py +537 -0
- snowflake/connector/vendored/requests/api.py +157 -0
- snowflake/connector/vendored/requests/auth.py +315 -0
- snowflake/connector/vendored/requests/certs.py +17 -0
- snowflake/connector/vendored/requests/compat.py +79 -0
- snowflake/connector/vendored/requests/cookies.py +561 -0
- snowflake/connector/vendored/requests/exceptions.py +140 -0
- snowflake/connector/vendored/requests/help.py +134 -0
- snowflake/connector/vendored/requests/hooks.py +33 -0
- snowflake/connector/vendored/requests/models.py +1033 -0
- snowflake/connector/vendored/requests/sessions.py +833 -0
- snowflake/connector/vendored/requests/status_codes.py +128 -0
- snowflake/connector/vendored/requests/structures.py +99 -0
- snowflake/connector/vendored/requests/utils.py +1093 -0
- snowflake/connector/vendored/urllib3/LICENSE.txt +21 -0
- snowflake/connector/vendored/urllib3/__init__.py +85 -0
- snowflake/connector/vendored/urllib3/_collections.py +355 -0
- snowflake/connector/vendored/urllib3/_version.py +2 -0
- snowflake/connector/vendored/urllib3/connection.py +572 -0
- snowflake/connector/vendored/urllib3/connectionpool.py +1137 -0
- snowflake/connector/vendored/urllib3/contrib/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/contrib/_appengine_environ.py +36 -0
- snowflake/connector/vendored/urllib3/contrib/_securetransport/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/contrib/_securetransport/bindings.py +519 -0
- snowflake/connector/vendored/urllib3/contrib/_securetransport/low_level.py +397 -0
- snowflake/connector/vendored/urllib3/contrib/appengine.py +314 -0
- snowflake/connector/vendored/urllib3/contrib/ntlmpool.py +130 -0
- snowflake/connector/vendored/urllib3/contrib/pyopenssl.py +509 -0
- snowflake/connector/vendored/urllib3/contrib/securetransport.py +920 -0
- snowflake/connector/vendored/urllib3/contrib/socks.py +216 -0
- snowflake/connector/vendored/urllib3/exceptions.py +323 -0
- snowflake/connector/vendored/urllib3/fields.py +274 -0
- snowflake/connector/vendored/urllib3/filepost.py +98 -0
- snowflake/connector/vendored/urllib3/packages/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/packages/backports/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/packages/backports/makefile.py +51 -0
- snowflake/connector/vendored/urllib3/packages/backports/weakref_finalize.py +155 -0
- snowflake/connector/vendored/urllib3/packages/six.py +1076 -0
- snowflake/connector/vendored/urllib3/poolmanager.py +540 -0
- snowflake/connector/vendored/urllib3/request.py +191 -0
- snowflake/connector/vendored/urllib3/response.py +885 -0
- snowflake/connector/vendored/urllib3/util/__init__.py +49 -0
- snowflake/connector/vendored/urllib3/util/connection.py +156 -0
- snowflake/connector/vendored/urllib3/util/proxy.py +57 -0
- snowflake/connector/vendored/urllib3/util/queue.py +22 -0
- snowflake/connector/vendored/urllib3/util/request.py +146 -0
- snowflake/connector/vendored/urllib3/util/response.py +107 -0
- snowflake/connector/vendored/urllib3/util/retry.py +620 -0
- snowflake/connector/vendored/urllib3/util/ssl_.py +495 -0
- snowflake/connector/vendored/urllib3/util/ssl_match_hostname.py +159 -0
- snowflake/connector/vendored/urllib3/util/ssltransport.py +221 -0
- snowflake/connector/vendored/urllib3/util/timeout.py +271 -0
- snowflake/connector/vendored/urllib3/util/url.py +435 -0
- snowflake/connector/vendored/urllib3/util/wait.py +152 -0
- snowflake/connector/version.py +3 -0
- snowflake/connector/wif_util.py +407 -0
- snowflake_connector_python-3.16.0.dist-info/METADATA +1475 -0
- snowflake_connector_python-3.16.0.dist-info/RECORD +246 -0
- snowflake_connector_python-3.16.0.dist-info/WHEEL +5 -0
- snowflake_connector_python-3.16.0.dist-info/entry_points.txt +4 -0
- snowflake_connector_python-3.16.0.dist-info/licenses/LICENSE.txt +202 -0
- snowflake_connector_python-3.16.0.dist-info/licenses/NOTICE +8 -0
- snowflake_connector_python-3.16.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
#ifndef FLATCC_EMITTER_H
|
|
2
|
+
#define FLATCC_EMITTER_H
|
|
3
|
+
|
|
4
|
+
#ifdef __cplusplus
|
|
5
|
+
extern "C" {
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Default implementation of a flatbuilder emitter.
|
|
10
|
+
*
|
|
11
|
+
* This may be used as a starting point for more advanced emitters,
|
|
12
|
+
* for example writing completed pages to disk or network and
|
|
13
|
+
* the recycling those pages.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
#include <stdlib.h>
|
|
17
|
+
#include <string.h>
|
|
18
|
+
|
|
19
|
+
#include "flatcc/flatcc_types.h"
|
|
20
|
+
#include "flatcc/flatcc_iov.h"
|
|
21
|
+
#include "flatcc/flatcc_alloc.h"
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* The buffer steadily grows during emission but the design allows for
|
|
25
|
+
* an extension where individual pages can recycled before the buffer
|
|
26
|
+
* is complete, for example because they have been transmitted.
|
|
27
|
+
*
|
|
28
|
+
* When done, the buffer can be cleared to free all memory, or reset to
|
|
29
|
+
* maintain an adaptive page pool for next buffer construction.
|
|
30
|
+
*
|
|
31
|
+
* Unlike an exponentially growing buffer, each buffer page remains
|
|
32
|
+
* stable in memory until reset, clear or recycle is called.
|
|
33
|
+
*
|
|
34
|
+
* Design notes for possible extensions:
|
|
35
|
+
*
|
|
36
|
+
* The buffer is a ring buffer marked by a front and a back page. The
|
|
37
|
+
* front and back may be the same page and may initially be absent.
|
|
38
|
+
* Anything outside these pages are unallocated pages for recycling.
|
|
39
|
+
* Any page between (but excluding) the front and back pages may be
|
|
40
|
+
* recycled by unlinking and relinking outside the front and back pages
|
|
41
|
+
* but then copy operations no longer makes sense. Each page stores the
|
|
42
|
+
* logical offset within the buffer but isn't otherwise used by the
|
|
43
|
+
* implemention - it might be used for network transmission. The buffer
|
|
44
|
+
* is not explicitly designed for multithreaded access but any page
|
|
45
|
+
* strictly between front and back is not touched unless recycled and in
|
|
46
|
+
* this case aligned allocation is useful to prevent cache line sharing.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/*
|
|
50
|
+
* Memory is allocated in fixed length page units - the first page is
|
|
51
|
+
* split between front and back so each get half the page size. If the
|
|
52
|
+
* size is a multiple of 128 then each page offset will be a multiple of
|
|
53
|
+
* 64, which may be useful for sequencing etc.
|
|
54
|
+
*/
|
|
55
|
+
#ifndef FLATCC_EMITTER_PAGE_SIZE
|
|
56
|
+
#define FLATCC_EMITTER_MAX_PAGE_SIZE 3000
|
|
57
|
+
#define FLATCC_EMITTER_PAGE_MULTIPLE 64
|
|
58
|
+
#define FLATCC_EMITTER_PAGE_SIZE ((FLATCC_EMITTER_MAX_PAGE_SIZE) &\
|
|
59
|
+
~(2 * (FLATCC_EMITTER_PAGE_MULTIPLE) - 1))
|
|
60
|
+
#endif
|
|
61
|
+
|
|
62
|
+
#ifndef FLATCC_EMITTER_ALLOC
|
|
63
|
+
#ifdef FLATCC_EMITTER_USE_ALIGNED_ALLOC
|
|
64
|
+
/*
|
|
65
|
+
* <stdlib.h> does not always provide aligned_alloc, so include whatever
|
|
66
|
+
* is required when enabling this feature.
|
|
67
|
+
*/
|
|
68
|
+
#define FLATCC_EMITTER_ALLOC(n) aligned_alloc(FLATCC_EMITTER_PAGE_MULTIPLE,\
|
|
69
|
+
(((n) + FLATCC_EMITTER_PAGE_MULTIPLE - 1) & ~(FLATCC_EMITTER_PAGE_MULTIPLE - 1)))
|
|
70
|
+
#ifndef FLATCC_EMITTER_FREE
|
|
71
|
+
#define FLATCC_EMITTER_FREE(p) aligned_free(p)
|
|
72
|
+
#endif
|
|
73
|
+
#endif
|
|
74
|
+
#endif
|
|
75
|
+
|
|
76
|
+
#ifndef FLATCC_EMITTER_ALLOC
|
|
77
|
+
#define FLATCC_EMITTER_ALLOC(n) FLATCC_ALLOC(n)
|
|
78
|
+
#endif
|
|
79
|
+
#ifndef FLATCC_EMITTER_FREE
|
|
80
|
+
#define FLATCC_EMITTER_FREE(p) FLATCC_FREE(p)
|
|
81
|
+
#endif
|
|
82
|
+
|
|
83
|
+
typedef struct flatcc_emitter_page flatcc_emitter_page_t;
|
|
84
|
+
typedef struct flatcc_emitter flatcc_emitter_t;
|
|
85
|
+
|
|
86
|
+
struct flatcc_emitter_page {
|
|
87
|
+
uint8_t page[FLATCC_EMITTER_PAGE_SIZE];
|
|
88
|
+
flatcc_emitter_page_t *next;
|
|
89
|
+
flatcc_emitter_page_t *prev;
|
|
90
|
+
/*
|
|
91
|
+
* The offset is relative to page start, but not necessarily
|
|
92
|
+
* to any present content if part of front or back page,
|
|
93
|
+
* and undefined for unused pages.
|
|
94
|
+
*/
|
|
95
|
+
flatbuffers_soffset_t page_offset;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/*
|
|
99
|
+
* Must be allocated and zeroed externally, e.g. on the stack
|
|
100
|
+
* then provided as emit_context to the flatbuilder along
|
|
101
|
+
* with the `flatcc_emitter` function.
|
|
102
|
+
*/
|
|
103
|
+
struct flatcc_emitter {
|
|
104
|
+
flatcc_emitter_page_t *front, *back;
|
|
105
|
+
uint8_t *front_cursor;
|
|
106
|
+
size_t front_left;
|
|
107
|
+
uint8_t *back_cursor;
|
|
108
|
+
size_t back_left;
|
|
109
|
+
size_t used;
|
|
110
|
+
size_t capacity;
|
|
111
|
+
size_t used_average;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/* Optional helper to ensure emitter is zeroed initially. */
|
|
115
|
+
static inline void flatcc_emitter_init(flatcc_emitter_t *E)
|
|
116
|
+
{
|
|
117
|
+
memset(E, 0, sizeof(*E));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* Deallocates all buffer memory making the emitter ready for next use. */
|
|
121
|
+
void flatcc_emitter_clear(flatcc_emitter_t *E);
|
|
122
|
+
|
|
123
|
+
/*
|
|
124
|
+
* Similar to `clear_flatcc_emitter` but heuristacally keeps some allocated
|
|
125
|
+
* memory between uses while gradually reducing peak allocations.
|
|
126
|
+
* For small buffers, a single page will remain available with no
|
|
127
|
+
* additional allocations or deallocations after first use.
|
|
128
|
+
*/
|
|
129
|
+
void flatcc_emitter_reset(flatcc_emitter_t *E);
|
|
130
|
+
|
|
131
|
+
/*
|
|
132
|
+
* Helper function that allows a page between front and back to be
|
|
133
|
+
* recycled while the buffer is still being constructed - most likely as part
|
|
134
|
+
* of partial copy or transmission. Attempting to recycle front or back
|
|
135
|
+
* pages will result in an error. Recycling pages outside the
|
|
136
|
+
* front and back will be valid but pointless. After recycling and copy
|
|
137
|
+
* operations are no longer well-defined and should be replaced with
|
|
138
|
+
* whatever logic is recycling the pages. The reset operation
|
|
139
|
+
* automatically recycles all (remaining) pages when emission is
|
|
140
|
+
* complete. After recycling, the `flatcc_emitter_size` function will
|
|
141
|
+
* return as if recycle was not called, but will only represent the
|
|
142
|
+
* logical size, not the size of the active buffer. Because a recycled
|
|
143
|
+
* page is fully utilized, it is fairly easy to compensate for this if
|
|
144
|
+
* required.
|
|
145
|
+
*
|
|
146
|
+
* Returns 0 on success.
|
|
147
|
+
*/
|
|
148
|
+
int flatcc_emitter_recycle_page(flatcc_emitter_t *E, flatcc_emitter_page_t *p);
|
|
149
|
+
|
|
150
|
+
/*
|
|
151
|
+
* The amount of data copied with `flatcc_emitter_copy_buffer` and related
|
|
152
|
+
* functions. Normally called at end of buffer construction but is
|
|
153
|
+
* always valid, as is the copy functions. The size is a direct
|
|
154
|
+
* function of the amount emitted data so the flatbuilder itself can
|
|
155
|
+
* also provide this information.
|
|
156
|
+
*/
|
|
157
|
+
static inline size_t flatcc_emitter_get_buffer_size(flatcc_emitter_t *E)
|
|
158
|
+
{
|
|
159
|
+
return E->used;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/*
|
|
163
|
+
* Returns buffer start iff the buffer fits on a single internal page.
|
|
164
|
+
* Only useful for fairly small buffers - about half the page size since
|
|
165
|
+
* one half of first page goes to vtables that likely use little space.
|
|
166
|
+
* Returns null if request could not be served.
|
|
167
|
+
*
|
|
168
|
+
* If `size_out` is not null, it is set to the buffer size, or 0 if
|
|
169
|
+
* operation failed.
|
|
170
|
+
*/
|
|
171
|
+
static inline void *flatcc_emitter_get_direct_buffer(flatcc_emitter_t *E, size_t *size_out)
|
|
172
|
+
{
|
|
173
|
+
if (E->front == E->back) {
|
|
174
|
+
if (size_out) {
|
|
175
|
+
*size_out = E->used;
|
|
176
|
+
}
|
|
177
|
+
return E->front_cursor;
|
|
178
|
+
}
|
|
179
|
+
if (size_out) {
|
|
180
|
+
*size_out = 0;
|
|
181
|
+
}
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/*
|
|
186
|
+
* Copies the internal flatcc_emitter representation to an externally
|
|
187
|
+
* provided linear buffer that must have size `flatcc_emitter_get_size`.
|
|
188
|
+
*
|
|
189
|
+
* If pages have been recycled, only the remaining pages will be copied
|
|
190
|
+
* and thus less data than what `flatcc_emitter_get_size` would suggest. It
|
|
191
|
+
* makes more sense to provide a customized copy operation when
|
|
192
|
+
* recycling pages.
|
|
193
|
+
*
|
|
194
|
+
* If the buffer is too small, nothing is copied, otherwise the
|
|
195
|
+
* full buffer is copied and the input buffer is returned.
|
|
196
|
+
*/
|
|
197
|
+
void *flatcc_emitter_copy_buffer(flatcc_emitter_t *E, void *buf, size_t size);
|
|
198
|
+
|
|
199
|
+
/*
|
|
200
|
+
* The emitter interface function to the flatbuilder API.
|
|
201
|
+
* `emit_context` should be of type `flatcc_emitter_t` for this
|
|
202
|
+
* particular implementation.
|
|
203
|
+
*
|
|
204
|
+
* This function is compatible with the `flatbuilder_emit_fun`
|
|
205
|
+
* type defined in "flatbuilder.h".
|
|
206
|
+
*/
|
|
207
|
+
int flatcc_emitter(void *emit_context,
|
|
208
|
+
const flatcc_iovec_t *iov, int iov_count,
|
|
209
|
+
flatbuffers_soffset_t offset, size_t len);
|
|
210
|
+
|
|
211
|
+
#ifdef __cplusplus
|
|
212
|
+
}
|
|
213
|
+
#endif
|
|
214
|
+
|
|
215
|
+
#endif /* FLATCC_EMITTER_H */
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#ifndef FLATCC_ENDIAN_H
|
|
2
|
+
#define FLATCC_ENDIAN_H
|
|
3
|
+
|
|
4
|
+
#ifdef __cplusplus
|
|
5
|
+
extern "C" {
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* This file provides helper macros to define type-specific macros and
|
|
10
|
+
* inline functions that convert between stored data and native data
|
|
11
|
+
* indedpently of both native (host) endianness and protocol endianness
|
|
12
|
+
* (i.e. the serialized endian format).
|
|
13
|
+
*
|
|
14
|
+
* To detect endianness correctly ensure one of the following is defined.
|
|
15
|
+
*
|
|
16
|
+
* __LITTLE_ENDIAN__
|
|
17
|
+
* __BIG_ENDIAN__
|
|
18
|
+
* FLATBUFFERS_LITTLEENDIAN=1
|
|
19
|
+
* FLATBUFFERS_LITTLEENDIAN=0
|
|
20
|
+
*
|
|
21
|
+
* Note: the Clang compiler likely already does this, but other
|
|
22
|
+
* compilers may have their own way, if at all.
|
|
23
|
+
*
|
|
24
|
+
* It is also necessary to include <endian.h> or a compatible
|
|
25
|
+
* implementation in order to provide:
|
|
26
|
+
*
|
|
27
|
+
* le16toh, le32to, le64toh, be16toh, be32toh, be64toh,
|
|
28
|
+
* htole16, htole32, htole64, htobe16, htobe32, htobe64.
|
|
29
|
+
*
|
|
30
|
+
* A simple way to ensure all of the above for most platforms is
|
|
31
|
+
* to include the portable endian support file:
|
|
32
|
+
*
|
|
33
|
+
* #include "flatcc/portable/pendian.h"
|
|
34
|
+
*
|
|
35
|
+
* It is also necessary to include
|
|
36
|
+
*
|
|
37
|
+
* #include "flatcc/flatcc_types.h"
|
|
38
|
+
*
|
|
39
|
+
* or an equivalent file. This makes it possible to change the
|
|
40
|
+
* endianness of the serialized data and the sizes of flatbuffer
|
|
41
|
+
* specific types such as `uoffset_t`.
|
|
42
|
+
*
|
|
43
|
+
* Note: the mentioned include files are likely already included
|
|
44
|
+
* by the file including this file, at least for the default
|
|
45
|
+
* configuration.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
#ifndef UINT8_t
|
|
49
|
+
#include <stdint.h>
|
|
50
|
+
#endif
|
|
51
|
+
|
|
52
|
+
/* These are needed to simplify accessor macros and are not found in <endian.h>. */
|
|
53
|
+
#ifndef le8toh
|
|
54
|
+
#define le8toh(n) (n)
|
|
55
|
+
#endif
|
|
56
|
+
|
|
57
|
+
#ifndef be8toh
|
|
58
|
+
#define be8toh(n) (n)
|
|
59
|
+
#endif
|
|
60
|
+
|
|
61
|
+
#ifndef htole8
|
|
62
|
+
#define htole8(n) (n)
|
|
63
|
+
#endif
|
|
64
|
+
|
|
65
|
+
#ifndef htobe8
|
|
66
|
+
#define htobe8(n) (n)
|
|
67
|
+
#endif
|
|
68
|
+
|
|
69
|
+
#include "flatcc/flatcc_accessors.h"
|
|
70
|
+
|
|
71
|
+
/* This is the binary encoding endianness, usually LE for flatbuffers. */
|
|
72
|
+
#if FLATBUFFERS_PROTOCOL_IS_LE
|
|
73
|
+
#define flatbuffers_endian le
|
|
74
|
+
#elif FLATBUFFERS_PROTOCOL_IS_BE
|
|
75
|
+
#define flatbuffers_endian be
|
|
76
|
+
#else
|
|
77
|
+
#error "flatbuffers has no defined endiannesss"
|
|
78
|
+
#endif
|
|
79
|
+
|
|
80
|
+
__flatcc_define_basic_scalar_accessors(flatbuffers_, flatbuffers_endian)
|
|
81
|
+
|
|
82
|
+
__flatcc_define_integer_accessors(flatbuffers_bool, flatbuffers_bool_t,
|
|
83
|
+
FLATBUFFERS_BOOL_WIDTH, flatbuffers_endian)
|
|
84
|
+
__flatcc_define_integer_accessors(flatbuffers_union_type, flatbuffers_union_type_t,
|
|
85
|
+
FLATBUFFERS_UTYPE_WIDTH, flatbuffers_endian)
|
|
86
|
+
|
|
87
|
+
__flatcc_define_integer_accessors(__flatbuffers_uoffset, flatbuffers_uoffset_t,
|
|
88
|
+
FLATBUFFERS_UOFFSET_WIDTH, flatbuffers_endian)
|
|
89
|
+
__flatcc_define_integer_accessors(__flatbuffers_soffset, flatbuffers_soffset_t,
|
|
90
|
+
FLATBUFFERS_SOFFSET_WIDTH, flatbuffers_endian)
|
|
91
|
+
__flatcc_define_integer_accessors(__flatbuffers_voffset, flatbuffers_voffset_t,
|
|
92
|
+
FLATBUFFERS_VOFFSET_WIDTH, flatbuffers_endian)
|
|
93
|
+
__flatcc_define_integer_accessors(__flatbuffers_utype, flatbuffers_utype_t,
|
|
94
|
+
FLATBUFFERS_UTYPE_WIDTH, flatbuffers_endian)
|
|
95
|
+
__flatcc_define_integer_accessors(__flatbuffers_thash, flatbuffers_thash_t,
|
|
96
|
+
FLATBUFFERS_THASH_WIDTH, flatbuffers_endian)
|
|
97
|
+
|
|
98
|
+
/* flatcc/portable/pendian.h sets LITTLE/BIG flags if possible, and always defines le16toh. */
|
|
99
|
+
#ifndef flatbuffers_is_native_pe
|
|
100
|
+
#if defined(__LITTLE_ENDIAN__) || FLATBUFFERS_LITTLEENDIAN
|
|
101
|
+
#undef FLATBUFFERS_LITTLEENDIAN
|
|
102
|
+
#define FLATBUFFERS_LITTLEENDIAN 1
|
|
103
|
+
#define flatbuffers_is_native_pe() (FLATBUFFERS_PROTOCOL_IS_LE)
|
|
104
|
+
#elif defined(__BIG_ENDIAN__) || (defined(FLATBUFFERS_LITTLEENDIAN) && !FLATBUFFERS_LITTLEENDIAN)
|
|
105
|
+
#undef FLATBUFFERS_LITTLEENDIAN
|
|
106
|
+
#define FLATBUFFERS_LITTLEENDIAN 0
|
|
107
|
+
#define flatbuffers_is_native_pe() (FLATBUFFERS_PROTOCOL_IS_BE)
|
|
108
|
+
#else
|
|
109
|
+
#define flatbuffers_is_native_pe() (__FLATBUFFERS_CONCAT(flatbuffers_endian, 16toh)(1) == 1)
|
|
110
|
+
#endif
|
|
111
|
+
#endif
|
|
112
|
+
|
|
113
|
+
#ifndef flatbuffers_is_native_le
|
|
114
|
+
#define flatbuffers_is_native_le() flatbuffers_is_native_pe()
|
|
115
|
+
#endif
|
|
116
|
+
|
|
117
|
+
#ifndef flatbuffers_is_native_be
|
|
118
|
+
#define flatbuffers_is_native_be() (!flatbuffers_is_native_pe())
|
|
119
|
+
#endif
|
|
120
|
+
|
|
121
|
+
#ifdef __cplusplus
|
|
122
|
+
}
|
|
123
|
+
#endif
|
|
124
|
+
|
|
125
|
+
#endif /* FLATCC_ENDIAN_H */
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Even C11 compilers depend on clib support for `static_assert` which
|
|
3
|
+
* isn't always present, so we deal with this here for all compilers.
|
|
4
|
+
*
|
|
5
|
+
* Outside include guard to handle scope counter.
|
|
6
|
+
*/
|
|
7
|
+
#include "flatcc/portable/pstatic_assert.h"
|
|
8
|
+
|
|
9
|
+
#ifndef FLATCC_FLATBUFFERS_H
|
|
10
|
+
#define FLATCC_FLATBUFFERS_H
|
|
11
|
+
|
|
12
|
+
#ifdef __cplusplus
|
|
13
|
+
extern "C" {
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
#ifndef flatcc_flatbuffers_defined
|
|
17
|
+
#define flatcc_flatbuffers_defined
|
|
18
|
+
|
|
19
|
+
#ifdef FLATCC_PORTABLE
|
|
20
|
+
#include "flatcc/flatcc_portable.h"
|
|
21
|
+
#endif
|
|
22
|
+
#include "flatcc/portable/pwarnings.h"
|
|
23
|
+
/* Needed by C99 compilers without FLATCC_PORTABLE. */
|
|
24
|
+
#include "flatcc/portable/pstdalign.h"
|
|
25
|
+
|
|
26
|
+
/* Handle fallthrough attribute in switch statements. */
|
|
27
|
+
#include "flatcc/portable/pattributes.h"
|
|
28
|
+
|
|
29
|
+
#include "flatcc/flatcc_alloc.h"
|
|
30
|
+
#include "flatcc/flatcc_assert.h"
|
|
31
|
+
|
|
32
|
+
#define __FLATBUFFERS_PASTE2(a, b) a ## b
|
|
33
|
+
#define __FLATBUFFERS_PASTE3(a, b, c) a ## b ## c
|
|
34
|
+
#define __FLATBUFFERS_CONCAT(a, b) __FLATBUFFERS_PASTE2(a, b)
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
* "flatcc_endian.h" requires the preceeding include files,
|
|
38
|
+
* or compatible definitions.
|
|
39
|
+
*/
|
|
40
|
+
#include "flatcc/portable/pendian.h"
|
|
41
|
+
#include "flatcc/flatcc_types.h"
|
|
42
|
+
#include "flatcc/flatcc_endian.h"
|
|
43
|
+
#include "flatcc/flatcc_identifier.h"
|
|
44
|
+
|
|
45
|
+
#ifndef FLATBUFFERS_WRAP_NAMESPACE
|
|
46
|
+
#define FLATBUFFERS_WRAP_NAMESPACE(ns, x) ns ## _ ## x
|
|
47
|
+
#endif
|
|
48
|
+
|
|
49
|
+
#endif /* flatcc_flatbuffers_defined */
|
|
50
|
+
|
|
51
|
+
#ifdef __cplusplus
|
|
52
|
+
}
|
|
53
|
+
#endif
|
|
54
|
+
|
|
55
|
+
#endif /* FLATCC_FLATBUFFERS_H */
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#ifndef FLATCC_IDENTIFIER_H
|
|
2
|
+
#define FLATCC_IDENTIFIER_H
|
|
3
|
+
|
|
4
|
+
#ifdef __cplusplus
|
|
5
|
+
extern "C" {
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
#ifndef FLATCC_FLATBUFFERS_H
|
|
9
|
+
#error "include via flatcc/flatcc_flatbuffers.h"
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#ifndef UINT8_MAX
|
|
13
|
+
#include <stdint.h>
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* FlatBuffers identifiers are normally specified by "file_identifer" in
|
|
18
|
+
* the schema, but a standard hash of the fully qualified type name can
|
|
19
|
+
* also be used. This file implements such a mapping, but the generated
|
|
20
|
+
* headers also contain the necessary information for known types.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* Returns the type hash of a given name in native endian format.
|
|
26
|
+
* Generated code already provides these, but if a name was changed
|
|
27
|
+
* in the schema it may be relevant to recompute the hash manually.
|
|
28
|
+
*
|
|
29
|
+
* The wire-format of this value should always be little endian.
|
|
30
|
+
*
|
|
31
|
+
* Note: this must be the fully qualified name, e.g. in the namespace
|
|
32
|
+
* "MyGame.Example":
|
|
33
|
+
*
|
|
34
|
+
* flatbuffers_type_hash_from_name("MyGame.Example.Monster");
|
|
35
|
+
*
|
|
36
|
+
* or, in the global namespace just:
|
|
37
|
+
*
|
|
38
|
+
* flatbuffers_type_hash_from_name("MyTable");
|
|
39
|
+
*
|
|
40
|
+
* This assumes 32 bit hash type. For other sizes, other FNV-1a
|
|
41
|
+
* constants would be required.
|
|
42
|
+
*
|
|
43
|
+
* Note that we reserve hash value 0 for missing or ignored value.
|
|
44
|
+
*/
|
|
45
|
+
static inline flatbuffers_thash_t flatbuffers_type_hash_from_name(const char *name)
|
|
46
|
+
{
|
|
47
|
+
uint32_t hash = UINT32_C(2166136261);
|
|
48
|
+
while (*name) {
|
|
49
|
+
hash ^= (unsigned char)*name;
|
|
50
|
+
hash = hash * UINT32_C(16777619);
|
|
51
|
+
++name;
|
|
52
|
+
}
|
|
53
|
+
if (hash == 0) {
|
|
54
|
+
hash = UINT32_C(2166136261);
|
|
55
|
+
}
|
|
56
|
+
return hash;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/*
|
|
60
|
+
* Type hash encoded as little endian file identifier string.
|
|
61
|
+
* Note: if type hash is 0, the identifier should be null which
|
|
62
|
+
* we cannot return in this interface.
|
|
63
|
+
*/
|
|
64
|
+
static inline void flatbuffers_identifier_from_type_hash(flatbuffers_thash_t type_hash, flatbuffers_fid_t out_identifier)
|
|
65
|
+
{
|
|
66
|
+
out_identifier[0] = (char)(type_hash & 0xff);
|
|
67
|
+
type_hash >>= 8;
|
|
68
|
+
out_identifier[1] = (char)(type_hash & 0xff);
|
|
69
|
+
type_hash >>= 8;
|
|
70
|
+
out_identifier[2] = (char)(type_hash & 0xff);
|
|
71
|
+
type_hash >>= 8;
|
|
72
|
+
out_identifier[3] = (char)(type_hash & 0xff);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* Native integer encoding of file identifier. */
|
|
76
|
+
static inline flatbuffers_thash_t flatbuffers_type_hash_from_identifier(const flatbuffers_fid_t identifier)
|
|
77
|
+
{
|
|
78
|
+
uint8_t *p = (uint8_t *)identifier;
|
|
79
|
+
|
|
80
|
+
return identifier ?
|
|
81
|
+
(uint32_t)p[0] + (((uint32_t)p[1]) << 8) + (((uint32_t)p[2]) << 16) + (((uint32_t)p[3]) << 24) : 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/*
|
|
85
|
+
* Convert a null terminated string identifier like "MONS" or "X" into a
|
|
86
|
+
* native type hash identifier, usually for comparison. This will not
|
|
87
|
+
* work with type hash strings because they can contain null bytes.
|
|
88
|
+
*/
|
|
89
|
+
static inline flatbuffers_thash_t flatbuffers_type_hash_from_string(const char *identifier)
|
|
90
|
+
{
|
|
91
|
+
flatbuffers_thash_t h = 0;
|
|
92
|
+
const uint8_t *p = (const uint8_t *)identifier;
|
|
93
|
+
|
|
94
|
+
if (!p[0]) return h;
|
|
95
|
+
h += ((flatbuffers_thash_t)p[0]);
|
|
96
|
+
if (!p[1]) return h;
|
|
97
|
+
h += ((flatbuffers_thash_t)p[1]) << 8;
|
|
98
|
+
if (!p[2]) return h;
|
|
99
|
+
h += ((flatbuffers_thash_t)p[2]) << 16;
|
|
100
|
+
/* No need to test for termination here. */
|
|
101
|
+
h += ((flatbuffers_thash_t)p[3]) << 24;
|
|
102
|
+
return h;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/*
|
|
106
|
+
* Computes the little endian wire format of the type hash. It can be
|
|
107
|
+
* used as a file identifer argument to various flatcc buffer calls.
|
|
108
|
+
*
|
|
109
|
+
* `flatbuffers_fid_t` is just `char [4]` for the default flatbuffers
|
|
110
|
+
* type system defined in `flatcc/flatcc_types.h`.
|
|
111
|
+
*/
|
|
112
|
+
static inline void flatbuffers_identifier_from_name(const char *name, flatbuffers_fid_t out_identifier)
|
|
113
|
+
{
|
|
114
|
+
flatbuffers_identifier_from_type_hash(flatbuffers_type_hash_from_name(name), out_identifier);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/*
|
|
118
|
+
* This is a collision free hash (a permutation) of the type hash to
|
|
119
|
+
* provide better distribution for use in hash tables. It is likely not
|
|
120
|
+
* necessary in praxis, and for uniqueness of identifiers it provides no
|
|
121
|
+
* advantage over just using the FNV-1a type hash, except when truncating
|
|
122
|
+
* the identifier to less than 32-bits.
|
|
123
|
+
*
|
|
124
|
+
* Note: the output should not be used in transmission. It provides no
|
|
125
|
+
* additional information and just complicates matters. Furthermore, the
|
|
126
|
+
* unmodified type hash has the benefit that it can seed a child namespace.
|
|
127
|
+
*/
|
|
128
|
+
static inline uint32_t flatbuffers_disperse_type_hash(flatbuffers_thash_t type_hash)
|
|
129
|
+
{
|
|
130
|
+
/* http://stackoverflow.com/a/12996028 */
|
|
131
|
+
uint32_t x = type_hash;
|
|
132
|
+
|
|
133
|
+
x = ((x >> 16) ^ x) * UINT32_C(0x45d9f3b);
|
|
134
|
+
x = ((x >> 16) ^ x) * UINT32_C(0x45d9f3b);
|
|
135
|
+
x = ((x >> 16) ^ x);
|
|
136
|
+
return x;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
/* We have hardcoded assumptions about identifier size. */
|
|
141
|
+
static_assert(sizeof(flatbuffers_fid_t) == 4, "unexpected file identifier size");
|
|
142
|
+
static_assert(sizeof(flatbuffers_thash_t) == 4, "unexpected type hash size");
|
|
143
|
+
|
|
144
|
+
#ifdef __cplusplus
|
|
145
|
+
}
|
|
146
|
+
#endif
|
|
147
|
+
|
|
148
|
+
#endif /* FLATCC_IDENTIFIER_H */
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#ifndef FLATCC_IOV_H
|
|
2
|
+
#define FLATCC_IOV_H
|
|
3
|
+
|
|
4
|
+
#ifdef __cplusplus
|
|
5
|
+
extern "C" {
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
#include <stdlib.h>
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* The emitter receives one, or a few buffers at a time via
|
|
12
|
+
* this type. <sys/iov.h> compatible iovec structure used for
|
|
13
|
+
* allocation and emitter interface.
|
|
14
|
+
*/
|
|
15
|
+
typedef struct flatcc_iovec flatcc_iovec_t;
|
|
16
|
+
struct flatcc_iovec {
|
|
17
|
+
void *iov_base;
|
|
18
|
+
size_t iov_len;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* The largest iovec vector the builder will issue. It will
|
|
23
|
+
* always be a relatively small number.
|
|
24
|
+
*/
|
|
25
|
+
#define FLATCC_IOV_COUNT_MAX 8
|
|
26
|
+
|
|
27
|
+
#ifdef __cplusplus
|
|
28
|
+
}
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
#endif /* FLATCC_IOV_H */
|