| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // "Generated" code for sample_service.mojom | |
| 6 define([ | |
| 7 "mojo/public/bindings/js/codec", | |
| 8 ], function(codec) { | |
| 9 | |
| 10 // Bar ---------------------------------------------------------------------- | |
| 11 | |
| 12 function Bar() { | |
| 13 this.alpha = 0; | |
| 14 this.beta = 0; | |
| 15 this.gamma = 0; | |
| 16 } | |
| 17 | |
| 18 Bar.encodedSize = codec.kStructHeaderSize + 8; | |
| 19 | |
| 20 Bar.decode = function(decoder) { | |
| 21 var val = new Bar(); | |
| 22 var numberOfBytes = decoder.read32(); | |
| 23 var numberOfFields = decoder.read32(); | |
| 24 // TODO(abarth): We need to support optional fields. | |
| 25 val.alpha = decoder.read8(); | |
| 26 val.beta = decoder.read8(); | |
| 27 val.gamma = decoder.read8(); | |
| 28 decoder.skip(5); | |
| 29 return val; | |
| 30 }; | |
| 31 | |
| 32 Bar.encode = function(encoder, val) { | |
| 33 encoder.write32(Bar.encodedSize); | |
| 34 encoder.write32(3); | |
| 35 encoder.write8(val.alpha); | |
| 36 encoder.write8(val.beta); | |
| 37 encoder.write8(val.gamma); | |
| 38 encoder.skip(5); | |
| 39 }; | |
| 40 | |
| 41 // Foo ---------------------------------------------------------------------- | |
| 42 | |
| 43 function Foo() { | |
| 44 this.x = 0; | |
| 45 this.y = 0; | |
| 46 this.a = 0; | |
| 47 this.b = 0; | |
| 48 this.c = 0; | |
| 49 this.bar = null; | |
| 50 this.data = []; | |
| 51 this.extra_bars = []; | |
| 52 this.name = ""; | |
| 53 this.files = []; | |
| 54 } | |
| 55 | |
| 56 Foo.encodedSize = codec.kStructHeaderSize + 64; | |
| 57 | |
| 58 Foo.decode = function(decoder) { | |
| 59 var val = new Foo(); | |
| 60 var numberOfBytes = decoder.read32(); | |
| 61 var numberofFields = decoder.read32(); | |
| 62 // TODO(abarth): We need to support optional fields. | |
| 63 val.x = decoder.read32(); | |
| 64 val.y = decoder.read32(); | |
| 65 var packed = decoder.read8(); | |
| 66 val.a = (packed >> 0) & 1; | |
| 67 val.b = (packed >> 1) & 1; | |
| 68 val.c = (packed >> 2) & 1; | |
| 69 decoder.skip(7); | |
| 70 val.bar = decoder.decodeStructPointer(Bar); | |
| 71 val.data = decoder.decodeArrayPointer(codec.Uint8); | |
| 72 val.extra_bars = decoder.decodeArrayPointer(new codec.PointerTo(Bar)); | |
| 73 val.name = decoder.decodeStringPointer(); | |
| 74 val.files = decoder.decodeArrayPointer(codec.Handle); | |
| 75 return val; | |
| 76 } | |
| 77 | |
| 78 Foo.encode = function(encoder, val) { | |
| 79 encoder.write32(Foo.encodedSize); | |
| 80 encoder.write32(10); | |
| 81 encoder.write32(val.x); | |
| 82 encoder.write32(val.y); | |
| 83 var packed = (val.a & 1) << 0 | | |
| 84 (val.b & 1) << 1 | | |
| 85 (val.c & 1) << 2; | |
| 86 encoder.write8(packed); | |
| 87 encoder.skip(7); | |
| 88 encoder.encodeStructPointer(Bar, val.bar); | |
| 89 encoder.encodeArrayPointer(codec.Uint8, val.data); | |
| 90 encoder.encodeArrayPointer(new codec.PointerTo(Bar), val.extra_bars); | |
| 91 encoder.encodeStringPointer(val.name); | |
| 92 encoder.encodeArrayPointer(codec.Handle, val.files); | |
| 93 }; | |
| 94 | |
| 95 var exports = {}; | |
| 96 exports.Bar = Bar; | |
| 97 exports.Foo = Foo; | |
| 98 return exports; | |
| 99 }); | |
| OLD | NEW |