OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE.md file. | |
4 | |
5 package dartino; | |
6 | |
7 import java.nio.ByteBuffer; | |
8 import java.nio.ByteOrder; | |
9 | |
10 class Segment { | |
11 public Segment(byte[] memory) { | |
12 buffer = ByteBuffer.wrap(memory); | |
13 buffer.order(ByteOrder.LITTLE_ENDIAN); | |
14 } | |
15 | |
16 public Segment(MessageReader reader, byte[] memory) { | |
17 buffer = ByteBuffer.wrap(memory); | |
18 buffer.order(ByteOrder.LITTLE_ENDIAN); | |
19 this.reader = reader; | |
20 } | |
21 | |
22 public ByteBuffer buffer() { return buffer; } | |
23 public MessageReader reader() { return reader; } | |
24 | |
25 public boolean getBoolean(int offset) { | |
26 return buffer.get(offset) != 0; | |
27 } | |
28 | |
29 public short getUnsigned(int offset) { | |
30 short result = (short)buffer.get(offset); | |
31 return (short)Math.abs(result); | |
32 } | |
33 | |
34 public int getUnsignedChar(int offset) { | |
35 int result = (int)buffer.getChar(offset); | |
36 return (int)Math.abs(result); | |
37 } | |
38 | |
39 public long getUnsignedInt(int offset) { | |
40 long result = (long)buffer.getInt(offset); | |
41 return (long)Math.abs(result); | |
42 } | |
43 | |
44 private ByteBuffer buffer; | |
45 private MessageReader reader; | |
46 } | |
OLD | NEW |