-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imbue builders and readers with cap tables
- Loading branch information
Showing
26 changed files
with
578 additions
and
138 deletions.
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,16 @@ | ||
package org.capnproto; | ||
|
||
public interface CapTableBuilder extends CapTableReader { | ||
|
||
class BuilderContext { | ||
public CapTableBuilder capTable; | ||
} | ||
|
||
int injectCap(ClientHook cap); | ||
|
||
void dropCap(int index); | ||
|
||
default ClientHook[] getTable() { | ||
return new ClientHook[0]; | ||
} | ||
} |
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,10 @@ | ||
package org.capnproto; | ||
|
||
public interface CapTableReader { | ||
|
||
class ReaderContext { | ||
public CapTableReader capTable; | ||
} | ||
|
||
ClientHook extractCap(int index); | ||
} |
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,32 @@ | ||
package org.capnproto; | ||
|
||
import static org.capnproto.ClientHook.BROKEN_CAPABILITY_BRAND; | ||
import static org.capnproto.ClientHook.NULL_CAPABILITY_BRAND; | ||
|
||
public final class Capability { | ||
|
||
public static ClientHook newBrokenCap(String reason) { | ||
return newBrokenClient(reason, false, BROKEN_CAPABILITY_BRAND); | ||
} | ||
|
||
public static ClientHook newBrokenCap(Throwable exc) { | ||
return newBrokenClient(exc, false, BROKEN_CAPABILITY_BRAND); | ||
} | ||
|
||
public static ClientHook newNullCap() { | ||
return newBrokenClient(RpcException.failed("Called null capability"), true, NULL_CAPABILITY_BRAND); | ||
} | ||
|
||
private static ClientHook newBrokenClient(String reason, boolean resolved, Object brand) { | ||
return newBrokenClient(RpcException.failed(reason), resolved, brand); | ||
} | ||
|
||
private static ClientHook newBrokenClient(Throwable exc, boolean resolved, Object brand) { | ||
return new ClientHook() { | ||
@Override | ||
public Object getBrand() { | ||
return brand; | ||
} | ||
}; | ||
} | ||
} |
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,29 @@ | ||
package org.capnproto; | ||
|
||
public interface ClientHook { | ||
|
||
static final Object NULL_CAPABILITY_BRAND = new Object(); | ||
static final Object BROKEN_CAPABILITY_BRAND = new Object(); | ||
|
||
/** | ||
Returns an opaque object that identifies who made this client. This can be used by an RPC adapter to | ||
discover when a capability it needs to marshal is one that it created in the first place, and | ||
therefore it can transfer the capability without proxying. | ||
*/ | ||
Object getBrand(); | ||
|
||
/** | ||
* Returns true if the capability was created as a result of assigning a Client to null or by | ||
* reading a null pointer out of a Cap'n Proto message. | ||
*/ | ||
default boolean isNull() { | ||
return getBrand() == NULL_CAPABILITY_BRAND; | ||
} | ||
|
||
/** | ||
* Returns true if the capability was created by newBrokenCap(). | ||
*/ | ||
default boolean isError() { | ||
return getBrand() == BROKEN_CAPABILITY_BRAND; | ||
} | ||
} |
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
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
Oops, something went wrong.