def read_stream(stream): user_id, username_size = \ Serialization.read(stream, HelloMessageNative.SERIALIZATION_HEADER) CURRENT_USER_PAYLOAD_FORMAT = HelloMessageNative.SERIALIZATION_PAYLOAD.format( username_size) username, birth_date, gender = \ Serialization.read(stream, CURRENT_USER_PAYLOAD_FORMAT) user_info = UserInfo(user_id, username, birth_date, gender) return HelloMessage(user_info)
def read(stream): user_id, username_size = \ Serialization.read(stream, UserInformation.SERIALIZATION_HEADER) CURRENT_USER_PAYLOAD_FORMAT = UserInformation.SERIALIZATION_PAYLOAD.format( username_size) username, birth_date, gender = \ Serialization.read(stream, CURRENT_USER_PAYLOAD_FORMAT) return UserInfo(user_id, username, datetime.fromtimestamp(birth_date), gender)
def read_stream(stream): timestamp, t_x, t_y, t_z, r_x, r_y, r_z, r_w = \ Serialization.read(stream, SnapshotMessageNative.SERIALIZATION_HEADER, expect_eof=True) translation, rotation = \ (t_x, t_y, t_z), (r_x, r_y, r_z, r_w) color_image = ColorImage.read(stream) depth_image = DepthImage.read(stream) (hunger, thirst, exhaustion, happiness) = \ Serialization.read(stream, SnapshotMessageNative.SERIALIZATION_TRAILER) user_feeling = \ (hunger, thirst, exhaustion, happiness) return Snapshot(timestamp, translation, rotation, color_image, depth_image, user_feeling)
def read_stream(stream): fields_number = \ Serialization.read(stream, ConfigMessageNative.SERIALIZATION_HEADER)[0] fields_config = [] for field_index in range(fields_number): field_size = \ Serialization.read(stream, ConfigMessageNative.SERIALIZATION_FIELD_HEADER)[0] FIELD_PAYLOAD_FORMAT = ConfigMessageNative.SERIALIZATION_FIELD_PAYLOAD.format( field_size) field = \ Serialization.read(stream, FIELD_PAYLOAD_FORMAT)[0] fields_config.append(field.decode(ConfigMessageNative.ENCODING)) return ConfigMessage(fields_config)
def read(stream, pixel_serialization_format, pixel_elements_count): width, height = \ Serialization.read(stream, SnapshotImage.SERIALIZATION_HEADER) image_size = width * height pixel_array_size = image_size * pixel_elements_count data = [] if 0 != pixel_array_size: SERIALIZATION_PAYLOAD_FORMAT = ( '{0}' + pixel_serialization_format).format(pixel_array_size) data = \ Serialization.read(stream, SERIALIZATION_PAYLOAD_FORMAT) return SnapshotImage(width, height, data, pixel_serialization_format, pixel_elements_count)