Skip to content

Commit f653548

Browse files
committed
adds burst to websocket adapter; move build to c++20
Signed-off-by: Will Rieger <[email protected]>
1 parent b0c653b commit f653548

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

cpp/csp/adapters/websocket/ClientInputAdapter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ ClientInputAdapter::ClientInputAdapter(
2828
void ClientInputAdapter::processMessage( void* c, size_t t, PushBatch* batch )
2929
{
3030

31-
if( type() -> type() == CspType::Type::STRUCT )
31+
if( dataType() -> type() == CspType::Type::STRUCT )
3232
{
3333
auto tick = m_converter -> asStruct( c, t );
3434
pushTick( std::move(tick), batch );
35-
} else if ( type() -> type() == CspType::Type::STRING )
35+
} else if ( dataType() -> type() == CspType::Type::STRING )
3636
{
3737
pushTick( std::string((char const*)c, t), batch );
3838
}

cpp/csp/python/adapters/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ if(CSP_BUILD_PARQUET_ADAPTER)
4040
endif()
4141

4242
if(CSP_BUILD_WS_CLIENT_ADAPTER)
43-
set(CMAKE_CXX_STANDARD 17)
44-
add_library(websocketadapterimpl SHARED websocketadapterimpl.cpp)
45-
target_link_libraries(websocketadapterimpl csp_core csp_engine cspimpl csp_websocket_client_adapter)
46-
install(TARGETS websocketadapterimpl RUNTIME DESTINATION ${CSP_RUNTIME_INSTALL_SUBDIR})
47-
set(CMAKE_CXX_STANDARD 20)
43+
add_library(websocketadapterimpl SHARED websocketadapterimpl.cpp)
44+
target_link_libraries(websocketadapterimpl csp_core csp_engine cspimpl csp_websocket_client_adapter)
45+
install(TARGETS websocketadapterimpl RUNTIME DESTINATION ${CSP_RUNTIME_INSTALL_SUBDIR})
4846
endif()

csp/adapters/websocket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def subscribe(
442442
properties["field_map"] = field_map
443443
properties["meta_field_map"] = meta_field_map
444444

445-
return _websocket_input_adapter_def(self, ts_type, properties, push_mode)
445+
return _websocket_input_adapter_def(self, ts_type, properties, push_mode=push_mode)
446446

447447
def send(self, x: ts["T"]):
448448
return _websocket_output_adapter_def(self, x)
@@ -452,7 +452,7 @@ def update_headers(self, x: ts[List[WebsocketHeaderUpdate]]):
452452

453453
def status(self, push_mode=csp.PushMode.NON_COLLAPSING):
454454
ts_type = Status
455-
return status_adapter_def(self, ts_type, push_mode)
455+
return status_adapter_def(self, ts_type, push_mode=push_mode)
456456

457457
def _create(self, engine, memo):
458458
"""method needs to return the wrapped c++ adapter manager"""

csp/tests/adapters/test_websocket.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import threading
44
import unittest
55
from datetime import datetime, timedelta
6+
from typing import List
67

78
import csp
89
from csp import ts
@@ -126,3 +127,35 @@ def g():
126127
csp.stop_engine(ws.status())
127128

128129
csp.run(g, starttime=datetime.now(pytz.UTC), realtime=True)
130+
131+
def test_send_recv_burst_json(self):
132+
class MsgStruct(csp.Struct):
133+
a: int
134+
b: str
135+
136+
@csp.node
137+
def send_msg_on_open(status: ts[Status]) -> ts[str]:
138+
if csp.ticked(status):
139+
return MsgStruct(a=1234, b="im a string").to_json()
140+
141+
@csp.node
142+
def my_edge_that_handles_burst(objs: ts[List[MsgStruct]]) -> ts[bool]:
143+
if csp.ticked(objs):
144+
return True
145+
146+
@csp.graph
147+
def g():
148+
ws = WebsocketAdapterManager("ws://localhost:8000/")
149+
status = ws.status()
150+
ws.send(send_msg_on_open(status))
151+
recv = ws.subscribe(MsgStruct, JSONTextMessageMapper(), push_mode=csp.PushMode.BURST)
152+
_ = my_edge_that_handles_burst(recv)
153+
csp.add_graph_output("recv", recv)
154+
csp.stop_engine(recv)
155+
156+
msgs = csp.run(g, starttime=datetime.now(pytz.UTC), realtime=True)
157+
obj = msgs["recv"][0][1]
158+
assert isinstance(obj, list)
159+
innerObj = obj[0]
160+
assert innerObj.a == 1234
161+
assert innerObj.b == "im a string"

0 commit comments

Comments
 (0)