tchannel 3.6.14 → 3.6.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/v2/args.js CHANGED
@@ -30,8 +30,6 @@ var errors = require('../errors');
30
30
 
31
31
  var Base = bufrw.Base;
32
32
  var LengthResult = bufrw.LengthResult;
33
- var WriteResult = bufrw.WriteResult;
34
- var ReadResult = bufrw.ReadResult;
35
33
 
36
34
  /* eslint-disable curly */
37
35
 
@@ -44,24 +42,24 @@ function ArgRW(sizerw) {
44
42
 
45
43
  inherits(ArgRW, bufrw.Base);
46
44
 
47
- ArgRW.prototype.byteLength = function byteLength(arg) {
45
+ ArgRW.prototype.poolByteLength = function poolByteLength(destResult, arg) {
48
46
  if (typeof arg === 'string') {
49
- return this.strrw.byteLength(arg);
47
+ return this.strrw.poolByteLength(destResult, arg);
50
48
  } else {
51
- return this.bufrw.byteLength(arg);
49
+ return this.bufrw.poolByteLength(destResult, arg);
52
50
  }
53
51
  };
54
52
 
55
- ArgRW.prototype.writeInto = function writeInto(arg, buffer, offset) {
53
+ ArgRW.prototype.poolWriteInto = function poolWriteInto(destResult, arg, buffer, offset) {
56
54
  if (typeof arg === 'string') {
57
- return this.strrw.writeInto(arg, buffer, offset);
55
+ return this.strrw.poolWriteInto(destResult, arg, buffer, offset);
58
56
  } else {
59
- return this.bufrw.writeInto(arg, buffer, offset);
57
+ return this.bufrw.poolWriteInto(destResult, arg, buffer, offset);
60
58
  }
61
59
  };
62
60
 
63
- ArgRW.prototype.readFrom = function readFrom(buffer, offset) {
64
- return this.bufrw.readFrom(buffer, offset);
61
+ ArgRW.prototype.poolReadFrom = function poolReadFrom(destResult, buffer, offset) {
62
+ return this.bufrw.poolReadFrom(destResult, buffer, offset);
65
63
  };
66
64
 
67
65
  var arg2 = new ArgRW(bufrw.UInt16BE);
@@ -75,50 +73,51 @@ function ArgsRW(argrw) {
75
73
  }
76
74
  inherits(ArgsRW, bufrw.Base);
77
75
 
78
- ArgsRW.prototype.byteLength = function byteLength(body) {
76
+ ArgsRW.prototype.poolByteLength = function poolByteLength(destResult, body) {
79
77
  var length = 0;
80
78
  var res;
81
79
 
82
- res = Checksum.RW.byteLength(body.csum);
80
+ res = Checksum.RW.poolByteLength(destResult, body.csum);
83
81
  if (res.err) return res;
84
82
  length += res.length;
85
83
 
86
84
  if (body.args === null) {
87
- return LengthResult.just(length);
85
+ return destResult.reset(null, length);
88
86
  }
89
87
 
90
88
  if (!Array.isArray(body.args)) {
91
- return LengthResult.error(errors.InvalidArgumentError({
89
+ return destResult.reset(null, errors.InvalidArgumentError({
92
90
  argType: typeof body.args,
93
91
  argConstructor: body.args.constructor.name
94
92
  }));
95
93
  }
96
94
 
97
95
  for (var i = 0; i < body.args.length; i++) {
98
- res = this.argrw.byteLength(body.args[i]);
96
+ res = this.argrw.poolByteLength(destResult, body.args[i]);
99
97
  if (res.err) return res;
100
98
  length += res.length;
101
99
  }
102
100
 
103
- return LengthResult.just(length);
101
+ return destResult.reset(null, length);
104
102
  };
105
103
 
106
- ArgsRW.prototype.writeInto = function writeInto(body, buffer, offset) {
104
+ var lenres = new LengthResult();
105
+ ArgsRW.prototype.poolWriteInto = function poolWriteInto(destResult, body, buffer, offset) {
107
106
  var start = offset;
108
107
  var res;
109
108
 
110
- var lenres = Checksum.RW.byteLength(body.csum);
111
- if (lenres.err) return WriteResult.error(lenres.err);
109
+ lenres = Checksum.RW.poolByteLength(lenres, body.csum);
110
+ if (lenres.err) return destResult.replace(lenres.err);
112
111
  offset += lenres.length;
113
112
 
114
113
  if (body.cont === null) {
115
- res = this.writeFragmentInto(body, buffer, offset);
114
+ res = this.writeFragmentInto(destResult, body, buffer, offset);
116
115
  if (res.err) return res;
117
116
  offset = res.offset;
118
117
  } else {
119
118
  // assume that something else already did the fragmentation correctly
120
119
  for (var i = 0; i < body.args.length; i++) {
121
- res = this.argrw.writeInto(body.args[i], buffer, offset);
120
+ res = this.argrw.poolWriteInto(destResult, body.args[i], buffer, offset);
122
121
  if (res.err) return res;
123
122
  var buf = buffer.slice(offset + this.overhead, res.offset);
124
123
  body.csum.update1(buf, body.csum.val);
@@ -126,34 +125,34 @@ ArgsRW.prototype.writeInto = function writeInto(body, buffer, offset) {
126
125
  }
127
126
  }
128
127
 
129
- res = Checksum.RW.writeInto(body.csum, buffer, start);
128
+ res = Checksum.RW.poolWriteInto(destResult, body.csum, buffer, start);
130
129
  if (!res.err) res.offset = offset;
131
130
 
132
131
  return res;
133
132
  };
134
133
 
135
- ArgsRW.prototype.readFrom = function readFrom(body, buffer, offset) {
134
+ ArgsRW.prototype.poolReadFrom = function poolReadFrom(destResult, body, buffer, offset) {
136
135
  var res;
137
136
 
138
137
  // TODO: missing symmetry: verify csum (requires prior somehow)
139
138
 
140
- res = Checksum.RW.readFrom(buffer, offset);
139
+ res = Checksum.RW.poolReadFrom(destResult, buffer, offset);
141
140
  if (res.err) return res;
142
141
  offset = res.offset;
143
142
  body.csum = res.value;
144
143
 
145
144
  body.args = [];
146
145
  while (offset < buffer.length) {
147
- res = this.argrw.readFrom(buffer, offset);
146
+ res = this.argrw.poolReadFrom(destResult, buffer, offset);
148
147
  if (res.err) return res;
149
148
  offset = res.offset;
150
149
  body.args.push(res.value);
151
150
  }
152
151
 
153
- return ReadResult.just(offset, body);
152
+ return destResult.reset(null, offset, body);
154
153
  };
155
154
 
156
- ArgsRW.prototype.writeFragmentInto = function writeFragmentInto(body, buffer, offset) {
155
+ ArgsRW.prototype.writeFragmentInto = function writeFragmentInto(destResult, body, buffer, offset) {
157
156
  var res;
158
157
  var i = 0;
159
158
  var remain = buffer.length - offset;
@@ -178,7 +177,7 @@ ArgsRW.prototype.writeFragmentInto = function writeFragmentInto(body, buffer, of
178
177
  body.flags |= Flags.Fragment;
179
178
  arg = body.args[i];
180
179
  }
181
- res = this.argrw.writeInto(arg, buffer, offset);
180
+ res = this.argrw.poolWriteInto(destResult, arg, buffer, offset);
182
181
  if (res.err) return res;
183
182
  var buf = buffer.slice(offset + this.overhead, res.offset);
184
183
  body.csum.update1(buf, body.csum.val);
@@ -186,7 +185,7 @@ ArgsRW.prototype.writeFragmentInto = function writeFragmentInto(body, buffer, of
186
185
  remain = buffer.length - offset;
187
186
  } while (remain >= this.overhead && ++i < body.args.length);
188
187
 
189
- return res || WriteResult.just(offset);
188
+ return res || destResult.reset(null, offset);
190
189
  };
191
190
 
192
191
  module.exports = ArgsRW;
package/v2/call.js CHANGED
@@ -37,6 +37,10 @@ var Frame = require('./frame');
37
37
  var CallFlags = require('./call_flags');
38
38
  var argsrw = new ArgsRW();
39
39
 
40
+ var ReadResult = bufrw.ReadResult;
41
+ var WriteResult = bufrw.WriteResult;
42
+ var readRes = new ReadResult(); // shared read result
43
+
40
44
  var CN_VALUE = new Buffer('cn').readUInt16BE(0, false);
41
45
  var RD_VALUE = new Buffer('rd').readUInt16BE(0, false);
42
46
 
@@ -66,6 +70,15 @@ function allNodeToString(buf, start, end) {
66
70
  return buf.toString('utf8', start, end);
67
71
  }
68
72
 
73
+ // Calls a pooled function and conveniently allocates a response object for it
74
+ function allocifyPoolFn(fn, ResultCons) {
75
+ return allocFn;
76
+
77
+ function allocFn(arg1, arg2, arg3) {
78
+ return fn(new ResultCons(), arg1, arg2, arg3);
79
+ }
80
+ }
81
+
69
82
  module.exports.Request = CallRequest;
70
83
  module.exports.Response = CallResponse;
71
84
 
@@ -87,16 +100,18 @@ function CallRequest(flags, ttl, tracing, service, headers, csum, args) {
87
100
 
88
101
  CallRequest.Cont = require('./cont').RequestCont;
89
102
  CallRequest.TypeCode = 0x03;
90
- CallRequest.RW = bufrw.Base(callReqLength, readCallReqFrom, writeCallReqInto);
103
+ CallRequest.RW = bufrw.Base(callReqLength, readCallReqFrom, writeCallReqInto, true);
91
104
 
92
105
  CallRequest.RW.lazy = {};
93
106
 
94
107
  CallRequest.RW.lazy.flagsOffset = Frame.Overhead;
95
- CallRequest.RW.lazy.readFlags = function readFlags(frame) {
108
+ CallRequest.RW.lazy.poolReadFlags = function poolReadFlags(destResult, frame) {
96
109
  // flags:1
97
- return bufrw.UInt8.readFrom(frame.buffer, CallRequest.RW.lazy.flagsOffset);
110
+ return bufrw.UInt8.poolReadFrom(destResult, frame.buffer, CallRequest.RW.lazy.flagsOffset);
98
111
  };
99
112
 
113
+ CallRequest.RW.lazy.readFlags = allocifyPoolFn(CallRequest.RW.lazy.poolReadFlags, ReadResult);
114
+
100
115
  CallRequest.RW.lazy.ttlOffset = CallRequest.RW.lazy.flagsOffset + 1;
101
116
  CallRequest.RW.lazy.readTTL = function readTTL(frame) {
102
117
  if (frame.cache.ttlValue !== null) {
@@ -113,24 +128,30 @@ CallRequest.RW.lazy.readTTL = function readTTL(frame) {
113
128
 
114
129
  return ttl;
115
130
  };
116
- CallRequest.RW.lazy.writeTTL = function writeTTL(ttl, frame) {
131
+ CallRequest.RW.lazy.poolWriteTTL = function poolWriteTTL(destResult, ttl, frame) {
117
132
  // ttl:4
118
- return bufrw.UInt32BE.writeInto(ttl, frame.buffer, CallRequest.RW.lazy.ttlOffset);
133
+ return bufrw.UInt32BE.poolWriteInto(destResult, ttl, frame.buffer, CallRequest.RW.lazy.ttlOffset);
119
134
  };
120
135
 
136
+ CallRequest.RW.lazy.writeTTL = allocifyPoolFn(CallRequest.RW.lazy.poolWriteTTL, WriteResult);
137
+
121
138
  CallRequest.RW.lazy.tracingOffset = CallRequest.RW.lazy.ttlOffset + 4;
122
- CallRequest.RW.lazy.readTracing = function lazyReadTracing(frame) {
139
+ CallRequest.RW.lazy.poolReadTracing = function poolLazyReadTracing(destResult, frame) {
123
140
  // tracing:24 traceflags:1
124
- return Tracing.RW.readFrom(frame.buffer, CallRequest.RW.lazy.tracingOffset);
141
+ return Tracing.RW.poolReadFrom(destResult, frame.buffer, CallRequest.RW.lazy.tracingOffset);
125
142
  };
126
143
 
144
+ CallRequest.RW.lazy.readTracing = allocifyPoolFn(CallRequest.RW.lazy.poolReadTracing, ReadResult);
145
+
127
146
  CallRequest.RW.lazy.serviceOffset = CallRequest.RW.lazy.tracingOffset + 25;
128
- CallRequest.RW.lazy.readService = function lazyReadService(frame) {
147
+ CallRequest.RW.lazy.poolReadService = function poolLazyReadService(destResult, frame) {
129
148
  // service~1
130
- return bufrw.str1.readFrom(frame.buffer, CallRequest.RW.lazy.serviceOffset);
149
+ return bufrw.str1.poolReadFrom(destResult, frame.buffer, CallRequest.RW.lazy.serviceOffset);
131
150
  };
132
151
 
133
- CallRequest.RW.lazy.readTracingValue = function readTracingValue(frame) {
152
+ CallRequest.RW.lazy.readService = allocifyPoolFn(CallRequest.RW.lazy.poolReadService, ReadResult);
153
+
154
+ CallRequest.RW.lazy.poolReadTracingValue = function poolReadTracingValue(destResult, frame) {
134
155
  if (frame.cache.tracingValue !== null) {
135
156
  return frame.cache.tracingValue;
136
157
  }
@@ -162,6 +183,7 @@ CallRequest.RW.lazy.readTracingValue = function readTracingValue(frame) {
162
183
  var flags = frame.buffer.readUInt8(offset, false);
163
184
  offset += 1;
164
185
 
186
+ // TODO: pool these objects
165
187
  var tracing = new TracingInfo(
166
188
  [spanid1, spanid2],
167
189
  [parentid1, parentid2],
@@ -174,6 +196,8 @@ CallRequest.RW.lazy.readTracingValue = function readTracingValue(frame) {
174
196
  return tracing;
175
197
  };
176
198
 
199
+ CallRequest.RW.lazy.readTracingValue = allocifyPoolFn(CallRequest.RW.lazy.poolReadTracingValue, ReadResult);
200
+
177
201
  function TracingInfo(spanid, parentid, traceid, flags) {
178
202
  this.spanid = spanid;
179
203
  this.parentid = parentid;
@@ -399,7 +423,7 @@ CallRequest.RW.lazy.readArg1Str = function readArg1Str(frame) {
399
423
  return arg1Str;
400
424
  };
401
425
 
402
- CallRequest.RW.lazy.readHeaders = function readHeaders(frame) {
426
+ CallRequest.RW.lazy.poolReadHeaders = function poolReadHeaders(destResult, frame) {
403
427
  // last fixed offset
404
428
  var offset = CallRequest.RW.lazy.serviceOffset;
405
429
 
@@ -407,7 +431,7 @@ CallRequest.RW.lazy.readHeaders = function readHeaders(frame) {
407
431
  offset = frame.cache.headerStartOffset;
408
432
  } else {
409
433
  // SKIP service~1
410
- var res = bufrw.str1.sizerw.readFrom(frame.buffer, offset);
434
+ var res = bufrw.str1.sizerw.poolReadFrom(destResult, frame.buffer, offset);
411
435
  if (res.err) {
412
436
  return res;
413
437
  }
@@ -416,10 +440,12 @@ CallRequest.RW.lazy.readHeaders = function readHeaders(frame) {
416
440
  }
417
441
 
418
442
  // READ nh:1 (hk~1 hv~1){nh}
419
- return header.header1.lazyRead(frame, offset);
443
+ return header.header1.poolLazyRead(destResult, frame, offset);
420
444
  };
421
445
 
422
- CallRequest.RW.lazy.readArg1 = function readArg1(frame, headers) {
446
+ CallRequest.RW.lazy.readHeaders = allocifyPoolFn(CallRequest.RW.lazy.poolReadHeaders, ReadResult);
447
+
448
+ CallRequest.RW.lazy.poolReadArg1 = function poolReadArg1(destResult, frame, headers) {
423
449
  var res = null;
424
450
  var offset = 0;
425
451
 
@@ -433,14 +459,14 @@ CallRequest.RW.lazy.readArg1 = function readArg1(frame, headers) {
433
459
  offset = CallRequest.RW.lazy.serviceOffset;
434
460
 
435
461
  // SKIP service~1
436
- res = bufrw.str1.sizerw.readFrom(frame.buffer, offset);
462
+ res = bufrw.str1.sizerw.poolReadFrom(destResult, frame.buffer, offset);
437
463
  if (res.err) {
438
464
  return res;
439
465
  }
440
466
  offset = res.offset + res.value;
441
467
 
442
468
  // SKIP nh:1 (hk~1 hv~1){nh}
443
- res = header.header1.lazySkip(frame, offset);
469
+ res = header.header1.poolLazySkip(destResult, frame, offset);
444
470
  if (res.err) {
445
471
  return res;
446
472
  }
@@ -448,23 +474,25 @@ CallRequest.RW.lazy.readArg1 = function readArg1(frame, headers) {
448
474
  }
449
475
 
450
476
  // SKIP csumtype:1 (csum:4){0,1}
451
- res = Checksum.RW.lazySkip(frame, offset);
477
+ res = Checksum.RW.poolLazySkip(destResult, frame, offset);
452
478
  if (res.err) {
453
479
  return res;
454
480
  }
455
481
  offset = res.offset;
456
482
 
457
483
  // READ arg~2
458
- return argsrw.argrw.readFrom(frame.buffer, offset);
484
+ return argsrw.argrw.poolReadFrom(destResult, frame.buffer, offset);
459
485
  };
460
486
 
487
+ CallRequest.RW.lazy.readArg1 = allocifyPoolFn(CallRequest.RW.lazy.poolReadArg1, ReadResult);
488
+
461
489
  CallRequest.RW.lazy.isFrameTerminal = function isFrameTerminal(frame) {
462
- var flags = CallRequest.RW.lazy.readFlags(frame);
490
+ var flags = CallRequest.RW.lazy.poolReadFlags(readRes, frame);
463
491
  var frag = flags.value & CallFlags.Fragment;
464
492
  return !frag;
465
493
  };
466
494
 
467
- function callReqLength(body) {
495
+ function callReqLength(destResult, body) {
468
496
  var res;
469
497
  var length = 0;
470
498
 
@@ -475,43 +503,43 @@ function callReqLength(body) {
475
503
  length += bufrw.UInt32BE.width;
476
504
 
477
505
  // tracing:24 traceflags:1
478
- res = Tracing.RW.byteLength(body.tracing);
506
+ res = Tracing.RW.poolByteLength(destResult, body.tracing);
479
507
  if (res.err) return res;
480
508
  length += res.length;
481
509
 
482
510
  // service~1
483
- res = bufrw.str1.byteLength(body.service);
511
+ res = bufrw.str1.poolByteLength(destResult, body.service);
484
512
  if (res.err) return res;
485
513
  length += res.length;
486
514
 
487
515
  // nh:1 (hk~1 hv~1){nh}
488
- res = header.header1.byteLength(body.headers);
516
+ res = header.header1.poolByteLength(destResult, body.headers);
489
517
  if (res.err) return res;
490
518
  length += res.length;
491
519
 
492
520
  // csumtype:1 (csum:4){0,1} (arg~2)*
493
- res = argsrw.byteLength(body);
521
+ res = argsrw.poolByteLength(destResult, body);
494
522
  if (!res.err) res.length += length;
495
523
 
496
524
  return res;
497
525
  }
498
526
 
499
- function readCallReqFrom(buffer, offset) {
527
+ function readCallReqFrom(destResult, buffer, offset) {
500
528
  var res;
501
529
  var body = new CallRequest();
502
530
 
503
531
  // flags:1
504
- res = bufrw.UInt8.readFrom(buffer, offset);
532
+ res = bufrw.UInt8.poolReadFrom(destResult, buffer, offset);
505
533
  if (res.err) return res;
506
534
  offset = res.offset;
507
535
  body.flags = res.value;
508
536
 
509
537
  // ttl:4
510
- res = bufrw.UInt32BE.readFrom(buffer, offset);
538
+ res = bufrw.UInt32BE.poolReadFrom(destResult, buffer, offset);
511
539
  if (res.err) return res;
512
540
 
513
541
  if (res.value <= 0) {
514
- return bufrw.ReadResult.error(errors.InvalidTTL({
542
+ return destResult.reset(errors.InvalidTTL({
515
543
  ttl: res.value,
516
544
  isParseError: true
517
545
  }), offset, body);
@@ -521,31 +549,31 @@ function readCallReqFrom(buffer, offset) {
521
549
  body.ttl = res.value;
522
550
 
523
551
  // tracing:24 traceflags:1
524
- res = Tracing.RW.readFrom(buffer, offset);
552
+ res = Tracing.RW.poolReadFrom(destResult, buffer, offset);
525
553
  if (res.err) return res;
526
554
  offset = res.offset;
527
555
  body.tracing = res.value;
528
556
 
529
557
  // service~1
530
- res = bufrw.str1.readFrom(buffer, offset);
558
+ res = bufrw.str1.poolReadFrom(destResult, buffer, offset);
531
559
  if (res.err) return res;
532
560
  offset = res.offset;
533
561
  body.service = res.value;
534
562
 
535
563
  // nh:1 (hk~1 hv~1){nh}
536
- res = header.header1.readFrom(buffer, offset);
564
+ res = header.header1.poolReadFrom(destResult, buffer, offset);
537
565
  if (res.err) return res;
538
566
  offset = res.offset;
539
567
  body.headers = res.value;
540
568
 
541
569
  // csumtype:1 (csum:4){0,1} (arg~2)*
542
- res = argsrw.readFrom(body, buffer, offset);
570
+ res = argsrw.poolReadFrom(destResult, body, buffer, offset);
543
571
  if (!res.err) res.value = body;
544
572
 
545
573
  return res;
546
574
  }
547
575
 
548
- function writeCallReqInto(body, buffer, offset) {
576
+ function writeCallReqInto(destResult, body, buffer, offset) {
549
577
  var start = offset;
550
578
  var res;
551
579
 
@@ -553,38 +581,38 @@ function writeCallReqInto(body, buffer, offset) {
553
581
  offset += bufrw.UInt8.width;
554
582
 
555
583
  if (body.ttl <= 0) {
556
- return bufrw.WriteResult.error(errors.InvalidTTL({
584
+ return destResult.reset(errors.InvalidTTL({
557
585
  ttl: body.ttl
558
586
  }), offset);
559
587
  }
560
588
 
561
589
  // ttl:4
562
- res = bufrw.UInt32BE.writeInto(body.ttl, buffer, offset);
590
+ res = bufrw.UInt32BE.poolWriteInto(destResult, body.ttl, buffer, offset);
563
591
  if (res.err) return res;
564
592
  offset = res.offset;
565
593
 
566
594
  // tracing:24 traceflags:1
567
- res = Tracing.RW.writeInto(body.tracing, buffer, offset);
595
+ res = Tracing.RW.poolWriteInto(destResult, body.tracing, buffer, offset);
568
596
  if (res.err) return res;
569
597
  offset = res.offset;
570
598
 
571
599
  // service~1
572
- res = bufrw.str1.writeInto(body.service, buffer, offset);
600
+ res = bufrw.str1.poolWriteInto(destResult, body.service, buffer, offset);
573
601
  if (res.err) return res;
574
602
  offset = res.offset;
575
603
 
576
604
  // nh:1 (hk~1 hv~1){nh}
577
- res = header.header1.writeInto(body.headers, buffer, offset);
605
+ res = header.header1.poolWriteInto(destResult, body.headers, buffer, offset);
578
606
  if (res.err) return res;
579
607
  offset = res.offset;
580
608
 
581
609
  // csumtype:1 (csum:4){0,1} (arg~2)* -- (may mutate body.flags)
582
- res = argsrw.writeInto(body, buffer, offset);
610
+ res = argsrw.poolWriteInto(destResult, body, buffer, offset);
583
611
  if (res.err) return res;
584
612
  offset = res.offset;
585
613
 
586
614
  // now we know the final flags, write them
587
- res = bufrw.UInt8.writeInto(body.flags, buffer, start);
615
+ res = bufrw.UInt8.poolWriteInto(destResult, body.flags, buffer, start);
588
616
  if (!res.err) res.offset = offset;
589
617
 
590
618
  return res;
@@ -609,28 +637,36 @@ function CallResponse(flags, code, tracing, headers, csum, args) {
609
637
  CallResponse.Cont = require('./cont').ResponseCont;
610
638
  CallResponse.TypeCode = 0x04;
611
639
  CallResponse.Codes = ResponseCodes;
612
- CallResponse.RW = bufrw.Base(callResLength, readCallResFrom, writeCallResInto);
640
+ CallResponse.RW = bufrw.Base(callResLength, readCallResFrom, writeCallResInto, true);
613
641
 
614
642
  CallResponse.RW.lazy = {};
615
643
 
616
644
  CallResponse.RW.lazy.flagsOffset = Frame.Overhead;
617
- CallResponse.RW.lazy.readFlags = function readFlags(frame) {
645
+ CallResponse.RW.lazy.poolReadFlags = function poolReadFlags(destResult, frame) {
618
646
  // flags:1
619
- return bufrw.UInt8.readFrom(frame.buffer, CallResponse.RW.lazy.flagsOffset);
647
+ return bufrw.UInt8.poolReadFrom(destResult, frame.buffer, CallResponse.RW.lazy.flagsOffset);
620
648
  };
621
649
 
650
+ CallResponse.RW.lazy.readFlags = allocifyPoolFn(CallResponse.RW.lazy.poolReadFlags, ReadResult);
651
+
622
652
  CallResponse.RW.lazy.codeOffset = CallResponse.RW.lazy.flagsOffset + 1;
653
+ CallResponse.RW.lazy.poolReadCode = function poolReadCode(destResult, frame) {
654
+ // code:1
655
+ return bufrw.UInt8.poolReadFrom(destResult, frame.buffer, CallResponse.RW.lazy.codeOffset);
656
+ };
623
657
  // TODO: readCode?
624
658
 
625
659
  CallResponse.RW.lazy.tracingOffset = CallResponse.RW.lazy.codeOffset + 1;
626
- CallResponse.RW.lazy.readTracing = function lazyReadTracing(frame) {
660
+ CallResponse.RW.lazy.poolReadTracing = function poolLazyReadTracing(destResult, frame) {
627
661
  // tracing:24 traceflags:1
628
- return Tracing.RW.readFrom(frame.buffer, CallResponse.RW.lazy.tracingOffset);
662
+ return Tracing.RW.poolReadFrom(destResult, frame.buffer, CallResponse.RW.lazy.tracingOffset);
629
663
  };
630
664
 
665
+ CallResponse.RW.lazy.readTracing = allocifyPoolFn(CallResponse.RW.lazy.poolReadTracing, ReadResult);
666
+
631
667
  CallResponse.RW.lazy.headersOffset = CallResponse.RW.lazy.tracingOffset + 25;
632
668
 
633
- CallResponse.RW.lazy.readHeaders = function readHeaders(frame) {
669
+ CallResponse.RW.lazy.poolReadHeaders = function poolReadHeaders(destResult, frame) {
634
670
  // last fixed offset
635
671
  var offset = CallResponse.RW.lazy.headersOffset;
636
672
 
@@ -638,10 +674,12 @@ CallResponse.RW.lazy.readHeaders = function readHeaders(frame) {
638
674
  // and any others
639
675
 
640
676
  // READ nh:1 (hk~1 hv~1){nh}
641
- return header.header1.lazyRead(frame, offset);
677
+ return header.header1.poolLazyRead(destResult, frame, offset);
642
678
  };
643
679
 
644
- CallResponse.RW.lazy.readArg1 = function readArg1(frame, headers) {
680
+ CallResponse.RW.lazy.readHeaders = allocifyPoolFn(CallResponse.RW.lazy.readHeaders, ReadResult);
681
+
682
+ CallResponse.RW.lazy.poolReadArg1 = function poolReadArg1(destResult, frame, headers) {
645
683
  var res = null;
646
684
  var offset = 0;
647
685
 
@@ -655,7 +693,7 @@ CallResponse.RW.lazy.readArg1 = function readArg1(frame, headers) {
655
693
  // and any others
656
694
 
657
695
  // SKIP nh:1 (hk~1 hv~1){nh}
658
- res = header.header1.lazySkip(frame, offset);
696
+ res = header.header1.poolLazySkip(destResult, frame, offset);
659
697
  if (res.err) {
660
698
  return res;
661
699
  }
@@ -663,23 +701,25 @@ CallResponse.RW.lazy.readArg1 = function readArg1(frame, headers) {
663
701
  }
664
702
 
665
703
  // SKIP csumtype:1 (csum:4){0,1}
666
- res = Checksum.RW.lazySkip(frame, offset);
704
+ res = Checksum.RW.poolLazySkip(destResult, frame, offset);
667
705
  if (res.err) {
668
706
  return res;
669
707
  }
670
708
  offset = res.offset;
671
709
 
672
710
  // READ arg~2
673
- return argsrw.argrw.readFrom(frame.buffer, offset);
711
+ return argsrw.argrw.poolReadFrom(destResult, frame.buffer, offset);
674
712
  };
675
713
 
714
+ CallResponse.RW.lazy.readArg1 = allocifyPoolFn(CallResponse.RW.lazy.readarg1, ReadResult);
715
+
676
716
  CallResponse.RW.lazy.isFrameTerminal = function isFrameTerminal(frame) {
677
- var flags = CallResponse.RW.lazy.readFlags(frame);
717
+ var flags = CallResponse.RW.lazy.poolReadFlags(readRes, frame);
678
718
  var frag = flags.value & CallFlags.Fragment;
679
719
  return !frag;
680
720
  };
681
721
 
682
- function callResLength(body) {
722
+ function callResLength(destResult, body) {
683
723
  var res;
684
724
  var length = 0;
685
725
 
@@ -689,58 +729,58 @@ function callResLength(body) {
689
729
  length += bufrw.UInt8.width;
690
730
 
691
731
  // tracing:24 traceflags:1
692
- res = Tracing.RW.byteLength(body.tracing);
732
+ res = Tracing.RW.poolByteLength(destResult, body.tracing);
693
733
  if (res.err) return res;
694
734
  length += res.length;
695
735
 
696
736
  // nh:1 (hk~1 hv~1){nh}
697
- res = header.header1.byteLength(body.headers);
737
+ res = header.header1.poolByteLength(destResult, body.headers);
698
738
  if (res.err) return res;
699
739
  length += res.length;
700
740
 
701
741
  // csumtype:1 (csum:4){0,1} (arg~2)*
702
- res = argsrw.byteLength(body);
742
+ res = argsrw.poolByteLength(destResult, body);
703
743
  if (!res.err) res.length += length;
704
744
 
705
745
  return res;
706
746
  }
707
747
 
708
- function readCallResFrom(buffer, offset) {
748
+ function readCallResFrom(destResult, buffer, offset) {
709
749
  var res;
710
750
  var body = new CallResponse();
711
751
 
712
752
  // flags:1
713
- res = bufrw.UInt8.readFrom(buffer, offset);
753
+ res = bufrw.UInt8.poolReadFrom(destResult, buffer, offset);
714
754
  if (res.err) return res;
715
755
  offset = res.offset;
716
756
  body.flags = res.value;
717
757
 
718
758
  // code:1
719
- res = bufrw.UInt8.readFrom(buffer, offset);
759
+ res = bufrw.UInt8.poolReadFrom(destResult, buffer, offset);
720
760
  if (res.err) return res;
721
761
  offset = res.offset;
722
762
  body.code = res.value;
723
763
 
724
764
  // tracing:24 traceflags:1
725
- res = Tracing.RW.readFrom(buffer, offset);
765
+ res = Tracing.RW.poolReadFrom(destResult, buffer, offset);
726
766
  if (res.err) return res;
727
767
  offset = res.offset;
728
768
  body.tracing = res.value;
729
769
 
730
770
  // nh:1 (hk~1 hv~1){nh}
731
- res = header.header1.readFrom(buffer, offset);
771
+ res = header.header1.poolReadFrom(destResult, buffer, offset);
732
772
  if (res.err) return res;
733
773
  offset = res.offset;
734
774
  body.headers = res.value;
735
775
 
736
776
  // csumtype:1 (csum:4){0,1} (arg~2)*
737
- res = argsrw.readFrom(body, buffer, offset);
777
+ res = argsrw.poolReadFrom(destResult, body, buffer, offset);
738
778
  if (!res.err) res.value = body;
739
779
 
740
780
  return res;
741
781
  }
742
782
 
743
- function writeCallResInto(body, buffer, offset) {
783
+ function writeCallResInto(destResult, body, buffer, offset) {
744
784
  var start = offset;
745
785
  var res;
746
786
 
@@ -748,27 +788,27 @@ function writeCallResInto(body, buffer, offset) {
748
788
  offset += bufrw.UInt8.width;
749
789
 
750
790
  // code:1
751
- res = bufrw.UInt8.writeInto(body.code, buffer, offset);
791
+ res = bufrw.UInt8.poolWriteInto(destResult, body.code, buffer, offset);
752
792
  if (res.err) return res;
753
793
  offset = res.offset;
754
794
 
755
795
  // tracing:24 traceflags:1
756
- res = Tracing.RW.writeInto(body.tracing, buffer, offset);
796
+ res = Tracing.RW.poolWriteInto(destResult, body.tracing, buffer, offset);
757
797
  if (res.err) return res;
758
798
  offset = res.offset;
759
799
 
760
800
  // nh:1 (hk~1 hv~1){nh}
761
- res = header.header1.writeInto(body.headers, buffer, offset);
801
+ res = header.header1.poolWriteInto(destResult, body.headers, buffer, offset);
762
802
  if (res.err) return res;
763
803
  offset = res.offset;
764
804
 
765
805
  // csumtype:1 (csum:4){0,1} (arg~2)* -- (may mutate body.flags)
766
- res = argsrw.writeInto(body, buffer, offset);
806
+ res = argsrw.poolWriteInto(destResult, body, buffer, offset);
767
807
  if (res.err) return res;
768
808
  offset = res.offset;
769
809
 
770
810
  // now we know the final flags, write them
771
- res = bufrw.UInt8.writeInto(body.flags, buffer, start);
811
+ res = bufrw.UInt8.poolWriteInto(destResult, body.flags, buffer, start);
772
812
  if (!res.err) res.offset = offset;
773
813
 
774
814
  return res;