(self, path, frame_index=None)
| 156 | |
| 157 | |
| 158 | def export_as_bin(self, path, frame_index=None): |
| 159 | if self.data_format == "int8": |
| 160 | float_code = 0 |
| 161 | sizeof_value = 8 |
| 162 | pack_format = '>b' |
| 163 | elif self.data_format == "int16": |
| 164 | float_code = 0 |
| 165 | sizeof_value = 16 |
| 166 | pack_format = '>h' |
| 167 | elif self.data_format == "int32": |
| 168 | float_code = 0 |
| 169 | sizeof_value = 32 |
| 170 | pack_format = '>i' |
| 171 | elif self.data_format == "int64": |
| 172 | float_code = 0 |
| 173 | sizeof_value = 64 |
| 174 | pack_format = '>q' |
| 175 | elif self.data_format == "float32": |
| 176 | float_code = 1 |
| 177 | sizeof_value = 32 |
| 178 | pack_format = '>f' |
| 179 | elif self.data_format == "float64": |
| 180 | float_code = 1 |
| 181 | sizeof_value = 64 |
| 182 | pack_format = '>d' |
| 183 | else: |
| 184 | "Unknown format" |
| 185 | return |
| 186 | |
| 187 | with open(path, "wb") as fout: |
| 188 | if frame_index is None: |
| 189 | fout.write(struct.pack('>I', len(self.frames))) |
| 190 | else: |
| 191 | fout.write(struct.pack('>I', 1)) |
| 192 | fout.write(struct.pack('>I', float_code)) |
| 193 | fout.write(struct.pack('>I', sizeof_value)) |
| 194 | fout.write(struct.pack('>I', self.frame_length)) |
| 195 | if frame_index is None: |
| 196 | for frame in self.frames: |
| 197 | self.export_frame_as_binary(float_code, fout, frame, pack_format) |
| 198 | else: |
| 199 | self.export_frame_as_binary(float_code, fout, self.frames[frame_index], pack_format) |
| 200 | |
| 201 | def export_frame_as_binary(self, float_code, fout, frame, pack_format): |
| 202 | if not self.hex_format: |
no test coverage detected