Class ProtobufSampleEncoder

Namespace
Kuestenlogik.Bowire.Protocol.Grpc.Mock
Assembly
Kuestenlogik.Bowire.Protocol.Grpc.dll

Hand-rolled protobuf wire-format encoder that emits a plausible sample instance of a message given only its Google.Protobuf.Reflection.MessageDescriptor. Complements Kuestenlogik.Bowire.Protocol.Rest.Mock.OpenApiSampleGenerator for the gRPC schema-only mock path: instead of JSON text, we produce the raw binary bytes the gRPC framer wraps in a length-prefixed envelope.

public static class ProtobufSampleEncoder
Inheritance
ProtobufSampleEncoder
Inherited Members

Remarks

Google.Protobuf's C# library has no DynamicMessage equivalent — the standard way to serialize a protobuf is through a code-generated message class. For a schema-only mock we don't have those classes; we only have the parsed Google.Protobuf.Reflection.FileDescriptors from a protoc --descriptor_set_out output. This encoder walks the descriptor directly and writes wire bytes with Google.Protobuf.CodedOutputStream, which is the same primitive the generated code ultimately calls.

Per-field sample values match the OpenAPI generator's instincts: int*/sint*/fixed*1, float/double1.5, string/bytes"sample", booltrue, enums → the zero value (the proto3-default), nested messages → recurse. Repeated fields carry three entries. Cyclic $ref-style schemas are tamed by a depth cap.

Methods

Encode(MessageDescriptor)

Encode one sample instance of descriptor as wire bytes.

public static byte[] Encode(MessageDescriptor descriptor)

Parameters

descriptor MessageDescriptor

Returns

byte[]