1// automatically generated by the FlatBuffers compiler, do not modify 2import * as flatbuffers from 'flatbuffers'; 3import { Character, unionToCharacter, unionListToCharacter } from './character'; 4export class Movie { 5 constructor() { 6 this.bb = null; 7 this.bb_pos = 0; 8 } 9 __init(i, bb) { 10 this.bb_pos = i; 11 this.bb = bb; 12 return this; 13 } 14 static getRootAsMovie(bb, obj) { 15 return (obj || new Movie()).__init(bb.readInt32(bb.position()) + bb.position(), bb); 16 } 17 static getSizePrefixedRootAsMovie(bb, obj) { 18 bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); 19 return (obj || new Movie()).__init(bb.readInt32(bb.position()) + bb.position(), bb); 20 } 21 static bufferHasIdentifier(bb) { 22 return bb.__has_identifier('MOVI'); 23 } 24 mainCharacterType() { 25 const offset = this.bb.__offset(this.bb_pos, 4); 26 return offset ? this.bb.readUint8(this.bb_pos + offset) : Character.NONE; 27 } 28 mainCharacter(obj) { 29 const offset = this.bb.__offset(this.bb_pos, 6); 30 return offset ? this.bb.__union_with_string(obj, this.bb_pos + offset) : null; 31 } 32 charactersType(index) { 33 const offset = this.bb.__offset(this.bb_pos, 8); 34 return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; 35 } 36 charactersTypeLength() { 37 const offset = this.bb.__offset(this.bb_pos, 8); 38 return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; 39 } 40 charactersTypeArray() { 41 const offset = this.bb.__offset(this.bb_pos, 8); 42 return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; 43 } 44 characters(index, obj) { 45 const offset = this.bb.__offset(this.bb_pos, 10); 46 return offset ? this.bb.__union_with_string(obj, this.bb.__vector(this.bb_pos + offset) + index * 4) : null; 47 } 48 charactersLength() { 49 const offset = this.bb.__offset(this.bb_pos, 10); 50 return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; 51 } 52 static getFullyQualifiedName() { 53 return 'Movie'; 54 } 55 static startMovie(builder) { 56 builder.startObject(4); 57 } 58 static addMainCharacterType(builder, mainCharacterType) { 59 builder.addFieldInt8(0, mainCharacterType, Character.NONE); 60 } 61 static addMainCharacter(builder, mainCharacterOffset) { 62 builder.addFieldOffset(1, mainCharacterOffset, 0); 63 } 64 static addCharactersType(builder, charactersTypeOffset) { 65 builder.addFieldOffset(2, charactersTypeOffset, 0); 66 } 67 static createCharactersTypeVector(builder, data) { 68 builder.startVector(1, data.length, 1); 69 for (let i = data.length - 1; i >= 0; i--) { 70 builder.addInt8(data[i]); 71 } 72 return builder.endVector(); 73 } 74 static startCharactersTypeVector(builder, numElems) { 75 builder.startVector(1, numElems, 1); 76 } 77 static addCharacters(builder, charactersOffset) { 78 builder.addFieldOffset(3, charactersOffset, 0); 79 } 80 static createCharactersVector(builder, data) { 81 builder.startVector(4, data.length, 4); 82 for (let i = data.length - 1; i >= 0; i--) { 83 builder.addOffset(data[i]); 84 } 85 return builder.endVector(); 86 } 87 static startCharactersVector(builder, numElems) { 88 builder.startVector(4, numElems, 4); 89 } 90 static endMovie(builder) { 91 const offset = builder.endObject(); 92 return offset; 93 } 94 static finishMovieBuffer(builder, offset) { 95 builder.finish(offset, 'MOVI'); 96 } 97 static finishSizePrefixedMovieBuffer(builder, offset) { 98 builder.finish(offset, 'MOVI', true); 99 } 100 static createMovie(builder, mainCharacterType, mainCharacterOffset, charactersTypeOffset, charactersOffset) { 101 Movie.startMovie(builder); 102 Movie.addMainCharacterType(builder, mainCharacterType); 103 Movie.addMainCharacter(builder, mainCharacterOffset); 104 Movie.addCharactersType(builder, charactersTypeOffset); 105 Movie.addCharacters(builder, charactersOffset); 106 return Movie.endMovie(builder); 107 } 108 unpack() { 109 return new MovieT(this.mainCharacterType(), (() => { 110 let temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this)); 111 if (temp === null) { 112 return null; 113 } 114 if (typeof temp === 'string') { 115 return temp; 116 } 117 return temp.unpack(); 118 })(), this.bb.createScalarList(this.charactersType.bind(this), this.charactersTypeLength()), (() => { 119 let ret = []; 120 for (let targetEnumIndex = 0; targetEnumIndex < this.charactersTypeLength(); ++targetEnumIndex) { 121 let targetEnum = this.charactersType(targetEnumIndex); 122 if (targetEnum === null || Character[targetEnum] === 'NONE') { 123 continue; 124 } 125 let temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex); 126 if (temp === null) { 127 continue; 128 } 129 if (typeof temp === 'string') { 130 ret.push(temp); 131 continue; 132 } 133 ret.push(temp.unpack()); 134 } 135 return ret; 136 })()); 137 } 138 unpackTo(_o) { 139 _o.mainCharacterType = this.mainCharacterType(); 140 _o.mainCharacter = (() => { 141 let temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this)); 142 if (temp === null) { 143 return null; 144 } 145 if (typeof temp === 'string') { 146 return temp; 147 } 148 return temp.unpack(); 149 })(); 150 _o.charactersType = this.bb.createScalarList(this.charactersType.bind(this), this.charactersTypeLength()); 151 _o.characters = (() => { 152 let ret = []; 153 for (let targetEnumIndex = 0; targetEnumIndex < this.charactersTypeLength(); ++targetEnumIndex) { 154 let targetEnum = this.charactersType(targetEnumIndex); 155 if (targetEnum === null || Character[targetEnum] === 'NONE') { 156 continue; 157 } 158 let temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex); 159 if (temp === null) { 160 continue; 161 } 162 if (typeof temp === 'string') { 163 ret.push(temp); 164 continue; 165 } 166 ret.push(temp.unpack()); 167 } 168 return ret; 169 })(); 170 } 171} 172export class MovieT { 173 constructor(mainCharacterType = Character.NONE, mainCharacter = null, charactersType = [], characters = []) { 174 this.mainCharacterType = mainCharacterType; 175 this.mainCharacter = mainCharacter; 176 this.charactersType = charactersType; 177 this.characters = characters; 178 } 179 pack(builder) { 180 const mainCharacter = builder.createObjectOffset(this.mainCharacter); 181 const charactersType = Movie.createCharactersTypeVector(builder, this.charactersType); 182 const characters = Movie.createCharactersVector(builder, builder.createObjectOffsetList(this.characters)); 183 return Movie.createMovie(builder, this.mainCharacterType, mainCharacter, charactersType, characters); 184 } 185} 186