sofarpcwire

package
v0.0.0-...-c671013 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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

func BuildSuccessResponse(appResponse any) ([]byte, error)

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 FormatValue(v any) any

func FormatValueSafe

func FormatValueSafe(v any) (out any, err error)

func LoadArgsFile

func LoadArgsFile(path string) ([]any, error)

func NormalizeArgs

func NormalizeArgs(args []any) []any

NormalizeArgs is kept for compatibility with existing tests and callers. New code should use PrepareArgs to avoid confusion with contract.NormalizeArgs.

func PrepareArgs

func PrepareArgs(args []any) []any

PrepareArgs adapts contract-normalized JSON-like args for the Hessian writer by replacing typed maps and collections with Java class adapters.

func PrepareValue

func PrepareValue(v any) any

PrepareValue adapts one contract-normalized value for Hessian encoding.

func TargetServiceUniqueName

func TargetServiceUniqueName(service, version, uniqueID string) string

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 DirectInvokeOptions struct {
	Addr             string
	Codec            byte
	Timeout          time.Duration
	ConnectTimeout   time.Duration
	RequestID        uint32
	MaxResponseBytes int64
}

type DirectInvokeResult

type DirectInvokeResult struct {
	RequestID uint32
	Request   EncodedRequest
	Response  boltclient.Response
	Decoded   *DecodedResponse
	DecodeErr 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL