forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage-header.ts
More file actions
58 lines (53 loc) · 2.35 KB
/
Copy pathmessage-header.ts
File metadata and controls
58 lines (53 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// automatically generated by the FlatBuffers compiler, do not modify
import { DictionaryBatch } from './dictionary-batch.js';
import { RecordBatch } from './record-batch.js';
import { Schema } from './schema.js';
import { SparseTensor } from './sparse-tensor.js';
import { Tensor } from './tensor.js';
/**
* ----------------------------------------------------------------------
* The root Message type
* This union enables us to easily send different message types without
* redundant storage, and in the future we can easily add new message types.
*
* Arrow implementations do not need to implement all of the message types,
* which may include experimental metadata types. For maximum compatibility,
* it is best to send data using RecordBatch
*/
export enum MessageHeader {
NONE = 0,
Schema = 1,
DictionaryBatch = 2,
RecordBatch = 3,
Tensor = 4,
SparseTensor = 5
}
export function unionToMessageHeader(
type: MessageHeader,
accessor: (obj:DictionaryBatch|RecordBatch|Schema|SparseTensor|Tensor) => DictionaryBatch|RecordBatch|Schema|SparseTensor|Tensor|null
): DictionaryBatch|RecordBatch|Schema|SparseTensor|Tensor|null {
switch(MessageHeader[type]) {
case 'NONE': return null;
case 'Schema': return accessor(new Schema())! as Schema;
case 'DictionaryBatch': return accessor(new DictionaryBatch())! as DictionaryBatch;
case 'RecordBatch': return accessor(new RecordBatch())! as RecordBatch;
case 'Tensor': return accessor(new Tensor())! as Tensor;
case 'SparseTensor': return accessor(new SparseTensor())! as SparseTensor;
default: return null;
}
}
export function unionListToMessageHeader(
type: MessageHeader,
accessor: (index: number, obj:DictionaryBatch|RecordBatch|Schema|SparseTensor|Tensor) => DictionaryBatch|RecordBatch|Schema|SparseTensor|Tensor|null,
index: number
): DictionaryBatch|RecordBatch|Schema|SparseTensor|Tensor|null {
switch(MessageHeader[type]) {
case 'NONE': return null;
case 'Schema': return accessor(index, new Schema())! as Schema;
case 'DictionaryBatch': return accessor(index, new DictionaryBatch())! as DictionaryBatch;
case 'RecordBatch': return accessor(index, new RecordBatch())! as RecordBatch;
case 'Tensor': return accessor(index, new Tensor())! as Tensor;
case 'SparseTensor': return accessor(index, new SparseTensor())! as SparseTensor;
default: return null;
}
}