(buffer: ArrayBuffer)
| 829 | |
| 830 | /** Decode an ArrayBuffer as intermediate serialization format. */ |
| 831 | export function arrayBuffer2SerializedExamples(buffer: ArrayBuffer): |
| 832 | SerializedExamples { |
| 833 | tf.util.assert(buffer != null, () => 'Received null or undefined buffer'); |
| 834 | // Check descriptor. |
| 835 | let offset = 0; |
| 836 | const descriptor = arrayBuffer2String( |
| 837 | buffer.slice(offset, DATASET_SERIALIZATION_DESCRIPTOR.length)); |
| 838 | tf.util.assert( |
| 839 | descriptor === DATASET_SERIALIZATION_DESCRIPTOR, |
| 840 | () => `Deserialization error: Invalid descriptor`); |
| 841 | offset += DATASET_SERIALIZATION_DESCRIPTOR.length; |
| 842 | // Skip the version part for now. It may be used in the future. |
| 843 | offset += 4; |
| 844 | |
| 845 | // Extract the length of the encoded manifest JSON as a Uint32. |
| 846 | const manifestLength = new Uint32Array(buffer, offset, 1); |
| 847 | offset += 4; |
| 848 | const manifestBeginByte = offset; |
| 849 | offset = manifestBeginByte + manifestLength[0]; |
| 850 | const manifestBytes = buffer.slice(manifestBeginByte, offset); |
| 851 | const manifestString = arrayBuffer2String(manifestBytes); |
| 852 | const manifest = JSON.parse(manifestString); |
| 853 | const data = buffer.slice(offset); |
| 854 | return {manifest, data}; |
| 855 | } |
| 856 | |
| 857 | /** |
| 858 | * Get valid windows in a long snippet. |
no test coverage detected