@@ -0,0 +1,1908 @@
+import io%0Aimport socket%0Aimport struct%0Aimport time%0A%0ABRUCE_PATH = '/var/run/bruce/bruce.socket'%0A%0AMSG_SIZE_FIELD_SIZE = 4%0AAPI_KEY_FIELD_SIZE = 2%0AAPI_VERSION_FIELD_SIZE = 2%0AFLAGS_FIELD_SIZE = 2%0APARTITION_KEY_FIELD_SIZE = 4%0ATOPIC_SIZE_FIELD_SIZE = 2%0ATIMESTAMP_FIELD_SIZE = 8%0AKEY_SIZE_FIELD_SIZE = 4%0AVALUE_SIZE_FIELD_SIZE = 4%0A%0AANY_PARTITION_FIXED_BYTES = MSG_SIZE_FIELD_SIZE + API_KEY_FIELD_SIZE + %5C%0A                            API_VERSION_FIELD_SIZE + FLAGS_FIELD_SIZE + %5C%0A                            TOPIC_SIZE_FIELD_SIZE + TIMESTAMP_FIELD_SIZE + %5C%0A                            KEY_SIZE_FIELD_SIZE + VALUE_SIZE_FIELD_SIZE%0A%0APARTITION_KEY_FIXED_BYTES = ANY_PARTITION_FIXED_BYTES + %5C%0A                            PARTITION_KEY_FIELD_SIZE%0A%0AANY_PARTITION_API_KEY = 256%0AANY_PARTITION_API_VERSION = 0%0A%0APARTITION_KEY_API_KEY = 257%0APARTITION_KEY_API_VERSION = 0%0A%0A%0Adef create_msg(partition, topic, key_bytes, value_bytes):%0A    topic_bytes = bytes(topic)%0A%0A    msg_size = PARTITION_KEY_FIXED_BYTES + %5C%0A               len(topic_bytes) + len(key_bytes) + len(value_bytes)%0A%0A    buf = io.BytesIO()%0A    flags = 0%0A    buf.write(struct.pack('%3Eihhhih', msg_size,%0A                          PARTITION_KEY_API_KEY,%0A                          PARTITION_KEY_API_VERSION, flags,%0A                          partition, len(topic_bytes)))%0A    buf.write(topic_bytes)%0A    buf.write(struct.pack('%3Eqi', int(time.time() * 1000), len(key_bytes)))%0A    buf.write(key_bytes)%0A    buf.write(struct.pack('%3Ei', len(value_bytes)))%0A    buf.write(value_bytes)%0A    result_bytes = buf.getvalue()%0A    buf.close()%0A    return result_bytes%0A%0A%0A# Create socket for sending to Bruce.%0Adef open_bruce_socket():%0A    return socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)%0A%0A%0Adef to_bruce(bruce_sock, bruce_path, topic, key, value, partition):%0A    partition_key_msg = create_msg(partition, topic, bytes(key), bytes(value))%0A    bruce_sock.sendto(partition_key_msg, bruce_path)%0A

Add bruce client