Skip to content

Commit 26d08c8

Browse files
Bas950porsager
authored andcommitted
feat: use ; as a delimiter for _box
1 parent 62a23bb commit 26d08c8

File tree

6 files changed

+42
-30
lines changed

6 files changed

+42
-30
lines changed

cjs/src/connection.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,9 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
738738
if (!!options.parsers[typarray] && !!options.serializers[typarray]) return;
739739
const parser = options.parsers[oid]
740740
options.shared.typeArrayMap[oid] = typarray
741-
options.parsers[typarray] = (xs) => arrayParser(xs, parser)
741+
options.parsers[typarray] = (xs) => arrayParser(xs, parser, typarray)
742742
options.parsers[typarray].array = true
743-
options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid], options)
743+
options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid], options, typarray)
744744
}
745745

746746
function tryNext(x, xs) {

cjs/src/types.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,19 @@ function arrayEscape(x) {
235235
.replace(escapeQuote, '\\"')
236236
}
237237

238-
const arraySerializer = module.exports.arraySerializer = function arraySerializer(xs, serializer, options) {
238+
const arraySerializer = module.exports.arraySerializer = function arraySerializer(xs, serializer, options, typarray) {
239239
if (Array.isArray(xs) === false)
240240
return xs
241241

242242
if (!xs.length)
243243
return '{}'
244244

245245
const first = xs[0]
246+
// Only _box (1020) has the ';' delimiter for arrays, all other types use the ',' delimiter
247+
const delimiter = typarray === 1020 ? ';' : ','
246248

247249
if (Array.isArray(first) && !first.type)
248-
return '{' + xs.map(x => arraySerializer(x, serializer)).join(',') + '}'
250+
return '{' + xs.map(x => arraySerializer(x, serializer, options, typarray)).join(delimiter) + '}'
249251

250252
return '{' + xs.map(x => {
251253
if (x === undefined) {
@@ -257,7 +259,7 @@ const arraySerializer = module.exports.arraySerializer = function arraySerialize
257259
return x === null
258260
? 'null'
259261
: '"' + arrayEscape(serializer ? serializer(x.type ? x.value : x) : '' + x) + '"'
260-
}).join(',') + '}'
262+
}).join(delimiter) + '}'
261263
}
262264

263265
const arrayParserState = {
@@ -268,13 +270,15 @@ const arrayParserState = {
268270
last: 0
269271
}
270272

271-
const arrayParser = module.exports.arrayParser = function arrayParser(x, parser) {
273+
const arrayParser = module.exports.arrayParser = function arrayParser(x, parser, typarray) {
272274
arrayParserState.i = arrayParserState.last = 0
273-
return arrayParserLoop(arrayParserState, x, parser)
275+
return arrayParserLoop(arrayParserState, x, parser, typarray)
274276
}
275277

276-
function arrayParserLoop(s, x, parser) {
278+
function arrayParserLoop(s, x, parser, typarray) {
277279
const xs = []
280+
// Only _box (1020) has the ';' delimiter for arrays, all other types use the ',' delimiter
281+
const delimiter = typarray === 1020 ? ';' : ','
278282
for (; s.i < x.length; s.i++) {
279283
s.char = x[s.i]
280284
if (s.quoted) {
@@ -292,13 +296,13 @@ function arrayParserLoop(s, x, parser) {
292296
s.quoted = true
293297
} else if (s.char === '{') {
294298
s.last = ++s.i
295-
xs.push(arrayParserLoop(s, x, parser))
299+
xs.push(arrayParserLoop(s, x, parser, typarray))
296300
} else if (s.char === '}') {
297301
s.quoted = false
298302
s.last < s.i && xs.push(parser ? parser(x.slice(s.last, s.i)) : x.slice(s.last, s.i))
299303
s.last = s.i + 1
300304
break
301-
} else if (s.char === ',' && s.p !== '}' && s.p !== '"') {
305+
} else if (s.char === delimiter && s.p !== '}' && s.p !== '"') {
302306
xs.push(parser ? parser(x.slice(s.last, s.i)) : x.slice(s.last, s.i))
303307
s.last = s.i + 1
304308
}

deno/src/connection.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -742,9 +742,9 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
742742
if (!!options.parsers[typarray] && !!options.serializers[typarray]) return;
743743
const parser = options.parsers[oid]
744744
options.shared.typeArrayMap[oid] = typarray
745-
options.parsers[typarray] = (xs) => arrayParser(xs, parser)
745+
options.parsers[typarray] = (xs) => arrayParser(xs, parser, typarray)
746746
options.parsers[typarray].array = true
747-
options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid], options)
747+
options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid], options, typarray)
748748
}
749749

750750
function tryNext(x, xs) {

deno/src/types.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,19 @@ function arrayEscape(x) {
236236
.replace(escapeQuote, '\\"')
237237
}
238238

239-
export const arraySerializer = function arraySerializer(xs, serializer, options) {
239+
export const arraySerializer = function arraySerializer(xs, serializer, options, typarray) {
240240
if (Array.isArray(xs) === false)
241241
return xs
242242

243243
if (!xs.length)
244244
return '{}'
245245

246246
const first = xs[0]
247+
// Only _box (1020) has the ';' delimiter for arrays, all other types use the ',' delimiter
248+
const delimiter = typarray === 1020 ? ';' : ','
247249

248250
if (Array.isArray(first) && !first.type)
249-
return '{' + xs.map(x => arraySerializer(x, serializer)).join(',') + '}'
251+
return '{' + xs.map(x => arraySerializer(x, serializer, options, typarray)).join(delimiter) + '}'
250252

251253
return '{' + xs.map(x => {
252254
if (x === undefined) {
@@ -258,7 +260,7 @@ export const arraySerializer = function arraySerializer(xs, serializer, options)
258260
return x === null
259261
? 'null'
260262
: '"' + arrayEscape(serializer ? serializer(x.type ? x.value : x) : '' + x) + '"'
261-
}).join(',') + '}'
263+
}).join(delimiter) + '}'
262264
}
263265

264266
const arrayParserState = {
@@ -269,13 +271,15 @@ const arrayParserState = {
269271
last: 0
270272
}
271273

272-
export const arrayParser = function arrayParser(x, parser) {
274+
export const arrayParser = function arrayParser(x, parser, typarray) {
273275
arrayParserState.i = arrayParserState.last = 0
274-
return arrayParserLoop(arrayParserState, x, parser)
276+
return arrayParserLoop(arrayParserState, x, parser, typarray)
275277
}
276278

277-
function arrayParserLoop(s, x, parser) {
279+
function arrayParserLoop(s, x, parser, typarray) {
278280
const xs = []
281+
// Only _box (1020) has the ';' delimiter for arrays, all other types use the ',' delimiter
282+
const delimiter = typarray === 1020 ? ';' : ','
279283
for (; s.i < x.length; s.i++) {
280284
s.char = x[s.i]
281285
if (s.quoted) {
@@ -293,13 +297,13 @@ function arrayParserLoop(s, x, parser) {
293297
s.quoted = true
294298
} else if (s.char === '{') {
295299
s.last = ++s.i
296-
xs.push(arrayParserLoop(s, x, parser))
300+
xs.push(arrayParserLoop(s, x, parser, typarray))
297301
} else if (s.char === '}') {
298302
s.quoted = false
299303
s.last < s.i && xs.push(parser ? parser(x.slice(s.last, s.i)) : x.slice(s.last, s.i))
300304
s.last = s.i + 1
301305
break
302-
} else if (s.char === ',' && s.p !== '}' && s.p !== '"') {
306+
} else if (s.char === delimiter && s.p !== '}' && s.p !== '"') {
303307
xs.push(parser ? parser(x.slice(s.last, s.i)) : x.slice(s.last, s.i))
304308
s.last = s.i + 1
305309
}

src/connection.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,9 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
739739
if (!!options.parsers[typarray] && !!options.serializers[typarray]) return;
740740
const parser = options.parsers[oid]
741741
options.shared.typeArrayMap[oid] = typarray
742-
options.parsers[typarray] = (xs) => arrayParser(xs, parser)
742+
options.parsers[typarray] = (xs) => arrayParser(xs, parser, typarray)
743743
options.parsers[typarray].array = true
744-
options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid], options)
744+
options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid], options, typarray)
745745
}
746746

747747
function tryNext(x, xs) {

src/types.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,19 @@ function arrayEscape(x) {
235235
.replace(escapeQuote, '\\"')
236236
}
237237

238-
export const arraySerializer = function arraySerializer(xs, serializer, options) {
238+
export const arraySerializer = function arraySerializer(xs, serializer, options, typarray) {
239239
if (Array.isArray(xs) === false)
240240
return xs
241241

242242
if (!xs.length)
243243
return '{}'
244244

245245
const first = xs[0]
246+
// Only _box (1020) has the ';' delimiter for arrays, all other types use the ',' delimiter
247+
const delimiter = typarray === 1020 ? ';' : ','
246248

247249
if (Array.isArray(first) && !first.type)
248-
return '{' + xs.map(x => arraySerializer(x, serializer)).join(',') + '}'
250+
return '{' + xs.map(x => arraySerializer(x, serializer, options, typarray)).join(delimiter) + '}'
249251

250252
return '{' + xs.map(x => {
251253
if (x === undefined) {
@@ -257,7 +259,7 @@ export const arraySerializer = function arraySerializer(xs, serializer, options)
257259
return x === null
258260
? 'null'
259261
: '"' + arrayEscape(serializer ? serializer(x.type ? x.value : x) : '' + x) + '"'
260-
}).join(',') + '}'
262+
}).join(delimiter) + '}'
261263
}
262264

263265
const arrayParserState = {
@@ -268,13 +270,15 @@ const arrayParserState = {
268270
last: 0
269271
}
270272

271-
export const arrayParser = function arrayParser(x, parser) {
273+
export const arrayParser = function arrayParser(x, parser, typarray) {
272274
arrayParserState.i = arrayParserState.last = 0
273-
return arrayParserLoop(arrayParserState, x, parser)
275+
return arrayParserLoop(arrayParserState, x, parser, typarray)
274276
}
275277

276-
function arrayParserLoop(s, x, parser) {
278+
function arrayParserLoop(s, x, parser, typarray) {
277279
const xs = []
280+
// Only _box (1020) has the ';' delimiter for arrays, all other types use the ',' delimiter
281+
const delimiter = typarray === 1020 ? ';' : ','
278282
for (; s.i < x.length; s.i++) {
279283
s.char = x[s.i]
280284
if (s.quoted) {
@@ -292,13 +296,13 @@ function arrayParserLoop(s, x, parser) {
292296
s.quoted = true
293297
} else if (s.char === '{') {
294298
s.last = ++s.i
295-
xs.push(arrayParserLoop(s, x, parser))
299+
xs.push(arrayParserLoop(s, x, parser, typarray))
296300
} else if (s.char === '}') {
297301
s.quoted = false
298302
s.last < s.i && xs.push(parser ? parser(x.slice(s.last, s.i)) : x.slice(s.last, s.i))
299303
s.last = s.i + 1
300304
break
301-
} else if (s.char === ',' && s.p !== '}' && s.p !== '"') {
305+
} else if (s.char === delimiter && s.p !== '}' && s.p !== '"') {
302306
xs.push(parser ? parser(x.slice(s.last, s.i)) : x.slice(s.last, s.i))
303307
s.last = s.i + 1
304308
}

0 commit comments

Comments
 (0)