Messaging#

A client and the server exchange Protocol Buffers messages. The file krpc.proto defines them. This page describes the messages and what they mean. The client specification states the precise behavior of a client, such as how it handles a refused connection or a failed one.

Messages#

Every message sent to or from the server is a Message, which holds one of the following:

message Message {
  oneof content {
    Request request = 1;
    Response response = 2;
    StreamUpdate stream_update = 3;
    ConnectionRequest connection_request = 4;
    ConnectionResponse connection_response = 5;
    Disconnect disconnect = 6;
  }
}

A client sends request, connection_request and disconnect messages, and the server sends response, stream_update, connection_response and disconnect messages.

Each protocol frames the messages in its own way, as its page describes. For example, TCP/IP sends the length of each encoded message as a varint, followed by the message bytes.

Connection Handshake#

A client connects by sending a connection_request as its first Message, and reading the server’s connection_response. The following Python code connects over TCP/IP:

# Send a connection request
message = KRPC.Message()
message.connection_request.protocol_version = 2
message.connection_request.client_name = "Example"
send_message(conn, message)

# Receive the connection response
response = recv_message(conn).connection_response

# Check the connection was successful
if response.status != KRPC.ConnectionResponse.OK:
    raise RuntimeError("Connection failed: " + response.message)
if response.protocol_version != 2:
    raise RuntimeError("The server does not support protocol version 2")
print("Connected to the server")

The two messages are:

message ConnectionRequest {
  reserved 1, 3;
  string client_name = 2;
  uint32 protocol_version = 4;
}

message ConnectionResponse {
  Status status = 1;
  enum Status {
    reserved 3;
    OK = 0;
    MALFORMED_MESSAGE = 1;
    TIMEOUT = 2;
    WRONG_PROTOCOL_VERSION = 4;
    DENIED = 5;
  }
  string message = 2;
  bytes client_identifier = 3;
  uint32 protocol_version = 4;
}

Set protocol_version to 2. The client_name field can be set to the name of the client to display on the in-game UI. The connection_response holds one of the following statuses:

Status

Meaning

OK

The connection is established.

MALFORMED_MESSAGE

The first message failed to parse, or was not a connection_request.

TIMEOUT

The connection_request did not arrive in time.

WRONG_PROTOCOL_VERSION

The server does not support the protocol version. See Protocol Version.

DENIED

The player, or a mod, denied the connection.

The message field describes a refusal. On success, protocol_version holds the version the server accepted, and client_identifier holds 16 bytes identifying the client. The identifier is the value that procedure KRPC.GetClientID returns.

The client specification states how a client connects, and how it reports a refused connection. See Connection.

Disconnecting#

Either side ends a connection by sending a disconnect:

message Disconnect {
  Reason reason = 1;
  string message = 2;
  enum Reason {
    CLOSED = 0;
    SERVER_STOPPED = 1;
    REMOVED = 2;
    MALFORMED_MESSAGE = 3;
    PROTOCOL_ERROR = 4;
    TIMEOUT = 5;
  }
}

The reasons are:

Reason

Sent when

CLOSED

The client closes the connection.

SERVER_STOPPED

The server stops.

REMOVED

The player removes the client from the server window.

MALFORMED_MESSAGE

A message fails to parse.

PROTOCOL_ERROR

A message arrives in the wrong direction, or a response carries an id that matches no waiting or abandoned request.

TIMEOUT

A message stops arriving partway.

The reason and the message field are informational. The following Python code closes a connection over TCP/IP:

# End the connection with a disconnect, then close the write side
disconnect = KRPC.Disconnect(reason=KRPC.Disconnect.CLOSED)
send_message(conn, KRPC.Message(disconnect=disconnect))
conn.shutdown(socket.SHUT_WR)

# Discard anything still arriving until the server closes its side, or a
# second passes with nothing
conn.settimeout(1)
try:
    while conn.recv(4096):
        pass
except TimeoutError:
    pass
