Section navigation

Public classStatic Codec

Namespace
Rowles.LeanCorpus.Codecs.CodecKit
Assembly
Rowles.LeanCorpus.dll

Primary entry point for all codec operations. Provides factory methods for primitive and composite codecs, as well as top-level encode/decode entry points.

public static class Codec
Inheritance
Codec

Public property Bool

Public property Float32BE

Public property Float32LE

Public property Float64BE

Public property Float64LE

Public property GuidDotNet

Public property GuidRfc4122

Public property Int16BE

Public property Int16LE

Public property Int32BE

Public property Int32LE

Public property Int64BE

Public property Int64LE

Public property Int8

Public property UInt16BE

Public property UInt16LE

Public property UInt32BE

Public property UInt32LE

Public property UInt64BE

Public property UInt64LE

Public property UInt8

Public property VarInt32

Public property VarInt64

Public property VarUInt32

Public property VarUInt64

Public method BytesBorrowed(int)

Public method BytesBorrowedRemaining()

Public method BytesOwned(int)

Public method BytesOwnedRemaining()

Public method Case<TBase, TCase>(object, string, ICodec<TCase>)

Public method Choice<TBase, TTag>(ICodec<TTag>, params CaseDefinition<TBase>[])

Tag-based discriminated union codec. Decode reads the tag, dispatches to the matching case codec; encode pattern-matches the value type.

Public method Decode<T>(ICodec<T>, ReadOnlySequence<byte>, CodecOptions?, CodecRegistry?)

Decodes a value of type T from the given bytes. Throws a CodecException on failure.

Public method Decode<T>(ICodec<T>, byte[], CodecOptions?, CodecRegistry?)

Decodes a value from a byte array.

Public method Decode<T>(ICodec<T>, ReadOnlySpan<byte>, CodecOptions?, CodecRegistry?)

Decodes a value from a ReadOnlySpan (copies to array first).

Public method EncodeAtomic<T>(ICodec<T>, T, IBufferWriter<byte>, CodecOptions?, CodecRegistry?)

Encodes a value atomically — stages to a scratch buffer first, only commits to the writer on success. If encoding fails, the writer remains untouched.

Public method EncodeSpan(ICodec<byte[]>, ReadOnlySpan<byte>, IBufferWriter<byte>, CodecOptions?, CodecRegistry?)

Encodes a ReadOnlySpan<T> body through a version-envelope codec without allocating a byte[]. If the codec is a Rowles.LeanCorpus.Codecs.CodecKit.Internal.VersionEnvelopeCodec<TBase, TVersion> the fast span path is used; otherwise falls back to the normal Encode<T>(ICodec<T>, T, IBufferWriter<byte>, CodecOptions?, CodecRegistry?) path.

Public method EncodeToArray<T>(ICodec<T>, T, CodecOptions?, CodecRegistry?)

Encodes a value and returns the bytes as a new array.

Public method Encode<T>(ICodec<T>, T, IBufferWriter<byte>, CodecOptions, CodecRegistry)

Encodes a value to the given writer.

Public method FixedFrame<T>(int, ICodec<T>, FramePadding?, TrailingDataPolicy)

Fixed-frame framing: [body][padding] with exactly size total bytes.

Public method From<TDep, TOut>(string, Func<TDep, ICodec<TOut>>)

Creates a dependent field factory that produces a codec from a previously decoded field value.

Public method LengthPrefixed<T>(ICodec<int>, ICodec<T>, TrailingDataPolicy)

Length-prefixed framing: [length][body]. The length codec writes/reads the body byte count.

Public method LengthPrefixed<T>(ICodec<long>, ICodec<T>, TrailingDataPolicy)

Length-prefixed framing with a long length codec.

Public method LengthPrefixed<T>(ICodec<uint>, ICodec<T>, TrailingDataPolicy)

Length-prefixed framing with a uint length codec.

Public method Magic(params byte[])

Public method Magic(uint)

