* Reads the metadata from a row or a prepared result response * @param {Number} kind * @returns {Object} * @throws {RangeError}
(kind)
| 326 | * @throws {RangeError} |
| 327 | */ |
| 328 | readMetadata(kind) { |
| 329 | let i; |
| 330 | //Determines if its a prepared metadata |
| 331 | const isPrepared = (kind === types.resultKind.prepared); |
| 332 | const meta = {}; |
| 333 | if (types.protocolVersion.supportsResultMetadataId(this.header.version) && isPrepared) { |
| 334 | meta.resultId = utils.copyBuffer(this.readShortBytes()); |
| 335 | } |
| 336 | //as used in Rows and Prepared responses |
| 337 | const flags = this.readInt(); |
| 338 | const columnLength = this.readInt(); |
| 339 | if (types.protocolVersion.supportsPreparedPartitionKey(this.header.version) && isPrepared) { |
| 340 | //read the pk columns |
| 341 | meta.partitionKeys = new Array(this.readInt()); |
| 342 | for (i = 0; i < meta.partitionKeys.length; i++) { |
| 343 | meta.partitionKeys[i] = this.readShort(); |
| 344 | } |
| 345 | } |
| 346 | if (flags & resultFlag.hasMorePages) { |
| 347 | meta.pageState = utils.copyBuffer(this.readBytes()); |
| 348 | } |
| 349 | if (flags & resultFlag.metadataChanged) { |
| 350 | meta.newResultId = utils.copyBuffer(this.readShortBytes()); |
| 351 | } |
| 352 | if (flags & resultFlag.continuousPaging) { |
| 353 | meta.continuousPageIndex = this.readInt(); |
| 354 | meta.lastContinuousPage = !!(flags & resultFlag.lastContinuousPage); |
| 355 | } |
| 356 | if (flags & resultFlag.globalTablesSpec) { |
| 357 | meta.global_tables_spec = true; |
| 358 | meta.keyspace = this.readString(); |
| 359 | meta.table = this.readString(); |
| 360 | } |
| 361 | meta.columns = new Array(columnLength); |
| 362 | meta.columnsByName = utils.emptyObject; |
| 363 | if (isPrepared) { |
| 364 | //for prepared metadata, we will need a index of the columns (param) by name |
| 365 | meta.columnsByName = {}; |
| 366 | } |
| 367 | for (i = 0; i < columnLength; i++) { |
| 368 | const col = {}; |
| 369 | if (!meta.global_tables_spec) { |
| 370 | col.ksname = this.readString(); |
| 371 | col.tablename = this.readString(); |
| 372 | } |
| 373 | col.name = this.readString(); |
| 374 | col.type = this.readType(); |
| 375 | meta.columns[i] = col; |
| 376 | if (isPrepared) { |
| 377 | meta.columnsByName[col.name] = i; |
| 378 | } |
| 379 | } |
| 380 | return meta; |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * Reads the error from the frame |
no test coverage detected