Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 define("mojo/public/js/codec", [ | 5 define("mojo/public/js/codec", [ |
| 6 "mojo/public/js/buffer", | 6 "mojo/public/js/buffer", |
| 7 "mojo/public/js/interface_types", | 7 "mojo/public/js/interface_types", |
| 8 "mojo/public/js/lib/interface_endpoint_handle", | 8 "mojo/public/js/lib/interface_endpoint_handle", |
| 9 "mojo/public/js/unicode", | 9 "mojo/public/js/unicode", |
| 10 ], function(buffer, types, interfaceEndpointHandle, unicode) { | 10 ], function(buffer, types, interfaceEndpointHandle, unicode) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 var kMessageV2HeaderSize = 48; | 36 var kMessageV2HeaderSize = 48; |
| 37 var kMapStructPayloadSize = 16; | 37 var kMapStructPayloadSize = 16; |
| 38 | 38 |
| 39 var kStructHeaderNumBytesOffset = 0; | 39 var kStructHeaderNumBytesOffset = 0; |
| 40 var kStructHeaderVersionOffset = 4; | 40 var kStructHeaderVersionOffset = 4; |
| 41 | 41 |
| 42 var kEncodedInvalidHandleValue = 0xFFFFFFFF; | 42 var kEncodedInvalidHandleValue = 0xFFFFFFFF; |
| 43 | 43 |
| 44 // Decoder ------------------------------------------------------------------ | 44 // Decoder ------------------------------------------------------------------ |
| 45 | 45 |
| 46 function Decoder(buffer, handles, base) { | 46 function Decoder(buffer, handles, base, associatedEndpointHandles) { |
|
yzshen1
2017/04/19 21:11:34
nit: it may make sense to re-order the parameters
wangjimmy
2017/04/20 15:36:44
Done.
| |
| 47 this.buffer = buffer; | 47 this.buffer = buffer; |
| 48 this.handles = handles; | 48 this.handles = handles; |
| 49 this.associatedEndpointHandles = associatedEndpointHandles; | |
| 49 this.base = base; | 50 this.base = base; |
| 50 this.next = base; | 51 this.next = base; |
| 51 } | 52 } |
| 52 | 53 |
| 53 Decoder.prototype.align = function() { | 54 Decoder.prototype.align = function() { |
| 54 this.next = align(this.next); | 55 this.next = align(this.next); |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 Decoder.prototype.skip = function(offset) { | 58 Decoder.prototype.skip = function(offset) { |
| 58 this.next += offset; | 59 this.next += offset; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 // TODO(abarth): To correctly decode a pointer, we need to know the real | 123 // TODO(abarth): To correctly decode a pointer, we need to know the real |
| 123 // base address of the array buffer. | 124 // base address of the array buffer. |
| 124 var offsetPointer = this.next; | 125 var offsetPointer = this.next; |
| 125 var offset = this.readUint64(); | 126 var offset = this.readUint64(); |
| 126 if (!offset) | 127 if (!offset) |
| 127 return 0; | 128 return 0; |
| 128 return offsetPointer + offset; | 129 return offsetPointer + offset; |
| 129 }; | 130 }; |
| 130 | 131 |
| 131 Decoder.prototype.decodeAndCreateDecoder = function(pointer) { | 132 Decoder.prototype.decodeAndCreateDecoder = function(pointer) { |
| 132 return new Decoder(this.buffer, this.handles, pointer); | 133 return new Decoder(this.buffer, this.handles, pointer, |
| 134 this.associatedEndpointHandles); | |
| 133 }; | 135 }; |
| 134 | 136 |
| 135 Decoder.prototype.decodeHandle = function() { | 137 Decoder.prototype.decodeHandle = function() { |
| 136 return this.handles[this.readUint32()] || null; | 138 return this.handles[this.readUint32()] || null; |
| 137 }; | 139 }; |
| 138 | 140 |
| 141 Decoder.prototype.decodeAssociatedEndpointHandle = function() { | |
| 142 if (this.associatedEndpointHandles) { | |
|
yzshen1
2017/04/19 21:11:34
Under what circumstances decodeAssociatedEndpointH
wangjimmy
2017/04/20 15:36:43
Yes. Before a new Decoder could be created without
| |
| 143 var index = this.readUint32(); | |
| 144 return this.associatedEndpointHandles[index] || null; | |
| 145 } | |
| 146 return null; | |
| 147 }; | |
| 148 | |
| 139 Decoder.prototype.decodeString = function() { | 149 Decoder.prototype.decodeString = function() { |
| 140 var numberOfBytes = this.readUint32(); | 150 var numberOfBytes = this.readUint32(); |
| 141 var numberOfElements = this.readUint32(); | 151 var numberOfElements = this.readUint32(); |
| 142 var base = this.next; | 152 var base = this.next; |
| 143 this.next += numberOfElements; | 153 this.next += numberOfElements; |
| 144 return unicode.decodeUtf8String( | 154 return unicode.decodeUtf8String( |
| 145 new Uint8Array(this.buffer.arrayBuffer, base, numberOfElements)); | 155 new Uint8Array(this.buffer.arrayBuffer, base, numberOfElements)); |
| 146 }; | 156 }; |
| 147 | 157 |
| 148 Decoder.prototype.decodeArray = function(cls) { | 158 Decoder.prototype.decodeArray = function(cls) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 var pointer = this.decodePointer(); | 217 var pointer = this.decodePointer(); |
| 208 if (!pointer) { | 218 if (!pointer) { |
| 209 return null; | 219 return null; |
| 210 } | 220 } |
| 211 var decoder = this.decodeAndCreateDecoder(pointer); | 221 var decoder = this.decodeAndCreateDecoder(pointer); |
| 212 return decoder.decodeMap(keyClass, valueClass); | 222 return decoder.decodeMap(keyClass, valueClass); |
| 213 }; | 223 }; |
| 214 | 224 |
| 215 // Encoder ------------------------------------------------------------------ | 225 // Encoder ------------------------------------------------------------------ |
| 216 | 226 |
| 217 function Encoder(buffer, handles, base) { | 227 function Encoder(buffer, handles, base, associatedEndpointHandles) { |
|
yzshen1
2017/04/19 21:11:34
nit: it may make sense to re-order the parameters
wangjimmy
2017/04/20 15:36:43
Done.
| |
| 218 this.buffer = buffer; | 228 this.buffer = buffer; |
| 219 this.handles = handles; | 229 this.handles = handles; |
| 230 this.associatedEndpointHandles = associatedEndpointHandles; | |
| 220 this.base = base; | 231 this.base = base; |
| 221 this.next = base; | 232 this.next = base; |
| 222 } | 233 } |
| 223 | 234 |
| 224 Encoder.prototype.align = function() { | 235 Encoder.prototype.align = function() { |
| 225 this.next = align(this.next); | 236 this.next = align(this.next); |
| 226 }; | 237 }; |
| 227 | 238 |
| 228 Encoder.prototype.skip = function(offset) { | 239 Encoder.prototype.skip = function(offset) { |
| 229 this.next += offset; | 240 this.next += offset; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 return this.writeUint64(0); | 307 return this.writeUint64(0); |
| 297 // TODO(abarth): To correctly encode a pointer, we need to know the real | 308 // TODO(abarth): To correctly encode a pointer, we need to know the real |
| 298 // base address of the array buffer. | 309 // base address of the array buffer. |
| 299 var offset = pointer - this.next; | 310 var offset = pointer - this.next; |
| 300 this.writeUint64(offset); | 311 this.writeUint64(offset); |
| 301 }; | 312 }; |
| 302 | 313 |
| 303 Encoder.prototype.createAndEncodeEncoder = function(size) { | 314 Encoder.prototype.createAndEncodeEncoder = function(size) { |
| 304 var pointer = this.buffer.alloc(align(size)); | 315 var pointer = this.buffer.alloc(align(size)); |
| 305 this.encodePointer(pointer); | 316 this.encodePointer(pointer); |
| 306 return new Encoder(this.buffer, this.handles, pointer); | 317 return new Encoder(this.buffer, this.handles, pointer, |
| 318 this.associatedEndpointHandles); | |
| 307 }; | 319 }; |
| 308 | 320 |
| 309 Encoder.prototype.encodeHandle = function(handle) { | 321 Encoder.prototype.encodeHandle = function(handle) { |
| 310 if (handle) { | 322 if (handle) { |
| 311 this.handles.push(handle); | 323 this.handles.push(handle); |
| 312 this.writeUint32(this.handles.length - 1); | 324 this.writeUint32(this.handles.length - 1); |
| 313 } else { | 325 } else { |
| 314 this.writeUint32(kEncodedInvalidHandleValue); | 326 this.writeUint32(kEncodedInvalidHandleValue); |
| 315 } | 327 } |
| 316 }; | 328 }; |
| 317 | 329 |
| 330 Encoder.prototype.encodeAssociatedEndpointHandle = function(endpointHandle) { | |
| 331 if (this.associatedEndpointHandles && endpointHandle) { | |
|
yzshen1
2017/04/19 21:11:34
Under what circumstances we would want to encode a
wangjimmy
2017/04/20 15:36:43
Removed. It shouldn't happen. I had a check becaus
| |
| 332 this.associatedEndpointHandles.push(endpointHandle); | |
| 333 this.writeUint32(this.associatedEndpointHandles.length - 1); | |
| 334 } else { | |
| 335 this.writeUint32(kEncodedInvalidHandleValue); | |
| 336 } | |
| 337 }; | |
| 338 | |
| 318 Encoder.prototype.encodeString = function(val) { | 339 Encoder.prototype.encodeString = function(val) { |
| 319 var base = this.next + kArrayHeaderSize; | 340 var base = this.next + kArrayHeaderSize; |
| 320 var numberOfElements = unicode.encodeUtf8String( | 341 var numberOfElements = unicode.encodeUtf8String( |
| 321 val, new Uint8Array(this.buffer.arrayBuffer, base)); | 342 val, new Uint8Array(this.buffer.arrayBuffer, base)); |
| 322 var numberOfBytes = kArrayHeaderSize + numberOfElements; | 343 var numberOfBytes = kArrayHeaderSize + numberOfElements; |
| 323 this.writeUint32(numberOfBytes); | 344 this.writeUint32(numberOfBytes); |
| 324 this.writeUint32(numberOfElements); | 345 this.writeUint32(numberOfElements); |
| 325 this.next += numberOfElements; | 346 this.next += numberOfElements; |
| 326 }; | 347 }; |
| 327 | 348 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 | 450 |
| 430 var kMessageInterfaceIdOffset = kStructHeaderSize; | 451 var kMessageInterfaceIdOffset = kStructHeaderSize; |
| 431 var kMessageNameOffset = kMessageInterfaceIdOffset + 4; | 452 var kMessageNameOffset = kMessageInterfaceIdOffset + 4; |
| 432 var kMessageFlagsOffset = kMessageNameOffset + 4; | 453 var kMessageFlagsOffset = kMessageNameOffset + 4; |
| 433 var kMessageRequestIDOffset = kMessageFlagsOffset + 8; | 454 var kMessageRequestIDOffset = kMessageFlagsOffset + 8; |
| 434 var kMessagePayloadInterfaceIdsPointerOffset = kMessageV2HeaderSize - 8; | 455 var kMessagePayloadInterfaceIdsPointerOffset = kMessageV2HeaderSize - 8; |
| 435 | 456 |
| 436 var kMessageExpectsResponse = 1 << 0; | 457 var kMessageExpectsResponse = 1 << 0; |
| 437 var kMessageIsResponse = 1 << 1; | 458 var kMessageIsResponse = 1 << 1; |
| 438 | 459 |
| 439 function Message(buffer, handles) { | 460 function Message(buffer, handles, associatedEndpointHandles) { |
| 461 if (associatedEndpointHandles === undefined) { | |
| 462 associatedEndpointHandles = []; | |
| 463 } | |
| 464 | |
| 440 this.buffer = buffer; | 465 this.buffer = buffer; |
| 441 this.handles = handles; | 466 this.handles = handles; |
| 467 this.associatedEndpointHandles = associatedEndpointHandles; | |
| 442 } | 468 } |
| 443 | 469 |
| 444 Message.prototype.getHeaderNumBytes = function() { | 470 Message.prototype.getHeaderNumBytes = function() { |
| 445 return this.buffer.getUint32(kStructHeaderNumBytesOffset); | 471 return this.buffer.getUint32(kStructHeaderNumBytesOffset); |
| 446 }; | 472 }; |
| 447 | 473 |
| 448 Message.prototype.getHeaderVersion = function() { | 474 Message.prototype.getHeaderVersion = function() { |
| 449 return this.buffer.getUint32(kStructHeaderVersionOffset); | 475 return this.buffer.getUint32(kStructHeaderVersionOffset); |
| 450 }; | 476 }; |
| 451 | 477 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 482 | 508 |
| 483 Message.prototype.setRequestID = function(requestID) { | 509 Message.prototype.setRequestID = function(requestID) { |
| 484 // TODO(darin): Verify that space was reserved for this field! | 510 // TODO(darin): Verify that space was reserved for this field! |
| 485 this.buffer.setUint64(kMessageRequestIDOffset, requestID); | 511 this.buffer.setUint64(kMessageRequestIDOffset, requestID); |
| 486 }; | 512 }; |
| 487 | 513 |
| 488 Message.prototype.setInterfaceId = function(interfaceId) { | 514 Message.prototype.setInterfaceId = function(interfaceId) { |
| 489 this.buffer.setUint32(kMessageInterfaceIdOffset, interfaceId); | 515 this.buffer.setUint32(kMessageInterfaceIdOffset, interfaceId); |
| 490 }; | 516 }; |
| 491 | 517 |
| 518 Message.prototype.setPayloadInterfaceIds = function(payloadInterfaceIds) { | |
|
yzshen1
2017/04/19 21:11:34
Is this supposed to be a private method? If yes pl
wangjimmy
2017/04/20 15:36:43
Done.
| |
| 519 if (this.getHeaderVersion() < 2) { | |
| 520 throw new Error( | |
| 521 "Version of message does not support payload interface ids."); | |
| 522 } | |
| 523 | |
| 524 var decoder = new Decoder(this.buffer, this.handles, | |
| 525 kMessageV2HeaderSize-8); | |
|
yzshen1
2017/04/19 21:11:34
I thought you have defined a constant for this off
wangjimmy
2017/04/20 15:36:43
Done. Used it in new patch. Thanks for the catch.
| |
| 526 var payloadInterfaceIdsOffset = decoder.decodePointer(); | |
| 527 var encoder = new Encoder(this.buffer, this.handles, | |
| 528 payloadInterfaceIdsOffset); | |
| 529 encoder.encodeArray(Uint32, payloadInterfaceIds); | |
| 530 }; | |
| 531 | |
| 532 Message.prototype.serializeAssociatedEndpointHandles = function( | |
| 533 associatedGroupController) { | |
| 534 if (this.associatedEndpointHandles.length > 0) { | |
| 535 if (this.getHeaderVersion() < 2) { | |
| 536 throw new Error(); | |
|
yzshen1
2017/04/19 21:11:34
Please give a description.
wangjimmy
2017/04/20 15:36:43
Done.
| |
| 537 } | |
| 538 | |
| 539 var data = []; | |
| 540 for (var i = 0; i < this.associatedEndpointHandles.length; i++) { | |
| 541 var handle = this.associatedEndpointHandles[i]; | |
| 542 data.push(associatedGroupController.associateInterface(handle)); | |
| 543 } | |
| 544 this.associatedEndpointHandles = []; | |
| 545 this.setPayloadInterfaceIds(data); | |
| 546 } | |
| 547 }; | |
| 548 | |
| 549 Message.prototype.deserializeAssociatedEndpointHandles = function( | |
| 550 associatedGroupController) { | |
| 551 if (this.getHeaderVersion() < 2) { | |
| 552 return true; | |
| 553 } | |
| 554 | |
| 555 this.associatedEndpointHandles = []; | |
| 556 var ids = this.getPayloadInterfaceIds(); | |
| 557 | |
| 558 var result = true; | |
| 559 for (var i = 0; i < ids.length; i++) { | |
| 560 var handle = associatedGroupController.createLocalEndpointHandle(ids[i]); | |
| 561 if (types.isValidInterfaceId(ids[i]) && !handle.isValid()) { | |
| 562 // |ids[i]| itself is valid but handle creation failed. In that case, | |
| 563 // mark deserialization as failed but continue to deserialize the | |
| 564 // rest of handles. | |
| 565 result = false; | |
| 566 } | |
| 567 this.associatedEndpointHandles.push(handle); | |
| 568 ids[i] = types.kInvalidInterfaceId; | |
| 569 } | |
| 570 | |
| 571 this.setPayloadInterfaceIds(ids); | |
| 572 return result; | |
| 573 }; | |
| 574 | |
| 492 | 575 |
| 493 // MessageBuilder ----------------------------------------------------------- | 576 // MessageBuilder ----------------------------------------------------------- |
| 494 | 577 |
| 495 function MessageBuilder(messageName, payloadSize) { | 578 function MessageBuilder(messageName, payloadSize) { |
| 496 // Currently, we don't compute the payload size correctly ahead of time. | 579 // Currently, we don't compute the payload size correctly ahead of time. |
| 497 // Instead, we resize the buffer at the end. | 580 // Instead, we resize the buffer at the end. |
| 498 var numberOfBytes = kMessageV0HeaderSize + payloadSize; | 581 var numberOfBytes = kMessageV0HeaderSize + payloadSize; |
| 499 this.buffer = new buffer.Buffer(numberOfBytes); | 582 this.buffer = new buffer.Buffer(numberOfBytes); |
| 500 this.handles = []; | 583 this.handles = []; |
| 501 var encoder = this.createEncoder(kMessageV0HeaderSize); | 584 var encoder = this.createEncoder(kMessageV0HeaderSize); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 522 this.buffer.trim(); | 605 this.buffer.trim(); |
| 523 var message = new Message(this.buffer, this.handles); | 606 var message = new Message(this.buffer, this.handles); |
| 524 this.buffer = null; | 607 this.buffer = null; |
| 525 this.handles = null; | 608 this.handles = null; |
| 526 this.encoder = null; | 609 this.encoder = null; |
| 527 return message; | 610 return message; |
| 528 }; | 611 }; |
| 529 | 612 |
| 530 // MessageWithRequestIDBuilder ----------------------------------------------- | 613 // MessageWithRequestIDBuilder ----------------------------------------------- |
| 531 | 614 |
| 532 function MessageWithRequestIDBuilder(messageName, payloadSize, flags, | 615 function MessageWithRequestIDBuilder(messageName, payloadSize, flags, |
|
yzshen1
2017/04/19 21:11:34
Please change this to MessageV1Builder. (And the o
wangjimmy
2017/04/20 15:36:43
Done.
| |
| 533 requestID) { | 616 requestID) { |
| 534 // Currently, we don't compute the payload size correctly ahead of time. | 617 // Currently, we don't compute the payload size correctly ahead of time. |
| 535 // Instead, we resize the buffer at the end. | 618 // Instead, we resize the buffer at the end. |
| 536 var numberOfBytes = kMessageV1HeaderSize + payloadSize; | 619 var numberOfBytes = kMessageV1HeaderSize + payloadSize; |
| 537 this.buffer = new buffer.Buffer(numberOfBytes); | 620 this.buffer = new buffer.Buffer(numberOfBytes); |
| 538 this.handles = []; | 621 this.handles = []; |
| 539 var encoder = this.createEncoder(kMessageV1HeaderSize); | 622 var encoder = this.createEncoder(kMessageV1HeaderSize); |
| 540 encoder.writeUint32(kMessageV1HeaderSize); | 623 encoder.writeUint32(kMessageV1HeaderSize); |
| 541 encoder.writeUint32(1); // version. | 624 encoder.writeUint32(1); // version. |
| 542 encoder.writeUint32(0); // interface ID. | 625 encoder.writeUint32(0); // interface ID. |
| 543 encoder.writeUint32(messageName); | 626 encoder.writeUint32(messageName); |
| 544 encoder.writeUint32(flags); | 627 encoder.writeUint32(flags); |
| 545 encoder.writeUint32(0); // padding. | 628 encoder.writeUint32(0); // padding. |
| 546 encoder.writeUint64(requestID); | 629 encoder.writeUint64(requestID); |
| 547 } | 630 } |
| 548 | 631 |
| 549 MessageWithRequestIDBuilder.prototype = | 632 MessageWithRequestIDBuilder.prototype = |
| 550 Object.create(MessageBuilder.prototype); | 633 Object.create(MessageBuilder.prototype); |
| 551 | 634 |
| 552 MessageWithRequestIDBuilder.prototype.constructor = | 635 MessageWithRequestIDBuilder.prototype.constructor = |
| 553 MessageWithRequestIDBuilder; | 636 MessageWithRequestIDBuilder; |
| 554 | 637 |
| 638 // MessageV2 ----------------------------------------------- | |
| 639 | |
| 640 function MessageV2Builder(messageName, payloadSize, flags, requestID) { | |
| 641 // Currently, we don't compute the payload size correctly ahead of time. | |
| 642 // Instead, we resize the buffer at the end. | |
| 643 var numberOfBytes = kMessageV2HeaderSize + payloadSize; | |
| 644 this.buffer = new buffer.Buffer(numberOfBytes); | |
| 645 this.handles = []; | |
| 646 | |
| 647 this.payload = null; | |
| 648 this.associatedEndpointHandles = []; | |
| 649 | |
| 650 this.encoder = this.createEncoder(kMessageV2HeaderSize); | |
| 651 this.encoder.writeUint32(kMessageV2HeaderSize); | |
| 652 this.encoder.writeUint32(2); // version. | |
| 653 // Gets set to an appropriate interfaceId for the endpoint by the IEC. | |
|
yzshen1
2017/04/19 21:11:34
Please change IEC to the full name.
wangjimmy
2017/04/20 15:36:43
Done.
| |
| 654 this.encoder.writeUint32(0); // interface ID.. | |
|
yzshen1
2017/04/19 21:11:34
Please remove a redundant '.'
wangjimmy
2017/04/20 15:36:43
Done.
| |
| 655 this.encoder.writeUint32(messageName); | |
| 656 this.encoder.writeUint32(flags); | |
| 657 this.encoder.writeUint32(0); // padding. | |
| 658 this.encoder.writeUint64(requestID); | |
| 659 } | |
| 660 | |
| 661 MessageV2Builder.prototype.createEncoder = function(size) { | |
| 662 var pointer = this.buffer.alloc(size); | |
| 663 return new Encoder(this.buffer, this.handles, pointer, | |
| 664 this.associatedEndpointHandles); | |
| 665 }; | |
| 666 | |
| 667 MessageV2Builder.prototype.setPayload = function(cls, val) { | |
| 668 this.payload = {cls: cls, val: val}; | |
| 669 }; | |
| 670 | |
| 671 MessageV2Builder.prototype.finish = function() { | |
| 672 if (!this.payload) { | |
| 673 throw new Error(); | |
|
yzshen1
2017/04/19 21:11:34
Please add a description.
wangjimmy
2017/04/20 15:36:43
Done.
| |
| 674 } | |
| 675 | |
| 676 this.encoder.encodeStructPointer(this.payload.cls, this.payload.val); | |
| 677 this.encoder.encodeArrayPointer(Uint32, | |
| 678 new Array(this.associatedEndpointHandles.length)); | |
| 679 | |
| 680 this.buffer.trim(); | |
| 681 var message = new Message(this.buffer, this.handles, | |
| 682 this.associatedEndpointHandles); | |
| 683 this.buffer = null; | |
| 684 this.handles = null; | |
| 685 this.encoder = null; | |
| 686 this.payload = null; | |
| 687 this.associatedEndpointHandles = null; | |
| 688 | |
| 689 return message; | |
| 690 }; | |
| 691 | |
| 555 // MessageReader ------------------------------------------------------------ | 692 // MessageReader ------------------------------------------------------------ |
| 556 | 693 |
| 557 function MessageReader(message) { | 694 function MessageReader(message) { |
| 558 this.decoder = new Decoder(message.buffer, message.handles, 0); | 695 this.decoder = new Decoder(message.buffer, message.handles, 0, |
| 696 message.associatedEndpointHandles); | |
| 559 var messageHeaderSize = this.decoder.readUint32(); | 697 var messageHeaderSize = this.decoder.readUint32(); |
| 560 this.payloadSize = message.buffer.byteLength - messageHeaderSize; | 698 this.payloadSize = message.buffer.byteLength - messageHeaderSize; |
| 561 var version = this.decoder.readUint32(); | 699 var version = this.decoder.readUint32(); |
| 562 var interface_id = this.decoder.readUint32(); | 700 var interface_id = this.decoder.readUint32(); |
| 563 this.messageName = this.decoder.readUint32(); | 701 this.messageName = this.decoder.readUint32(); |
| 564 this.flags = this.decoder.readUint32(); | 702 this.flags = this.decoder.readUint32(); |
| 565 // Skip the padding. | 703 // Skip the padding. |
| 566 this.decoder.skip(4); | 704 this.decoder.skip(4); |
| 567 if (version >= 1) | 705 if (version >= 1) |
| 568 this.requestID = this.decoder.readUint64(); | 706 this.requestID = this.decoder.readUint64(); |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 851 Interface.call(this, cls); | 989 Interface.call(this, cls); |
| 852 } | 990 } |
| 853 | 991 |
| 854 NullableInterface.prototype = Object.create(Interface.prototype); | 992 NullableInterface.prototype = Object.create(Interface.prototype); |
| 855 | 993 |
| 856 function AssociatedInterfacePtrInfo() { | 994 function AssociatedInterfacePtrInfo() { |
| 857 } | 995 } |
| 858 | 996 |
| 859 AssociatedInterfacePtrInfo.prototype.encodedSize = 8; | 997 AssociatedInterfacePtrInfo.prototype.encodedSize = 8; |
| 860 | 998 |
| 999 AssociatedInterfacePtrInfo.decode = function(decoder) { | |
| 1000 return new types.AssociatedInterfacePtrInfo( | |
| 1001 decoder.decodeAssociatedEndpointHandle(), decoder.readUint32()); | |
| 1002 }; | |
| 1003 | |
| 1004 AssociatedInterfacePtrInfo.encode = function(encoder, val) { | |
| 1005 var associatedinterfacePtrInfo = | |
| 1006 val ? val : new types.AssociatedInterfacePtrInfo(null, 0); | |
| 1007 encoder.encodeAssociatedEndpointHandle( | |
| 1008 associatedinterfacePtrInfo.interfaceEndpointHandle); | |
| 1009 encoder.writeUint32(associatedinterfacePtrInfo.version); | |
| 1010 }; | |
| 1011 | |
| 861 function NullableAssociatedInterfacePtrInfo() { | 1012 function NullableAssociatedInterfacePtrInfo() { |
| 862 } | 1013 } |
| 863 | 1014 |
| 864 NullableAssociatedInterfacePtrInfo.encodedSize = | 1015 NullableAssociatedInterfacePtrInfo.encodedSize = |
| 865 AssociatedInterfacePtrInfo.encodedSize; | 1016 AssociatedInterfacePtrInfo.encodedSize; |
| 866 | 1017 |
| 1018 NullableAssociatedInterfacePtrInfo.decode = | |
| 1019 AssociatedInterfacePtrInfo.decode; | |
| 1020 | |
| 1021 NullableAssociatedInterfacePtrInfo.encode = | |
| 1022 AssociatedInterfacePtrInfo.encode; | |
| 1023 | |
| 867 function InterfaceRequest() { | 1024 function InterfaceRequest() { |
| 868 } | 1025 } |
| 869 | 1026 |
| 870 InterfaceRequest.encodedSize = 4; | 1027 InterfaceRequest.encodedSize = 4; |
| 871 | 1028 |
| 872 InterfaceRequest.decode = function(decoder) { | 1029 InterfaceRequest.decode = function(decoder) { |
| 873 return new types.InterfaceRequest(decoder.decodeHandle()); | 1030 return new types.InterfaceRequest(decoder.decodeHandle()); |
| 874 }; | 1031 }; |
| 875 | 1032 |
| 876 InterfaceRequest.encode = function(encoder, val) { | 1033 InterfaceRequest.encode = function(encoder, val) { |
| 877 encoder.encodeHandle(val ? val.handle : null); | 1034 encoder.encodeHandle(val ? val.handle : null); |
| 878 }; | 1035 }; |
| 879 | 1036 |
| 880 function NullableInterfaceRequest() { | 1037 function NullableInterfaceRequest() { |
| 881 } | 1038 } |
| 882 | 1039 |
| 883 NullableInterfaceRequest.encodedSize = InterfaceRequest.encodedSize; | 1040 NullableInterfaceRequest.encodedSize = InterfaceRequest.encodedSize; |
| 884 | 1041 |
| 885 NullableInterfaceRequest.decode = InterfaceRequest.decode; | 1042 NullableInterfaceRequest.decode = InterfaceRequest.decode; |
| 886 | 1043 |
| 887 NullableInterfaceRequest.encode = InterfaceRequest.encode; | 1044 NullableInterfaceRequest.encode = InterfaceRequest.encode; |
| 888 | 1045 |
| 889 function AssociatedInterfaceRequest() { | 1046 function AssociatedInterfaceRequest() { |
| 890 } | 1047 } |
| 891 | 1048 |
| 1049 AssociatedInterfaceRequest.decode = function(decoder) { | |
| 1050 var handle = decoder.decodeAssociatedEndpointHandle(); | |
| 1051 return new types.AssociatedInterfaceRequest(handle); | |
| 1052 }; | |
| 1053 | |
| 1054 AssociatedInterfaceRequest.encode = function(encoder, val) { | |
| 1055 encoder.encodeAssociatedEndpointHandle( | |
| 1056 val ? val.interfaceEndpointHandle : null); | |
| 1057 }; | |
| 1058 | |
| 892 AssociatedInterfaceRequest.encodedSize = 4; | 1059 AssociatedInterfaceRequest.encodedSize = 4; |
| 893 | 1060 |
| 894 function NullableAssociatedInterfaceRequest() { | 1061 function NullableAssociatedInterfaceRequest() { |
| 895 } | 1062 } |
| 896 | 1063 |
| 897 NullableAssociatedInterfaceRequest.encodedSize = | 1064 NullableAssociatedInterfaceRequest.encodedSize = |
| 898 AssociatedInterfaceRequest.encodedSize; | 1065 AssociatedInterfaceRequest.encodedSize; |
| 899 | 1066 |
| 1067 NullableAssociatedInterfaceRequest.decode = | |
| 1068 AssociatedInterfaceRequest.decode; | |
| 1069 | |
| 1070 NullableAssociatedInterfaceRequest.encode = | |
| 1071 AssociatedInterfaceRequest.encode; | |
| 1072 | |
| 900 function MapOf(keyClass, valueClass) { | 1073 function MapOf(keyClass, valueClass) { |
| 901 this.keyClass = keyClass; | 1074 this.keyClass = keyClass; |
| 902 this.valueClass = valueClass; | 1075 this.valueClass = valueClass; |
| 903 } | 1076 } |
| 904 | 1077 |
| 905 MapOf.prototype.encodedSize = 8; | 1078 MapOf.prototype.encodedSize = 8; |
| 906 | 1079 |
| 907 MapOf.prototype.decode = function(decoder) { | 1080 MapOf.prototype.decode = function(decoder) { |
| 908 return decoder.decodeMapPointer(this.keyClass, this.valueClass); | 1081 return decoder.decodeMapPointer(this.keyClass, this.valueClass); |
| 909 }; | 1082 }; |
| 910 | 1083 |
| 911 MapOf.prototype.encode = function(encoder, val) { | 1084 MapOf.prototype.encode = function(encoder, val) { |
| 912 encoder.encodeMapPointer(this.keyClass, this.valueClass, val); | 1085 encoder.encodeMapPointer(this.keyClass, this.valueClass, val); |
| 913 }; | 1086 }; |
| 914 | 1087 |
| 915 function NullableMapOf(keyClass, valueClass) { | 1088 function NullableMapOf(keyClass, valueClass) { |
| 916 MapOf.call(this, keyClass, valueClass); | 1089 MapOf.call(this, keyClass, valueClass); |
| 917 } | 1090 } |
| 918 | 1091 |
| 919 NullableMapOf.prototype = Object.create(MapOf.prototype); | 1092 NullableMapOf.prototype = Object.create(MapOf.prototype); |
| 920 | 1093 |
| 921 var exports = {}; | 1094 var exports = {}; |
| 922 exports.align = align; | 1095 exports.align = align; |
| 923 exports.isAligned = isAligned; | 1096 exports.isAligned = isAligned; |
| 924 exports.Message = Message; | 1097 exports.Message = Message; |
| 925 exports.MessageBuilder = MessageBuilder; | 1098 exports.MessageBuilder = MessageBuilder; |
| 1099 exports.MessageV2Builder = MessageV2Builder; | |
| 926 exports.MessageWithRequestIDBuilder = MessageWithRequestIDBuilder; | 1100 exports.MessageWithRequestIDBuilder = MessageWithRequestIDBuilder; |
| 927 exports.MessageReader = MessageReader; | 1101 exports.MessageReader = MessageReader; |
| 928 exports.kArrayHeaderSize = kArrayHeaderSize; | 1102 exports.kArrayHeaderSize = kArrayHeaderSize; |
| 929 exports.kMapStructPayloadSize = kMapStructPayloadSize; | 1103 exports.kMapStructPayloadSize = kMapStructPayloadSize; |
| 930 exports.kStructHeaderSize = kStructHeaderSize; | 1104 exports.kStructHeaderSize = kStructHeaderSize; |
| 931 exports.kEncodedInvalidHandleValue = kEncodedInvalidHandleValue; | 1105 exports.kEncodedInvalidHandleValue = kEncodedInvalidHandleValue; |
| 932 exports.kMessageV0HeaderSize = kMessageV0HeaderSize; | 1106 exports.kMessageV0HeaderSize = kMessageV0HeaderSize; |
| 933 exports.kMessageV1HeaderSize = kMessageV1HeaderSize; | 1107 exports.kMessageV1HeaderSize = kMessageV1HeaderSize; |
| 934 exports.kMessageV2HeaderSize = kMessageV2HeaderSize; | 1108 exports.kMessageV2HeaderSize = kMessageV2HeaderSize; |
| 935 exports.kMessagePayloadInterfaceIdsPointerOffset = | 1109 exports.kMessagePayloadInterfaceIdsPointerOffset = |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 963 exports.AssociatedInterfacePtrInfo = AssociatedInterfacePtrInfo; | 1137 exports.AssociatedInterfacePtrInfo = AssociatedInterfacePtrInfo; |
| 964 exports.NullableAssociatedInterfacePtrInfo = | 1138 exports.NullableAssociatedInterfacePtrInfo = |
| 965 NullableAssociatedInterfacePtrInfo; | 1139 NullableAssociatedInterfacePtrInfo; |
| 966 exports.AssociatedInterfaceRequest = AssociatedInterfaceRequest; | 1140 exports.AssociatedInterfaceRequest = AssociatedInterfaceRequest; |
| 967 exports.NullableAssociatedInterfaceRequest = | 1141 exports.NullableAssociatedInterfaceRequest = |
| 968 NullableAssociatedInterfaceRequest; | 1142 NullableAssociatedInterfaceRequest; |
| 969 exports.MapOf = MapOf; | 1143 exports.MapOf = MapOf; |
| 970 exports.NullableMapOf = NullableMapOf; | 1144 exports.NullableMapOf = NullableMapOf; |
| 971 return exports; | 1145 return exports; |
| 972 }); | 1146 }); |
| OLD | NEW |