OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 part of bindings; | |
6 | |
7 class DataHeader { | |
8 static const int kHeaderSize = 8; | |
9 static const int kSizeOffset = 0; | |
10 static const int kNumFieldsOffset = 4; | |
11 final int size; | |
12 final int numFields; | |
13 | |
14 const DataHeader(this.size, this.numFields); | |
15 | |
16 String toString() => "DataHeader($size, $numFields)"; | |
17 } | |
18 | |
19 abstract class Struct { | |
20 final int encodedSize; | |
21 | |
22 Struct(this.encodedSize); | |
23 | |
24 void encode(Encoder encoder); | |
25 | |
26 Message serialize() { | |
27 var encoder = new Encoder(encodedSize); | |
28 encode(encoder); | |
29 return encoder.message; | |
30 } | |
31 | |
32 ServiceMessage serializeWithHeader(MessageHeader header) { | |
33 var encoder = new Encoder(encodedSize + header.size); | |
34 header.encode(encoder); | |
35 encode(encoder); | |
36 return new ServiceMessage(encoder.message, header); | |
37 } | |
38 } | |
OLD | NEW |