@@ -46,6 +46,10 @@ namespace teascript {
4646using JsonAdapter = JsonAdapterPico;
4747}
4848#elif TEASCRIPT_JSONSUPPORT == TEASCRIPT_JSON_NLOHMANN
49+ # if !defined( TEASCRIPT_BSONSUPPORT)
50+ // nlohmann supports BSON
51+ # define TEASCRIPT_BSONSUPPORT 1
52+ # endif
4953#if __has_include("teascript/ext/JsonAdapterNlohmann.hpp")
5054# include " teascript/ext/JsonAdapterNlohmann.hpp"
5155#else
@@ -76,6 +80,9 @@ using JsonAdapter = JsonAdapterBoost;
7680# error unsupported JSON flavor for TeaScript
7781#endif
7882
83+ #if !defined( TEASCRIPT_BSONSUPPORT)
84+ # define TEASCRIPT_BSONSUPPORT 0
85+ #endif
7986
8087namespace teascript {
8188
@@ -117,6 +124,23 @@ class JsonSupport
117124 {
118125 Adapter::FromValueObject ( rObj, rOut );
119126 }
127+
128+ // EXPERIMENTAL BSON support (nlohmann adapter must be used!)
129+ #if TEASCRIPT_BSONSUPPORT
130+ // / Constructs a ValueObject structure from the given BSON buffer.
131+ static ValueObject ReadBsonBuffer ( Context &rContext, Buffer const &rBuffer )
132+ {
133+ return Adapter::FromBSON ( rContext, rBuffer );
134+ }
135+
136+ // / Constructs a Bson buffer from the given ValueObject.
137+ // / \return the constructed buffer or false on error.
138+ // / \note the object must only contain supported types and layout for Json.
139+ static ValueObject WriteBsonBuffer ( ValueObject const &rObj )
140+ {
141+ return Adapter::ToBSON ( rObj );
142+ }
143+ #endif
120144};
121145
122146} // namespace teascript
0 commit comments