Expose operation envelopes in CultNet CSharp
This commit is contained in:
parent
631d9bd3ab
commit
94f95e380d
6 changed files with 138 additions and 0 deletions
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://github.com/GameCult/cultnet-ts/contracts/cultnet.operation-request.schema.json",
|
||||
"title": "CultNet Operation Request",
|
||||
"type": "object",
|
||||
"required": ["schemaVersion", "messageId", "serviceId", "operation", "payloadSchema", "payload"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"schemaVersion": { "const": "cultnet.operation_request.v0" },
|
||||
"messageId": { "type": "string", "minLength": 1 },
|
||||
"serviceId": { "type": "string", "minLength": 1 },
|
||||
"operation": { "type": "string", "minLength": 1 },
|
||||
"payloadSchema": { "type": "string", "minLength": 1 },
|
||||
"payloadEncoding": { "const": "messagepack-base64" },
|
||||
"payload": { "type": "string", "minLength": 1, "contentEncoding": "base64" },
|
||||
"sourceRuntimeId": { "type": "string", "minLength": 1 },
|
||||
"targetRuntimeId": { "type": "string", "minLength": 1 }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://github.com/GameCult/cultnet-ts/contracts/cultnet.operation-response.schema.json",
|
||||
"title": "CultNet Operation Response",
|
||||
"type": "object",
|
||||
"required": ["schemaVersion", "messageId", "serviceId", "operation", "status", "payloadSchema", "payload"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"schemaVersion": { "const": "cultnet.operation_response.v0" },
|
||||
"messageId": { "type": "string", "minLength": 1 },
|
||||
"serviceId": { "type": "string", "minLength": 1 },
|
||||
"operation": { "type": "string", "minLength": 1 },
|
||||
"status": { "type": "string", "minLength": 1 },
|
||||
"payloadSchema": { "type": "string", "minLength": 1 },
|
||||
"payloadEncoding": { "const": "messagepack-base64" },
|
||||
"payload": { "type": "string", "minLength": 1, "contentEncoding": "base64" },
|
||||
"diagnostics": { "type": "array", "items": { "type": "string" } },
|
||||
"sourceRuntimeId": { "type": "string", "minLength": 1 }
|
||||
}
|
||||
}
|
||||
|
|
@ -55,6 +55,8 @@ namespace GameCult.Networking
|
|||
CultNetSchemaVersions.Error => Deserialize<CultNetErrorMessage>(payload),
|
||||
CultNetSchemaVersions.SampleChangeName => Deserialize<CultNetSampleChangeNameMessage>(payload),
|
||||
CultNetSchemaVersions.SampleChat => Deserialize<CultNetSampleChatMessage>(payload),
|
||||
CultNetSchemaVersions.OperationRequest => Deserialize<CultNetOperationRequestMessage>(payload),
|
||||
CultNetSchemaVersions.OperationResponse => Deserialize<CultNetOperationResponseMessage>(payload),
|
||||
CultNetSchemaVersions.DocumentDelete => Deserialize<CultNetDocumentDeleteMessage>(payload),
|
||||
CultNetSchemaVersions.DocumentPutRaw => Deserialize<CultNetDocumentPutRawMessage>(payload),
|
||||
CultNetSchemaVersions.SnapshotRequest => Deserialize<CultNetSnapshotRequestMessage>(payload),
|
||||
|
|
|
|||
|
|
@ -56,6 +56,14 @@ namespace GameCult.Networking
|
|||
/// </summary>
|
||||
public const string SampleChat = "cultnet.sample.chat.v0";
|
||||
/// <summary>
|
||||
/// Generic typed service operation request contract identifier.
|
||||
/// </summary>
|
||||
public const string OperationRequest = "cultnet.operation_request.v0";
|
||||
/// <summary>
|
||||
/// Generic typed service operation response contract identifier.
|
||||
/// </summary>
|
||||
public const string OperationResponse = "cultnet.operation_response.v0";
|
||||
/// <summary>
|
||||
/// document delete contract identifier.
|
||||
/// </summary>
|
||||
public const string DocumentDelete = "cultnet.document_delete.v0";
|
||||
|
|
@ -519,6 +527,60 @@ namespace GameCult.Networking
|
|||
[Key("text")] public string Text { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes one typed operation on an advertised service.
|
||||
/// </summary>
|
||||
[MessagePackObject]
|
||||
public class CultNetOperationRequestMessage : ICultNetSchemaMessage
|
||||
{
|
||||
/// <summary>Gets or sets the wire schema version.</summary>
|
||||
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.OperationRequest;
|
||||
/// <summary>Gets or sets the correlation id.</summary>
|
||||
[Key("messageId")] public string MessageId { get; set; } = string.Empty;
|
||||
/// <summary>Gets or sets the advertised service id.</summary>
|
||||
[Key("serviceId")] public string ServiceId { get; set; } = string.Empty;
|
||||
/// <summary>Gets or sets the requested operation.</summary>
|
||||
[Key("operation")] public string Operation { get; set; } = string.Empty;
|
||||
/// <summary>Gets or sets the inner payload schema.</summary>
|
||||
[Key("payloadSchema")] public string PayloadSchema { get; set; } = string.Empty;
|
||||
/// <summary>Gets or sets the inner payload encoding.</summary>
|
||||
[Key("payloadEncoding")] public string PayloadEncoding { get; set; } = "messagepack-base64";
|
||||
/// <summary>Gets or sets the encoded inner payload.</summary>
|
||||
[Key("payload")] public string Payload { get; set; } = string.Empty;
|
||||
/// <summary>Gets or sets the calling runtime id.</summary>
|
||||
[Key("sourceRuntimeId")] public string? SourceRuntimeId { get; set; }
|
||||
/// <summary>Gets or sets an optional target runtime id.</summary>
|
||||
[Key("targetRuntimeId")] public string? TargetRuntimeId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the correlated result of one typed service operation.
|
||||
/// </summary>
|
||||
[MessagePackObject]
|
||||
public class CultNetOperationResponseMessage : ICultNetSchemaMessage
|
||||
{
|
||||
/// <summary>Gets or sets the wire schema version.</summary>
|
||||
[Key("schemaVersion")] public string SchemaVersion { get; set; } = CultNetSchemaVersions.OperationResponse;
|
||||
/// <summary>Gets or sets the request correlation id.</summary>
|
||||
[Key("messageId")] public string MessageId { get; set; } = string.Empty;
|
||||
/// <summary>Gets or sets the advertised service id.</summary>
|
||||
[Key("serviceId")] public string ServiceId { get; set; } = string.Empty;
|
||||
/// <summary>Gets or sets the completed operation.</summary>
|
||||
[Key("operation")] public string Operation { get; set; } = string.Empty;
|
||||
/// <summary>Gets or sets the operation status.</summary>
|
||||
[Key("status")] public string Status { get; set; } = string.Empty;
|
||||
/// <summary>Gets or sets the inner payload schema.</summary>
|
||||
[Key("payloadSchema")] public string PayloadSchema { get; set; } = string.Empty;
|
||||
/// <summary>Gets or sets the inner payload encoding.</summary>
|
||||
[Key("payloadEncoding")] public string PayloadEncoding { get; set; } = "messagepack-base64";
|
||||
/// <summary>Gets or sets the encoded inner payload.</summary>
|
||||
[Key("payload")] public string Payload { get; set; } = string.Empty;
|
||||
/// <summary>Gets or sets transport-level diagnostics.</summary>
|
||||
[Key("diagnostics")] public string[] Diagnostics { get; set; } = Array.Empty<string>();
|
||||
/// <summary>Gets or sets the responding runtime id.</summary>
|
||||
[Key("sourceRuntimeId")] public string? SourceRuntimeId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raw document record carried over CultNet.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -322,6 +322,20 @@ namespace GameCult.Networking
|
|||
WireContracts = new[] { CultNetWireContracts.SchemaV0, CultNetWireContracts.GameCultNetworkingV0 }
|
||||
},
|
||||
new SchemaResourceSpec
|
||||
{
|
||||
FileName = "cultnet.operation-request.schema.json",
|
||||
Kind = "wire_message",
|
||||
SchemaVersion = CultNetSchemaVersions.OperationRequest,
|
||||
WireContracts = new[] { CultNetWireContracts.SchemaV0 }
|
||||
},
|
||||
new SchemaResourceSpec
|
||||
{
|
||||
FileName = "cultnet.operation-response.schema.json",
|
||||
Kind = "wire_message",
|
||||
SchemaVersion = CultNetSchemaVersions.OperationResponse,
|
||||
WireContracts = new[] { CultNetWireContracts.SchemaV0 }
|
||||
},
|
||||
new SchemaResourceSpec
|
||||
{
|
||||
FileName = "cultnet.document-delete.schema.json",
|
||||
Kind = "wire_message",
|
||||
|
|
|
|||
|
|
@ -431,6 +431,27 @@ namespace GameCult.Networking.Tests
|
|||
Is.EqualTo(new int?[] { 64, 64, 64 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CultNetSchemaMessageSerialization_RoundTrips_OperationEnvelope()
|
||||
{
|
||||
var request = new CultNetOperationRequestMessage
|
||||
{
|
||||
MessageId = "plugin-42",
|
||||
ServiceId = "sai.vn",
|
||||
Operation = "project",
|
||||
PayloadSchema = "gamecult.eve.plugin_abi.request.v1",
|
||||
Payload = "gaZzY2hlbWHEJ2dhbWVjdWx0LmV2ZS5wbHVnaW5fYWJpLnJlcXVlc3QudjE=",
|
||||
SourceRuntimeId = "eve-unity"
|
||||
};
|
||||
|
||||
var payload = CultNetSchemaMessageSerialization.Serialize(request);
|
||||
var roundTrip = (CultNetOperationRequestMessage)CultNetSchemaMessageSerialization.Deserialize(payload);
|
||||
|
||||
Assert.That(roundTrip.MessageId, Is.EqualTo(request.MessageId));
|
||||
Assert.That(roundTrip.ServiceId, Is.EqualTo("sai.vn"));
|
||||
Assert.That(roundTrip.PayloadSchema, Is.EqualTo("gamecult.eve.plugin_abi.request.v1"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LiteNetLibTransportProfile_AdvertisesLegacyAndSchemaChannels()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue