Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/src/streaming_data_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from streaming_data_types.status_x5f2 import deserialise_x5f2, serialise_x5f2
from streaming_data_types.units_un00 import serialise_un00, deserialise_un00
from streaming_data_types.pulse_metadata_pu00 import serialise_pu00, deserialise_pu00
from streaming_data_types.vetoes_vc00 import serialise_vc00, deserialise_vc00

__version__ = version

Expand All @@ -39,6 +40,7 @@
"da00": serialise_da00,
"un00": serialise_un00,
"pu00": serialise_pu00,
"vc00": serialise_vc00,
}


Expand All @@ -59,4 +61,5 @@
"da00": deserialise_da00,
"un00": deserialise_un00,
"pu00": deserialise_pu00,
"vc00": deserialise_vc00,
}
67 changes: 67 additions & 0 deletions python/src/streaming_data_types/fbschemas/vetoes_vc00/Vetoes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# automatically generated by the FlatBuffers compiler, do not modify

# namespace:

import flatbuffers
from flatbuffers.compat import import_numpy
np = import_numpy()

class Vetoes(object):
__slots__ = ['_tab']

@classmethod
def GetRootAs(cls, buf, offset=0):
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
x = Vetoes()
x.Init(buf, n + offset)
return x

@classmethod
def GetRootAsVetoes(cls, buf, offset=0):
"""This method is deprecated. Please switch to GetRootAs."""
return cls.GetRootAs(buf, offset)
@classmethod
def VetoesBufferHasIdentifier(cls, buf, offset, size_prefixed=False):
return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x76\x63\x30\x30", size_prefixed=size_prefixed)

# Vetoes
def Init(self, buf, pos):
self._tab = flatbuffers.table.Table(buf, pos)

# Vetoes
def Timestamp(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
if o != 0:
return self._tab.Get(flatbuffers.number_types.Int64Flags, o + self._tab.Pos)
return 0

# Vetoes
def Vetoes(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
if o != 0:
return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos)
return 0

def VetoesStart(builder):
builder.StartObject(2)

def Start(builder):
VetoesStart(builder)

def VetoesAddTimestamp(builder, timestamp):
builder.PrependInt64Slot(0, timestamp, 0)

def AddTimestamp(builder, timestamp):
VetoesAddTimestamp(builder, timestamp)

def VetoesAddVetoes(builder, vetoes):
builder.PrependUint32Slot(1, vetoes, 0)

def AddVetoes(builder, vetoes):
VetoesAddVetoes(builder, vetoes)

def VetoesEnd(builder):
return builder.EndObject()

def End(builder):
return VetoesEnd(builder)
Empty file.
28 changes: 28 additions & 0 deletions python/src/streaming_data_types/vetoes_vc00.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from collections import namedtuple

import flatbuffers

from streaming_data_types.fbschemas.vetoes_vc00 import Vetoes
from streaming_data_types.utils import check_schema_identifier

FILE_IDENTIFIER = b"vc00"

VetoesInfo = namedtuple("VetoesInfo", ("timestamp_ns", "vetoes"))


def deserialise_vc00(buffer) -> VetoesInfo:
check_schema_identifier(buffer, FILE_IDENTIFIER)
vetoes = Vetoes.Vetoes.GetRootAsVetoes(buffer, 0)
return VetoesInfo(
vetoes.Timestamp(),
vetoes.Vetoes(),
)


def serialise_vc00(timestamp_ns: int, vetoes: int) -> bytes:
builder = flatbuffers.Builder(128)
Vetoes.Start(builder)
Vetoes.AddTimestamp(builder, timestamp_ns)
Vetoes.AddVetoes(builder, vetoes)
builder.Finish(Vetoes.VetoesEnd(builder), file_identifier=FILE_IDENTIFIER)
return bytes(builder.Output())
31 changes: 31 additions & 0 deletions python/tests/test_vc00.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest

from streaming_data_types import DESERIALISERS, SERIALISERS
from streaming_data_types.exceptions import WrongSchemaException
from streaming_data_types.vetoes_vc00 import deserialise_vc00, serialise_vc00


class TestSerialisationUn00:
def test_serialises_and_deserialises_vc00_message_correctly(self):
"""
Round-trip to check what we serialise is what we get back.
"""
buf = serialise_vc00(1234567890, 0x1)
entry = deserialise_vc00(buf)

assert entry.timestamp_ns == 1234567890
assert entry.vetoes == 0x1

def test_if_buffer_has_wrong_id_then_throws(self):
buf = serialise_vc00(1234567890, 0x1)

# Manually hack the id
buf = bytearray(buf)
buf[4:8] = b"1234"

with pytest.raises(WrongSchemaException):
deserialise_vc00(buf)

def test_schema_type_is_in_global_serialisers_list(self):
assert "vc00" in SERIALISERS
assert "vc00" in DESERIALISERS
54 changes: 28 additions & 26 deletions rust/src/flatbuffers_generated/mod.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
#[path = "6s4t_run_stop.rs"]
pub mod run_stop_6s4t;
#[path = "ad00_area_detector_array.rs"]
pub mod area_detector_array_ad00;
#[path = "al00_alarm.rs"]
pub mod alarm_al00;
#[path = "answ_action_response.rs"]
pub mod action_response_answ;
#[path = "da00_dataarray.rs"]
pub mod dataarray_da00;
#[path = "pu00_pulse_metadata.rs"]
pub mod pulse_metadata_pu00;
#[path = "fc00_forwarder_config.rs"]
pub mod forwarder_config_fc00;
#[path = "vc00_veto_configuration.rs"]
pub mod veto_configuration_vc00;
#[path = "df12_det_spec_map.rs"]
pub mod det_spec_map_df12;
#[path = "ep01_epics_connection.rs"]
pub mod epics_connection_ep01;
#[path = "ev44_events.rs"]
pub mod events_ev44;
#[path = "f144_logdata.rs"]
pub mod logdata_f144;
#[path = "fc00_forwarder_config.rs"]
pub mod forwarder_config_fc00;
#[path = "hs01_event_histogram.rs"]
pub mod event_histogram_hs01;
#[path = "ad00_area_detector_array.rs"]
pub mod area_detector_array_ad00;
#[path = "un00_units.rs"]
pub mod units_un00;
#[path = "se00_data.rs"]
pub mod data_se00;
#[path = "ep01_epics_connection.rs"]
pub mod epics_connection_ep01;
#[path = "6s4t_run_stop.rs"]
pub mod run_stop_6s4t;
#[path = "json_json.rs"]
pub mod json_json;
#[path = "pl72_run_start.rs"]
pub mod run_start_pl72;
#[path = "pu00_pulse_metadata.rs"]
pub mod pulse_metadata_pu00;
#[path = "se00_data.rs"]
pub mod data_se00;
#[path = "un00_units.rs"]
pub mod units_un00;
#[path = "wrdn_finished_writing.rs"]
pub mod finished_writing_wrdn;
#[path = "answ_action_response.rs"]
pub mod action_response_answ;
#[path = "x5f2_status.rs"]
pub mod status_x5f2;
#[path = "da00_dataarray.rs"]
pub mod dataarray_da00;
#[path = "hs01_event_histogram.rs"]
pub mod event_histogram_hs01;
#[path = "f144_logdata.rs"]
pub mod logdata_f144;
#[path = "wrdn_finished_writing.rs"]
pub mod finished_writing_wrdn;
#[path = "al00_alarm.rs"]
pub mod alarm_al00;
Loading