Skip to content

Getting Started with .NET

andrew edited this page Jun 8, 2023 · 5 revisions

Supported Runtimes

  • .NET Framework 4.7.2
  • .NET Framework 4.8
  • .NET Core 3.1
  • .NET 5+

Install the Runtime

To install the Bebop .NET runtime you can use the following command in the Package Manager Console:

Install-Package bebop
Package NuGet Stable Downloads
bebop bebop bebop

Install the Compiler Tools

To install the Bebop Compiler tools you can use the following command in the Package Manager Console:

Install-Package bebop-tools
Package NuGet Stable Downloads
bebop-tools bebop-tools bebop-tools

Configuring the Compiler Tools

Inside of your project file add a new ItemGroup

<ItemGroup>
  <Bebop Include="**/*.bop" OutputDir="./Models/" OutputFile="IpcModels.g.cs" Namespace="RainwayIPC.Models" />
</ItemGroup>

When the <Bebop> item group is present in your project all schemas that match the provided Include path are compiled in accordance with the output parameters defined whenever you build your project (meaning that schema changes reflect immediately in your project.)

Any issues encountered while compiling your schemas can now also be inspected from the error list.

Using Bebop Mirroring

Mirroring is a Bebop feature supported by the .NET runtime implementation that allows for records to be access and handled dynamically. For instance, you can define a class as a RecordHandler and bind it's methods to be invoked whenever a record of a certain type is decoded.

    [RecordHandler]
    public class ExampleHandler
    {

        [BindRecord(typeof(BebopRecord<ChatMessage>))]
        public async Task HandleChat(object state, ChatMessage chat)
        {
            ...
        }
    }

Arbitrary data can then be decoded dynamically by leveraging the records opcode, and the method bound to it is fired.

// fired when a message is received from the network.
public void OnMessage(byte[] data) {
  // decodes our network messages
  var networkMessage = NetworkMessage.Decode(data);
  // decodes and invokes the handler (if any) for the decoded record
  // if the record is ChatMessage then HandleChat is invoked..
  BebopMirror.HandleRecord(networkMessage.IncomingRecordData, networkMessage.IncomingOpcode, stateObject);
}

Notes:

  • If your RecordHandler is non-static the Bebop runtime will create a new instance of that class and hold onto the reference.
  • Bound methods currently cannot return any values and use an event driven pattern. Invoked methods do not block.