capnproto / capnproto-java Goto Github PK
View Code? Open in Web Editor NEWCap'n Proto in pure Java
License: Other
Cap'n Proto in pure Java
License: Other
Just a thought. Maybe I'll get around to doing this and make a PR
I notice that the C++ RPC implementation uses a concurrency model that's very similar to the actor pattern. Should we do ours with Akka? I suspect there may be better choices for actors on Java platforms (strange as that may seem), but it would probably make it easier to integrate it with web application frameworks like Play and Spray.
My story: I've been working towards a web app framework predicated on the idea that most high-quality GUI components can be thought of as visualizations of remote reactive data structures. It's dawned on me, though, that if I want to usher in a new age of platform-agnostic remote object interfaces, I should probably just help out with cap'n proto.
All my builds using org.capnproto#runtime;0.1.0-SNAPSHOT just started failing. Did something happen?
Hello,
I am new to the world of managing Java jar files and I am having the task of generating the Java jar file for capnproto using g++ v4.8 in our RHEL6 environment.
I downloaded the source from here and followed the below steps to generate the jar file.
cd ~/tmp/capnproto/capnproto-java-master/runtime/src/main/java
Write the list of files to be compiled to a temp file.
$ find org -name *.java > /var/tmp/javafiles
Create classes directory
$ mkdir classes
Perform compilation.
$ /usr/local/java/jdk/bin/javac -d classes -cp . @/var/tmp/ javafiles
create jar
$ jar cf capnproto.jar -C ./classes org/capnproto
Verify that the jar file has required classes.
$ jar tf capnproto.jar
As I wasn’t sure about the method, I made some changes to ‘CAPNP_CXX_FLAGS’ variable in the Makefile and ran ‘make’ to generate the capnpc.java file but not sure how to generate the jar file out of that.
Can you please let me know what’s the correct way to generate the jar files for capnproto?
Please let me know if something isn’t clear.
Hi,
It looks like there is a problem with generics resolution. The java class generated from the following definition schema won't compile:
@0xc3788dd6d95d5829;
using Java = import "/java.capnp";
$Java.package("com.example.collection");
$Java.outerClassname("MapCapnp");
struct MapStruct(K, V)
{
entries @0 :List(Entry);
struct Entry
{
key @0 :K;
value @1 :V;
}
}
line 48 of MapCapnp.java shows these compilation errors:
Multiple markers at this line
- V_e5cf7b7b99eed732_Reader cannot be resolved to a type
- K_e5cf7b7b99eed732_Reader cannot be resolved to a type
- The constructor
StructList.Factory<MapCapnp.MapStruct.Entry.Builder<K_e5cf7b7b99eed732_Builder,V_e5cf7b7b99eed732_Builder>,MapCapnp.MapStruct.Entry.Reader<K_e5cf7b7b99eed732_Reader,V_e5cf7b7b99eed732_Reader>>(St
ructFactory<MapCapnp.MapStruct.Entry.Builder<K_e5cf7b7b99eed732_Builder,V_e5cf7b7b99eed732_Builder>,MapCapnp.MapStruct.Entry.Reader<K_e5cf7b7b99eed732_Reader,V_e5cf7b7b99eed732_Reader>>) refers
to the missing type K_e5cf7b7b99eed732_Reader
Thanks!
We are writing capnp-maven-plugin.
We would like to support java 1.7 and I see that the runtime is actually tested and working under 1.7.
However, the current snapshot is built and deployed with 1.8.
I suggest you add the "source and target" settings to your compiler.
After passing a ByteBuffer
to org.capnproto.Serialize.read(byteBuffer)
the result of byteBuffer.position()
is 8 bytes. The actual message size is confirmed to be 208 bytes.
Also tried with other messages of different sizes and keep getting the same result.
Discussed with Kenton here: http://stackoverflow.com/questions/32021239/capn-proto-finding-message-size-in-java
Seems to be a bug.
Hello David
Just hit this part:
case schema::Type::TEXT:
case schema::Type::DATA:
case schema::Type::ENUM:
case schema::Type::INTERFACE:
case schema::Type::ANY_POINTER:
case schema::Type::LIST:
KJ_FAIL_REQUIRE("unimplemented");
If you don't have time to work on this now, could you provide some guidance on what you think needs to happen to extend the code to support these? We don't care too much about AnyPointer right now, but we need all the others.
Cheers
Albert
Can we use the java capnproto implementation to efficiently write millions of records into a large binary file and then read those records back?
Let's assume to simplify that only one struct is defined, and that all the records we write are of that struct. Writes and then reads are sequential (streaming).
What is expected for efficiency is the ability to reuse message builders and readers or at least the byte buffers they use internally.
When using a StructList the size is not checked when adding new entries.
For example:
StructList.Builder<PhoneNumber.Builder> personPhones
= person.initPhones(0);
personPhones.get(0).setNumber("08031/12345");
personPhones.get(0).setType(PhoneType.WORK);
personPhones.get(1).setNumber("0160/9876543");
personPhones.get(1).setType(PhoneType.MOBILE);
Will give no error or exception but the data is not written.
Or worste if you have a bit of space:
StructList.Builder<PhoneNumber.Builder> personPhones
= person.initPhones(1);
personPhones.get(0).setNumber("08031/12345");
personPhones.get(0).setType(PhoneType.WORK);
personPhones.get(1).setNumber("0160/9876543");
personPhones.get(1).setType(PhoneType.MOBILE);
You get the following:
work phone: 031/12
So your data is destroyed.
In both cases I would expect an exception.
Hi
I want to using capnproto-java in mac os,but when I use sbt compile,it failed with following errors
https://gist.github.com/theSinner/74e2715c7288da527952
Hello. This is the most stupid issue ever. I'm reading your website:
You will need to install the latest release of the Cap’n Proto schema compiler.
Success! Now I've got capnp
.
Then, running
make
should build capnpc-java.
Um, running make
from where?
Oh, OK, I need to clone this repo, cd
into it and run make. Now I've got ./capnpc-java
.
On Windows,
Happy Linux-user, skipping...
Note that you’ll need to include java.capnp so that you can use the package and outerClassname annotations.
Include where?
using Java = import "/capnp/java.capnp";
yields
schema.capnp:2:21-40: error: Import failed: /capnp/java.capnp
schema.capnp:3:2-6: error: Not defined: Java
schema.capnp:4:2-6: error: Not defined: Java
/capnp/java.capnp
looks like I need a directory called capnp
at my mounting point (/
), which looks strange.
using Java = import "./compiler/src/main/schema/capnp/java.capnp";
Oh, I need to include it here.
Success!
Looks like there are several unclear places in your manual.
Thanks!
Hi,
I am considering using capnproto-java for a new project architecture.
The Readme mentions since October 9th 2014 that the project is in work in progress state.
Version number is still very low.
When reading the blog, the project seems to be in eternal beta stage but mostly production ready.
Can you clarify the project maturity and eventually the features that are implemented but not production ready yet ?
Is there any reasons to not have a 1.0 version yet ? I understand capnproto cpp itself is not at 1.0 also, but you use different versions.
Thank you + regards
Cyril H
For example, where is java.capnp
?
compilation terminated.
make: *** [capnpc-java] Error 1
[trace] Stack trace suppressed: run last examples/:makeExamples for the full output.
[trace] Stack trace suppressed: run last compiler/:makeCpp for the full output.
error Nonzero exit value: 2
error Nonzero exit value: 2
[error] Total time: 1 s, completed Jun 29, 2015 7:35:02 PM
capnproto-java$ last compiler/*:makeCpp
java.lang.RuntimeException: Nonzero exit value: 2
at scala.sys.package$.error(package.scala:27)
at scala.Predef$.error(Predef.scala:142)
at sbt.AbstractProcessBuilder.getString(ProcessImpl.scala:146)
at sbt.AbstractProcessBuilder.$bang$bang(ProcessImpl.scala:148)
at Build$$anonfun$2.apply$mcV$sp(build.scala:74)
at Build$$anonfun$2.apply(build.scala:73)
at Build$$anonfun$2.apply(build.scala:73)
at sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:45)
at sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:45)
at sbt.std.Transform$$anon$4.work(System.scala:64)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
at sbt.Execute.work(Execute.scala:244)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
error Nonzero exit value: 2
Hi!
TL;DR:
I'm wondering how to get a byte[] array from a MessageBuilder
instance. The API by default seems geared toward ByteBuffers and Java NIO, but an escape hatch from that would be very welcome: I need a byte[] array as a serialization result since that's what the next step of my code expects.
I'd simply like to achieve the MessageBuilder
→ byte[]
conversion as efficiently as possible.
More info:
I could of course use ByteBuffers and the NIO API, but that is just a straight-up broken API w.r.t this use case:
When serializing, I cannot know in advance how big the target buffer should be (the ByteBuffer
type demands some capacity as an argument) and I know of no simple way for get that information at that time. The result of this is that I would either need to grossly over-allocate, or allocate a random size and apparently manually(!) reallocate when that size proves inadequate. Both options are really unappetizing as the first is usually wasteful in resources without providing any scalability guarantee (i.e. it still might break when the message is too big), and the second is wasteful in CPU time and memory allocations.
Since Java does not have unsigned primitive types the generated type for UInt8, UInt16, UInt32 must be short, int, long instead of byte, short, int. For UInt64 is no real solution available but here is the impact not as big as for the smaller types.
// Current UInt8
public final byte getM0() {
return _getByteField(0);
}
public final void setM0(byte value) {
_setByteField(0, value);
}
// Expected UInt8
public final short getM0() {
return _getByteField(0) & 0xFF;
}
public final void setM0(short value) {
_setByteField(0, (byte) value);
}
// Current UInt16
public final short getM1() {
return _getShortField(1);
}
public final void setM1(short value) {
_setShortField(1, value);
}
// Expected UInt16
public final int getM1() {
return _getShortField(1) & 0xFFFF;
}
public final void setM1(int value) {
_setShortField(1, (short) value);
}
// Current UInt32
public final int getM2() {
return _getIntField(2);
}
public final void setM2(int value) {
_setIntField(2, value);
}
// Expected UInt32
public final long getM2() {
return _getIntField(2) & 0xFFFF_FFFFL;
}
public final void setM2(long value) {
_setIntField(2, (int) value);
}
Hello,
we've currently considering protocol buffers for serializing the data. But they seem to be slow while deserializing using java and don't have support for int16 (or int8) as Cap'n Proto does. Cap'n Proto documentation says nothing about arrays, but only lists. As our data mostly consists of short-arrays and need a very fast access to them, lists are inappropriate for us.
Can you help us to learn whether Cap'n Proto does support array serialization in java?
Thanks in advance.
Alexey
Is it possible to get access to the size in bytes of a serialized (packed or unpacked, either is fine) message? I'm working with a protocol where some messages are defined using capnproto, and the protocol requires sending an unsigned 32-bit big-endian integer representing the size of the message to follow.
I understand that the provided stream types do serialize some data about the messages upon serialization (number of segments, etc), but I consider that information private to capnproto (and besides which, the values are calculated on writing the data to the wire and therefore too late for me to use).
Is there a tested procedure to build this project on Windows? What are the dependencies needed? I assume we need to install gcc and make on windows?
It looks like capnproto-java currently only uses heap java.nio.ByteBuffer
s. Has anybody tested the library using direct ByteBuffer
s? Would it be acceptable to add a few functions to the write API to use them?
The main capnproto website mentions a canonicalization algorithm. Does this package implement that, or otherwise output serialized data in a canonical manner?
If be a jar package and manage with maven, That is very convenience for us. Do you think?
Has anyone done a comparison between those two in Java? I know Java has limitations and it is unfair to compare with C++ implementation. What about comparison between other serialization protocols in Java? Thanks.
There's an example of a generic struct on Cap’n Proto page:
...
struct Map(Key, Value) {
entries @0 :List(Entry);
struct Entry {
key @0 :Key;
value @1 :Value;
}
}
...
After compiling it, I cannot seem to find the corresponding
public static final Factory factory
field in the class Map
. There are factories for other types mentioned in the example, but not for this one. Why is that? Does it have anything to do with generics in Java not being reifiable?
We might be interested in using capn proto at my company, but the generated classes look extremely hard to use. We'd like to instead generate kotlin classes with default constructors, values, etc. What things would need to be modified in a fork of this project in order to get that working? It appears we would need to modify capnpc-java.c++
. Is that all?
Cool to see a Java port. Interested more about how this works and it'd be cool to add a note about that. Looks like you use a tool called clang to autogenerate the Java code from the C++ code? Not sure if I'm reading that right.
I have a schema defined like:
struct Car {
carId @0 :UInt32;
recommendedServiceIntervals @1 :List(Float64);
}
I am using the generated code like
MessageBuilder message = new MessageBuilder();
Car.Builder builder = message.initRoot(Car.factory);
PrimitiveList.Double.Builder listBuilder = builder.initRecommendedServiceIntervals(4);
Now this issue is that PrimitiveList.Double.Builder does not have any function for setting the elements of the list. I was using TextList.Builder earlier and I can see that it has a function like:
TextList.Builder.set(index, Text.Reader)
Shouldn't PrimitiveList.Double.Builder have a similar "set" function? Or am I doing this completely wrong?
Thanks,
Zarian.
I saw the work done in #16 for publishing packages on Sonatype - for Java projects purely using Maven it would be pretty good to be able to download this from the central maven repository and not having a dependency on SBT/Scala etc.
I'm currently maintaining a fork of this for our internal purposes that builds/packages using Maven rather than SBT and have ported the tests from Scala to Java. I appreciate that there were probably reasons you didn't go down this route in the first place (and I'm happy to change the package names etc and keep the fork up to date), but would you consider accepting a PR for this?
Is there a way to generate plain Java object(s) from a capnproto schema file?
For example, using the following
struct Person {
name @0 :Text;
birthdate @1 :Date;
}
struct Date {
year @0 :Int16;
month @1 :UInt8;
day @2 :UInt8;
}
to generate
Person.java
-----------
public class Person {
String name;
Date birthdate;
// getters
// setters
// constructor
// hashcode and equals
// ...
}
Date.java
---------
public class Date {
int year;
int month;
int day;
// getters
// setters
// constructor
// hashcode and equals
// ...
}
What I am trying to do is convert capnp messages to json/parquet etc.
If there's a way to generate POJOs like this and then methods to deserialize the serialized messages into such POJOs, then the conversion to other formats would become very straightforward. I understand that deserializing the message into an object like this would undo some of the speed benefits of capnproto, but I am not sure if there's a better way towards conversion to other formats.
a part of my capnp:
@0xb1185f68a81b6c14;
using Java = import "java.capnp";
$Java.package("com.cloudflare.schemas");
$Java.outerClassname("CdnMessage");
using import "request.capnp".Request;
struct Message {
sourceId @0 :Text;
seq @1 :UInt32;
union {
unset @2 :Void;
request @3 :Request;
text @4 :Text;
data @5 :Data;
}
}
I use as follows:
org.capnproto.MessageReader message = org.capnproto.SerializePacked.
read(new org.capnproto.ArrayInputStream(ByteBuffer.wrap(bytes)));
bytes are a byte array and have right content. I test the ArrayInputStream is right by:
org.capnproto.ArrayInputStream ais = new org.capnproto.ArrayInputStream(ByteBuffer.wrap(bytes));
ByteBuffer buf = ais.getReadBuffer();
byte[] bytes = new byte[availableBytes];
buf.get(bytes);
OutputStream out = new FileOutputStream("capnproto.log");
out.write(bytes);
out.close();
now all is right. but
next:
CdnMessage.Message.Reader capnpMessage = message.getRoot(CdnMessage.Message.factory);
have a error and the stack is as follows:
Exception in thread "main" java.lang.IndexOutOfBoundsException
at java.nio.Buffer.checkIndex(Buffer.java:538)
at java.nio.HeapByteBuffer.getLong(HeapByteBuffer.java:410)
at org.capnproto.SegmentReader.get(SegmentReader.java:39)
at org.capnproto.WireHelpers.readStructPointer(WireHelpers.java:884)
at org.capnproto.StructFactory.fromPointerReaderRefDefault(StructFactory.java:34)
at org.capnproto.StructFactory.fromPointerReader(StructFactory.java:41)
at org.capnproto.StructFactory.fromPointerReader(StructFactory.java:24)
at org.capnproto.AnyPointer$Reader.getAs(AnyPointer.java:56)
at org.capnproto.MessageReader.getRoot(MessageReader.java:38)
at src.Test.main(Test.java:34)
where did I make a mistake?
when trying to serialize lists of size 2^24 or bigger, IndexOutOfBoundsException is thrown.
java.lang.IndexOutOfBoundsException
at java.nio.Buffer.checkIndex(Buffer.java:546)
at java.nio.HeapByteBuffer.putLong(HeapByteBuffer.java:432)
at org.capnproto.StructBuilder._setLongField(StructBuilder.java:127)
Despite the exception, I assumed it could be related to lack of memory so i tried to increase heap size, but it didn't help.
Here's a problem I encountered when I try to read capn message from a byte array.
ArrayInputStream sets limit on wrapped ByteBuffer, which defaults to 8192, usually larger then byte array size, causing ByteBuffer::limit to throw IllegalArgumentException.
Here's the stack:
Exception in thread "main" java.lang.IllegalArgumentException
at java.nio.Buffer.limit(Buffer.java:275)
at org.capnproto.ArrayInputStream.read(ArrayInputStream.java:43)
at org.capnproto.BufferedInputStreamWrapper.readAtLeast(BufferedInputStreamWrapper.java:101)
at org.capnproto.BufferedInputStreamWrapper.getReadBuffer(BufferedInputStreamWrapper.java:83)
at org.capnproto.PackedInputStream.read(PackedInputStream.java:47)
at org.capnproto.Serialize.fillBuffer(Serialize.java:42)
at org.capnproto.Serialize.read(Serialize.java:56)
at org.capnproto.SerializePacked.readFromUnbuffered(SerializePacked.java:42)
at org.capnproto.SerializePacked.readFromUnbuffered(SerializePacked.java:36)
I encounter a error, but Cap'n Proto version is 0.4.1 latest. My computer is linux. Next is the error.
g++ compiler/src/main/cpp/capnpc-java.c++ -std=c++11 -pthread -I/home/work/logforward/capnproto/include -pthread -L/home/work/logforward/capnproto/lib -lcapnp -lkj -o capnpc-java
compiler/src/main/cpp/capnpc-java.c++:50:2: error: #error "This version of capnpc-java requires Cap'n Proto version 0.5 or higher."
#error "This version of capnpc-java requires Cap'n Proto version 0.5 or higher."
Greetings!
Thanks so much for taking this project on an all the work.
While experimenting with this I was wondering about the output format and the reasons for it. It seems that since you are generating the classes you could wrap some of the boilerplate in the generated code. For example, a cleaner end-user interface might be something like:
// Under the hood this does new MessageBuiilder and initRoot
AddressBook addressBook = new AddressBook();
// The People inner class wraps the generics
AddressBook.People people = addressBook.initPeople(2);
// Again, we wrap the generics
AddressBook.Person alice = people.get(0);
alice.setId(123);
alice.setName("Alice");
alice.setEmail("[email protected]");
AddressBook.Person.Phones alicePhones = alice.initPhones(1)
alicePhones.get(0).setNumber("555-1212");
...etc.
This would get rid of a lot of the messy generic boilerplate. Offhand, do you know of anything that would prevent it from being modified (i.e. by me) to do this?
Thanks,
-Andrew
What is the most efficient way to edit an existing message? Basically I want to set a few fields on an already built message, but it seems that I need the builder for that (as there are no set methods on the Reader).
Is there a basic concept what is best to use this? Thanks!
When building on Mac OS X (10.9.4), the current build system's use of pkg-config can fail to retrieve the capnp install path and break the build: https://gist.github.com/pwais/a1b20c2ba6010efb9f44
I had installed capnp from source/github using capnp's standard autotools-based build system (so to /usr/local).
To work around the capnproto-java compile issue, I simply added this to my .bash_login:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib
I'm not sure what a good fix for capnproto-java might be. Should the Makefile just look in /usr/local/ if pkg-config returns non-zero?
Hello.
I'm looking for a way to manipulate a deserialized message and serialize it back.
On C++ equivalent, there's MessageBuilder::setRoot()
for that purpose.
But in current Java implementation, I could't find anything like that.
Is there any alternative method for achieving that?
Hi @dwrensha
I've opened up a ticket to ask a question however if there is a better medium for asking please direct me.
I've been using capnproto-java to write multiple packed messages to a single file.
However part way through reading the file back I get the following error
java.nio.BufferOverflowException: null
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:206) ~[na:1.8.0_131]
at org.capnproto.PackedInputStream.read(PackedInputStream.java:114) ~[runtime-0.1.1.jar:0.1.1]
at org.capnproto.Serialize.fillBuffer(Serialize.java:42) ~[runtime-0.1.1.jar:0.1.1]
at org.capnproto.Serialize.read(Serialize.java:89) ~[runtime-0.1.1.jar:0.1.1]
at org.capnproto.SerializePacked.read(SerializePacked.java:32) ~[runtime-0.1.1.jar:0.1.1]
at org.capnproto.SerializePacked.read(SerializePacked.java:27) ~[runtime-0.1.1.jar:0.1.1]
The exception seems to occur at a very specific message in the file (13681638 message deep).
I was wondering if you had any hints on what I may be doing incorrectly.
I've attached a zip file that demonstrates the issue. Done with the last version (as of this issue).
Unzip the file, then follow the instructions in the ReadMe to compile and run the test.
Hi,
While experimenting with capnproto-java we faced the fact that it actually does not generate the import statements in java classes. This is not a problem when dealing with a trivial project having a single package, but in a multi-package java project, the generated classes won't compile.
Example:
Suppose those schema files:
'com/example/foo/foo.capnp' file:
@0xad8d23def0a030d1;
using Java = import "/java.capnp";
$Java.package("com.example.foo");
$Java.outerClassname("FooCapnp");
struct FooStruct
{
code @0 :Text;
}
and 'com/example/bar/bar.capnp' file:
@0x92a6d746aea85bb2;
using Java = import "/java.capnp";
using import "/com/example/foo/foo.capnp".FooStruct;
$Java.package("com.example.bar");
$Java.outerClassname("BarCapnp");
struct BarStruct
{
foo @0 :FooStruct;
}
Then BarCapnp.java do not contain the necessary import statement:
import com.example.foo.FooCapnp;
For your information, we are implementing a capnp-maven-plugin which provide compilation at build phase. It will be available shortly in github.
Thanks!
Does capnproto-java have support for checking equality and generating hash's on StructReader's? My application is currently using Protobuf, and I am currently investigating capnproto as a replacement. Protobuf generates equals and hash methods on its generated objects, and my application relies on those methods.
Is it possible for the compiler to generate equals and hash methods for its objects, as well as handling schema changes like how Protobuf handles it? Requiring the programmer to write the methods and remembering to update the equals and hash methods when the schema changes is bound to create problems.
Thanks.
It is possible to create a valid capnproto schema that will result in invalid generated Java code.
Example schema
@0xd9beba3d746ee890;
using Java = import "java.capnp";
$Java.package("com.amidvidy.test");
$Java.outerClassname("Test");
struct Test {
enum MyType {
foo @0;
bar @1;
}
myType :union {
none @0 :Void;
value @1 :MyType;
}
}
generated Java code has both an enum MyType
and a static class MyType
:
// many lines omitted
public enum MyType {
FOO,
BAR,
_NOT_IN_SCHEMA,
}
public static class MyType {
public static final org.capnproto.StructSize STRUCT_SIZE = new org.capnproto.StructSize((short)1,(short)0);
public static final class Factory extends org.capnproto.StructFactory<Builder, Reader> {
public Factory() {
}
// many lines omitted
Compilation yields an error as expected:
Test.java:63: error: enum MyType is already defined in class TestStruct
public static class MyType {
^
This is fairly easy to work around (just give the enum or union a different name) but it still seems like this should be fixed by namespacing the generated enums separately from the classes, or mangling their names somehow.
Hi
I have opened this to get org.capnproto so we can publish the jars
I've read about FlatBuffers C# port being slower than protobuf on their discussion group. Did anyone tested capnproto-java performance ?
Please let me know if there is a more appropriate place to post this question, I already looked for a google group, sorry! I believe both issues #40 and #42 touch on this but I'm still not sure how to construct a MessageBuilder
from a MessageReader
.
My use case is:
new MessageBuilder()
MessageBuilder
using Serialize.write()
MessageReader
using Serialize.read()
MyMessageClass
from MessageReader.getRoot(MyMessageClass.factory)
To accomplish step 5 right now I just have a really ugly CapnpUtil.builder()
method that constructs a new MessageBuilder
and manually copies over each known field from the MessageReader
. You hinted at MessageBuilder.setRoot()
but it is very unclear to me how to use this.
thanks for the excellent library :)
Could you make and publish the first release, please?
Currently using dependency "org.capnproto" % "runtime" % "0.1.0-SNAPSHOT" does not tie the client project into any specific version of capnp-java, and each client build might end up using a different capnp build.
I have the following struct:
struct NaMask {
union {
allZeroes @0 :Void; # every value is available
simpleBitMask @1 :List(Bool);
allOnes @2 :Void; # no value is available / empty
}
}
I can set it to allOnes:
scala> res2.setAllOnes(org.capnproto.Void.VOID)
scala> res2.which
res20: org.velvia.CapnColumn.NaMask.Which = ALL_ONES
I can initialize the member that is a List(Bool):
scala> res2.initSimpleBitMask(5)
res8: org.capnproto.PrimitiveList.Boolean.Builder = org.capnproto.PrimitiveList$Boolean$Builder@7f0c715e
scala> res8.set(1, true)
scala> res8.set(2, true)
However, I cannot set it:
scala> res2.setSimpleBitMask(res8)
<console>:14: error: type mismatch;
found : org.capnproto.PrimitiveList.Boolean.Builder
required: org.capnproto.PrimitiveList.Boolean.Reader
res2.setSimpleBitMask(res8)
^
How do I get a PrimitiveList.Boolean.Reader out of the Builder?
Also, you appear to be able to call set on the PrimitiveList.Boolean.Builder
on an index higher than the size, and no error or exception is thrown.
How get all fields from a capnproto dynamically ? Only kown capnproto filename and top level message struct. Thanks very much
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.