UNPKG

postgrejs

Version:

Professional PostgreSQL client NodeJS

39 lines (38 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.decodeBinaryArray = decodeBinaryArray; const buffer_reader_js_1 = require("../protocol/buffer-reader.js"); function decodeBinaryArray(buf, decoder, options = {}) { if (!buf.length) return null; const io = new buffer_reader_js_1.BufferReader(buf); const ndims = io.readInt32BE(); io.readInt32BE(); // hasNulls const elementOID = io.readInt32BE(); // element oid if (ndims === 0) return []; const dims = []; const readDim = (level) => { const elemCount = dims[level]; const target = new Array(elemCount); for (let i = 0; i < elemCount; i++) { if (level < dims.length - 1) { target[i] = readDim(level + 1); continue; } const len = io.readInt32BE(); if (len === -1) target[i] = null; else { const b = io.readBuffer(len); target[i] = decoder(b, { ...options, elementOID }); } } return target; }; for (let d = 0; d < ndims; d++) { dims[d] = io.readInt32BE(); io.readInt32BE(); // LBound } return readDim(0); }