SpawnDev.BlazorJS.MessagePack 1.4.1

dotnet add package SpawnDev.BlazorJS.MessagePack --version 1.4.1                
NuGet\Install-Package SpawnDev.BlazorJS.MessagePack -Version 1.4.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SpawnDev.BlazorJS.MessagePack" Version="1.4.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SpawnDev.BlazorJS.MessagePack --version 1.4.1                
#r "nuget: SpawnDev.BlazorJS.MessagePack, 1.4.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SpawnDev.BlazorJS.MessagePack as a Cake Addin
#addin nuget:?package=SpawnDev.BlazorJS.MessagePack&version=1.4.1

// Install SpawnDev.BlazorJS.MessagePack as a Cake Tool
#tool nuget:?package=SpawnDev.BlazorJS.MessagePack&version=1.4.1                

SpawnDev.BlazorJS.MessagePack

MessagePack binary Javascript encoder and decoder for Blazor WebAssembly.

NuGet version

SpawnDev.BlazorJS.MessagePack brings the amazing MessagePack library to Blazor WebAssembly.

SpawnDev.BlazorJS.MessagePack uses SpawnDev.BlazorJS for Javascript interop allowing strongly typed, full usage of the MessagePack Javascript library. Voice, video and data channels are all fully supported in Blazor WebAssembly. The SpawnDev.BlazorJS.MessagePack API is a strongly typed version of the API found at the MessagePack repo.

Demo

Basic Demo

Getting started

Add the Nuget package SpawnDev.BlazorJS.MessagePack to your project using your package manager of choice.

dotnet add package SpawnDev.BlazorJS.MessagePack

Add MessagePack Javascript Library
Add to index.html

<script src="_content/SpawnDev.BlazorJS.MessagePack/msgpack.min.js"></script>

Modify the Blazor WebAssembly Program.cs to initialize SpawnDev.BlazorJS for Javascript interop.
Example Program.cs

using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using SpawnDev.BlazorJS;
using SpawnDev.BlazorJS.MessagePack.Demo;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

// Add SpawnDev.BlazorJS interop
builder.Services.AddBlazorJSRuntime();

// Run app using BlazorJSRunAsync
await builder.Build().BlazorJSRunAsync();

Example Home.razor

@page "/"

<PageTitle>SpawnDev.BlazorJS.MessagePack</PageTitle>

<h1>SpawnDev.BlazorJS.MessagePack</h1>

<p>
    This demo converts text to binary using MessagePack Javascript library and SpawnDev.BlazorJS.MessagePack
</p>
<div>
    <textarea style="width: 600px; word-wrap: break-word; white-space: normal;" @bind=@incoming></textarea>
    <button @onclick=@Submit>Pack</button>
</div>
<div>
    <pre style="width: 600px; word-wrap: break-word; white-space: normal;">@((MarkupString)outgoing)</pre>
</div>
<div>
    <pre style="width: 600px; word-wrap: break-word; white-space: normal;">@((MarkupString)readback)</pre>
</div>

Example Home.razor.cs

using SpawnDev.BlazorJS.JSObjects;
using SpawnDev.BlazorJS.MessagePack;

namespace SpawnDev.BlazorJS.MessagePack.Demo.Pages
{
    public partial class Home
    {
        string outgoing = "";
        string incoming = "";
        string readback = "";

        void Submit()
        {
            // encode to a Uint8Array using MessagePack
            using Uint8Array uint8Array = MessagePackSerializer.Encode(incoming);
            // the Uint8Array could now be sent over WebRTC, saved to file, etc.
            // for this demo we are converting to hex and displaying it
            var bytes = uint8Array.ReadBytes();
            outgoing = Convert.ToHexString(bytes);
            // decode to a string using MessagePack
            readback = MessagePackSerializer.Decode<string>(uint8Array);
        }
    }
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.4.1 88 12/4/2024
1.4.0 99 11/10/2024
1.3.1 89 8/6/2024
1.3.0 95 7/26/2024
1.2.1 86 7/23/2024
1.2.0 82 7/17/2024
1.1.1 123 6/18/2024
1.1.0 105 6/12/2024
1.0.1 123 6/5/2024
1.0.0 107 6/5/2024