conn.close()

The client specification states the closing sequence, and how a client handles a connection that ends. See Connection.

Invoking Remote Procedures#

Remote procedures are grouped into services. Each service has a unique name, and each procedure has a unique name within its service.

A client sends a Request holding one or more procedure calls. The server replies with a Response holding each call’s return value or error.

Each request carries an id, which the server copies onto the response to it. The procedure calls in a request run in order, and the results in the response are in the same order as the calls. The client specification states how a client numbers and matches requests. See Calls.

A client may send requests without waiting for the responses to earlier ones. The server runs a client’s requests one at a time, in the order they were sent, so their responses arrive in that order too. A call that waits on the game holds up the requests behind it. The server reads up to 16 requests ahead, and leaves the rest to the transport’s flow control, which holds the client’s writes until the server catches up.

A client must also read what the server sends. The server ends the connection of a client that leaves more than 16 MB of responses and stream updates unread.

Anatomy of a Request#

A request is a Request message:

message Request {
  uint64 id = 2;
  repeated ProcedureCall calls = 1;
}

message ProcedureCall {
  string service = 1;
  string procedure = 2;
  uint32 service_id = 4;
  uint32 procedure_id = 5;
  repeated Argument arguments = 3;
}

message Argument {
  uint32 position = 1;
  bytes value = 2;
  bool is_null = 3;
}

The fields of a procedure call are:

  • service - The name of the service that defines the procedure.

  • procedure - The name of the procedure.

  • service_id - The integer identifier of the service that defines the procedure.

  • procedure_id - The integer identifier of the procedure.

  • arguments - A list of Argument messages holding the values of the procedure’s arguments. The fields of an argument are:

    • position - The zero-indexed position of the argument in the procedure’s signature.

    • value - The value of the argument, encoded according to the parameter’s type. Ignored when is_null is set.

    • is_null - Whether the argument’s value is null. When set, value is unset. Only permitted for parameters that accept null. See why null has a flag of its own.

A call names its service with service or service_id, and its procedure with procedure or procedure_id. The integer identifiers make both the messages and the client code smaller, which suits a client on a microcontroller.

An identifier is the first 4 bytes of the SHA-256 hash of the UTF-8 name, read as a little-endian integer. The procedure name is the one the request carries, e.g. Vessel_get_Name. An identifier is as stable as the name it comes from.

A service or procedure can also set its identifier by hand, to resolve a clash. GetServices reports every identifier, hashed or set by hand. Service identifiers 1 to 255 are reserved for the services that ship with kRPC, which keeps them short on the wire.

The classes, enumerations, structures and exceptions of a service have identifiers by the same rule, from the type’s name. They share one identifier space per service, apart from the procedures. An error and a Type message carry the identifiers next to the names.

A parameter can have a default value, listed in the procedure’s description. A call can leave out the Argument for such a parameter, and the procedure runs with the default. The position field says which parameter each of the remaining arguments is for.

Anatomy of a Response#

A response is a Response message:

message Response {
  uint64 id = 3;
  Error error = 1;
  repeated ProcedureResult results = 2;
}

message ProcedureResult {
  Error error = 1;
  bytes value = 2;
  bool is_null = 3;
}

message Error {
  string service = 1;
  string exception = 2;
  uint32 service_id = 5;
  uint32 exception_id = 6;
  string description = 3;
  string stack_trace = 4;
}

A response holds the id of the request it answers, and one result per call. The value field of a result holds the procedure’s return value, encoded according to its return type.

The is_null field marks a null return value. When it is set, value is unset. It is only set for procedures whose return value is nullable. See null values.

A call that fails sets the error field of its result. This includes a call with an argument the server cannot decode, an argument position past the procedure’s last parameter, or two arguments at one position. The other calls in the request still run. A request that fails as a whole sets the error field of the response, and the response holds no results.

