File size: 2,409 Bytes
78c921d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
// 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;
  }
}