diff --git a/src/runtime_lib.jl b/src/runtime_lib.jl index 263c700..e5b4124 100644 --- a/src/runtime_lib.jl +++ b/src/runtime_lib.jl @@ -145,10 +145,10 @@ function write_bool(ptr, from_bits, value) segment = ptr.traverser.segments[ptr.segment] # println("Writing value ", value, " at segment ", ptr.segment, ", byte ", ptr.offset * 8 + from รท 8) - byte = unsafe_load!(Ptr{type}(pointer(segment) + 8 * ptr.offset + byte_position)) + byte = unsafe_load(Ptr{UInt8}(pointer(segment) + 8 * ptr.offset + byte_position)) # make the desired position zero and then place `value` to it byte = byte & ~(UInt8(1) << in_byte_position) | (value << in_byte_position) - unsafe_store!(Ptr{type}(pointer(segment) + 8 * ptr.offset + byte_position), byte) + unsafe_store!(Ptr{UInt8}(pointer(segment) + 8 * ptr.offset + byte_position), byte) end # "Bits" types except for bool. diff --git a/src/schema.capnp.jl b/src/schema.capnp.jl index ff079f5..1247654 100644 --- a/src/schema.capnp.jl +++ b/src/schema.capnp.jl @@ -1445,35 +1445,35 @@ if !@isdefined(capnp); eval(:(module capnp end)); end Capnp.write_bits(ptr, 0, UInt16, 1) # union discriminant end function Value_getInt8(ptr) - value = Capnp.read_bits(ptr, 2, UInt8) + value = Capnp.read_bits(ptr, 2, Int8) value end function Value_setInt8(ptr, value) - Capnp.write_bits(ptr, 2, UInt8, value) + Capnp.write_bits(ptr, 2, Int8, value) Capnp.write_bits(ptr, 0, UInt16, 2) # union discriminant end function Value_getInt16(ptr) - value = Capnp.read_bits(ptr, 2, UInt16) + value = Capnp.read_bits(ptr, 2, Int16) value end function Value_setInt16(ptr, value) - Capnp.write_bits(ptr, 2, UInt16, value) + Capnp.write_bits(ptr, 2, Int16, value) Capnp.write_bits(ptr, 0, UInt16, 3) # union discriminant end function Value_getInt32(ptr) - value = Capnp.read_bits(ptr, 4, UInt32) + value = Capnp.read_bits(ptr, 4, Int32) value end function Value_setInt32(ptr, value) - Capnp.write_bits(ptr, 4, UInt32, value) + Capnp.write_bits(ptr, 4, Int32, value) Capnp.write_bits(ptr, 0, UInt16, 4) # union discriminant end function Value_getInt64(ptr) - value = Capnp.read_bits(ptr, 8, UInt64) + value = Capnp.read_bits(ptr, 8, Int64) value end function Value_setInt64(ptr, value) - Capnp.write_bits(ptr, 8, UInt64, value) + Capnp.write_bits(ptr, 8, Int64, value) Capnp.write_bits(ptr, 0, UInt16, 5) # union discriminant end function Value_getUint8(ptr) diff --git a/src/schema_tree.jl b/src/schema_tree.jl index f1e5d39..a9f2a6c 100644 --- a/src/schema_tree.jl +++ b/src/schema_tree.jl @@ -92,10 +92,10 @@ capnp_sizeof(::SchemaFloat32) = 4 capnp_sizeof(::SchemaFloat64) = 8 # capnp_type_to_bits_type(::SchemaTypeBool) = Bool see capnp_sizeof -capnp_type_to_bits_type(::SchemaInt8) = UInt8 -capnp_type_to_bits_type(::SchemaInt16) = UInt16 -capnp_type_to_bits_type(::SchemaInt32) = UInt32 -capnp_type_to_bits_type(::SchemaInt64) = UInt64 +capnp_type_to_bits_type(::SchemaInt8) = Int8 +capnp_type_to_bits_type(::SchemaInt16) = Int16 +capnp_type_to_bits_type(::SchemaInt32) = Int32 +capnp_type_to_bits_type(::SchemaInt64) = Int64 capnp_type_to_bits_type(::SchemaUInt8) = UInt8 capnp_type_to_bits_type(::SchemaUInt16) = UInt16 capnp_type_to_bits_type(::SchemaUInt32) = UInt32 diff --git a/test/elementary.capnp b/test/elementary.capnp new file mode 100644 index 0000000..dd8f74c --- /dev/null +++ b/test/elementary.capnp @@ -0,0 +1,7 @@ +@0x930cadbc14628588; + +struct Test { + booleanFalse @0 :Bool; + booleanTrue @1 :Bool; + signed64 @2 :Int64; +} \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 2eeeabd..e3317ae 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -27,6 +27,36 @@ end @test result == expected end +@testset "Elementary types" begin + run(`capnpc -o./capnpc-jl test/elementary.capnp`) + include("elementary.capnp.jl") + + # writing part + message = Capnp.AllocMessageBuilder() + test = initRoot_Test(message) + Test_setBooleanFalse(test, false) + Test_setBooleanTrue(test, true) + Test_setSigned64(test, -1) + + # finish writing and flush into buffer for reading + buffer = IOBuffer() + writeMessageToStream(message, buffer) + seek(buffer, 0) + + # reading part + message = Capnp.MessageReader(buffer) + test = root_Test(message) + + booleanFalse = Test_getBooleanFalse(test) + @test booleanFalse == false + + booleanTrue = Test_getBooleanTrue(test) + @test booleanTrue == true + + signed64 = Test_getSigned64(test) + @test signed64 == -1 +end + @testset "Lists" begin run(`capnpc -o./capnpc-jl test/lists.capnp`) include("lists.capnp.jl")