The fields of an error are:

  • service - The service that defines the exception type, when the error is one of the exceptions a service lists. Empty otherwise.

  • exception - The name of that exception type. Empty otherwise.

  • service_id - The identifier of that service. 0 otherwise.

  • exception_id - The identifier of that exception type. 0 otherwise.

  • description - A description of the error.

  • stack_trace - The stack trace on the server. Empty unless the server’s verbose errors setting is on.

Example Invocation#

The following Python code invokes KRPC.GetStatus over an open connection conn:

# Invoke the KRPC.GetStatus RPC, in a request with the id 1
message = KRPC.Message()
message.request.id = 1
call = message.request.calls.add()
call.service = "KRPC"
call.procedure = "GetStatus"
send_message(conn, message)

# Receive the response, which carries the id of the request it answers
response = recv_message(conn).response
assert response.id == 1

# Check for an error in the response
if response.HasField("error"):
    raise RuntimeError("ERROR: " + str(response.error))

# Check for an error in the results
assert len(response.results) == 1
if response.results[0].HasField("error"):
    raise RuntimeError("ERROR: " + str(response.results[0].error))

# Decode the return value, a ServerStatus structure sent as a Tuple of its
# fields
status = KRPC.Tuple.FromString(response.results[0].value)

# Print out the server version, the first field
print(decode_string(status.items[0]))

KRPC is the module the Protocol Buffers compiler generates from krpc.proto, imported from krpc.schema.KRPC_pb2. The send_message and recv_message helpers are defined earlier in the script, shown under TCP/IP.

Protocol Buffers Encoding#

An argument or a return value is encoded according to its type, using the Protocol Buffers encoding of a single value with no field tag:

Type code

Encoding

DOUBLE, FLOAT

Little-endian IEEE 754, in 8 and 4 bytes.

SINT32, SINT64

A zigzag encoded varint.

UINT32, UINT64, BOOL

A varint.

STRING

The length of its UTF-8 bytes as a varint, then the bytes.

BYTES

The length as a varint, then the bytes.

ENUMERATION

The value, encoded as a SINT32.

CLASS

The object’s identifier, encoded as a UINT64. See Proxy Objects.

STREAM, EVENT

The stream’s identifier, encoded as a UINT64. See Streams.

STRUCT

A Tuple message. See Structures.

TUPLE, LIST, SET, DICTIONARY

The Tuple, List, Set or Dictionary message, with each item encoded according to its own type.

PROCEDURE_CALL, SERVICES

The serialized message of the same name.

An argument’s encoding fills its bytes exactly. The call fails with an error if:

  • Bytes are left over after a value, or a value is cut short.

  • A TUPLE, LIST, SET, DICTIONARY or STRUCT message holds an unknown field.

  • A SINT32, UINT32 or ENUMERATION value is out of its 32-bit range.

  • An ENUMERATION value is one the enumeration does not declare. For a flags enumeration, it is a value holding a bit outside the union of the values the enumeration declares.

  • A BOOL value is not 0 or 1.

  • A TUPLE has the wrong number of items.

Null Values#

The is_null field on the Argument or ProcedureResult message marks a null value of any type. When it is set, the value field is unset.

A separate flag lets every type carry null in the same way. A zero-length value cannot stand for null, as it is already the encoding of an empty collection. Reserving a value of each type for null would take that value away from the type.

A value nested inside another value has no flag of its own. A nullable list element, tuple item, dictionary value or structure field carries a presence bool before its value instead. For example, a LIST of nullable SINT32 holding 42 and null:

List.items[0] = 01 54         present, then the SINT32 42
List.items[1] = 00            null

The bool is one byte, encoded as a BOOL value. The value’s encoding follows it when the bool is true. A position that is not nullable is encoded as its value alone, and a null in one is an error.

Streams#

A stream runs a remote procedure on every update, and sends its result to the client. The client receives the values without a call for each one.

AddStream adds a stream of a remote procedure, and AddFunctionStream adds a stream of a server side function. Both return a STREAM value, which is the stream’s identifier as a UINT64. An event is also a stream.

