MCPcopy Index your code
hub / github.com/nodejs/node / convertProtocols

Function convertProtocols

lib/tls.js:252–272  ·  view source on GitHub ↗
(protocols)

Source from the content-addressed store, hash-verified

250// Convert protocols array into valid OpenSSL protocols list
251// ("\x06spdy/2\x08http/1.1\x08http/1.0")
252function convertProtocols(protocols) {
253 const lens = new Array(protocols.length);
254 const buff = Buffer.allocUnsafe(protocols.reduce((p, c, i) => {
255 const len = Buffer.byteLength(c);
256 if (len > 255) {
257 throw new ERR_OUT_OF_RANGE('The byte length of the protocol at index ' +
258 `${i} exceeds the maximum length.`, '<= 255', len, true);
259 }
260 lens[i] = len;
261 return p + 1 + len;
262 }, 0));
263
264 let offset = 0;
265 for (let i = 0, c = protocols.length; i < c; i++) {
266 buff[offset++] = lens[i];
267 buff.write(protocols[i], offset);
268 offset += lens[i];
269 }
270
271 return buff;
272}
273
274exports.convertALPNProtocols = function convertALPNProtocols(protocols, out) {
275 // If protocols is Array - translate it into buffer

Callers 1

tls.jsFile · 0.85

Calls 2

reduceMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…