Example #1
0
 def serialize(self):
     config_message = protocol_proto.ConfigMessage()
     for field in self.fields:
         proto_field = config_message.fields_config.fields.add()
         proto_field.name = field
     return Serialization.serialize_tunnled_message(
         config_message.SerializeToString())
Example #2
0
 def serialize(self):
     hello_message = protocol_proto.HelloMessage()
     hello_message.user_data.user_id = self.user_info.user_id
     hello_message.user_data.username = self.user_info.username
     hello_message.user_data.birthday = self.user_info.birth_date
     hello_message.user_data.gender = HelloMessageProto.GENDER_TABLE[
         self.user_info.gender].number
     return Serialization.serialize_tunnled_message(
         hello_message.SerializeToString())
Example #3
0
 def write_user_information(self, user_info):
     proto_user = mind_proto.User()
     proto_user.user_id = user_info.user_id
     proto_user.username = user_info.username
     proto_user.birthday = user_info.birth_date
     proto_user.gender = ProtobufMindWriter.GENDER_TABLE[user_info.gender]
     proto_user_bytes = Serialization.serialize_tunnled_message(
         proto_user.SerializeToString())
     self.stream.write(proto_user_bytes)
     return len(proto_user_bytes)
Example #4
0
 def write_user_information(self, user_info):
     username_size = len(user_info.username)
     birth_date_as_number = user_info.birth_date
     user_info_bytes_untunneled  = 																		\
      pack(self.get_user_info_serialization_format(user_info), 											\
              user_info.user_id,                                        										\
              username_size,                                                 								\
              user_info.username.encode(BinaryMindWriter.ENCODING),   										\
              birth_date_as_number,                                          								\
              self.gender.encode(BinaryMindWriter.ENCODING))
     user_info_bytes = Serialization.serialize_tunnled_message(
         user_info_bytes_untunneled)
     self.stream.write(user_info_bytes)
     return len(user_info_bytes)
Example #5
0
 def write_snapshot(self, snapshot):
     header =                                                                                                \
      pack(BinaryMindWriter.SERIALIZATION_ENDIANITY + BinaryMindWriter.SERIALIZATION_HEADER_SNAPSHOT,		\
       snapshot.timestamp,                                                                        		\
       *snapshot.pose.translation.get(),                                                          		\
       *snapshot.pose.rotation.get())
     body       =                                                                         	\
      snapshot.color_image.serialize() + snapshot.depth_image.serialize()
     trailer      =                                                                           \
        pack(BinaryMindWriter.SERIALIZATION_ENDIANITY + BinaryMindWriter.SERIALIZATION_TRAILER_SNAPSHOT,	\
             *snapshot.user_feeling.get())
     snapshot_bytes_untunneled = header + body + trailer
     snapshot_bytes = Serialization.serialize_tunnled_message(
         snapshot_bytes_untunneled)
     self.stream.write(snapshot_bytes)
     return len(snapshot_bytes)
Example #6
0
    def write_snapshot(self, snapshot):
        proto_snapshot = mind_proto.Snapshot()
        proto_snapshot.datetime = snapshot.timestamp

        translation = mind_proto.Pose.Translation()
        translation.x, translation.y, translation.z = snapshot.pose.translation.get(
        )
        rotation = mind_proto.Pose.Rotation()
        rotation.x, rotation.y, rotation.z, rotation.w = snapshot.pose.rotation.get(
        )

        pose = mind_proto.Pose()
        pose.rotation.CopyFrom(rotation)
        pose.translation.CopyFrom(translation)
        proto_snapshot.pose.CopyFrom(pose)

        color_image = mind_proto.ColorImage()
        color_image.width, color_image.height, color_image.data =                   \
            snapshot.color_image.width, snapshot.color_image.height, snapshot.color_image.data
        proto_snapshot.color_image.CopyFrom(color_image)

        depth_image = mind_proto.DepthImage()
        depth_image.width, depth_image.height =                                     \
            snapshot.depth_image.width, snapshot.depth_image.height
        depth_image.data.extend(snapshot.depth_image.data)
        proto_snapshot.depth_image.CopyFrom(depth_image)

        feelings = mind_proto.Feelings()
        feelings.hunger, feelings.thirst, feelings.exhaustion, feelings.happiness = \
            snapshot.user_feelings.get()
        proto_snapshot.feelings.CopyFrom(feelings)

        proto_snapshot_bytes = Serialization.serialize_tunnled_message(
            proto_snapshot.SerializeToString())
        self.stream.write(proto_snapshot_bytes)
        return len(proto_snapshot_bytes)