Each stream belongs to the client that created it. RemoveStream removes a stream, and the server removes a client’s streams when the client disconnects. Removing a stream, or setting its rate, does nothing once the stream has ended. An identifier the server never issued is an error.

A stream runs on every physics tick, unless SetStreamRate gives it a lower target rate. The results of a tick’s streams are sent in one stream_update. A stream’s first result is sent in the update after it is added. A later result that has not changed since the last update is left out.

The client specification states how a client delivers stream values, and how updates are ordered relative to responses. See Streams.

Anatomy of a Stream Update#

A stream update is a StreamUpdate message:

message StreamUpdate {
  repeated StreamResult results = 1;
}

A StreamUpdate holds one StreamResult for each of the client’s streams whose result changed:

message StreamResult {
  uint64 id = 1;
  ProcedureResult result = 2;
}

The fields are:

  • id - The identifier of the stream, from the STREAM or EVENT value that added it.

  • result - The result of the stream’s procedure, as the same ProcedureResult a call to it returns. See Anatomy of a Response.

A result with its error field set is the last result for that stream. See streams-error-ends-the-stream in the client specification.

Events#

An event is a stream of a bool, and fires when the stream’s value is true. An event is created by AddEvent, or by another procedure with an event return type. The procedure returns an EVENT value, which is the identifier of the event’s stream as a UINT64. After its first value, the stream holds only firings, as the server sends a value only when the event fires.

KRPC Service#

The server provides a core service called KRPC. Its procedures give clients the basic functionality they build on: the definitions of the server’s services, and streams and server side functions. A client library calls these procedures for the program using it. They are described below.

The service also has members for programs to use directly, such as the GetStatus and HoldTick procedures and the GameScene, Paused and Clients properties. A program calls them through its client library, like the members of any other service. They are listed in each client’s API reference, such as the Python one.

GetServices#

The GetServices procedure describes every service the server provides. A client can use it to introspect the services, as the Python and Lua clients do to build their API when they connect. It returns a Services message, described under Service Description Message.

AddStream#

The AddStream procedure adds a stream of a remote procedure. Its argument is the call, as a ProcedureCall message. See Anatomy of a Request. It returns the stream’s identifier, described under Streams.

A procedure with no return value runs on each update for its effects. Its first run sends a result with an empty value. Later runs send nothing, unless an error ends the stream.

AddFunctionStream#

The AddFunctionStream procedure adds a stream that evaluates a server side function on each update. Its argument is the function, built using the KRPC.Expression class.

The procedure returns the stream’s identifier. The stream’s values have the type given by the function’s ReturnType property. The function must take no parameters. Any exception from the function ends the stream with that error. A function with no value runs for its effects, and sends results as a procedure with no return value does.

AddEvent#

The AddEvent procedure adds an event that fires when a server side function evaluates to true. Its argument is the function, built using the KRPC.Expression class. The function must take no parameters and return a bool.

The procedure returns the identifier of the event’s stream. The function is evaluated on each stream update, and the event fires on every update it returns true. Any exception from the function ends the event’s stream with that error.

RunFunction#

The RunFunction procedure evaluates a server side function once, within a single physics tick. Its first argument is the function, built using the KRPC.Expression class.

The second argument is a list of the function’s arguments, one per parameter of a function built with Expression.Lambda. Each is encoded according to the type given by the function’s ParameterTypes property, and is null for a null value. A function that is not a lambda takes no arguments, and the list defaults to empty.

The result is a bytes value, holding the function’s value encoded according to its ReturnType. A null value sets is_null. A function with no value returns empty bytes, which HasReturnType tells apart from an empty collection.

The client specification states how a client builds and runs functions. See Server Side Functions.

CompileFunction#

The CompileFunction procedure compiles a server side function in advance, and returns nothing. This keeps the compile time of a large function out of its first run.

SetStreamRate#