Public method Map<TIn, TOut>(ICodec<TIn>, Func<TIn, TOut>, Func<TOut, TIn>)

Creates a codec that transforms values using the given encode/decode delegates. User delegate exceptions are wrapped in UserCodeException.

Public method Optional<T>(ICodec<T>, ICodec<bool>)

Flag-based optional: a bool discriminator precedes the body. true → body present, false → absent (returns default).

Public method Optional<T, TSentinel>(ICodec<T>, ICodec<TSentinel>, TSentinel, TSentinel)

Sentinel-based optional: if the decoded sentinel equals absentValue, the result is default/null. Otherwise the full body is decoded.

Public method Padding(int, byte)

Public method Record<T>()

Creates a new record builder for type T.

Public method RepeatFrom<T>(ICodec<T>, string)

Creates a DependentFieldFactory<TDep, TOut> that produces a Repeat(count) codec where the count comes from a parent field. Use with Field<TDep, TField>(string, Func<T, TField>, DependentFieldFactory<TDep, TField>).

Public method RepeatPrefixed<T>(ICodec<T>, ICodec<int>)

Decode/encode a count-prefixed list with an int count codec. The count is read/written first, then that many elements follow.

Public method RepeatPrefixed<T>(ICodec<T>, ICodec<long>)

Decode/encode a count-prefixed list with a long count codec.

Public method RepeatPrefixed<T>(ICodec<T>, ICodec<uint>)

Decode/encode a count-prefixed list with a uint count codec.

Public method Repeat<T>(ICodec<T>, int)

Decode/encode a fixed number of T items. Path segment: [index] for each element.

Public method Skip(int)

Public method Then<TFirst, TSecond>(ICodec<TFirst>, ICodec<TSecond>)

Sequences two codecs: first is decoded/encoded but its result is discarded. The returned codec operates on the second codec's type.

Public method TryDecode<T>(ICodec<T>, ReadOnlySequence<byte>, CodecOptions?, CodecRegistry?)

Tries to decode a value. Returns a CodecResult<T> instead of throwing. On failure, the reader position is restored.

Public method TryDecode<T>(ICodec<T>, byte[], CodecOptions?, CodecRegistry?)

Tries to decode a value from a byte array.

Public method TryEncode<T>(ICodec<T>, T, IBufferWriter<byte>, CodecOptions?, CodecRegistry?)

Tries to encode a value. Returns a CodecResult<T> instead of throwing.

Public method Utf8BytesBorrowed(int)

Public method Utf8BytesOwned(int)

Public method Utf8String(int)

Public method Utf8StringRemaining()

Public method Validate<T>(ICodec<T>, Func<T, bool>, Func<T, string>)

Wraps a codec with a validation predicate. On decode or encode, if the predicate returns false, a CodecValidationException is thrown.

Public method Validate<T>(ICodec<T>, Func<T, bool>, string)

Wraps a codec with a validation predicate and a fixed error message.

Public method VersionCase<TBase, TCase>(object, string, ICodec<TCase>)

Public method VersionEnvelope<TBase, TVersion>(ICodec<TVersion>, ICodec<long>, Func<TVersion, byte[], TBase>, params VersionCaseDefinition<TBase>[])

Version-envelope codec: [version][body-length][body]. Known versions decode via their case codec; unknown versions are preserved via the unknown delegate.

Public method Versioned<TBase, TVersion>(ICodec<TVersion>, params VersionCaseDefinition<TBase>[])

Version-based discriminated union codec. Decode reads the version, dispatches to the matching case codec; encode pattern-matches the value type.

Public method WithChecksum<T>(ICodec<T>, ChecksumAlgorithmId, ChecksumPlacement)

Wraps a codec with checksum computation and verification.

Public method WithCompression<T>(ICodec<T>, CodecCompressionLevel, ICodec<uint>?)

Wraps a codec with Deflate compression/decompression. Wire format: [compressed-length][compressed-payload].