Files
zeekay 2aa8261f86 rebrand: complete capnp → ZAP across all C# source/build files
Finishes the in-flight capnp→ZAP rebrand on this branch. The prior commits
renamed identifiers/namespaces/files/projects (Capnp.Net.Runtime→Zap.Net.Runtime,
CapnpC→ZapC, .capnp→.zap) but left the human-readable brand name "Cap'n Proto"
throughout doc-comments, .csproj/.nuspec descriptions, README, MSBuild .xaml
rule display names, and the generated XML doc. This completes brand neutrality:

- Replace 154 "Cap'n Proto" / 4 "Cap'n-Proto" / 1 "Cap'n'p" prose occurrences
  with "ZAP" across 32 first-party files (runtime, generator, zapc-csharp,
  MSBuild integration, chocolatey nuspecs, README, docs, XML doc).
- Revert the LICENSE provenance URL to the real upstream fork
  (c80k/capnproto-dotnetcore) — upstream-fork license headers must stay.
- Canonicalize project/repo URLs to github.com/zap-proto/cs (were fabricated
  c80k/zap-dotnetcore) in csproj/nuspec/VERIFICATION/README badges.
- Canonicalize docs URLs zap-protocol(.github.io|/zap-cs|/zap-cpp-core)
  → zap-proto.dev / github.com/zap-proto/{cs,cpp-core}.
- Collapse redundant "zap \"ZAP\"" PackageTags to "zap".

Verified consistent (no toolchain on host): every .sln/.csproj ProjectReference
resolves; all namespaces are Zap*/ZapC*; MSBuild task chain
(GenerateZapFileCodeBehindTask, ZapFiles ItemGroup, _ZapcCsharp_TaskAssembly)
is uniformly renamed; props/targets/xaml/coverage/chocolatey carry no capnp.

Deliberately preserved as upstream-derived test data (not first-party source):
upstream Cap'n Proto schema fixtures (rpc.zap, rpc-twoparty.zap, json.zap,
rpc-csharp.zap), golden compiler-error outputs (errors.txt), and the
machine-generated DO-NOT-EDIT test.zap.{c++,h}. Their "Cap'n Proto" strings are
the literal output of the external schema compiler the compat test matches.
2026-06-19 23:46:57 -07:00

104 lines
4.1 KiB
C#

using System;
using System.Collections.Generic;
namespace Zap
{
/// <summary>
/// Provides deep-copy functionality to re-serialize an existing deserializer state into another serializer state.
/// </summary>
public static class Reserializing
{
/// <summary>
/// Performs a deep copy of an existing deserializer state into another serializer state.
/// This implementation does not analyze the source object graph and therefore cannot detect multiple references to the same object.
/// Such cases will result in object duplication.
/// </summary>
/// <param name="from">source state</param>
/// <param name="to">target state</param>
/// <exception cref="ArgumentNullException"><paramref name="to"/> is null.</exception>
/// <exception cref="InvalidOperationException">Target state was already set to a different object type than the source state.</exception>
/// <exception cref="DeserializationException">Security violation due to amplification attack or stack overflow DoS attack,
/// or illegal pointer detected during deserialization.</exception>
public static void DeepCopy(DeserializerState from, SerializerState to)
{
if (to == null)
throw new ArgumentNullException(nameof(to));
if (from.Caps != null && to.Caps != null)
{
to.Caps.Clear();
to.Caps.AddRange(from.Caps);
}
var ds = to.Rewrap<DynamicSerializerState>();
IReadOnlyList<DeserializerState> items;
switch (from.Kind)
{
case ObjectKind.Struct:
ds.SetStruct(from.StructDataCount, from.StructPtrCount);
ds.Allocate();
from.StructDataSection.CopyTo(ds.StructDataSection);
for (int i = 0; i < from.StructPtrCount; i++)
{
DeepCopy(from.StructReadPointer(i), ds.BuildPointer(i));
}
break;
case ObjectKind.ListOfBits:
ds.SetListOfValues(1, from.ListElementCount);
from.RawData.CopyTo(ds.RawData);
break;
case ObjectKind.ListOfBytes:
ds.SetListOfValues(8, from.ListElementCount);
from.RawData.CopyTo(ds.RawData);
break;
case ObjectKind.ListOfEmpty:
ds.SetListOfValues(0, from.ListElementCount);
break;
case ObjectKind.ListOfInts:
ds.SetListOfValues(32, from.ListElementCount);
from.RawData.CopyTo(ds.RawData);
break;
case ObjectKind.ListOfLongs:
ds.SetListOfValues(64, from.ListElementCount);
from.RawData.CopyTo(ds.RawData);
break;
case ObjectKind.ListOfShorts:
ds.SetListOfValues(16, from.ListElementCount);
from.RawData.CopyTo(ds.RawData);
break;
case ObjectKind.ListOfPointers:
ds.SetListOfPointers(from.ListElementCount);
items = (IReadOnlyList<DeserializerState>)from.RequireList();
for (int i = 0; i < from.ListElementCount; i++)
{
DeepCopy(items[i], ds.BuildPointer(i));
}
break;
case ObjectKind.ListOfStructs:
ds.SetListOfStructs(from.ListElementCount, from.StructDataCount, from.StructPtrCount);
items = (IReadOnlyList<DeserializerState>)from.RequireList();
for (int i = 0; i < from.ListElementCount; i++)
{
DeepCopy(items[i], ds.ListBuildStruct(i));
}
break;
case ObjectKind.Capability:
ds.SetCapability(from.CapabilityIndex);
break;
}
to.InheritFrom(ds);
}
}
}