The SetStreamRate procedure sets the target update rate of a stream, in hertz. Its arguments are the identifier of the stream and the rate, as a float. A rate of zero, the default, updates the stream on every physics tick.

RemoveStream#

The RemoveStream procedure removes a stream. Its argument is the stream’s identifier, from AddStream, AddFunctionStream or an EVENT value.

Service Description Message#

The GetServices procedure returns a Services message, holding a Service message for each service the server provides:

message Services {
  repeated Service services = 1;
}

message Service {
  string name = 1;
  uint32 id = 10;
  repeated Procedure procedures = 2;
  repeated Class classes = 3;
  repeated Enumeration enumerations = 4;
  repeated Struct structs = 9;
  repeated Exception exceptions = 5;
  string documentation = 6;
  bool deprecated = 7;
  string deprecated_reason = 8;
}

The fields of a Service are:

  • name - The name of the service.

  • id - The identifier of the service, for the service_id field of a call.

  • procedures - A list of Procedure messages, one for each procedure defined by the service.

  • classes - A list of Class messages, one for each KRPCClass defined by the service.

  • enumerations - A list of Enumeration messages, one for each KRPCEnum defined by the service.

  • structs - A list of Struct messages, one for each KRPCStruct defined by the service.

  • exceptions - A list of Exception messages, one for each KRPCException defined by the service.

  • documentation - Documentation for the service.

  • deprecated - Whether the service is deprecated.

  • deprecated_reason - The reason for the deprecation.

The documentation field of each description message holds C# XML documentation, with the markup described under Documentation. A member marked deprecated still works, and its deprecated_reason may be empty.

Procedures#

Details about a procedure are given by a Procedure message, with the format:

message Procedure {
  string name = 1;
  uint32 id = 9;
  repeated Parameter parameters = 2;
  Type return_type = 3;
  repeated GameScene game_scenes = 6;
  string documentation = 5;
  bool deprecated = 7;
  string deprecated_reason = 8;
}
message Parameter {
  string name = 1;
  Type type = 2;
  bool has_default_value = 5;
  bytes default_value = 3;
  bool default_value_is_null = 6;
}

The fields are:

  • name - The name of the procedure. See Procedure Names for more information.

  • id - The identifier of the procedure, for the procedure_id field of a call.

  • parameters - A list of Parameter messages containing details of the procedure’s parameters, with the following fields:

    • name - The name of the parameter, to allow parameter passing by name.

    • type - The type of the parameter. Its nullable field says whether null can be passed as the argument for this parameter.

    • has_default_value - Whether the parameter has a default value. When it is not set, the parameter is required and default_value and default_value_is_null are unset.

    • default_value - The default value of the parameter, encoded according to the parameter’s type. Set only when has_default_value is set and default_value_is_null is not. A zero-length value is a valid default, for example an empty collection.

    • default_value_is_null - Whether the default value is null. Set only when has_default_value is set, in which case default_value is unset.

    The presence and nullability of the default value are given by these three fields as follows:

    Default value

    has_default_value

    default_value_is_null

    default_value

    none (required parameter)

    unset

    unset

    unset

    a value (including an empty collection)

    set

    unset

    encoded bytes (may be zero-length)

    null

    set

    set

    unset

  • return_type - The return type of the procedure. If the procedure does not return anything the field is unset, so its code reads as NONE. Its nullable field says whether the procedure can return null.

  • game_scenes - The game scenes that the procedure is available in. If this repeated field is empty, the procedure is available in all game scenes.

  • documentation - Documentation for the procedure.

  • deprecated - Whether the procedure is deprecated.

  • deprecated_reason - The reason for the deprecation.

  • internal - Whether the procedure is for client libraries only, which call it to implement streams, events and server side functions. The services a client library exposes leave it out.

Classes#

Details about each KRPCClass are specified in a Class message, with the format:

message Class {
  string name = 1;
  uint32 id = 5;
  string documentation = 2;
  bool deprecated = 3;
  string deprecated_reason = 4;
}

