| 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 class BuilderSegment extends Segment { | |
| 8 public BuilderSegment(MessageBuilder builder, int id, int size) { | |
| 9 super(new byte[size]); | |
| 10 this.builder = builder; | |
| 11 this.id = id; | |
| 12 used = 0; | |
| 13 } | |
| 14 | |
| 15 public boolean hasSpaceForBytes(int bytes) { | |
| 16 return used + bytes < buffer().capacity(); | |
| 17 } | |
| 18 | |
| 19 public int allocate(int bytes) { | |
| 20 if (!hasSpaceForBytes(bytes)) return -1; | |
| 21 int result = used; | |
| 22 used += bytes; | |
| 23 return result; | |
| 24 } | |
| 25 | |
| 26 public int id() { return id; } | |
| 27 public int used() { return used; } | |
| 28 public MessageBuilder builder() { return builder; } | |
| 29 | |
| 30 public boolean hasNext() { return next != null; } | |
| 31 public BuilderSegment next() { return next; } | |
| 32 public void setNext(BuilderSegment segment) { next = segment; } | |
| 33 | |
| 34 private MessageBuilder builder; | |
| 35 private int id; | |
| 36 private BuilderSegment next; | |
| 37 private int used; | |
| 38 } | |
| OLD | NEW |