SpawnDev.BlazorJS.MessagePack 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SpawnDev.BlazorJS.MessagePack --version 1.0.0                
NuGet\Install-Package SpawnDev.BlazorJS.MessagePack -Version 1.0.0                
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.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SpawnDev.BlazorJS.MessagePack --version 1.0.0                
#r "nuget: SpawnDev.BlazorJS.MessagePack, 1.0.0"                
#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.0.0

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

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.

nuget install SpawnDev.BlazorJS.MessagePack

Modify the Blazor WASM 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;
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();

// Load the MessagePack Javascript library at startup (optional)
// Could also be done in component or a service as needed.
await MessagePack.Init();

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

Example Home.razor

@page "/"
@using SpawnDev.BlazorJS.JSObjects

<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>

@code {
    string outgoing = "";
    string incoming = "";
    string readback = "";

    void Submit()
    {
        // encode using MessagePack to a Uint8Array
        using Uint8Array uint8Array = MessagePack.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);
        // demo decode
        readback = MessagePack.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. 
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.0 73 11/10/2024
1.3.1 81 8/6/2024
1.3.0 87 7/26/2024
1.2.1 78 7/23/2024
1.2.0 71 7/17/2024
1.1.1 115 6/18/2024
1.1.0 97 6/12/2024
1.0.1 114 6/5/2024
1.0.0 99 6/5/2024