The fields are:

  • name - The name of the class.

  • id - The identifier of the class.

  • documentation - Documentation for the class.

  • deprecated - Whether the class is deprecated.

  • deprecated_reason - The reason for the deprecation.

Enumerations#

Details about each KRPCEnum are specified in an Enumeration message, with the format:

message Enumeration {
  string name = 1;
  uint32 id = 7;
  repeated EnumerationValue values = 2;
  string documentation = 3;
  bool deprecated = 4;
  string deprecated_reason = 5;
  bool flags = 6;
}

message EnumerationValue {
  string name = 1;
  int32 value = 2;
  string documentation = 3;
  bool deprecated = 4;
  string deprecated_reason = 5;
}

The fields are:

  • name - The name of the enumeration.

  • id - The identifier of the enumeration.

  • values - A list of EnumerationValue messages, indicating the values that the enumeration can be assigned. The fields are:

    • name - The name associated with the value for the enumeration.

    • value - The possible value for the enumeration as a 32-bit integer.

    • documentation - Documentation for the enumeration value.

    • deprecated - Whether the enumeration value is deprecated.

    • deprecated_reason - The reason for the deprecation.

  • documentation - Documentation for the enumeration.

  • deprecated - Whether the enumeration is deprecated.

  • deprecated_reason - The reason for the deprecation.

  • flags - Whether the enumeration is a flags enumeration. A value of one is any combination of its values: a number holding no bit outside the union of the values it declares. A value of any other enumeration is one of the values it declares.

Structures#

A structure is a compound value with named fields, sent as the values of its fields. Details about each KRPCStruct are specified in a Struct message, with the format:

message Struct {
  string name = 1;
  uint32 id = 6;
  repeated StructField fields = 2;
  string documentation = 3;
  bool deprecated = 4;
  string deprecated_reason = 5;
}

message StructField {
  string name = 1;
  Type type = 2;
  string documentation = 3;
  bool deprecated = 4;
  string deprecated_reason = 5;
}

The fields are:

  • name - The name of the structure.

  • id - The identifier of the structure.

  • fields - A list of StructField messages, one for each field of the structure, in the order their values are encoded in. The fields are:

    • name - The name of the field.

    • type - The type of the field, as a Type message. A field may have any type a parameter or return value may have, including a class, a collection or another structure. Its nullable field says whether the field can be null.

    • documentation - Documentation for the field.

    • deprecated - Whether the field is deprecated.

    • deprecated_reason - The reason for the deprecation.

  • documentation - Documentation for the structure.

  • deprecated - Whether the structure is deprecated.

  • deprecated_reason - The reason for the deprecation.

A value of a structure type is encoded as a Tuple message whose items are the encoded values of the structure’s fields, in the order the fields list gives them. This is the encoding of a tuple of the field types. The field names appear only in the definition above.

A nullable field carries a presence bool, as described under Null Values. is_null on the enclosing Argument or ProcedureResult applies to the whole structure.

Exceptions#

Details about each KRPCException are specified in an Exception message, with the format:

message Exception {
  string name = 1;
  uint32 id = 6;
  string documentation = 2;
  bool deprecated = 3;
  string deprecated_reason = 4;
  string mapped_type = 5;
}

The fields are:

  • name - The name of the exception type.

  • id - The identifier of the exception type, as in the exception_id field of an error.

  • documentation - Documentation for the exception.

  • deprecated - Whether the exception is deprecated.

  • deprecated_reason - The reason for the deprecation.

  • mapped_type - The full name of the .NET exception the server reports as this exception, for example System.ArgumentException. Empty if there is none.

Procedure Names#

