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"); assert(textList.get(2).toString() == "thud");
val structList = builder.getStructList(); val structList = builder.getStructList();
//assert(3 == structList.size()); assert(3 == structList.size());
//assert(structList.get(0).getTextField().toString() == "structlist 1") //assert(structList.get(0).getTextField().toString() == "structlist 1")
//assert(structList.get(1).getTextField().toString() == "structlist 2") //assert(structList.get(1).getTextField().toString() == "structlist 2")
//assert(structList.get(2).getTextField().toString() == "structlist 3") //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 offset; // in bytes
public final int size; // 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) { public Reader(ByteBuffer buffer, int offset, int size) {
this.buffer = buffer; this.buffer = buffer;
this.offset = offset * 8; this.offset = offset * 8;
@ -104,6 +110,12 @@ public final class Data {
public final int offset; // in bytes public final int offset; // in bytes
public final int size; // 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) { public Builder(ByteBuffer buffer, int offset, int size) {
this.buffer = buffer; this.buffer = buffer;
this.offset = offset; this.offset = offset;

View file

@ -70,6 +70,13 @@ public final class Text {
public final int offset; // in bytes public final int offset; // in bytes
public final int size; // in bytes, not including NUL terminator 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) { public Reader(ByteBuffer buffer, int offset, int size) {
this.buffer = buffer; this.buffer = buffer;
this.offset = offset * 8; this.offset = offset * 8;
@ -121,6 +128,12 @@ public final class Text {
public final int offset; // in bytes public final int offset; // in bytes
public final int size; // 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) { public Builder(ByteBuffer buffer, int offset, int size) {
this.buffer = buffer; this.buffer = buffer;
this.offset = offset; this.offset = offset;

View file

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