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/unicode", | 8 "mojo/public/js/unicode", |
9 ], function(buffer, types, unicode) { | 9 ], function(buffer, types, unicode) { |
10 | 10 |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 }; | 446 }; |
447 | 447 |
448 Message.prototype.getName = function() { | 448 Message.prototype.getName = function() { |
449 return this.buffer.getUint32(kMessageNameOffset); | 449 return this.buffer.getUint32(kMessageNameOffset); |
450 }; | 450 }; |
451 | 451 |
452 Message.prototype.getFlags = function() { | 452 Message.prototype.getFlags = function() { |
453 return this.buffer.getUint32(kMessageFlagsOffset); | 453 return this.buffer.getUint32(kMessageFlagsOffset); |
454 }; | 454 }; |
455 | 455 |
456 Message.prototype.getInterfaceId = function() { | |
457 return this.buffer.getUint32(kMessageInterfaceIdOffset); | |
458 }; | |
459 | |
460 Message.prototype.isResponse = function() { | 456 Message.prototype.isResponse = function() { |
461 return (this.getFlags() & kMessageIsResponse) != 0; | 457 return (this.getFlags() & kMessageIsResponse) != 0; |
462 }; | 458 }; |
463 | 459 |
464 Message.prototype.expectsResponse = function() { | 460 Message.prototype.expectsResponse = function() { |
465 return (this.getFlags() & kMessageExpectsResponse) != 0; | 461 return (this.getFlags() & kMessageExpectsResponse) != 0; |
466 }; | 462 }; |
467 | 463 |
468 Message.prototype.setRequestID = function(requestID) { | 464 Message.prototype.setRequestID = function(requestID) { |
469 // TODO(darin): Verify that space was reserved for this field! | 465 // TODO(darin): Verify that space was reserved for this field! |
470 this.buffer.setUint64(kMessageRequestIDOffset, requestID); | 466 this.buffer.setUint64(kMessageRequestIDOffset, requestID); |
471 }; | 467 }; |
472 | 468 |
473 Message.prototype.setInterfaceId = function(interfaceId) { | |
474 this.buffer.setUint32(kMessageInterfaceIdOffset, interfaceId); | |
475 }; | |
476 | 469 |
477 | |
478 // MessageBuilder ----------------------------------------------------------- | 470 // MessageBuilder ----------------------------------------------------------- |
479 | 471 |
480 function MessageBuilder(messageName, payloadSize) { | 472 function MessageBuilder(messageName, payloadSize) { |
481 // Currently, we don't compute the payload size correctly ahead of time. | 473 // Currently, we don't compute the payload size correctly ahead of time. |
482 // Instead, we resize the buffer at the end. | 474 // Instead, we resize the buffer at the end. |
483 var numberOfBytes = kMessageHeaderSize + payloadSize; | 475 var numberOfBytes = kMessageHeaderSize + payloadSize; |
484 this.buffer = new buffer.Buffer(numberOfBytes); | 476 this.buffer = new buffer.Buffer(numberOfBytes); |
485 this.handles = []; | 477 this.handles = []; |
486 var encoder = this.createEncoder(kMessageHeaderSize); | 478 var encoder = this.createEncoder(kMessageHeaderSize); |
487 encoder.writeUint32(kMessageHeaderSize); | 479 encoder.writeUint32(kMessageHeaderSize); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 MessageWithRequestIDBuilder; | 530 MessageWithRequestIDBuilder; |
539 | 531 |
540 // MessageReader ------------------------------------------------------------ | 532 // MessageReader ------------------------------------------------------------ |
541 | 533 |
542 function MessageReader(message) { | 534 function MessageReader(message) { |
543 this.decoder = new Decoder(message.buffer, message.handles, 0); | 535 this.decoder = new Decoder(message.buffer, message.handles, 0); |
544 var messageHeaderSize = this.decoder.readUint32(); | 536 var messageHeaderSize = this.decoder.readUint32(); |
545 this.payloadSize = message.buffer.byteLength - messageHeaderSize; | 537 this.payloadSize = message.buffer.byteLength - messageHeaderSize; |
546 var version = this.decoder.readUint32(); | 538 var version = this.decoder.readUint32(); |
547 var interface_id = this.decoder.readUint32(); | 539 var interface_id = this.decoder.readUint32(); |
| 540 if (interface_id != 0) { |
| 541 throw new Error("Receiving non-zero interface ID. Associated interfaces "
+ |
| 542 "are not yet supported."); |
| 543 } |
548 this.messageName = this.decoder.readUint32(); | 544 this.messageName = this.decoder.readUint32(); |
549 this.flags = this.decoder.readUint32(); | 545 this.flags = this.decoder.readUint32(); |
550 // Skip the padding. | 546 // Skip the padding. |
551 this.decoder.skip(4); | 547 this.decoder.skip(4); |
552 if (version >= 1) | 548 if (version >= 1) |
553 this.requestID = this.decoder.readUint64(); | 549 this.requestID = this.decoder.readUint64(); |
554 this.decoder.skip(messageHeaderSize - this.decoder.next); | 550 this.decoder.skip(messageHeaderSize - this.decoder.next); |
555 } | 551 } |
556 | 552 |
557 MessageReader.prototype.decodeStruct = function(cls) { | 553 MessageReader.prototype.decodeStruct = function(cls) { |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 exports.Handle = Handle; | 913 exports.Handle = Handle; |
918 exports.NullableHandle = NullableHandle; | 914 exports.NullableHandle = NullableHandle; |
919 exports.Interface = Interface; | 915 exports.Interface = Interface; |
920 exports.NullableInterface = NullableInterface; | 916 exports.NullableInterface = NullableInterface; |
921 exports.InterfaceRequest = InterfaceRequest; | 917 exports.InterfaceRequest = InterfaceRequest; |
922 exports.NullableInterfaceRequest = NullableInterfaceRequest; | 918 exports.NullableInterfaceRequest = NullableInterfaceRequest; |
923 exports.MapOf = MapOf; | 919 exports.MapOf = MapOf; |
924 exports.NullableMapOf = NullableMapOf; | 920 exports.NullableMapOf = NullableMapOf; |
925 return exports; | 921 return exports; |
926 }); | 922 }); |
OLD | NEW |