@nativescript/windows-jsc 0.1.0-alpha.0 → 0.1.0-next.2026-08-03-30819078286

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,55 +1,13 @@
1
- # @nativescript/windows-jsc
2
-
3
- NativeScript Windows runtime on **JavaScriptCore**, no Node. **Working** — the full WinRT demo
4
- passes (`exit 0`): typed WinRT calls, a 20-call stress loop, and a `JsonObject` round-trip.
5
-
6
- ## As an app runtime (drop-in for `@nativescript/windows`)
7
- Publishes as `@nativescript/windows-jsc`, the **same** WinUI 3 framework as `@nativescript/windows`
8
- with the JavaScriptCore runtime DLL — swap the dependency and an app runs unchanged. Build the
9
- framework with the engine flag (needs a real `JavaScriptCore.lib` in `vendor/x64`):
10
- ```sh
11
- pwsh -File ../../template/build.ps1 -Engine jsc # or: npm run build
12
- ```
13
- The engine → runtime-DLL adapter (the C ABI the WinUI 3 host P/Invokes) follows the reference
14
- implementation in `../windows-quickjs/src/abi.rs`. See `../README.md` for the full contract.
15
-
16
- ## The engine binary — Playwright's WebKit (current)
17
- The official WebKit WinCairo buildbot is dead (last Windows build Sept 2024), and there's no NuGet/npm
18
- prebuilt. The **current** source of a Windows `JavaScriptCore.dll` is **Playwright**, which rebuilds
19
- WebKit constantly:
20
-
21
- ```
22
- https://playwright.download.prss.microsoft.com/dbazure/download/playwright/builds/webkit/<rev>/webkit-win64.zip
23
- ```
24
- (`<rev>` from `packages/playwright-core/browsers.json` in microsoft/playwright — 2331 at time of
25
- writing; the vendored `JavaScriptCore.dll` is dated 2026-07-14). It exports the full JSC C API and
26
- depends only on `icuin77.dll` / `icuuc77.dll` (+ `icudt77.dll` data).
27
-
28
- `vendor/x64/` holds (committed, no LFS): `JavaScriptCore.dll` (33 MB), `icudt77.dll` (32 MB),
29
- `icuin77.dll`, `icuuc77.dll`, and `JavaScriptCore.lib` — an **import lib generated from the DLL's
30
- exports** (no `.lib` ships in the zip):
31
- ```sh
32
- llvm-objdump -p JavaScriptCore.dll | awk '/Export Table/{f=1;next} f&&/0x/{print $NF}' \
33
- | grep -E '^(JS|WK|k)' | awk '{print ($0 ~ /^k/) ? $0" DATA" : $0}' > exports # k* are DATA symbols
34
- printf 'EXPORTS\n' > JavaScriptCore.def; cat exports >> JavaScriptCore.def
35
- lib /def:JavaScriptCore.def /machine:x64 /out:JavaScriptCore.lib
36
- ```
37
-
38
- ## Build & run
39
- ```sh
40
- cargo build --release --features jsc_link --manifest-path packages/windows-jsc/Cargo.toml
41
- target/release/nativescript-windows.exe
42
- ```
43
- `build.rs` links `JavaScriptCore.lib` and copies the DLLs beside the exe.
44
-
45
- ## Shim = napi-android's JSC provider (public C API), + two Windows fixes
46
- `jsc-api.cpp` is over JSC's stable public C API (no WebKit internals), so it's version-robust. Two
47
- bugs surfaced on Windows and are fixed in the vendored shim:
48
- - **UTF-16 read truncation**: `CopyTo` did `memcpy(buf, chars, size)` where `size` is a count of
49
- 2-byte `JSChar` → copied half the bytes (`'hi'`→`'h'`). Fixed to `size * sizeof(JSChar)`.
50
- - **napi functions weren't constructors**: `FunctionInfo`'s `JSClassDefinition` set `callAsFunction`
51
- but not `callAsConstructor`, so a JS `Proxy` over them wasn't a constructor (`new
52
- Windows.Data.Json.JsonObject()` → "not a constructor"). Added a `CallAsConstructor` callback (the
53
- JSC analog of the QuickJS `JS_SetConstructorBit` fix; V8's napi functions are constructable by
54
- default).
55
- Also `EXTERN_C` on the JSR bring-up decls (`jsr_common.h`) so the Rust host's `extern "C"` resolves.
1
+ # @nativescript/windows-jsc
2
+
3
+ NativeScript Windows runtime on **JavaScriptCore**.
4
+
5
+
6
+ ## The engine binary — Playwright's WebKit (current)
7
+ The official WebKit WinCairo buildbot is dead (last Windows build Sept 2024), and there's no NuGet/npm
8
+ prebuilt. The **current** source of a Windows `JavaScriptCore.dll` is **Playwright**, which rebuilds
9
+ WebKit constantly:
10
+
11
+ ```
12
+ https://playwright.download.prss.microsoft.com/dbazure/download/playwright/builds/webkit/<rev>/webkit-win64.zip
13
+ ```
@@ -1,13 +1,13 @@
1
- <Application
2
- x:Class="__PROJECT_NAME__.App"
3
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5
- xmlns:local="using:__PROJECT_NAME__">
6
- <Application.Resources>
7
- <ResourceDictionary>
8
- <ResourceDictionary.MergedDictionaries>
9
- <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
10
- </ResourceDictionary.MergedDictionaries>
11
- </ResourceDictionary>
12
- </Application.Resources>
13
- </Application>
1
+ <Application
2
+ x:Class="__PROJECT_NAME__.App"
3
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5
+ xmlns:local="using:__PROJECT_NAME__">
6
+ <Application.Resources>
7
+ <ResourceDictionary>
8
+ <ResourceDictionary.MergedDictionaries>
9
+ <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
10
+ </ResourceDictionary.MergedDictionaries>
11
+ </ResourceDictionary>
12
+ </Application.Resources>
13
+ </Application>
@@ -1,35 +1,35 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <Package
3
- xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
4
- xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
5
- xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
6
- IgnorableNamespaces="uap rescap">
7
- <Identity Name="__APP_IDENTIFIER__" Publisher="CN=__PROJECT_NAME__" Version="1.0.0.0" />
8
- <Properties>
9
- <DisplayName>__PROJECT_NAME__</DisplayName>
10
- <PublisherDisplayName>__PROJECT_NAME__</PublisherDisplayName>
11
- <Logo>Assets\StoreLogo.png</Logo>
12
- </Properties>
13
- <Dependencies>
14
- <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.26100.0" />
15
- <!-- WinUI3 / Windows App SDK 1.6 framework package (framework-dependent). Required so the
16
- registered app can activate Microsoft.UI.Xaml.* (else REGDB_E_CLASSNOTREG at startup). -->
17
- <PackageDependency Name="Microsoft.WindowsAppRuntime.1.6" MinVersion="6000.0.0.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
18
- </Dependencies>
19
- <Resources>
20
- <Resource Language="en-US" />
21
- </Resources>
22
- <Applications>
23
- <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="Windows.FullTrustApplication">
24
- <uap:VisualElements DisplayName="__PROJECT_NAME__" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="A NativeScript Windows application" BackgroundColor="#65ADF1">
25
- <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" />
26
- <uap:SplashScreen Image="Assets\SplashScreen.png" />
27
- </uap:VisualElements>
28
- </Application>
29
- </Applications>
30
- <Capabilities>
31
- <rescap:Capability Name="runFullTrust" />
32
- <Capability Name="internetClient" />
33
- <Capability Name="privateNetworkClientServer" />
34
- </Capabilities>
35
- </Package>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Package
3
+ xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
4
+ xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
5
+ xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
6
+ IgnorableNamespaces="uap rescap">
7
+ <Identity Name="__APP_IDENTIFIER__" Publisher="CN=__PROJECT_NAME__" Version="1.0.0.0" />
8
+ <Properties>
9
+ <DisplayName>__PROJECT_NAME__</DisplayName>
10
+ <PublisherDisplayName>__PROJECT_NAME__</PublisherDisplayName>
11
+ <Logo>Assets\StoreLogo.png</Logo>
12
+ </Properties>
13
+ <Dependencies>
14
+ <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.26100.0" />
15
+ <!-- WinUI3 / Windows App SDK 1.6 framework package (framework-dependent). Required so the
16
+ registered app can activate Microsoft.UI.Xaml.* (else REGDB_E_CLASSNOTREG at startup). -->
17
+ <PackageDependency Name="Microsoft.WindowsAppRuntime.1.6" MinVersion="6000.0.0.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
18
+ </Dependencies>
19
+ <Resources>
20
+ <Resource Language="en-US" />
21
+ </Resources>
22
+ <Applications>
23
+ <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="Windows.FullTrustApplication">
24
+ <uap:VisualElements DisplayName="__PROJECT_NAME__" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="A NativeScript Windows application" BackgroundColor="#65ADF1">
25
+ <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" />
26
+ <uap:SplashScreen Image="Assets\SplashScreen.png" />
27
+ </uap:VisualElements>
28
+ </Application>
29
+ </Applications>
30
+ <Capabilities>
31
+ <rescap:Capability Name="runFullTrust" />
32
+ <Capability Name="internetClient" />
33
+ <Capability Name="privateNetworkClientServer" />
34
+ </Capabilities>
35
+ </Package>
@@ -1,34 +1,34 @@
1
- using System;
2
- using System.Threading;
3
- using Microsoft.UI.Dispatching;
4
- using Microsoft.UI.Xaml;
5
- using WinRT;
6
-
7
- // Windows-only WinUI desktop app. The custom entry point (DISABLE_XAML_GENERATED_MAIN)
8
- // has no platform attribute, so CA1416 treats every Windows API call site as "reachable
9
- // on all platforms." Declaring the assembly's supported platform once tells the analyzer
10
- // the whole assembly only runs on Windows >= 17763, silencing those false positives.
11
- [assembly: System.Runtime.Versioning.SupportedOSPlatform("windows10.0.17763.0")]
12
-
13
- namespace __PROJECT_NAME__
14
- {
15
- public static class Program
16
- {
17
- [System.STAThread]
18
- public static void Main(string[] args)
19
- {
20
- ComWrappersSupport.InitializeComWrappers();
21
-
22
- Application.Start((_callbackParams) =>
23
- {
24
- var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
25
- if (dispatcherQueue != null)
26
- {
27
- SynchronizationContext.SetSynchronizationContext(new DispatcherQueueSynchronizationContext(dispatcherQueue));
28
- }
29
-
30
- new App();
31
- });
32
- }
33
- }
34
- }
1
+ using System;
2
+ using System.Threading;
3
+ using Microsoft.UI.Dispatching;
4
+ using Microsoft.UI.Xaml;
5
+ using WinRT;
6
+
7
+ // Windows-only WinUI desktop app. The custom entry point (DISABLE_XAML_GENERATED_MAIN)
8
+ // has no platform attribute, so CA1416 treats every Windows API call site as "reachable
9
+ // on all platforms." Declaring the assembly's supported platform once tells the analyzer
10
+ // the whole assembly only runs on Windows >= 17763, silencing those false positives.
11
+ [assembly: System.Runtime.Versioning.SupportedOSPlatform("windows10.0.17763.0")]
12
+
13
+ namespace __PROJECT_NAME__
14
+ {
15
+ public static class Program
16
+ {
17
+ [System.STAThread]
18
+ public static void Main(string[] args)
19
+ {
20
+ ComWrappersSupport.InitializeComWrappers();
21
+
22
+ Application.Start((_callbackParams) =>
23
+ {
24
+ var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
25
+ if (dispatcherQueue != null)
26
+ {
27
+ SynchronizationContext.SetSynchronizationContext(new DispatcherQueueSynchronizationContext(dispatcherQueue));
28
+ }
29
+
30
+ new App();
31
+ });
32
+ }
33
+ }
34
+ }
@@ -1,9 +1,9 @@
1
- <!--
2
- Runtime Directives for .NET Native.
3
- See https://go.microsoft.com/fwlink/?LinkID=391919
4
- -->
5
- <Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
6
- <Application>
7
- <Assembly Name="*Application*" Dynamic="Required All" />
8
- </Application>
9
- </Directives>
1
+ <!--
2
+ Runtime Directives for .NET Native.
3
+ See https://go.microsoft.com/fwlink/?LinkID=391919
4
+ -->
5
+ <Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
6
+ <Application>
7
+ <Assembly Name="*Application*" Dynamic="Required All" />
8
+ </Application>
9
+ </Directives>
@@ -1,161 +1,161 @@
1
- using System;
2
- using System.Buffers;
3
- using System.Buffers.Binary;
4
- using System.Text;
5
-
6
- namespace NativeScriptBridge;
7
-
8
- internal readonly struct HandleRef(int id)
9
- {
10
- public readonly int Id = id;
11
- }
12
-
13
- // Carries a raw IUnknown/IInspectable pointer from a WinRT proxy (tag 0x0A).
14
- // CoerceBin calls Marshal.GetObjectForIUnknown to create a managed RCW.
15
- internal readonly struct WinRtRef(long ptr)
16
- {
17
- public readonly long Ptr = ptr;
18
- }
19
-
20
- internal ref struct BinReader(ReadOnlySpan<byte> buf)
21
- {
22
- private readonly ReadOnlySpan<byte> _buf = buf;
23
- private int _pos = 0;
24
-
25
- public byte ReadByte() => _buf[_pos++];
26
-
27
- public int ReadI32()
28
- {
29
- var v = BinaryPrimitives.ReadInt32LittleEndian(_buf[_pos..]);
30
- _pos += 4;
31
- return v;
32
- }
33
-
34
- public long ReadI64()
35
- {
36
- var v = BinaryPrimitives.ReadInt64LittleEndian(_buf[_pos..]);
37
- _pos += 8;
38
- return v;
39
- }
40
-
41
- public ushort ReadU16()
42
- {
43
- var v = BinaryPrimitives.ReadUInt16LittleEndian(_buf[_pos..]);
44
- _pos += 2;
45
- return v;
46
- }
47
-
48
- public double ReadF64()
49
- {
50
- var v = BinaryPrimitives.ReadDoubleLittleEndian(_buf[_pos..]);
51
- _pos += 8;
52
- return v;
53
- }
54
-
55
- public string ReadString16()
56
- {
57
- var len = ReadU16();
58
- var s = Encoding.UTF8.GetString(_buf.Slice(_pos, len));
59
- _pos += len;
60
- // Intern so repeated method/type names reuse the same heap string.
61
- // Eliminates the allocation on every subsequent warm-path call.
62
- return string.Intern(s);
63
- }
64
-
65
- public string ReadString32()
66
- {
67
- var len = BinaryPrimitives.ReadUInt32LittleEndian(_buf.Slice(_pos, 4));
68
- _pos += 4;
69
- var s = Encoding.UTF8.GetString(_buf.Slice(_pos, (int)len));
70
- _pos += (int)len;
71
- return string.Intern(s);
72
- }
73
-
74
- public uint ReadU32()
75
- {
76
- var v = BinaryPrimitives.ReadUInt32LittleEndian(_buf.Slice(_pos, 4));
77
- _pos += 4;
78
- return v;
79
- }
80
-
81
- public object?[] ReadArgs()
82
- {
83
- var count = ReadByte();
84
- if (count == 0) return [];
85
- var args = new object?[count];
86
- for (int i = 0; i < count; i++)
87
- {
88
- var tag = ReadByte();
89
- args[i] = tag switch
90
- {
91
- 0x00 => null,
92
- 0x01 => (object)false,
93
- 0x02 => (object)true,
94
- 0x03 => (object)ReadI32(),
95
- 0x04 => (object)ReadF64(),
96
- 0x05 => (object)ReadString16(),
97
- 0x06 => (object)new HandleRef(ReadI32()),
98
- 0x0A => (object)new WinRtRef(ReadI64()),
99
- _ => null,
100
- };
101
- }
102
- return args;
103
- }
104
- }
105
-
106
- internal ref struct BinWriter(ArrayBufferWriter<byte> buf)
107
- {
108
- private readonly ArrayBufferWriter<byte> _buf = buf;
109
-
110
- public void WriteByte(byte b)
111
- {
112
- _buf.GetSpan(1)[0] = b;
113
- _buf.Advance(1);
114
- }
115
-
116
- public void WriteI32(int v)
117
- {
118
- BinaryPrimitives.WriteInt32LittleEndian(_buf.GetSpan(4), v);
119
- _buf.Advance(4);
120
- }
121
-
122
- public void WriteU16(ushort v)
123
- {
124
- BinaryPrimitives.WriteUInt16LittleEndian(_buf.GetSpan(2), v);
125
- _buf.Advance(2);
126
- }
127
-
128
- public void WriteU32(uint v)
129
- {
130
- BinaryPrimitives.WriteUInt32LittleEndian(_buf.GetSpan(4), v);
131
- _buf.Advance(4);
132
- }
133
-
134
- public void WriteI64(long v)
135
- {
136
- BinaryPrimitives.WriteInt64LittleEndian(_buf.GetSpan(8), v);
137
- _buf.Advance(8);
138
- }
139
-
140
- public void WriteF64(double v)
141
- {
142
- BinaryPrimitives.WriteDoubleLittleEndian(_buf.GetSpan(8), v);
143
- _buf.Advance(8);
144
- }
145
-
146
- public void WriteString32(ReadOnlySpan<char> s)
147
- {
148
- var byteCount = Encoding.UTF8.GetByteCount(s);
149
- WriteU32((uint)byteCount);
150
- Encoding.UTF8.GetBytes(s, _buf.GetSpan(byteCount));
151
- _buf.Advance(byteCount);
152
- }
153
-
154
- public void WriteString16(ReadOnlySpan<char> s)
155
- {
156
- var byteCount = Encoding.UTF8.GetByteCount(s);
157
- WriteU16((ushort)byteCount);
158
- Encoding.UTF8.GetBytes(s, _buf.GetSpan(byteCount));
159
- _buf.Advance(byteCount);
160
- }
161
- }
1
+ using System;
2
+ using System.Buffers;
3
+ using System.Buffers.Binary;
4
+ using System.Text;
5
+
6
+ namespace NativeScriptBridge;
7
+
8
+ internal readonly struct HandleRef(int id)
9
+ {
10
+ public readonly int Id = id;
11
+ }
12
+
13
+ // Carries a raw IUnknown/IInspectable pointer from a WinRT proxy (tag 0x0A).
14
+ // CoerceBin calls Marshal.GetObjectForIUnknown to create a managed RCW.
15
+ internal readonly struct WinRtRef(long ptr)
16
+ {
17
+ public readonly long Ptr = ptr;
18
+ }
19
+
20
+ internal ref struct BinReader(ReadOnlySpan<byte> buf)
21
+ {
22
+ private readonly ReadOnlySpan<byte> _buf = buf;
23
+ private int _pos = 0;
24
+
25
+ public byte ReadByte() => _buf[_pos++];
26
+
27
+ public int ReadI32()
28
+ {
29
+ var v = BinaryPrimitives.ReadInt32LittleEndian(_buf[_pos..]);
30
+ _pos += 4;
31
+ return v;
32
+ }
33
+
34
+ public long ReadI64()
35
+ {
36
+ var v = BinaryPrimitives.ReadInt64LittleEndian(_buf[_pos..]);
37
+ _pos += 8;
38
+ return v;
39
+ }
40
+
41
+ public ushort ReadU16()
42
+ {
43
+ var v = BinaryPrimitives.ReadUInt16LittleEndian(_buf[_pos..]);
44
+ _pos += 2;
45
+ return v;
46
+ }
47
+
48
+ public double ReadF64()
49
+ {
50
+ var v = BinaryPrimitives.ReadDoubleLittleEndian(_buf[_pos..]);
51
+ _pos += 8;
52
+ return v;
53
+ }
54
+
55
+ public string ReadString16()
56
+ {
57
+ var len = ReadU16();
58
+ var s = Encoding.UTF8.GetString(_buf.Slice(_pos, len));
59
+ _pos += len;
60
+ // Intern so repeated method/type names reuse the same heap string.
61
+ // Eliminates the allocation on every subsequent warm-path call.
62
+ return string.Intern(s);
63
+ }
64
+
65
+ public string ReadString32()
66
+ {
67
+ var len = BinaryPrimitives.ReadUInt32LittleEndian(_buf.Slice(_pos, 4));
68
+ _pos += 4;
69
+ var s = Encoding.UTF8.GetString(_buf.Slice(_pos, (int)len));
70
+ _pos += (int)len;
71
+ return string.Intern(s);
72
+ }
73
+
74
+ public uint ReadU32()
75
+ {
76
+ var v = BinaryPrimitives.ReadUInt32LittleEndian(_buf.Slice(_pos, 4));
77
+ _pos += 4;
78
+ return v;
79
+ }
80
+
81
+ public object?[] ReadArgs()
82
+ {
83
+ var count = ReadByte();
84
+ if (count == 0) return [];
85
+ var args = new object?[count];
86
+ for (int i = 0; i < count; i++)
87
+ {
88
+ var tag = ReadByte();
89
+ args[i] = tag switch
90
+ {
91
+ 0x00 => null,
92
+ 0x01 => (object)false,
93
+ 0x02 => (object)true,
94
+ 0x03 => (object)ReadI32(),
95
+ 0x04 => (object)ReadF64(),
96
+ 0x05 => (object)ReadString16(),
97
+ 0x06 => (object)new HandleRef(ReadI32()),
98
+ 0x0A => (object)new WinRtRef(ReadI64()),
99
+ _ => null,
100
+ };
101
+ }
102
+ return args;
103
+ }
104
+ }
105
+
106
+ internal ref struct BinWriter(ArrayBufferWriter<byte> buf)
107
+ {
108
+ private readonly ArrayBufferWriter<byte> _buf = buf;
109
+
110
+ public void WriteByte(byte b)
111
+ {
112
+ _buf.GetSpan(1)[0] = b;
113
+ _buf.Advance(1);
114
+ }
115
+
116
+ public void WriteI32(int v)
117
+ {
118
+ BinaryPrimitives.WriteInt32LittleEndian(_buf.GetSpan(4), v);
119
+ _buf.Advance(4);
120
+ }
121
+
122
+ public void WriteU16(ushort v)
123
+ {
124
+ BinaryPrimitives.WriteUInt16LittleEndian(_buf.GetSpan(2), v);
125
+ _buf.Advance(2);
126
+ }
127
+
128
+ public void WriteU32(uint v)
129
+ {
130
+ BinaryPrimitives.WriteUInt32LittleEndian(_buf.GetSpan(4), v);
131
+ _buf.Advance(4);
132
+ }
133
+
134
+ public void WriteI64(long v)
135
+ {
136
+ BinaryPrimitives.WriteInt64LittleEndian(_buf.GetSpan(8), v);
137
+ _buf.Advance(8);
138
+ }
139
+
140
+ public void WriteF64(double v)
141
+ {
142
+ BinaryPrimitives.WriteDoubleLittleEndian(_buf.GetSpan(8), v);
143
+ _buf.Advance(8);
144
+ }
145
+
146
+ public void WriteString32(ReadOnlySpan<char> s)
147
+ {
148
+ var byteCount = Encoding.UTF8.GetByteCount(s);
149
+ WriteU32((uint)byteCount);
150
+ Encoding.UTF8.GetBytes(s, _buf.GetSpan(byteCount));
151
+ _buf.Advance(byteCount);
152
+ }
153
+
154
+ public void WriteString16(ReadOnlySpan<char> s)
155
+ {
156
+ var byteCount = Encoding.UTF8.GetByteCount(s);
157
+ WriteU16((ushort)byteCount);
158
+ Encoding.UTF8.GetBytes(s, _buf.GetSpan(byteCount));
159
+ _buf.Advance(byteCount);
160
+ }
161
+ }