default text builder was broken

This commit is contained in:
David Renshaw 2014-10-26 19:24:30 -04:00
parent 10f775a11e
commit 7357bc344e
4 changed files with 35 additions and 9 deletions

View file

@ -162,7 +162,7 @@ object TestUtil {
assert(textList.get(2).toString() == "thud");
val structList = builder.getStructList();
//assert(3 == structList.size());
assert(3 == structList.size());
//assert(structList.get(0).getTextField().toString() == "structlist 1")
//assert(structList.get(1).getTextField().toString() == "structlist 2")
//assert(structList.get(2).getTextField().toString() == "structlist 3")

View file

@ -66,6 +66,12 @@ public final class Data {
public final int offset; // in bytes
public final int size; // in bytes
public Reader() {
this.buffer = ByteBuffer.allocate(0);
this.offset = 0;
this.size = 0;
}
public Reader(ByteBuffer buffer, int offset, int size) {
this.buffer = buffer;
this.offset = offset * 8;
@ -104,6 +110,12 @@ public final class Data {
public final int offset; // in bytes
public final int size; // in bytes
public Builder() {
this.buffer = ByteBuffer.allocate(0);
this.offset = 0;
this.size = 0;
}
public Builder(ByteBuffer buffer, int offset, int size) {
this.buffer = buffer;
this.offset = offset;

View file

@ -70,6 +70,13 @@ public final class Text {
public final int offset; // in bytes
public final int size; // in bytes, not including NUL terminator
public Reader() {
// TODO what about the null terminator?
this.buffer = ByteBuffer.allocate(0);
this.offset = 0;
this.size = 0;
}
public Reader(ByteBuffer buffer, int offset, int size) {
this.buffer = buffer;
this.offset = offset * 8;
@ -121,6 +128,12 @@ public final class Text {
public final int offset; // in bytes
public final int size; // in bytes
public Builder() {
this.buffer = ByteBuffer.allocate(0);
this.offset = 0;
this.size = 0;
}
public Builder(ByteBuffer buffer, int offset, int size) {
this.buffer = buffer;
this.offset = offset;

View file

@ -344,15 +344,17 @@ final class WireHelpers {
throw new DecodeException("INLINE_COMPOSITE list with non-STRUCT elements not supported.");
}
int oldDataSize = StructPointer.dataSize(oldTag);
int oldPointerCount = StructPointer.ptrCount(oldTag);
short oldPointerCount = StructPointer.ptrCount(oldTag);
int oldStep = (oldDataSize + oldPointerCount * Constants.POINTER_SIZE_IN_WORDS);
int elementCount = WirePointer.inlineCompositeListElementCount(oldTag);
if (oldDataSize >= elementSize.data && oldPointerCount >= elementSize.pointers) {
//# Old size is at least as large as we need. Ship it.
return factory.constructBuilder(resolved.segment, resolved.ptr * Constants.BYTES_PER_WORD,
elementCount, oldDataSize * Constants.BITS_PER_WORD, oldPointerCount,
ElementSize.INLINE_COMPOSITE);
elementCount,
oldStep * Constants.BITS_PER_WORD,
oldDataSize * Constants.BITS_PER_WORD, oldPointerCount);
//ElementSize.INLINE_COMPOSITE);
}
//# The structs in this list are smaller than expected, probably written using an older
@ -403,7 +405,7 @@ final class WireHelpers {
if (WirePointer.isNull(ref)) {
if (defaultBuffer == null) {
return new Text.Builder(null, 0, 0);
return new Text.Builder();
} else {
Text.Builder builder = initTextPointer(refOffset, segment, defaultSize);
// TODO is there a way to do this with bulk methods?
@ -467,7 +469,7 @@ final class WireHelpers {
if (WirePointer.isNull(ref)) {
if (defaultBuffer == null) {
return new Data.Builder(ByteBuffer.allocate(0), 0, 0);
return new Data.Builder();
} else {
Data.Builder builder = initDataPointer(refOffset, segment, defaultSize);
// TODO is there a way to do this with bulk methods?
@ -822,8 +824,7 @@ final class WireHelpers {
if (WirePointer.isNull(ref)) {
if (defaultBuffer == null) {
// XXX -- what about null terminator?
return new Text.Reader(ByteBuffer.wrap(new byte[0]), 0, 0);
return new Text.Reader();
} else {
return new Text.Reader(defaultBuffer, defaultOffset, defaultSize);
}
@ -861,7 +862,7 @@ final class WireHelpers {
if (WirePointer.isNull(ref)) {
if (defaultBuffer == null) {
return new Data.Reader(ByteBuffer.wrap(new byte[0]), 0, 0);
return new Data.Reader();
} else {
return new Data.Reader(defaultBuffer, defaultOffset, defaultSize);
}