Types#
Identifiers#
An identifier can only contain the ASCII letters and digits, and must start with an upper case
letter. They should follow CamelCase capitalization
conventions. The names of parameters and enumeration values follow the same rule, but can also start
with a lower case letter. The _ character is reserved for joining the parts of a procedure name,
such as Vessel_get_Name.
Each client converts an identifier to its own case, by splitting it into words:
Identifier |
Python |
Java |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
A run of capitals is an acronym, and a run of capitals ending in s is a plural acronym. A word
with more than one capital, such as PeA, splits at each capital unless it is a compound word,
such as UInt. Spell it out, as in PeriapsisAltitude. Case Conversion
specifies the rules and lists the compound words.
Names are unique within their scope, compared case-insensitively. Some clients convert names that
differ only in case to one name: RCSEnabled and RcsEnabled are both rcs_enabled in
Python. The scopes are:
the procedures and properties of a service
the methods, static methods and properties of a class
the values of an enumeration
the fields of a structure
the parameters of a procedure or method
A property Foo also takes the names GetFoo and SetFoo, as some clients name its
getter and setter that way. A method GetFoo beside it is an error.
Serializable Types#
A type can only be used as a parameter or return type if kRPC knows how to serialize it. The following types are serializable:
The C# types
double,float,int,long,uint,ulong,bool,stringandbyte[]Any type annotated with
KRPCClassAny type annotated with
KRPCEnumAny type annotated with
KRPCStructCollections of serializable types:
System.Collections.Generic.IList<T>whereTis a serializable typeSystem.Collections.Generic.IDictionary<K,V>whereKis one ofint,long,uint,ulong,boolorstringandVis a serializable typeSystem.Collections.Generic.HashSet<V>whereVis a serializable typeSystem.Tuple<...>where all of the tuple’s value types are serializable types
Return types can be
voidProtocol buffer message types from namespace
KRPC.Service.Messages
Null Values#
A parameter, a return value, a structure field or a position nested inside one of them may be
null only when it is declared nullable. This applies uniformly to every serializable
type – class types, string, collections and value types alike. The server enforces it:
Passing
nullas an argument for a parameter that is not nullable fails the call with an error.Returning
nullfrom a procedure, method or property getter that is not nullable fails the call with an error.A
nullin a structure field that is not nullable fails the call with an error, naming the field.
A parameter is nullable if any of the following hold:
It is annotated with
KRPCNullable.It has a default value of
null(for exampleVessel target = null). A null default is itself a declaration thatnullis a valid value, so no further annotation is needed.Its type is a nullable value type,
Nullable<T>(for exampleint?); see below.
A return value is nullable if the Nullable parameter of its KRPCProcedure,
KRPCMethod or KRPCProperty attribute is set to true, or if its type
is Nullable<T>. For a property, Nullable = true makes the getter’s return value and the
setter’s argument nullable.
Return nullability is always declared, as kRPC reads the attribute rather than the method body.
A structure field is nullable if the Nullable parameter of its
KRPCProperty attribute is set, or if its type is Nullable<T>. Setting
Nullable on a value-typed field is an error. Write the field as Nullable<T> instead.
Nullable Value Types#
A parameter, return value or structure field of type Nullable<T> – int?, float?,
bool?, an enum? and so on – is automatically nullable; it needs neither
KRPCNullable nor Nullable = true. To clients it appears as an ordinary value of
type T that may be null.
Only value types can be Nullable<T>. A nullable reference type annotation such as
string? or IList<int>? is a compile-time annotation, and the ? is erased before kRPC
reads the type. Such a parameter or return value is treated as non-nullable.
Use KRPCNullable or Nullable = true to make a reference-typed parameter,
return value or structure field nullable, and a path on KRPCNullable to make a
reference-typed position nested inside one nullable. See Nullable Positions.