setTextPointer

This commit is contained in:
David Renshaw 2014-05-17 23:06:32 -04:00
parent 2ba6629c1b
commit 33fb16a5cd
2 changed files with 22 additions and 10 deletions

View file

@ -7,7 +7,7 @@ public class Text {
public static final class Reader {
public final ByteBuffer buffer;
public final int offset; // in bytes
public final int size; // in bytes
public final int size; // in bytes, not including NUL terminator
public Reader(ByteBuffer buffer, int offset, int size) {
this.buffer = buffer;
@ -44,9 +44,15 @@ public class Text {
public static final class Builder {
public final ByteBuffer buffer;
public final int offset;
public Builder(ByteBuffer buffer) {
// size not including the NUL terminator
public final int size;
public Builder(ByteBuffer buffer, int offset, int size) {
this.buffer = buffer;
this.offset = offset;
this.size = size;
}
}

View file

@ -61,9 +61,9 @@ final class WireHelpers {
}
// size is in bytes
public static void initTextPointer(int refOffset,
SegmentBuilder segment,
int size) {
public static Text.Builder initTextPointer(int refOffset,
SegmentBuilder segment,
int size) {
//# The byte list must include a NUL terminator.
int byteSize = size + 1;
@ -73,13 +73,19 @@ final class WireHelpers {
//# Initialize the pointer.
ListPointer.set(segment.buffer, refOffset, FieldSize.BYTE, byteSize);
throw new Error("unimplemented");
return new Text.Builder(segment.buffer, ptrOffset, size);
}
public static void setTextPointer(int refOffset,
SegmentBuilder segment,
Text.Reader value) {
throw new Error("unimplemented");
public static Text.Builder setTextPointer(int refOffset,
SegmentBuilder segment,
Text.Reader value) {
Text.Builder builder = initTextPointer(refOffset, segment, value.size);
// TODO is there a way to do this with bulk methods?
for (int i = 0; i < builder.size; ++i) {
builder.buffer.put(builder.offset + i, value.buffer.get(value.offset + i));
}
return builder;
}
public static StructReader readStructPointer(SegmentReader segment,