def populateMessage(message, count): # Note: If a field of the same name is added to an existing message, # the value passed when calling add_field will overwrite the existing # value. message.add_field("CHAR-FIELD", 'c') message.add_field("BOOL-FIELD-TRUE", True) message.add_field("BOOL-FIELD-FALSE", False) message.add_field(libgmsec_python3.I8Field("I8-FIELD", count)) message.add_field(libgmsec_python3.I16Field("I16-FIELD", count)) message.add_field(libgmsec_python3.I32Field("I32-FIELD", count)) message.add_field(libgmsec_python3.I64Field("I64-FIELD", count)) message.add_field(libgmsec_python3.U8Field("U8-FIELD", count)) message.add_field(libgmsec_python3.U16Field("U16-FIELD", count)) message.add_field(libgmsec_python3.U32Field("U32-FIELD", count)) message.add_field(libgmsec_python3.U64Field("U64-FIELD", count)) message.add_field(libgmsec_python3.StringField("STRING-FIELD", "This is a test")) message.add_field(libgmsec_python3.F32Field("F32-FIELD", (1 + 1. / count))) message.add_field(libgmsec_python3.F64Field("F64-FIELD", (1 + 1. / count))) message.add_field(libgmsec_python3.BinaryField("BIN-FIELD", "JLMNOPQ", 7))
def publishTestMessage(connMgr, subject): i = 123 # Create a Message object message = libgmsec_python3.Message(subject, libgmsec_python3.Message.PUBLISH) # Add fields to the Message message.add_field("F", False) message.add_field(libgmsec_python3.I32Field("I", i)) message.add_field(libgmsec_python3.U16Field("K", i)) message.add_field("S", "This is a test") message.add_field(libgmsec_python3.F32Field("D", 1 + 1. / i)) message.add_field(libgmsec_python3.BinaryField("X", "JLMNOPQ", 7)) # Publish Message connMgr.publish(message) # Output the Message's XML string representation by invoking Log macro libgmsec_python3.log_info("Sent:\n" + message.to_XML())
def populateMessage(message): # Add Fields of varying data types to the Message value = 1 message.add_field(libgmsec_python3.CharField("CHAR-FIELD", 'c')) message.add_field(libgmsec_python3.BooleanField("BOOL-FIELD-TRUE", True)) message.add_field(libgmsec_python3.BooleanField("BOOL-FIELD-FALSE", False)) message.add_field(libgmsec_python3.I8Field("I8-FIELD", value)) message.add_field(libgmsec_python3.I16Field("I16-FIELD", value)) message.add_field(libgmsec_python3.I32Field("I32-FIELD", value)) message.add_field(libgmsec_python3.I64Field("I64-FIELD", value)) message.add_field(libgmsec_python3.U8Field("U8-FIELD", value)) message.add_field(libgmsec_python3.U16Field("U16-FIELD", value)) message.add_field(libgmsec_python3.U32Field("U32-FIELD", value)) message.add_field(libgmsec_python3.U64Field("U64-FIELD", value)) message.add_field( libgmsec_python3.StringField("STRING-FIELD", "This is a test")) message.add_field(libgmsec_python3.F32Field("F32-FIELD", (1 + 1. / value))) message.add_field(libgmsec_python3.F64Field("F64-FIELD", (1 + 1. / value))) message.add_field(libgmsec_python3.BinaryField("BIN-FIELD", "JLMNOPQ", 7))
def populateMessage(message, value): # Note: Since C++ is a strongly-typed language, it is possible to use # type casting to add Field objects to a Message without having to # first create a Field object, then add it to the message. message.add_field(libgmsec_python3.CharField("CHAR-FIELD", 'c')) message.add_field(libgmsec_python3.BooleanField("BOOL-FIELD-TRUE", True)) message.add_field(libgmsec_python3.BooleanField("BOOL-FIELD-FALSE", False)) message.add_field(libgmsec_python3.I8Field("I8-FIELD", value % 128)) message.add_field(libgmsec_python3.I16Field("I16-FIELD", value)) message.add_field(libgmsec_python3.I32Field("I32-FIELD", value)) message.add_field(libgmsec_python3.I64Field("I64-FIELD", value)) message.add_field(libgmsec_python3.U8Field("U8-FIELD", value % 256)) message.add_field(libgmsec_python3.U16Field("U16-FIELD", value)) message.add_field(libgmsec_python3.U32Field("U32-FIELD", value)) message.add_field(libgmsec_python3.U64Field("U64-FIELD", value)) message.add_field( libgmsec_python3.StringField("STRING-FIELD", "This is a test")) message.add_field(libgmsec_python3.F32Field("F32-FIELD", (1 + 1. / value))) message.add_field(libgmsec_python3.F64Field("F64-FIELD", (1 + 1. / value))) message.add_field(libgmsec_python3.BinaryField("BIN-FIELD", "JLMNOPQ", 7))
1. Creating a BinaryField 2. Adding BinaryField to a Message 3. Retrieve BinaryField from the Message using Field Iterator 4. Verify BinaryField and Message Field are the same """ import libgmsec_python3 as lp import binascii # 1. Create BinaryField, and display information regarding it # blob = bytearray() for i in range(0, 256): blob.append(i) binField = lp.BinaryField('BIN-FIELD-1', blob, len(blob)) print("\nBinaryField...\n") print("Field Name is : " + binField.get_name()) print("Field Type is : " + str(binField.get_type())) print("Field Len : " + str(binField.get_length())) print("Field as string : ") print(binField.get_string_value()) print("Field as raw data:") binData = binField.get_value() print(binascii.hexlify(binData)) print("\n") # 2. Create Message and add existing BinaryField, and an anonymous one # msg = lp.Message('GMSEC.FOO.BAR', lp.Message.PUBLISH)