-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generate AnyStruct and AnyList #94
Open
vaci
wants to merge
1
commit into
capnproto:master
Choose a base branch
from
vaci:any-others
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors | ||
// Licensed under the MIT License: | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package org.capnproto; | ||
|
||
public final class AnyList { | ||
|
||
public static final class Factory extends ListFactory<Builder, Reader> { | ||
Factory() { | ||
super(ElementSize.VOID); | ||
} | ||
|
||
public final Reader asReader(Builder builder) { | ||
return builder.asReader(); | ||
} | ||
|
||
@Override | ||
public Builder constructBuilder(SegmentBuilder segment, int ptr, int elementCount, int step, int structDataSize, short structPointerCount) { | ||
return new Builder(segment, ptr, elementCount, step, structDataSize, structPointerCount); | ||
} | ||
|
||
@Override | ||
public Reader constructReader(SegmentReader segment, int ptr, int elementCount, int step, int structDataSize, short structPointerCount, int nestingLimit) { | ||
return new Reader(segment, ptr, elementCount, step, structDataSize, structPointerCount, nestingLimit); | ||
} | ||
} | ||
|
||
public static final Factory factory = new Factory(); | ||
|
||
public static final ListList.Factory<Builder,Reader> listFactory = new ListList.Factory<>(factory); | ||
|
||
public static final class Builder extends ListBuilder { | ||
Builder(SegmentBuilder segment, int ptr, int elementCount, int step, int structDataSize, short structPointerCount) { | ||
super(segment, ptr, elementCount, step, structDataSize, structPointerCount); | ||
} | ||
|
||
public final Reader asReader() { | ||
return new Reader(this.segment, this.ptr, this.elementCount, this.step, this.structDataSize, this.structPointerCount, 0x7fffffff); | ||
} | ||
|
||
public final <T> T initAs(Factory<T> factory) { | ||
return factory.constructBuilder(this.segment, this.ptr, this.elementCount, this.step, this.structDataSize, this.structPointerCount); | ||
} | ||
|
||
public final <T> T setAs(Factory<T> factory) { | ||
return factory.constructBuilder(this.segment, this.ptr, this.elementCount, this.step, this.structDataSize, this.structPointerCount); | ||
} | ||
} | ||
|
||
public static final class Reader extends ListReader { | ||
Reader(SegmentReader segment, int ptr, int elementCount, int step, int structDataSize, short structPointerCount, int nestingLimit) { | ||
super(segment, ptr, elementCount, step, structDataSize, structPointerCount, nestingLimit); | ||
} | ||
|
||
public final <T> T getAs(Factory<T> factory) { | ||
return factory.constructReader(this.segment, this.ptr, this.elementCount, this.step, this.structDataSize, this.structPointerCount, this.nestingLimit); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors | ||
// Licensed under the MIT License: | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package org.capnproto; | ||
|
||
public final class AnyStruct { | ||
|
||
public static final StructSize STRUCT_SIZE = new StructSize((short)0,(short)0); | ||
|
||
public static final class Factory extends StructFactory<Builder, Reader> { | ||
public Factory() { | ||
} | ||
|
||
public final Reader constructReader(SegmentReader segment, int data,int pointers, int dataSize, short pointerCount, int nestingLimit) { | ||
return new Reader(segment, data, pointers, dataSize, pointerCount, nestingLimit); | ||
} | ||
|
||
public final Builder constructBuilder(SegmentBuilder segment, int data,int pointers, int dataSize, short pointerCount) { | ||
return new Builder(segment, data, pointers, dataSize, pointerCount); | ||
} | ||
|
||
public final StructSize structSize() { | ||
return AnyStruct.STRUCT_SIZE; | ||
} | ||
|
||
public final Reader asReader(Builder builder) { | ||
return builder.asReader(); | ||
} | ||
} | ||
|
||
public static final Factory factory = new Factory(); | ||
|
||
public static final StructList.Factory<Builder, Reader> listFactory = | ||
new StructList.Factory<>(factory); | ||
|
||
public static final class Builder extends StructBuilder { | ||
Builder(SegmentBuilder segment, int data, int pointers,int dataSize, short pointerCount){ | ||
super(segment, data, pointers, dataSize, pointerCount); | ||
} | ||
|
||
public final Reader asReader() { | ||
return new Reader(segment, data, pointers, dataSize, pointerCount, 0x7fffffff); | ||
} | ||
|
||
public final <T> T initAs(StructBuilder.Factory<T> factory) { | ||
return factory.constructBuilder(this.segment, this.data, this.pointers, this.dataSize, this.pointerCount); | ||
} | ||
|
||
public final <T> T setAs(StructBuilder.Factory<T> factory) { | ||
return factory.constructBuilder(this.segment, this.data, this.pointers, this.dataSize, this.pointerCount); | ||
} | ||
} | ||
|
||
public static final class Reader extends StructReader { | ||
Reader(SegmentReader segment, int data, int pointers,int dataSize, short pointerCount, int nestingLimit){ | ||
super(segment, data, pointers, dataSize, pointerCount, nestingLimit); | ||
} | ||
|
||
public final <T> T getAs(StructReader.Factory<T> factory) { | ||
return factory.constructReader(this.segment, this.data, this.pointers, this.dataSize, this.pointerCount, this.nestingLimit); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this end up giving a wrong value for the
expectedElementSize
parameter ofWireHelpers.readListPointer()
? Maybe we need to add acheckElementSize
parameter, like in capnproto-c++? https://github.com/capnproto/capnproto/blob/master/c%2B%2B/src/capnp/layout.c%2B%2B#L2237There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That probably explains why my round-trip test for AnyList fails!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I right in thinking that the actual element size has to be written out when initListPointer is called?
In that case, I think I need to allow the user to pass the appropriate factory to the generated accessor when initiialising the list for building.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree. For a field
I think we should generate a method like
public <B> B initFooAs(ListFactory<B, ?> factory, int size)
.(capnproto-c++ does something similar)