Documentation ¶
Overview ¶
Package codegen contains functions and types used by the weaver_gen.go files generated by "weaver generate". The APIs in this package are not suitable for direct use by Service Weaver applications.
Index ¶
- Variables
- func CatchPanics(r interface{}) error
- func ComponentConfigValidator(path, cfg string) error
- func Register(reg Registration)
- type AutoMarshal
- type CallEdge
- type Decoder
- func (d *Decoder) Bool() bool
- func (d *Decoder) Byte() byte
- func (d *Decoder) Bytes() []byte
- func (d *Decoder) Complex128() complex128
- func (d *Decoder) Complex64() complex64
- func (d *Decoder) DecodeBinaryUnmarshaler(value encoding.BinaryUnmarshaler)
- func (d *Decoder) DecodeProto(value proto.Message)
- func (d *Decoder) Empty() bool
- func (d *Decoder) Error() error
- func (d *Decoder) Float32() float32
- func (d *Decoder) Float64() float64
- func (d *Decoder) Int() int
- func (d *Decoder) Int16() int16
- func (d *Decoder) Int32() int32
- func (d *Decoder) Int64() int64
- func (d *Decoder) Int8() int8
- func (d *Decoder) Len() int
- func (d *Decoder) Read(n int) []byte
- func (d *Decoder) Rune() rune
- func (d *Decoder) String() string
- func (d *Decoder) Uint() uint
- func (d *Decoder) Uint16() uint16
- func (d *Decoder) Uint32() uint32
- func (d *Decoder) Uint64() uint64
- func (d *Decoder) Uint8() uint8
- type Encoder
- func (e *Encoder) Bool(arg bool)
- func (e *Encoder) Byte(arg byte)
- func (e *Encoder) Bytes(arg []byte)
- func (e *Encoder) Complex128(arg complex128)
- func (e *Encoder) Complex64(arg complex64)
- func (e *Encoder) Data() []byte
- func (e *Encoder) EncodeBinaryMarshaler(value encoding.BinaryMarshaler)
- func (e *Encoder) EncodeProto(value proto.Message)
- func (e *Encoder) Error(err error)
- func (e *Encoder) Float32(arg float32)
- func (e *Encoder) Float64(arg float64)
- func (e *Encoder) Grow(bytesNeeded int) []byte
- func (e *Encoder) Int(arg int)
- func (e *Encoder) Int16(arg int16)
- func (e *Encoder) Int32(arg int32)
- func (e *Encoder) Int64(arg int64)
- func (e *Encoder) Int8(arg int8)
- func (e *Encoder) Len(l int)
- func (e *Encoder) Reset(n int)
- func (e *Encoder) Rune(arg rune)
- func (e *Encoder) String(arg string)
- func (e *Encoder) Uint(arg uint)
- func (e *Encoder) Uint16(arg uint16)
- func (e *Encoder) Uint32(arg uint32)
- func (e *Encoder) Uint64(arg uint64)
- func (e *Encoder) Uint8(arg uint8)
- type Hasher
- func (h *Hasher) Sum64() uint64
- func (h *Hasher) WriteFloat32(v float32)
- func (h *Hasher) WriteFloat64(v float64)
- func (h *Hasher) WriteInt(v int)
- func (h *Hasher) WriteInt16(v int16)
- func (h *Hasher) WriteInt32(v int32)
- func (h *Hasher) WriteInt64(v int64)
- func (h *Hasher) WriteInt8(v int8)
- func (h *Hasher) WriteString(v string)
- func (h *Hasher) WriteUint(v uint)
- func (h *Hasher) WriteUint16(v uint16)
- func (h *Hasher) WriteUint32(v uint32)
- func (h *Hasher) WriteUint64(v uint64)
- func (h *Hasher) WriteUint8(v uint8)
- type MethodLabels
- type MethodMetrics
- type OrderedCode
- type OrderedEncoder
- func (e *OrderedEncoder) Encode() OrderedCode
- func (e *OrderedEncoder) Reset()
- func (e *OrderedEncoder) WriteFloat32(f float32)
- func (e *OrderedEncoder) WriteFloat64(f float64)
- func (e *OrderedEncoder) WriteInt(x int)
- func (e *OrderedEncoder) WriteInt16(x int16)
- func (e *OrderedEncoder) WriteInt32(x int32)
- func (e *OrderedEncoder) WriteInt64(x int64)
- func (e *OrderedEncoder) WriteInt8(x int8)
- func (e *OrderedEncoder) WriteString(s string)
- func (e *OrderedEncoder) WriteUint(x uint)
- func (e *OrderedEncoder) WriteUint16(x uint16)
- func (e *OrderedEncoder) WriteUint32(x uint32)
- func (e *OrderedEncoder) WriteUint64(x uint64)
- func (e *OrderedEncoder) WriteUint8(x uint8)
- type Registration
- type Server
- type Stub
Constants ¶
This section is empty.
Variables ¶
var ( // The following metrics are automatically populated for the user. // // TODO(mwhittaker): Allow the user to disable these metrics. // It adds ~169ns of latency per method call. MethodCounts = metrics.NewCounterMap[MethodLabels]( "serviceweaver_remote_method_count", "Count of Service Weaver component method invocations", ) MethodErrors = metrics.NewCounterMap[MethodLabels]( "serviceweaver_remote_method_error_count", "Count of Service Weaver component method invocations that result in an error", ) MethodLatencies = metrics.NewHistogramMap[MethodLabels]( "serviceweaver_remote_method_latency_micros", "Duration, in microseconds, of Service Weaver component method execution", metrics.NonNegativeBuckets, ) MethodBytesRequest = metrics.NewHistogramMap[MethodLabels]( "serviceweaver_remote_method_bytes_request", "Number of bytes in Service Weaver component method requests", metrics.NonNegativeBuckets, ) MethodBytesReply = metrics.NewHistogramMap[MethodLabels]( "serviceweaver_remote_method_bytes_reply", "Number of bytes in Service Weaver component method replies", metrics.NonNegativeBuckets, ) )
Functions ¶
func CatchPanics ¶
func CatchPanics(r interface{}) error
CatchPanics recovers from panic() calls that occur during encoding, decoding, and RPC execution.
func ComponentConfigValidator ¶
ComponentConfigValidator checks that cfg is a valid configuration for the component type whose fully qualified name is given by path.
Types ¶
type AutoMarshal ¶
AutoMarshal is the interface implemented by structs with weaver.AutoMarshal declarations.
type CallEdge ¶ added in v0.7.2
CallEdge records that fact that the Caller component uses the Callee component. Both types are types of the corresponding component interfaces.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder deserializes data from a byte slice data in the expected results.
func NewDecoder ¶
NewDecoder instantiates a new Decoder for a given byte slice.
func (*Decoder) Complex128 ¶
func (d *Decoder) Complex128() complex128
Complex128 decodes a value of type complex128.
func (*Decoder) DecodeBinaryUnmarshaler ¶
func (d *Decoder) DecodeBinaryUnmarshaler(value encoding.BinaryUnmarshaler)
DecodeBinaryMarshaler deserializes the value from a byte slice using UnmarshalBinary.
func (*Decoder) DecodeProto ¶
DecodeProto deserializes the value from a byte slice using proto serialization.
func (*Decoder) Error ¶
Error decodes an error. We construct an instance of a special error value that provides Is and Unwrap support.
func (*Decoder) Len ¶
Len attempts to decode an int32.
Panics if the result is negative (except -1).
NOTE that this method should be called only in the generated code, to avoid generating repetitive code that decodes the length of a non-basic type (e.g., slice, map).
func (*Decoder) Read ¶
Read reads and returns n bytes from the decoder and advances the decode past the read bytes.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder serializes data in a byte slice data.
func NewEncoder ¶
func NewEncoder() *Encoder
func (*Encoder) Bool ¶
Bool encodes an arg of type bool. Serialize boolean values as an uint8 that encodes either 0 or 1.
func (*Encoder) Bytes ¶
Bytes encodes an arg of type []byte. For a byte slice, we encode its length, followed by the serialized content. If the slice is nil, we encode length as -1.
func (*Encoder) Complex128 ¶
func (e *Encoder) Complex128(arg complex128)
Complex128 encodes an arg of type complex128.
func (*Encoder) Complex64 ¶
Complex64 encodes an arg of type complex64. We encode the real and the imaginary parts one after the other.
func (*Encoder) EncodeBinaryMarshaler ¶
func (e *Encoder) EncodeBinaryMarshaler(value encoding.BinaryMarshaler)
EncodeBinaryMarshaler serializes value into a byte slice using its MarshalBinary method.
func (*Encoder) EncodeProto ¶
EncodeProto serializes value into a byte slice using proto serialization.
func (*Encoder) Error ¶
Error encodes an arg of type error. We save enough type information to allow errors.Unwrap() and errors.Is() to work correctly.
func (*Encoder) Grow ¶
Grow increases the size of the encoder's data if needed. Only appends a new slice if there is not enough capacity to satisfy bytesNeeded. Returns the slice fragment that contains bytesNeeded.
func (*Encoder) Int ¶
Int encodes an arg of type int. Int can have 32 bits or 64 bits based on the machine type. To simplify our reasoning, we encode the highest possible value.
func (*Encoder) Len ¶
Len attempts to encode l as an int32.
Panics if l is bigger than an int32 or a negative length (except -1).
NOTE that this method should be called only in the generated code, to avoid generating repetitive code that encodes the length of a non-basic type (e.g., slice, map).
func (*Encoder) Reset ¶
Reset resets the Encoder to use a buffer with a capacity of at least the provided size. All encoded data is lost.
func (*Encoder) String ¶
String encodes an arg of type string. For a string, we encode its length, followed by the serialized content.
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher computes a non-cryptographic hash of the sequence of values added to it.
If the same sequence of values is added to two differ Hashers, they will produce the same result, even if they are in different processes.
func (*Hasher) Sum64 ¶
Sum64 returns the 64-bit hash of the sequence of values added so far. The resulting is in the range [1,2^64-2], i.e., it is never 0 or math.MaxUint64.
func (*Hasher) WriteFloat32 ¶
WriteFloat32 adds a float32 to the hasher.
func (*Hasher) WriteFloat64 ¶
WriteFloat64 adds a float64 to the hasher.
func (*Hasher) WriteInt16 ¶
WriteInt16 adds a int16 to the hasher.
func (*Hasher) WriteInt32 ¶
WriteInt32 adds a int32 to the hasher.
func (*Hasher) WriteInt64 ¶
WriteInt64 adds a int64 to the hasher.
func (*Hasher) WriteString ¶
WriteString adds a string to the hasher.
func (*Hasher) WriteUint16 ¶
WriteUint16 adds a uint16 to the hasher.
func (*Hasher) WriteUint32 ¶
WriteUint32 adds a uint32 to the hasher.
func (*Hasher) WriteUint64 ¶
WriteUint64 adds a uint64 to the hasher.
func (*Hasher) WriteUint8 ¶
WriteUint8 adds a uint8 to the hasher.
type MethodLabels ¶
type MethodMetrics ¶
type MethodMetrics struct { Count *metrics.Counter // See MethodCounts. ErrorCount *metrics.Counter // See MethodErrors. Latency *metrics.Histogram // See MethodLatencies. BytesRequest *metrics.Histogram // See MethodBytesRequest. BytesReply *metrics.Histogram // See MethodBytesReply. }
MethodMetrics contains metrics for a single Service Weaver component method.
func MethodMetricsFor ¶
func MethodMetricsFor(labels MethodLabels) *MethodMetrics
MethodMetricsFor returns metrics for the specified method.
type OrderedCode ¶
type OrderedCode string
OrderedCode is an order preserving encoded value.
const Infinity OrderedCode = "\xFF"
Infinity is the greatest element of the set of all OrderedCodes. That is, for every OrderedCode x produced by an Encoder, Infinity > x.
type OrderedEncoder ¶
type OrderedEncoder struct {
// contains filtered or unexported fields
}
OrderedEncoder serializes values in an order preserving fashion. When multiple values are serialized together, their lexicographic ordering is preserved. For example,
var e orderedcode.OrderedEncoder e.WriteUint8(1) e.WriteFloat32(2.0) e.OrderedCode()
func (*OrderedEncoder) Encode ¶
func (e *OrderedEncoder) Encode() OrderedCode
Encode returns the encoding.
func (*OrderedEncoder) Reset ¶
func (e *OrderedEncoder) Reset()
Reset resets the encoder to be empty, but retains any previously used space for future serialization.
func (*OrderedEncoder) WriteFloat32 ¶
func (e *OrderedEncoder) WriteFloat32(f float32)
WriteFloat32 serializes a value of type float32.
func (*OrderedEncoder) WriteFloat64 ¶
func (e *OrderedEncoder) WriteFloat64(f float64)
WriteFloat64 serializes a value of type float64.
func (*OrderedEncoder) WriteInt ¶
func (e *OrderedEncoder) WriteInt(x int)
WriteInt serializes a value of type int.
func (*OrderedEncoder) WriteInt16 ¶
func (e *OrderedEncoder) WriteInt16(x int16)
WriteInt16 serializes a value of type int16.
func (*OrderedEncoder) WriteInt32 ¶
func (e *OrderedEncoder) WriteInt32(x int32)
WriteInt32 serializes a value of type int32.
func (*OrderedEncoder) WriteInt64 ¶
func (e *OrderedEncoder) WriteInt64(x int64)
WriteInt64 serializes a value of type int64.
func (*OrderedEncoder) WriteInt8 ¶
func (e *OrderedEncoder) WriteInt8(x int8)
WriteInt8 serializes a value of type int8.
func (*OrderedEncoder) WriteString ¶
func (e *OrderedEncoder) WriteString(s string)
WriteString serializes a value of type string.
func (*OrderedEncoder) WriteUint ¶
func (e *OrderedEncoder) WriteUint(x uint)
WriteUint serializes a value of type uint.
func (*OrderedEncoder) WriteUint16 ¶
func (e *OrderedEncoder) WriteUint16(x uint16)
WriteUint16 serializes a value of type uint16.
func (*OrderedEncoder) WriteUint32 ¶
func (e *OrderedEncoder) WriteUint32(x uint32)
WriteUint32 serializes a value of type uint32.
func (*OrderedEncoder) WriteUint64 ¶
func (e *OrderedEncoder) WriteUint64(x uint64)
WriteUint64 serializes a value of type uint64.
func (*OrderedEncoder) WriteUint8 ¶
func (e *OrderedEncoder) WriteUint8(x uint8)
WriteUint8 serializes a value of type uint8.
type Registration ¶
type Registration struct { Name string // full package-prefixed component name Iface reflect.Type // interface type for the component Impl reflect.Type // implementation type (struct) ConfigFn func(impl any) any // returns pointer to config field in local impl if non-nil Routed bool // True if calls to this component should be routed // Functions that return different types of stubs. LocalStubFn func(impl any, tracer trace.Tracer) any ClientStubFn func(stub Stub, caller string) any ServerStubFn func(impl any, load func(key uint64, load float64)) Server }
Registration is the configuration needed to register a Service Weaver component.
func Registered ¶
func Registered() []*Registration
Registered returns the components registered with Register.
type Server ¶
type Server interface { // GetStubFn returns a handler function for the given method. For example, // if a Service Weaver component defined an Echo method, then GetStubFn("Echo") // would return a handler that deserializes the arguments, executes the // method, and serializes the results. // // TODO(mwhittaker): Rename GetHandler? This is returning a call.Handler. GetStubFn(method string) func(ctx context.Context, args []byte) ([]byte, error) }
A Server allows a Service Weaver component in one process to receive and execute methods via RPC from a Service Weaver component in a different process. It is the dual of a Stub.
type Stub ¶
type Stub interface { // Tracer returns a new tracer. // // TODO(mwhittaker): Move tracer out of stub? It doesn't really fit with // the abstraction? Tracer() trace.Tracer // Run executes the provided method with the provided serialized arguments. // At code generation time, an object's methods are deterministically // ordered. method is the index into this slice. args and results are the // serialized arguments and results, respectively. shardKey is the shard // key for routed components, and 0 otherwise. Run(ctx context.Context, method int, args []byte, shardKey uint64) (results []byte, err error) }
A Stub allows a Service Weaver component in one process to invoke methods via RPC on a Service Weaver component in a different process.