annotate src/capnproto-0.6.0/c++/samples/calculator.capnp @ 84:08ae793730bd

Add null config files
author Chris Cannam
date Mon, 02 Mar 2020 14:03:47 +0000
parents 0994c39f1e94
children
rev   line source
cannam@62 1 # Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
cannam@62 2 # Licensed under the MIT License:
cannam@62 3 #
cannam@62 4 # Permission is hereby granted, free of charge, to any person obtaining a copy
cannam@62 5 # of this software and associated documentation files (the "Software"), to deal
cannam@62 6 # in the Software without restriction, including without limitation the rights
cannam@62 7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
cannam@62 8 # copies of the Software, and to permit persons to whom the Software is
cannam@62 9 # furnished to do so, subject to the following conditions:
cannam@62 10 #
cannam@62 11 # The above copyright notice and this permission notice shall be included in
cannam@62 12 # all copies or substantial portions of the Software.
cannam@62 13 #
cannam@62 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
cannam@62 15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
cannam@62 16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
cannam@62 17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
cannam@62 18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
cannam@62 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
cannam@62 20 # THE SOFTWARE.
cannam@62 21
cannam@62 22 @0x85150b117366d14b;
cannam@62 23
cannam@62 24 interface Calculator {
cannam@62 25 # A "simple" mathematical calculator, callable via RPC.
cannam@62 26 #
cannam@62 27 # But, to show off Cap'n Proto, we add some twists:
cannam@62 28 #
cannam@62 29 # - You can use the result from one call as the input to the next
cannam@62 30 # without a network round trip. To accomplish this, evaluate()
cannam@62 31 # returns a `Value` object wrapping the actual numeric value.
cannam@62 32 # This object may be used in a subsequent expression. With
cannam@62 33 # promise pipelining, the Value can actually be used before
cannam@62 34 # the evaluate() call that creates it returns!
cannam@62 35 #
cannam@62 36 # - You can define new functions, and then call them. This again
cannam@62 37 # shows off pipelining, but it also gives the client the
cannam@62 38 # opportunity to define a function on the client side and have
cannam@62 39 # the server call back to it.
cannam@62 40 #
cannam@62 41 # - The basic arithmetic operators are exposed as Functions, and
cannam@62 42 # you have to call getOperator() to obtain them from the server.
cannam@62 43 # This again demonstrates pipelining -- using getOperator() to
cannam@62 44 # get each operator and then using them in evaluate() still
cannam@62 45 # only takes one network round trip.
cannam@62 46
cannam@62 47 evaluate @0 (expression :Expression) -> (value :Value);
cannam@62 48 # Evaluate the given expression and return the result. The
cannam@62 49 # result is returned wrapped in a Value interface so that you
cannam@62 50 # may pass it back to the server in a pipelined request. To
cannam@62 51 # actually get the numeric value, you must call read() on the
cannam@62 52 # Value -- but again, this can be pipelined so that it incurs
cannam@62 53 # no additional latency.
cannam@62 54
cannam@62 55 struct Expression {
cannam@62 56 # A numeric expression.
cannam@62 57
cannam@62 58 union {
cannam@62 59 literal @0 :Float64;
cannam@62 60 # A literal numeric value.
cannam@62 61
cannam@62 62 previousResult @1 :Value;
cannam@62 63 # A value that was (or, will be) returned by a previous
cannam@62 64 # evaluate().
cannam@62 65
cannam@62 66 parameter @2 :UInt32;
cannam@62 67 # A parameter to the function (only valid in function bodies;
cannam@62 68 # see defFunction).
cannam@62 69
cannam@62 70 call :group {
cannam@62 71 # Call a function on a list of parameters.
cannam@62 72 function @3 :Function;
cannam@62 73 params @4 :List(Expression);
cannam@62 74 }
cannam@62 75 }
cannam@62 76 }
cannam@62 77
cannam@62 78 interface Value {
cannam@62 79 # Wraps a numeric value in an RPC object. This allows the value
cannam@62 80 # to be used in subsequent evaluate() requests without the client
cannam@62 81 # waiting for the evaluate() that returns the Value to finish.
cannam@62 82
cannam@62 83 read @0 () -> (value :Float64);
cannam@62 84 # Read back the raw numeric value.
cannam@62 85 }
cannam@62 86
cannam@62 87 defFunction @1 (paramCount :Int32, body :Expression)
cannam@62 88 -> (func :Function);
cannam@62 89 # Define a function that takes `paramCount` parameters and returns the
cannam@62 90 # evaluation of `body` after substituting these parameters.
cannam@62 91
cannam@62 92 interface Function {
cannam@62 93 # An algebraic function. Can be called directly, or can be used inside
cannam@62 94 # an Expression.
cannam@62 95 #
cannam@62 96 # A client can create a Function that runs on the server side using
cannam@62 97 # `defFunction()` or `getOperator()`. Alternatively, a client can
cannam@62 98 # implement a Function on the client side and the server will call back
cannam@62 99 # to it. However, a function defined on the client side will require a
cannam@62 100 # network round trip whenever the server needs to call it, whereas
cannam@62 101 # functions defined on the server and then passed back to it are called
cannam@62 102 # locally.
cannam@62 103
cannam@62 104 call @0 (params :List(Float64)) -> (value :Float64);
cannam@62 105 # Call the function on the given parameters.
cannam@62 106 }
cannam@62 107
cannam@62 108 getOperator @2 (op :Operator) -> (func :Function);
cannam@62 109 # Get a Function representing an arithmetic operator, which can then be
cannam@62 110 # used in Expressions.
cannam@62 111
cannam@62 112 enum Operator {
cannam@62 113 add @0;
cannam@62 114 subtract @1;
cannam@62 115 multiply @2;
cannam@62 116 divide @3;
cannam@62 117 }
cannam@62 118 }