Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(794)

Side by Side Diff: mojo/bindings/java/src/org/chromium/mojo/bindings/Struct.java

Issue 371603003: Adding a router class to handle messages that expect responses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix findbugs issue Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/bindings/java/src/org/chromium/mojo/bindings/RouterImpl.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 package org.chromium.mojo.bindings; 5 package org.chromium.mojo.bindings;
6 6
7 import org.chromium.mojo.system.Core; 7 import org.chromium.mojo.system.Core;
8 8
9 /** 9 /**
10 * Base class for all mojo structs. 10 * Base class for all mojo structs.
(...skipping 24 matching lines...) Expand all
35 public final int numFields; 35 public final int numFields;
36 36
37 /** 37 /**
38 * Constructor. 38 * Constructor.
39 */ 39 */
40 public DataHeader(int size, int numFields) { 40 public DataHeader(int size, int numFields) {
41 super(); 41 super();
42 this.size = size; 42 this.size = size;
43 this.numFields = numFields; 43 this.numFields = numFields;
44 } 44 }
45
46 /**
47 * @see Object#hashCode()
48 */
49 @Override
50 public int hashCode() {
51 final int prime = 31;
52 int result = 1;
53 result = prime * result + numFields;
54 result = prime * result + size;
55 return result;
56 }
57
58 /**
59 * @see Object#equals(Object)
60 */
61 @Override
62 public boolean equals(Object object) {
63 if (object == this)
64 return true;
65 if (object == null)
66 return false;
67 if (getClass() != object.getClass())
68 return false;
69
70 DataHeader other = (DataHeader) object;
71 return (numFields == other.numFields &&
72 size == other.size);
73 }
45 } 74 }
46 75
47 /** 76 /**
48 * The base size of the struct. 77 * The base size of the struct.
49 */ 78 */
50 protected final int mEncodedBaseSize; 79 protected final int mEncodedBaseSize;
51 80
52 /** 81 /**
53 * Constructor. 82 * Constructor.
54 */ 83 */
(...skipping 11 matching lines...) Expand all
66 * 95 *
67 * @param core the |Core| implementation used to generate handles. Only used if the |Struct| 96 * @param core the |Core| implementation used to generate handles. Only used if the |Struct|
68 * being encoded contains interfaces, can be |null| otherwise. 97 * being encoded contains interfaces, can be |null| otherwise.
69 */ 98 */
70 public Message serialize(Core core) { 99 public Message serialize(Core core) {
71 Encoder encoder = new Encoder(core, mEncodedBaseSize); 100 Encoder encoder = new Encoder(core, mEncodedBaseSize);
72 encode(encoder); 101 encode(encoder);
73 return encoder.getMessage(); 102 return encoder.getMessage();
74 } 103 }
75 104
105 /**
106 * Returns the serialization of the struct prepended with the given header.
107 *
108 * @param header the header to prepend to the returned message.
109 * @param core the |Core| implementation used to generate handles. Only used if the |Struct|
110 * being encoded contains interfaces, can be |null| otherwise.
111 */
112 public MessageWithHeader serializeWithHeader(Core core, MessageHeader header ) {
113 Encoder encoder = new Encoder(core, mEncodedBaseSize + header.getSize()) ;
114 header.encode(encoder);
115 encode(encoder);
116 return new MessageWithHeader(encoder.getMessage(), header);
117 }
118
76 } 119 }
OLDNEW
« no previous file with comments | « mojo/bindings/java/src/org/chromium/mojo/bindings/RouterImpl.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698