Skip to content

Commit

Permalink
Update capnp files from capnproto-c++-1.0.0 (#542)
Browse files Browse the repository at this point in the history
This copies the files found in the capnproto-c++-1.0.0 release,
overwriting the old copies in `std` in this repo.
  • Loading branch information
davidhubbard committed Aug 11, 2023
1 parent 1855ade commit 01cac8d
Show file tree
Hide file tree
Showing 11 changed files with 438 additions and 304 deletions.
27 changes: 12 additions & 15 deletions std/capnp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,21 @@ are actually legal go. However, this is not meant to be a
general-purpose solution; it is only intended to work for the base
schemas.

# Extra Annotations
# Footnote: annotations get an underscore in certain cases

Under certain circumstances, `capnpc-go` will sometimes generate illegal
go code. As an example, if two declarations `Foo` and `foo` exist in the
schema, `capnpc-go` will capitalize the latter so that it will be
exported, which will cause a name collision.
Under certain circumstances, `capnpc-go` will rename the identifier when it
generates go code. As an example, if two declarations `struct Foo` and
`annotation foo` exist in the schema, `capnpc-go` has to capitalize
`annotation foo` in the generated code. But that would not compile since
there is already a `Foo` from `struct Foo`.

To address this kind of issue, some of the schema have been manually
modified after importing, adding `$Go.name` annotations which prevent
these errors.
To address this kind of issue, `capnpc-go` will change the annotation to
`Foo_` (by adding the trailing "_"). This can be overridden on a
case-by-case basis if you need some other name. Just add `$Go.name`:

# Versions

The schemas checked in to this repository are those in capnproto commit
ad4079b (master at the time of writing). Unfortunately, the stable
release is *very* old, and some schemas out in the wild (notably
sandstorm) have started expecting more recent versions of the base
schemas.
```
annotation foo(struct, field) :Void $Go.name("fooAnnotation");
```

# Directory Structure

Expand Down
23 changes: 23 additions & 0 deletions std/capnp/c++.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ $namespace("capnp::annotations");

annotation namespace(file): Text;
annotation name(field, enumerant, struct, enum, interface, method, param, group, union): Text;

annotation allowCancellation(interface, method, file) :Void;
# Indicates that the server-side implementation of a method is allowed to be canceled when the
# client requests cancellation. Without this annotation, once a method call has been delivered to
# the server-side application code, any requests by the client to cancel it will be ignored, and
# the method will run to completion anyway. This applies even for local in-process calls.
#
# This behavior applies specifically to implementations that inherit from the C++ `Foo::Server`
# interface. The annotation won't affect DynamicCapability::Server implementations; they must set
# the cancellation mode at runtime.
#
# When applied to an interface rather than an individual method, the annotation applies to all
# methods in the interface. When applied to a file, it applies to all methods defined in the file.
#
# It's generally recommended that this annotation be applied to all methods. However, when doing
# so, it is important that the server implementation use cancellation-safe code. See:
#
# https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#cancellation
#
# If your code is not cancellation-safe, then allowing cancellation might give a malicious client
# an easy way to induce use-after-free or other bugs in your server, by requesting cancellation
# when not expected.

using Go = import "/go.capnp";
$Go.package("cxx");
$Go.import("capnproto.org/go/capnp/v3/std/capnp/cxx");
13 changes: 13 additions & 0 deletions std/capnp/compat/json.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ struct Value {
# "binary" and "date" types in text, since JSON has no analog of these. This is basically the
# reason this extension exists. We do NOT recommend using `call` unless you specifically need
# to be compatible with some silly format that uses this syntax.

raw @7 :Text;
# Used to indicate that the text should be written directly to the output without
# modifications. Use this if you have an already serialized JSON value and don't want
# to feel the cost of deserializing the value just to serialize it again.
#
# The parser will never produce a `raw` value -- this is only useful for serialization.
#
# WARNING: You MUST ensure that the value is valid stand-alone JSOn. It will not be verified.
# Invalid JSON could mjake the whole message unparsable. Worse, a malicious raw value could
# perform JSON injection attacks. Make sure that the value was produced by a trustworthy JSON
# encoder.
}

struct Field {
Expand Down Expand Up @@ -113,6 +125,7 @@ annotation hex @0xf061e22f0ae5c7b5 (field) :Void;

annotation notification @0xa0a054dea32fd98c (method) :Void;
# Indicates that this method is a JSON-RPC "notification", meaning it expects no response.

using Go = import "/go.capnp";
$Go.package("json");
$Go.import("capnproto.org/go/capnp/v3/std/capnp/json");
139 changes: 84 additions & 55 deletions std/capnp/compat/json/json.capnp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 14 additions & 9 deletions std/capnp/cxx/c++.capnp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions std/capnp/persistent.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ annotation persistent(interface, field) :Void;
#
# Note that absence of the $persistent annotation doesn't mean a capability of that type isn't
# persistent; it just means not *all* such capabilities are persistent.

using Go = import "/go.capnp";
$Go.package("persistent");
$Go.import("capnproto.org/go/capnp/v3/std/capnp/persistent");
4 changes: 1 addition & 3 deletions std/capnp/rpc-twoparty.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,8 @@ struct JoinResult {
# implements the join by waiting for all the `JoinKeyParts` and then performing its own join on
# them, then going back and answering all the join requests afterwards.

cap @2 :AnyPointer;
cap @2 :Capability;
# One of the JoinResults will have a non-null `cap` which is the joined capability.
#
# TODO(cleanup): Change `AnyPointer` to `Capability` when that is supported.
}
using Go = import "/go.capnp";
$Go.package("rpctwoparty");
Expand Down

0 comments on commit 01cac8d

Please sign in to comment.