Vendors SnowLuma/protobuf-dsl into the monorepo as @snowluma/proton, with
edge-case fixes applied on top of the upstream source. Reference copy of
the unmodified upstream is kept under dev/protobuf-dsl/.
Edge cases fixed (each with a regression test):
- Aliased pb / pb_repeated marker imports (`import { pb as P }`)
— collector now resolves the marker name through the import resolver
- Concrete interface with a generic-instantiated message field
(`wrapped: pb<5, Wrapper<uint_32>>`) — field typeName now resolves
to the mangled form, and the inner instantiation is queued for
monomorphization
- Generic template with a generic-instantiated field
(`interface Outer<U> { x: pb<5, Wrapper<U>> }`) — the inner
instantiation is now re-substituted and re-monomorphized at outer
instantiation time
- Wrapper-binding synthetic SourceFile was empty-text — getText()
returned garbage, breaking mangled name computation downstream
- Cross-file forwarded wrappers (chain → imported base) were not
detected — parseFileForDefinitions now resolves imports recursively
(value imports only, with cycle protection)
- matchForwardedKnownWrapper did not propagate typePattern — chain
treated <X> as the encoded type instead of Wrapper<X>
- Synthetic-SF WeakMap was private to analyzer.ts — replacer could
not see it. Moved to utils.ts so typeNodeToMangledName picks it up
automatically.
Defensive guard: any field whose typeName resolves to neither a primitive
nor a known message now throws at analyze() time, instead of silently
leaking the WireType.Varint placeholder into codegen.
95/95 tests pass; tsc --noEmit clean.
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { protobuf_encode, protobuf_decode } from '@snowluma/proton';
|
|
|
|
export function encodeViaWrapper<T>(value: T): Uint8Array {
|
|
return protobuf_encode<T>(value);
|
|
}
|
|
|
|
export function decodeViaWrapper<T>(data: Uint8Array): T {
|
|
return protobuf_decode<T>(data);
|
|
}
|
|
|
|
export const encodeArrowWrapper = <T>(value: T): Uint8Array => protobuf_encode<T>(value);
|
|
|
|
export const decodeArrowWrapper = <T>(data: Uint8Array): T => protobuf_decode<T>(data);
|
|
|
|
export function encodeSecondGeneric<Ignored, T>(_ignored: Ignored, value: T): Uint8Array {
|
|
return protobuf_encode<T>(value);
|
|
}
|
|
|
|
export function passthroughOnly<T>(value: T): T {
|
|
return value;
|
|
}
|
|
|
|
export const wrapperObject = {
|
|
encode<T>(value: T): Uint8Array {
|
|
return protobuf_encode<T>(value);
|
|
},
|
|
decode<T>(data: Uint8Array): T {
|
|
return protobuf_decode<T>(data);
|
|
},
|
|
encodeArrow: <T>(value: T): Uint8Array => protobuf_encode<T>(value),
|
|
};
|
|
|
|
export function encodeWithBranch<T>(value: T, enabled: boolean): Uint8Array {
|
|
if (enabled) {
|
|
return protobuf_encode<T>(value);
|
|
}
|
|
return protobuf_encode<T>(value);
|
|
}
|
|
|
|
export function encodeWithNestedHelper<T>(value: T): Uint8Array {
|
|
function inner(payload: T): Uint8Array {
|
|
return protobuf_encode<T>(payload);
|
|
}
|
|
return inner(value);
|
|
}
|
|
|
|
export function encodeChained<T>(value: T): Uint8Array {
|
|
return encodeViaWrapper<T>(value);
|
|
} |