Barotrauma Client Doc
Barotrauma.INetSerializableStruct Interface Reference

Interface that allows the creation of automatically serializable and deserializable structs.

More...

Inheritance diagram for Barotrauma.INetSerializableStruct:
Barotrauma.CampaignMode.SaveInfo Barotrauma.MedicalClinic.NetAffliction Barotrauma.MedicalClinic.NetCrewMember Barotrauma.MedicalClinic.NetHealRequest Barotrauma.MedicalClinic.NetPendingCrew Barotrauma.MedicalClinic.NetRemovedAffliction Barotrauma.Networking.TempClient

Public Member Functions

void Write (IWriteMessage msg)
 Serializes the struct into a network message More...
 

Static Public Member Functions

static T Read< T > (IReadMessage inc)
 Deserializes a network message into a struct. More...
 
static dynamic ReadDynamic (Type type, IReadMessage inc)
 

Detailed Description

Interface that allows the creation of automatically serializable and deserializable structs.

public enum PurchaseResult
{
Completed,
Declined
}
[NetworkSerialize]
struct NetStoreTransaction : INetSerializableStruct
{
public long Timestamp { get; set; }
public PurchaseResult Result { get; set; }
public NetPurchasedItem? PurchasedItem { get; set; }
}
[NetworkSerialize]
struct NetPurchasedItem : INetSerializableStruct
{
public string Identifier;
public string[] Tags;
public int Amount;
}

Supported types are:
bool
byte
ushort
short
uint
int
ulong
long
float
double
string
Microsoft.Xna.Framework.Color
Microsoft.Xna.Framework.Vector2
In addition arrays, enums, Nullable<T> and Option<T> are supported.
Using Nullable<T> or Option<T> will make the field or property optional.

See also
NetworkSerialize

Definition at line 584 of file INetSerializableStruct.cs.

Member Function Documentation

◆ Read< T >()

static T Barotrauma.INetSerializableStruct.Read< T > ( IReadMessage  inc)
static

Deserializes a network message into a struct.

public void ClientRead(IReadMessage inc)
{
NetStoreTransaction transaction = INetSerializableStruct.Read<NetStoreTransaction>(inc);
if (transaction.Result == PurchaseResult.Declined)
{
Console.WriteLine("Purchase declined!");
return;
}
if (transaction.PurchasedItem is { } item)
{
// Purchased 3x Wrench with tags: smallitem, mechanical, tool
Console.WriteLine($"Purchased {item.Amount}x {item.Identifier} with tags: {string.Join(", ", item.Tags)}");
}
}
Parameters
incIncoming network message
Template Parameters
TType of the struct that implements INetSerializableStruct
Returns
A new struct of type T with fields and properties deserialized
Type Constraints
T :INetSerializableStruct 
T :T 
T :ReadDynamic 
T :typeof 
T :T 
T :inc 

◆ ReadDynamic()

static dynamic Barotrauma.INetSerializableStruct.ReadDynamic ( Type  type,
IReadMessage  inc 
)
static

Definition at line 613 of file INetSerializableStruct.cs.

◆ Write()

void Barotrauma.INetSerializableStruct.Write ( IWriteMessage  msg)

Serializes the struct into a network message

public void ServerWrite(IWriteMessage msg) { INetSerializableStruct transaction = new NetStoreTransaction { Result = PurchaseResult.Completed, Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds(), PurchasedItem = new NetPurchasedItem { Identifier = "Wrench", Amount = 3, Tags = new []{ "smallitem", "mechanical", "tool" } } };

transaction.Write(msg); }

Parameters
msgOutgoing network message

Definition at line 652 of file INetSerializableStruct.cs.

Barotrauma.Networking.ChatMessageType.Console
@ Console
Barotrauma.CauseOfDeathType.Unknown
@ Unknown