def _serialise_double(builder: flatbuffers.Builder, data: np.ndarray, source: int): DoubleStart(builder) DoubleAddValue(builder, data.item()) value_position = DoubleEnd(builder) LogData.LogDataStart(builder) LogData.LogDataAddSourceName(builder, source) LogData.LogDataAddValue(builder, value_position) LogData.LogDataAddValueType(builder, Value.Double)
def _serialise_float(builder: flatbuffers.Builder, data: np.ndarray, source: int): FloatStart(builder) FloatAddValue(builder, data.item()) value_position = FloatEnd(builder) LogData.LogDataStart(builder) LogData.LogDataAddSourceName(builder, source) LogData.LogDataAddValue(builder, value_position) LogData.LogDataAddValueType(builder, Value.Float)
def _serialise_ulong(builder: flatbuffers.Builder, data: np.ndarray, source: int): ULongStart(builder) ULongAddValue(builder, data.item()) value_position = ULongEnd(builder) LogData.LogDataStart(builder) LogData.LogDataAddSourceName(builder, source) LogData.LogDataAddValue(builder, value_position) LogData.LogDataAddValueType(builder, Value.ULong)
def _serialise_ushort(builder: flatbuffers.Builder, data: np.ndarray, source: int): UShortStart(builder) UShortAddValue(builder, data.item()) value_position = UShortEnd(builder) LogData.LogDataStart(builder) LogData.LogDataAddSourceName(builder, source) LogData.LogDataAddValue(builder, value_position) LogData.LogDataAddValueType(builder, Value.UShort)
def _serialise_ubyte(builder: flatbuffers.Builder, data: np.ndarray, source: int): UByteStart(builder) UByteAddValue(builder, data.item()) value_position = UByteEnd(builder) LogData.LogDataStart(builder) LogData.LogDataAddSourceName(builder, source) LogData.LogDataAddValue(builder, value_position) LogData.LogDataAddValueType(builder, Value.UByte)
def _serialise_string(builder: flatbuffers.Builder, data: np.ndarray, source: int): string_offset = builder.CreateString(data.item()) StringStart(builder) StringAddValue(builder, string_offset) value_position = StringEnd(builder) LogData.LogDataStart(builder) LogData.LogDataAddSourceName(builder, source) LogData.LogDataAddValue(builder, value_position) LogData.LogDataAddValueType(builder, Value.String)
def _serialise_doublearray(builder: flatbuffers.Builder, data: np.ndarray, source: int): ArrayDoubleStartValueVector(builder, len(data)) for single_value in reversed(data): builder.PrependFloat64(single_value) array_offset = builder.EndVector(len(data)) ArrayDoubleStart(builder) ArrayDoubleAddValue(builder, array_offset) value_position = ArrayDoubleEnd(builder) LogData.LogDataStart(builder) LogData.LogDataAddSourceName(builder, source) LogData.LogDataAddValue(builder, value_position) LogData.LogDataAddValueType(builder, Value.ArrayDouble)
def _serialise_stringarray(builder: flatbuffers.Builder, data: np.ndarray, source: int): string_offsets = [ builder.CreateString(string_item) for string_item in reversed(data) ] ArrayStringStartValueVector(builder, len(data)) for string_offset in string_offsets: builder.PrependSOffsetTRelative(string_offset) string_array_offset = builder.EndVector(len(data)) ArrayStringStart(builder) ArrayStringAddValue(builder, string_array_offset) value_position = ArrayStringEnd(builder) LogData.LogDataStart(builder) LogData.LogDataAddSourceName(builder, source) LogData.LogDataAddValue(builder, value_position) LogData.LogDataAddValueType(builder, Value.ArrayString)
def _complete_buffer( builder, timestamp_unix_ns: int, alarm_status: Union[int, None] = None, alarm_severity: Union[int, None] = None, ) -> bytearray: LogData.LogDataAddTimestamp(builder, timestamp_unix_ns) if alarm_status is not None: LogData.LogDataAddStatus(builder, alarm_status) # Only include severity if status was provided, it would be meaningless by itself if alarm_severity is not None: LogData.LogDataAddSeverity(builder, alarm_severity) log_msg = LogData.LogDataEnd(builder) builder.Finish(log_msg) buff = builder.Output() buff[4:8] = FILE_IDENTIFIER return buff