-
-
Notifications
You must be signed in to change notification settings - Fork 234
Expose native column encoder context #6249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JorisGoosen
merged 9 commits into
jasp-stats:development
from
FBartos:bridge/native-decoder-api
Jun 5, 2026
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
72ebc4e
Expose native column decoder bridge APIs
FBartos 7a0fa75
Expose native column encoder context
FBartos ed7c12e
Keep encoder context with ColumnEncoder
FBartos c21e37f
Use ColumnEncoder decodeJson for scoped replay
FBartos 3c0575c
Move extra option encodings into DataBridge
FBartos 647fde9
Use existing Boost null stream in SyntaxInterface
FBartos 1766f05
Centralize SyntaxInterface logging setup
FBartos 32ca2fb
Include extra option encodings in bridge predicates
FBartos 37de18a
Add native column decoder context tests
FBartos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| // | ||
| // Copyright (C) 2013-2025 University of Amsterdam | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 2 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| // | ||
|
|
||
| #include "columnencodercontext.h" | ||
|
|
||
| #include <stdexcept> | ||
|
|
||
| static Json::Value columnTypesToJson(const ColumnEncoder::colTypeMap & columnTypes) | ||
| { | ||
| Json::Value columns(Json::arrayValue); | ||
| for(const auto & nameType : columnTypes) | ||
| { | ||
| Json::Value column(Json::objectValue); | ||
| column["name"] = nameType.first; | ||
| column["type"] = columnTypeToString(nameType.second); | ||
| columns.append(column); | ||
| } | ||
|
|
||
| return columns; | ||
| } | ||
|
|
||
| static ColumnEncoder::colTypeMap columnTypesFromJson(const Json::Value & columns, const char * fieldName) | ||
| { | ||
| ColumnEncoder::colTypeMap columnTypes; | ||
|
|
||
| if(columns.isNull()) | ||
| return columnTypes; | ||
| if(!columns.isArray()) | ||
| throw std::runtime_error(std::string("Column encoder context field '") + fieldName + "' must be an array."); | ||
|
|
||
| for(const Json::Value & column : columns) | ||
| { | ||
| if(!column.isObject() || !column["name"].isString() || !column["type"].isString()) | ||
| throw std::runtime_error(std::string("Column encoder context field '") + fieldName + "' must contain objects with string 'name' and 'type' fields."); | ||
|
|
||
| columnTypes[column["name"].asString()] = columnTypeFromString(column["type"].asString()); | ||
| } | ||
|
|
||
| return columnTypes; | ||
| } | ||
|
|
||
| static Json::Value parsePayloadJson(const char * payloadJson) | ||
| { | ||
| if(!payloadJson) | ||
| throw std::runtime_error("Cannot decode column text from a null JSON payload."); | ||
|
|
||
| Json::Value payload; | ||
| Json::Reader reader; | ||
| if(!reader.parse(payloadJson, payload)) | ||
| throw std::runtime_error("Could not parse column text JSON payload."); | ||
|
|
||
| return payload; | ||
| } | ||
|
|
||
| ColumnEncoderContext::ColumnEncoderContext(const ColumnEncoder::colTypeMap & columns, const ColumnEncoder::colTypeMap & extra) | ||
| : _columns(columns), _extra(extra), _supplied(true) | ||
| { | ||
| } | ||
|
|
||
| ColumnEncoderContext ColumnEncoderContext::fromJson(const Json::Value & context) | ||
| { | ||
| if(!context.isObject()) | ||
| throw std::runtime_error("Column encoder context must be a JSON object."); | ||
|
|
||
| if(!context.isMember("version") || !context["version"].isInt()) | ||
| throw std::runtime_error("Column encoder context must contain integer version 1."); | ||
| if(context["version"].asInt() != Version) | ||
| throw std::runtime_error("Unsupported column encoder context version."); | ||
|
|
||
| return ColumnEncoderContext( | ||
| columnTypesFromJson(context["columns"], "columns"), | ||
| columnTypesFromJson(context["extra"], "extra") | ||
| ); | ||
| } | ||
|
|
||
| ColumnEncoderContext ColumnEncoderContext::fromJsonString(const char * contextJson) | ||
| { | ||
| if(!contextJson || std::string(contextJson).empty()) | ||
| return ColumnEncoderContext(); | ||
|
|
||
| Json::Value context; | ||
| Json::Reader reader; | ||
| if(!reader.parse(contextJson, context)) | ||
| throw std::runtime_error("Could not parse column encoder context JSON."); | ||
|
|
||
| return fromJson(context); | ||
| } | ||
|
|
||
| Json::Value ColumnEncoderContext::toJson() const | ||
| { | ||
| Json::Value context(Json::objectValue); | ||
| context["version"] = Version; | ||
| context["columns"] = columnTypesToJson(_columns); | ||
| context["extra"] = columnTypesToJson(_extra); | ||
|
|
||
| return context; | ||
| } | ||
|
|
||
| ScopedColumnEncoderContext::ScopedColumnEncoderContext(const ColumnEncoderContext & context, ColumnEncoder & extraEncoder) | ||
| : _supplied(context.supplied()), _extraEncoder(extraEncoder) | ||
| { | ||
| if(!_supplied) | ||
| return; | ||
|
|
||
| _previousColumns = ColumnEncoder::columnEncoder()->currentNames(); | ||
| _previousExtra = _extraEncoder.currentNames(); | ||
|
|
||
| ColumnEncoder::columnEncoder()->setCurrentNames(context.columns()); | ||
| _extraEncoder.setCurrentNames(context.extra()); | ||
| } | ||
|
|
||
| ScopedColumnEncoderContext::~ScopedColumnEncoderContext() | ||
| { | ||
| if(!_supplied) | ||
| return; | ||
|
|
||
| ColumnEncoder::columnEncoder()->setCurrentNames(_previousColumns); | ||
| _extraEncoder.setCurrentNames(_previousExtra); | ||
| } | ||
|
|
||
| Json::Value decodeColumnJson(const char * payloadJson, const char * encoderContextJson, ColumnEncoder & extraEncoder, bool replaceNames) | ||
| { | ||
| Json::Value payload = parsePayloadJson(payloadJson); | ||
| ColumnEncoderContext context = ColumnEncoderContext::fromJsonString(encoderContextJson); | ||
| ScopedColumnEncoderContext scopedContext(context, extraEncoder); | ||
|
|
||
| ColumnEncoder::decodeJson(payload, replaceNames); | ||
|
|
||
| return payload; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // | ||
| // Copyright (C) 2013-2025 University of Amsterdam | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 2 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| // | ||
|
|
||
| #ifndef COLUMNENCODERCONTEXT_H | ||
| #define COLUMNENCODERCONTEXT_H | ||
|
|
||
| #include "columnencoder.h" | ||
|
|
||
| class ColumnEncoderContext | ||
| { | ||
| public: | ||
| static constexpr int Version = 1; | ||
|
|
||
| ColumnEncoderContext() = default; | ||
| ColumnEncoderContext(const ColumnEncoder::colTypeMap & columns, const ColumnEncoder::colTypeMap & extra); | ||
|
|
||
| static ColumnEncoderContext fromJson(const Json::Value & context); | ||
| static ColumnEncoderContext fromJsonString(const char * contextJson); | ||
|
|
||
| Json::Value toJson() const; | ||
|
|
||
| const ColumnEncoder::colTypeMap& columns() const { return _columns; } | ||
| const ColumnEncoder::colTypeMap& extra() const { return _extra; } | ||
| bool supplied() const { return _supplied; } | ||
|
|
||
| private: | ||
| ColumnEncoder::colTypeMap _columns; | ||
| ColumnEncoder::colTypeMap _extra; | ||
| bool _supplied = false; | ||
| }; | ||
|
|
||
| class ScopedColumnEncoderContext | ||
| { | ||
| public: | ||
| ScopedColumnEncoderContext(const ColumnEncoderContext & context, ColumnEncoder & extraEncoder); | ||
| ~ScopedColumnEncoderContext(); | ||
|
|
||
| private: | ||
| bool _supplied = false; | ||
| ColumnEncoder & _extraEncoder; | ||
| ColumnEncoder::colTypeMap _previousColumns; | ||
| ColumnEncoder::colTypeMap _previousExtra; | ||
| }; | ||
|
|
||
| Json::Value decodeColumnJson(const char * payloadJson, const char * encoderContextJson, ColumnEncoder & extraEncoder, bool replaceNames = true); | ||
|
|
||
| #endif // COLUMNENCODERCONTEXT_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now a double definition. Very ugly. Should be moved to DataBridge instead. That way it covers both engine and syntaxbridge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 3c0575c. I moved this out of
ColumnEncoderand madeDataBridgethe single owner of the extra-options encoder.Concretely:
ColumnEncoder::extraOptionsPrefix()DataBridgeEngine::_extraEncodingsgl_extraEncodingsrbridge_init()to derive the extra encoder from the activeDataBridge, andrbridge_setDataBridge()now refreshes that borrowed pointer whenever SyntaxInterface recreates its DataBridgeSo Engine and SyntaxInterface now share the same ownership model through DataBridge, and SyntaxBridge only borrows the encoder for context capture/decode.