floating point accessors
This commit is contained in:
parent
d5de5f6419
commit
d461bc40e2
5 changed files with 41 additions and 5 deletions
|
@ -11,6 +11,7 @@ class EncodingSuite extends FunSuite {
|
|||
val allTypes = message.initRoot(TestAllTypes.Builder.factory);
|
||||
allTypes.setVoidField();
|
||||
allTypes.setBoolField(true);
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,8 +26,9 @@ struct TestAllTypes {
|
|||
uInt16Field @7 : UInt16;
|
||||
uInt32Field @8 : UInt32;
|
||||
uInt64Field @9 : UInt64;
|
||||
# float32Field @10 : Float32;
|
||||
# float64Field @11 : Float64;
|
||||
float32Field @10 : Float32;
|
||||
float64Field @11 : Float64;
|
||||
textField @12 : Text;
|
||||
# ...
|
||||
}
|
||||
|
||||
|
|
|
@ -14,12 +14,13 @@ object Build extends sbt.Build {
|
|||
project(
|
||||
id = "compiler",
|
||||
base = file("compiler")
|
||||
).settings(makeCppTask).dependsOn(runtime)
|
||||
).dependsOn(runtime)
|
||||
.settings(makeCppTask)
|
||||
.settings(compile <<= compile in Compile dependsOn makeCpp)
|
||||
.settings(compileTestSchemaTask)
|
||||
|
||||
.settings(test <<= test in Test dependsOn compileTestSchema )
|
||||
.settings(test <<= test in Test dependsOn compileTestSchema)
|
||||
.settings(unmanagedSourceDirectories in Test += sourceDirectory.value / "test" / "generated")
|
||||
.settings(cleanFiles += sourceDirectory.value / "test" / "generated")
|
||||
|
||||
lazy val runtime =
|
||||
project(
|
||||
|
|
|
@ -67,6 +67,23 @@ public final class StructBuilder {
|
|||
this.segment.buffer.putLong(this.data + offset * 8, value);
|
||||
}
|
||||
|
||||
public final float getFloatField(int offset) {
|
||||
return this.segment.buffer.getFloat(this.data + offset * 4);
|
||||
}
|
||||
|
||||
public final void setFloatField(int offset, float value) {
|
||||
this.segment.buffer.putFloat(this.data + offset * 4, value);
|
||||
}
|
||||
|
||||
public final double getDoubleField(int offset) {
|
||||
return this.segment.buffer.getDouble(this.data + offset * 8);
|
||||
}
|
||||
|
||||
public final void setDoubleField(int offset, double value) {
|
||||
this.segment.buffer.putDouble(this.data + offset * 8, value);
|
||||
}
|
||||
|
||||
|
||||
public final PointerBuilder getPointerField(int index) {
|
||||
return new PointerBuilder(this.segment, this.pointers + index);
|
||||
}
|
||||
|
|
|
@ -67,6 +67,22 @@ public final class StructReader {
|
|||
}
|
||||
}
|
||||
|
||||
public final float getFloatField(int offset) {
|
||||
if ((offset + 1) * 32 <= this.dataSize) {
|
||||
return this.segment.buffer.getFloat(this.data + offset * 4);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public final double getDoubleField(int offset) {
|
||||
if ((offset + 1) * 64 <= this.dataSize) {
|
||||
return this.segment.buffer.getDouble(this.data + offset * 8);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public final PointerReader getPointerField(int ptrIndex) {
|
||||
if (ptrIndex < this.pointerCount) {
|
||||
return new PointerReader(this.segment,
|
||||
|
|
Loading…
Reference in a new issue