Python bindings: Add packet context accessors
[babeltrace.git] / bindings / python / examples / ctf_writer.py
index b7bd73f2b5252fd7b8613893c81b8aa6f3ec9349..b33af931deebd8fd333348432dfe4708eae76997 100644 (file)
@@ -54,6 +54,14 @@ int32_type.signed = True
 uint16_type = CTFWriter.IntegerFieldDeclaration(16)
 uint16_type.signed = False
 
+# Add a custom uint16_t field in the stream's packet context
+packet_context_type = stream_class.packet_context_type
+print("\nFields in default packet context:")
+for field in packet_context_type.fields:
+               print(str(type(field[1])) + " " + field[0])
+packet_context_type.add_field(uint16_type, "a_custom_packet_context_field")
+stream_class.packet_context_type = packet_context_type
+
 # Create a string type
 string_type = CTFWriter.StringFieldDeclaration()
 
@@ -120,4 +128,9 @@ for i in range(100):
 
        stream.append_event(event)
 
+# Populate custom packet context field before flushing
+packet_context = stream.packet_context
+field = packet_context.field("a_custom_packet_context_field")
+field.value = 42
+
 stream.flush()
This page took 0.024832 seconds and 4 git commands to generate.