{"modulePath":"github.com/hex1n/sofarpc-cli","version":"v0.0.0-20261202072051-c67101320811","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package sofarpcwire\n\nPackage sofarpcwire implements the BOLT v1 + Hessian v1 wire encoding/decoding for SOFARPC generic invoke.\n\nFile layout for the decoder side:\n\n  - decoder.go — Hessian decoder struct, top-level tag dispatcher, list/map/object readers, type/length/ref helpers.\n  - decoder\\_primitive.go — low-level primitive readers (bytes, ints, UTF-8, chunked strings).\n  - response.go — Sofa-layer adapters that flatten the generic decoded value into the DecodedResponse shape.\n\n## Constants\n\n```go\nconst (\n\tTraceContextKey = \"rpc_trace_context\"\n\n\t// TraceCallerApp is the caller identity providers log as the remote\n\t// app, so agent-originated calls are recognizable in their logs.\n\tTraceCallerApp = \"sofarpc-cli\"\n)\n```\nSOFARPC 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.\n\nThe 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.\n\n```go\nconst (\n\tRequestClass  = \"com.alipay.sofa.rpc.core.request.SofaRequest\"\n\tResponseClass = \"com.alipay.sofa.rpc.core.response.SofaResponse\"\n\n\tDefaultVersion    = \"1.0\"\n\tGenericType       = \"2\"\n\tInvokeTypeSync    = \"sync\"\n\tRequestBaggageKey = \"rpc_req_baggage\"\n)\n```\n\n## Functions\n\n```go\nfunc BuildSuccessResponse(appResponse any) ([]byte, error)\n```\nBuildSuccessResponse 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.\n\n```go\nfunc FormatValue(v any) any\n```\n\n```go\nfunc FormatValueSafe(v any) (out any, err error)\n```\n\n```go\nfunc LoadArgsFile(path string) ([]any, error)\n```\n\n```go\nfunc NormalizeArgs(args []any) []any\n```\nNormalizeArgs is kept for compatibility with existing tests and callers. New code should use PrepareArgs to avoid confusion with contract.NormalizeArgs.\n\n```go\nfunc PrepareArgs(args []any) []any\n```\nPrepareArgs adapts contract-normalized JSON-like args for the Hessian writer by replacing typed maps and collections with Java class adapters.\n\n```go\nfunc PrepareValue(v any) any\n```\nPrepareValue adapts one contract-normalized value for Hessian encoding.\n\n```go\nfunc TargetServiceUniqueName(service, version, uniqueID string) string\n```\n\n## Types\n\n```go\ntype DecodedResponse struct {\n\tIsError       bool\n\tErrorMsg      string\n\tAppResponse   any\n\tResponseProps map[string]string\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc DecodeResponse(content []byte) (DecodedResponse, error)\n```\n\n```go\nfunc (r DecodedResponse) Result() (any, error)\n```\nResult returns the application value in the JSON shape tool output uses.\n\n```go\ntype DirectInvokeOptions struct {\n\tAddr             string\n\tCodec            byte\n\tTimeout          time.Duration\n\tConnectTimeout   time.Duration\n\tRequestID        uint32\n\tMaxResponseBytes int64\n}\n```\n\n```go\ntype DirectInvokeResult struct {\n\tRequestID uint32\n\tRequest   EncodedRequest\n\tResponse  boltclient.Response\n\tDecoded   *DecodedResponse\n\tDecodeErr error\n}\n```\n\n```go\nfunc InvokeDirect(ctx context.Context, spec RequestSpec, opts DirectInvokeOptions) (DirectInvokeResult, error)\n```\n\n```go\ntype EncodedRequest struct {\n\tClass                   string\n\tHeader                  map[string]string\n\tContent                 []byte\n\tTargetServiceUniqueName string\n}\n```\n\n```go\nfunc BuildGenericRequest(spec RequestSpec) (EncodedRequest, error)\n```\n\n```go\nfunc BuildJSONRequest(spec RequestSpec) (EncodedRequest, error)\n```\nBuildJSONRequest encodes spec for a provider's Jackson serializer.\n\nThe 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.\n\n```go\ntype RequestSpec struct {\n\tService    string\n\tMethod     string\n\tParamTypes []string\n\t// Args are contract-normalized JSON-like values. BuildGenericRequest calls\n\t// PrepareArgs to adapt typed maps and collections for Hessian encoding.\n\tArgs           []any\n\tVersion        string\n\tUniqueID       string\n\tTargetAppName  string\n\tRequestBaggage map[string]string\n\t// Trace is the caller's SOFATracer context. The zero value sends no\n\t// trace, which leaves the provider to mint its own trace id.\n\tTrace TraceContext\n}\n```\n\n```go\ntype TraceContext struct {\n\tTraceID   string\n\tRPCID     string\n\tCallerApp string\n\tCallerIP  string\n\tSampled   bool\n}\n```\nTraceContext is the caller half of a SOFATracer trace. The zero value carries no trace and is encoded as nothing.\n\n```go\nfunc NewTraceContext() TraceContext\n```\nNewTraceContext 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.\n\n","path":"github.com/hex1n/sofarpc-cli/internal/sofarpcwire","name":"sofarpcwire","synopsis":"Package sofarpcwire implements the BOLT v1 + Hessian v1 wire encoding/decoding for SOFARPC generic invoke.","isRedistributable":true}
