Documentation
¶
Overview ¶
Package sofarpcwire implements the BOLT v1 + Hessian v1 wire encoding/decoding for SOFARPC generic invoke.
File layout for the decoder side:
- decoder.go — Hessian decoder struct, top-level tag dispatcher, list/map/object readers, type/length/ref helpers.
- decoder_primitive.go — low-level primitive readers (bytes, ints, UTF-8, chunked strings).
- response.go — Sofa-layer adapters that flatten the generic decoded value into the DecodedResponse shape.
Index ¶
- Constants
- func BuildSuccessResponse(appResponse any) ([]byte, error)
- func FormatValue(v any) any
- func FormatValueSafe(v any) (out any, err error)
- func LoadArgsFile(path string) ([]any, error)
- func NormalizeArgs(args []any) []any
- func PrepareArgs(args []any) []any
- func PrepareValue(v any) any
- func TargetServiceUniqueName(service, version, uniqueID string) string
- type DecodedResponse
- type DirectInvokeOptions
- type DirectInvokeResult
- type EncodedRequest
- type RequestSpec
- type TraceContext
Constants ¶
const ( TraceContextKey = "rpc_trace_context" // TraceCallerApp is the caller identity providers log as the remote // app, so agent-originated calls are recognizable in their logs. TraceCallerApp = "sofarpc-cli" )
SOFARPC carries the caller's tracing context in SofaRequest.requestProps["rpc_trace_context"]. A provider running SOFATracer adopts sofaTraceId from that map as its server span's trace id (RpcSofaTracer.serverReceived), so an id generated here is the id that shows up in the provider's digest and business logs. Without it the provider mints its own trace id, which the caller never learns.
The Java bolt client puts this map in the hessian-encoded request content, not in the BOLT header, so encoding it alongside rpc_req_baggage is the faithful shape.
const ( RequestClass = "com.alipay.sofa.rpc.core.request.SofaRequest" ResponseClass = "com.alipay.sofa.rpc.core.response.SofaResponse" DefaultVersion = "1.0" GenericType = "2" InvokeTypeSync = "sync" RequestBaggageKey = "rpc_req_baggage" )
Variables ¶
This section is empty.
Functions ¶
func BuildSuccessResponse ¶
BuildSuccessResponse encodes a SofaResponse envelope that carries appResponse as its application payload with no error or response props. It is the symmetric counterpart to DecodeResponse and exists so tests can synthesize server frames without pinning hand-captured hex fixtures. appResponse may be any value writeValue accepts — a plain scalar, a javaTypedObject, a map, or a list.
func FormatValue ¶
func FormatValueSafe ¶
func LoadArgsFile ¶
func NormalizeArgs ¶
NormalizeArgs is kept for compatibility with existing tests and callers. New code should use PrepareArgs to avoid confusion with contract.NormalizeArgs.
func PrepareArgs ¶
PrepareArgs adapts contract-normalized JSON-like args for the Hessian writer by replacing typed maps and collections with Java class adapters.
func PrepareValue ¶
PrepareValue adapts one contract-normalized value for Hessian encoding.
func TargetServiceUniqueName ¶
Types ¶
type DecodedResponse ¶
type DecodedResponse struct {
IsError bool
ErrorMsg string
AppResponse any
ResponseProps map[string]string
// contains filtered or unexported fields
}
func DecodeResponse ¶
func DecodeResponse(content []byte) (DecodedResponse, error)
func (DecodedResponse) Result ¶
func (r DecodedResponse) Result() (any, error)
Result returns the application value in the JSON shape tool output uses.
type DirectInvokeOptions ¶
type DirectInvokeResult ¶
type DirectInvokeResult struct {
RequestID uint32
Request EncodedRequest
Response boltclient.Response
Decoded *DecodedResponse
DecodeErr error
}
func InvokeDirect ¶
func InvokeDirect(ctx context.Context, spec RequestSpec, opts DirectInvokeOptions) (DirectInvokeResult, error)
type EncodedRequest ¶
type EncodedRequest struct {
Class string
Header map[string]string
Content []byte
TargetServiceUniqueName string
}
func BuildGenericRequest ¶
func BuildGenericRequest(spec RequestSpec) (EncodedRequest, error)
func BuildJSONRequest ¶
func BuildJSONRequest(spec RequestSpec) (EncodedRequest, error)
BuildJSONRequest encodes spec for a provider's Jackson serializer.
The request props Hessian carries inside SofaRequest travel as flattened BOLT header keys here ("rpc_trace_context.sofaTraceId"), which is where the provider's JSON decoder rebuilds them from. The generic-invoke markers are left out: to the provider this is an ordinary typed call.
type RequestSpec ¶
type RequestSpec struct {
Service string
Method string
ParamTypes []string
// Args are contract-normalized JSON-like values. BuildGenericRequest calls
// PrepareArgs to adapt typed maps and collections for Hessian encoding.
Args []any
Version string
UniqueID string
TargetAppName string
RequestBaggage map[string]string
// Trace is the caller's SOFATracer context. The zero value sends no
// trace, which leaves the provider to mint its own trace id.
Trace TraceContext
}
type TraceContext ¶
type TraceContext struct {
TraceID string
RPCID string
CallerApp string
CallerIP string
Sampled bool
}
TraceContext is the caller half of a SOFATracer trace. The zero value carries no trace and is encoded as nothing.
func NewTraceContext ¶
func NewTraceContext() TraceContext
NewTraceContext mints a root trace context in SOFATracer's own TraceIdGenerator format: 8 hex chars of the local IPv4, epoch milliseconds, a 1000-9000 sequence, and the pid. Keeping the format matters because log platforms parse origin and time out of the id.