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 part of bindings; | 5 part of bindings; |
6 | 6 |
7 int align(int size) => size + (kAlignment - (size % kAlignment)) % kAlignment; | 7 int align(int size) => size + (kAlignment - (size % kAlignment)) % kAlignment; |
8 | 8 |
9 const int kAlignment = 8; | 9 const int kAlignment = 8; |
10 const int kSerializedHandleSize = 4; | 10 const int kSerializedHandleSize = 4; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 _base + offset, value, Endianness.LITTLE_ENDIAN); | 173 _base + offset, value, Endianness.LITTLE_ENDIAN); |
174 | 174 |
175 void encodeDouble(double value, int offset) => _buffer.buffer.setFloat64( | 175 void encodeDouble(double value, int offset) => _buffer.buffer.setFloat64( |
176 _base + offset, value, Endianness.LITTLE_ENDIAN); | 176 _base + offset, value, Endianness.LITTLE_ENDIAN); |
177 | 177 |
178 void encodeHandle(core.MojoHandle value, int offset, bool nullable) { | 178 void encodeHandle(core.MojoHandle value, int offset, bool nullable) { |
179 if ((value == null) || !value.isValid) { | 179 if ((value == null) || !value.isValid) { |
180 encodeInvalideHandle(offset, nullable); | 180 encodeInvalideHandle(offset, nullable); |
181 } else { | 181 } else { |
182 encodeUint32(_buffer.handles.length, offset); | 182 encodeUint32(_buffer.handles.length, offset); |
183 _buffer.handles.add(value); | 183 _buffer.handles.add(value.pass()); |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 void encodeMessagePipeHandle( | 187 void encodeMessagePipeHandle( |
188 core.MojoMessagePipeEndpoint value, int offset, bool nullable) => | 188 core.MojoMessagePipeEndpoint value, int offset, bool nullable) => |
189 encodeHandle(value != null ? value.handle : null, offset, nullable); | 189 encodeHandle(value != null ? value.handle : null, offset, nullable); |
190 | 190 |
191 void encodeConsumerHandle( | 191 void encodeConsumerHandle( |
192 core.MojoDataPipeConsumer value, int offset, bool nullable) => | 192 core.MojoDataPipeConsumer value, int offset, bool nullable) => |
193 encodeHandle(value != null ? value.handle : null, offset, nullable); | 193 encodeHandle(value != null ? value.handle : null, offset, nullable); |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 bool decodeBool(int offset, int bit) => | 558 bool decodeBool(int offset, int bit) => |
559 (decodeUint8(offset) & (1 << bit)) != 0; | 559 (decodeUint8(offset) & (1 << bit)) != 0; |
560 | 560 |
561 core.MojoHandle decodeHandle(int offset, bool nullable) { | 561 core.MojoHandle decodeHandle(int offset, bool nullable) { |
562 int index = decodeInt32(offset); | 562 int index = decodeInt32(offset); |
563 if (index == -1) { | 563 if (index == -1) { |
564 if (!nullable) { | 564 if (!nullable) { |
565 throw new MojoCodecError( | 565 throw new MojoCodecError( |
566 'Trying to decode an invalid handle from a non-nullable type.'); | 566 'Trying to decode an invalid handle from a non-nullable type.'); |
567 } | 567 } |
568 return new core.MojoHandle(core.MojoHandle.INVALID); | 568 return new core.MojoHandle.invalid(); |
569 } | 569 } |
570 _validator.claimHandle(index); | 570 _validator.claimHandle(index); |
571 return _handles[index]; | 571 return _handles[index]; |
572 } | 572 } |
573 | 573 |
574 core.MojoMessagePipeEndpoint decodeMessagePipeHandle( | 574 core.MojoMessagePipeEndpoint decodeMessagePipeHandle( |
575 int offset, bool nullable) => | 575 int offset, bool nullable) => |
576 new core.MojoMessagePipeEndpoint(decodeHandle(offset, nullable)); | 576 new core.MojoMessagePipeEndpoint(decodeHandle(offset, nullable)); |
577 | 577 |
578 core.MojoDataPipeConsumer decodeConsumerHandle(int offset, bool nullable) => | 578 core.MojoDataPipeConsumer decodeConsumerHandle(int offset, bool nullable) => |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 throw new MojoCodecError( | 824 throw new MojoCodecError( |
825 'Incorrect header for map. The size is incorrect.'); | 825 'Incorrect header for map. The size is incorrect.'); |
826 } | 826 } |
827 if (header.version != kMapStructHeader.version) { | 827 if (header.version != kMapStructHeader.version) { |
828 throw new MojoCodecError( | 828 throw new MojoCodecError( |
829 'Incorrect header for map. The version is incorrect.'); | 829 'Incorrect header for map. The version is incorrect.'); |
830 } | 830 } |
831 return header; | 831 return header; |
832 } | 832 } |
833 } | 833 } |
OLD | NEW |