Read and write every copy of a TLV SMPP lets repeat, and drop the dormant tlvMap
Test / lint (pull_request) Successful in 21s
Test / test (18) (pull_request) Successful in 28s
Test / test (20) (pull_request) Successful in 31s
Test / test (22) (pull_request) Successful in 29s
Test / test (24) (pull_request) Successful in 30s
Test / test (26) (pull_request) Successful in 29s
Mirror / push (push) Successful in 6s
Test / lint (pull_request) Successful in 21s
Test / test (18) (pull_request) Successful in 28s
Test / test (20) (pull_request) Successful in 31s
Test / test (22) (pull_request) Successful in 29s
Test / test (24) (pull_request) Successful in 30s
Test / test (26) (pull_request) Successful in 29s
Mirror / push (push) Successful in 6s
This commit is contained in:
+7
-4
@@ -2,7 +2,7 @@ import type { Concat } from './concat.ts';
|
||||
import type { ParamValue } from './defs/types.ts';
|
||||
import type { PduObject } from './pdu.ts';
|
||||
import type { SmppLog } from './log.ts';
|
||||
import type { Tlv } from './defs/tlvs.ts';
|
||||
import type { Tlv, TlvScalar } from './defs/tlvs.ts';
|
||||
import { ExpiringGroups } from './expiring-groups.ts';
|
||||
import { decodeMessage } from './message.ts';
|
||||
import { messageOctets } from './message-body.ts';
|
||||
@@ -52,6 +52,10 @@ type Group = {
|
||||
total: number;
|
||||
};
|
||||
|
||||
function copied(value: TlvScalar): TlvScalar {
|
||||
return Buffer.isBuffer(value) ? Buffer.from(value) : value;
|
||||
}
|
||||
|
||||
/** Wire reads hand back views, so retaining one segment would pin the whole PDU it arrived in. */
|
||||
function detach(pduObj: PduObject): PduObject {
|
||||
const params: Record<string, ParamValue> = {};
|
||||
@@ -62,9 +66,7 @@ function detach(pduObj: PduObject): PduObject {
|
||||
}
|
||||
|
||||
for (const [name, tlv] of Object.entries(pduObj.tlvs)) {
|
||||
tlvs[name] = Buffer.isBuffer(tlv.tagValue)
|
||||
? { ...tlv, tagValue: Buffer.from(tlv.tagValue) }
|
||||
: tlv;
|
||||
tlvs[name] = { ...tlv, tagValue: Array.isArray(tlv.tagValue) ? tlv.tagValue.map(copied) : copied(tlv.tagValue) };
|
||||
}
|
||||
|
||||
// short_message holds the same octets wherever it was not decoded, so one copy covers both.
|
||||
@@ -78,6 +80,7 @@ function detach(pduObj: PduObject): PduObject {
|
||||
// A cstring param arrives as a string, and source_addr alone can carry most of a 1 MiB PDU.
|
||||
function sizeOf(value: unknown): number {
|
||||
if (Buffer.isBuffer(value)) return value.length;
|
||||
if (Array.isArray(value)) return value.reduce<number>((sum, copy) => sum + sizeOf(copy), 0);
|
||||
|
||||
return typeof value === 'string' ? value.length : 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user