Procedure names are CamelCase. Whether a procedure is a service procedure, class method, class property, and what class (if any) it belongs to is determined by its name:

  • ProcedureName - a standard procedure that is just part of a service.

  • get_PropertyName - a procedure that returns the value of a property in a service.

  • set_PropertyName - a procedure that sets the value of a property in a service.

  • ClassName_MethodName - a class method.

  • ClassName_static_StaticMethodName - a static class method.

  • ClassName_get_PropertyName - a class property getter.

  • ClassName_set_PropertyName - a class property setter.

Only letters and numbers are permitted in class, method and property names. Underscores can therefore be used to split the name into its constituent parts.

Type#

The GetServices procedure returns type information about parameters, return values and others as Type messages. The format of these messages is as follows:

message Type {
  TypeCode code = 1;
  string service = 2;
  string name = 3;
  uint32 service_id = 6;
  uint32 id = 7;
  repeated Type types = 4;
  bool nullable = 5;

  enum TypeCode {
    reserved 203;
    NONE = 0;

    // Values
    DOUBLE = 1;
    FLOAT = 2;
    SINT32 = 3;
    SINT64 = 4;
    UINT32 = 5;
    UINT64 = 6;
    BOOL = 7;
    STRING = 8;
    BYTES = 9;

    // Objects
    CLASS = 100;
    ENUMERATION = 101;
    STRUCT = 102;

    // Messages, except an EVENT or STREAM value, which is the uint64 id of its stream
    EVENT = 200;
    PROCEDURE_CALL = 201;
    STREAM = 202;
    SERVICES = 204;

    // Collections
    TUPLE = 300;
    LIST = 301;
    SET = 302;
    DICTIONARY = 303;
  };
}

The code field specifies the type. NONE is the code of an unset type, such as the return type of a procedure that returns no value.

For CLASS, ENUMERATION and STRUCT types the service and name fields specify the service that defines the class, enumeration or structure and its name. The service_id and id fields hold their identifiers. For all other types the names are empty and the identifiers are 0.

For collection types the types repeated field will contain the sub-types:

  • TUPLE types contain one or more types in the types field.

  • LIST and SET types contain a single type in the types field.

  • DICTIONARY types contain two types in the types field: the key type, then the value type.

For all other types the types field is empty. A STRUCT type carries only the name of its structure, and its field types are in the Struct message of the service that defines it.

The nullable field says whether the position the type describes can hold null. It is a property of that position rather than of the type, so the same type is nullable in one place and not in another. The positions that can be nullable are a parameter, a return value, a structure field, a list element, a tuple item and a dictionary value. A dictionary key and a set element cannot.

How the null itself is carried depends on the position. An argument, a result and a default value each have a flag of their own, Argument.is_null, ProcedureResult.is_null and Parameter.default_value_is_null. A value nested inside another value has no such flag, and carries a leading presence bool instead, as described under Null Values.

GameScene#

A procedure’s game_scenes field lists the GameScene values it is available in. An empty list means every scene:

enum GameScene {
  SPACE_CENTER = 0;
  FLIGHT = 1;
  TRACKING_STATION = 2;
  EDITOR_VAB = 3;
  EDITOR_SPH = 4;
  MISSION_BUILDER = 5;
  ASTRONAUT_COMPLEX = 6;
  MISSION_CONTROL = 7;
  RESEARCH_AND_DEVELOPMENT = 8;
  ADMINISTRATION = 9;
};

ASTRONAUT_COMPLEX through ADMINISTRATION each name a facility open within SPACE_CENTER.

Proxy Objects#

kRPC allows procedures to create objects on the server, and pass a unique identifier for them to the client. This allows the client to create a proxy object for the actual object, whose methods and properties make remote procedure calls to the server. Object identifiers have type uint64.

When a procedure returns a proxy object or takes one as a parameter, the type code is CLASS.

The is_null field of the ProcedureResult or Argument message signals a null object reference, as it does a null value of any other type. The object identifier is never used to represent null on the wire.

The server never issues the object identifier 0, and clients can rely on this. The C++ and C-nano clients represent an object that refers to nothing in their own APIs as an object with identifier 0, so 0 must never become a valid identifier.