{"modulePath":"github.com/wavetermdev/waveterm","version":"v0.14.5","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package wshutil\n\n## Constants\n\n```go\nconst (\n\tMode_Normal  = \"normal\"\n\tMode_Esc     = \"esc\"\n\tMode_WaveEsc = \"waveesc\"\n)\n```\n\n```go\nconst (\n\tDefaultRoute     = \"wavesrv\"\n\tElectronRoute    = \"electron\"\n\tControlRoute     = \"$control\"      // control plane route\n\tControlRootRoute = \"$control:root\" // control plane route to root router\n\n\tControlPrefix = \"$\"\n\n\tRoutePrefix_Conn       = \"conn:\"\n\tRoutePrefix_Controller = \"controller:\"\n\tRoutePrefix_Proc       = \"proc:\"\n\tRoutePrefix_Tab        = \"tab:\"\n\tRoutePrefix_FeBlock    = \"feblock:\"\n\tRoutePrefix_Builder    = \"builder:\"\n\tRoutePrefix_Link       = \"link:\"\n\tRoutePrefix_Job        = \"job:\"\n\tRoutePrefix_Bare       = \"bare:\"\n)\n```\n\n```go\nconst BEL = 0x07\n```\n\n```go\nconst CtxDoneChSize = 10\n```\n\n```go\nconst DefaultInputChSize = 32\n```\n\n```go\nconst DefaultMessageChSize = 32\n```\n\n```go\nconst DefaultOutputChSize = 32\n```\n\n```go\nconst DefaultTimeoutMs = 5000\n```\n\n```go\nconst ESC = 0x1b\n```\n\n```go\nconst HexChars = \"0123456789ABCDEF\"\n```\n\n```go\nconst LinkKind_Leaf = \"leaf\"\n```\n\n```go\nconst LinkKind_Router = \"router\"\n```\n\n```go\nconst MaxBufferedDataSize = 256 * 1024\n```\n\n```go\nconst RespChSize = 32\n```\n\n```go\nconst RouterInputChQueueSize = 100\n```\n\n```go\nconst ST = 0x9c\n```\n\n```go\nconst WaveJwtTokenVarName = wavebase.WaveJwtTokenVarName\n```\n\n```go\nconst WaveOSC = \"23198\"\n```\nthese should both be 5 characters\n\n```go\nconst WaveOSCPrefix = \"\\x1b]\" + WaveOSC + \";\"\n```\n\n```go\nconst WaveOSCPrefixLen = 5 + 3 // \\x1b] + WaveOSC + ; + \\x07\n\n```\n\n```go\nconst WaveServerOSC = \"23199\"\n```\n\n```go\nconst WaveServerOSCPrefix = \"\\x1b]\" + WaveServerOSC + \";\"\n```\n\n## Variables\n\n```go\nvar BacklogLogThresholds = map[int]bool{1: true, 5: true, 10: true, 20: true, 30: true, 40: true, 50: true, 100: true, 200: true, 500: true, 1000: true}\n```\n\n```go\nvar WshCommandDeclMap = wshrpc.GenerateWshCommandDeclMap()\n```\n\n## Functions\n\n```go\nfunc AdaptMsgChToPty(outputCh chan []byte, oscEsc string, output io.Writer) error\n```\n\n```go\nfunc AdaptOutputChToStream(outputCh chan []byte, output io.Writer) error\n```\n\n```go\nfunc AdaptStreamToMsgCh(input io.Reader, output chan baseds.RpcInputChType, readCallback func()) error\n```\n\n```go\nfunc DoShutdown(reason string, exitCode int, quiet bool)\n```\n\n```go\nfunc EncodeWaveOSCBytes(oscNum string, barr []byte) ([]byte, error)\n```\n\n```go\nfunc EncodeWaveOSCMessageEx(oscNum string, msg *RpcMessage) ([]byte, error)\n```\n\n```go\nfunc ExtractUnverifiedRpcContext(tokenStr string) (*wshrpc.RpcContext, error)\n```\nonly for use on client\n\n```go\nfunc ExtractUnverifiedSocketName(tokenStr string) (string, error)\n```\nonly for use on client\n\n```go\nfunc GetInfo() wshrpc.RemoteInfo\n```\n\n```go\nfunc GetIsCanceledFromContext(ctx context.Context) bool\n```\n\n```go\nfunc GetRpcSourceFromContext(ctx context.Context) string\n```\n\n```go\nfunc HandleStdIOClient(logName string, input chan utilfn.LineOutput, output io.Writer)\n```\nblocking, returns if there is an error, or on EOF of input\n\n```go\nfunc InstallRcFiles() error\n```\n\n```go\nfunc MakeBuilderRouteId(builderId string) string\n```\n\n```go\nfunc MakeClientJWTToken(rpcCtx wshrpc.RpcContext) (string, error)\n```\n\n```go\nfunc MakeConnectionRouteId(connId string) string\n```\n\n```go\nfunc MakeControllerRouteId(blockId string) string\n```\n\n```go\nfunc MakeFeBlockRouteId(blockId string) string\n```\n\n```go\nfunc MakeJobRouteId(jobId string) string\n```\n\n```go\nfunc MakeLinkRouteId(linkId baseds.LinkId) string\n```\n\n```go\nfunc MakeProcRouteId(procId string) string\n```\n\n```go\nfunc MakeRandomProcRouteId() string\n```\n\n```go\nfunc MakeTabRouteId(tabId string) string\n```\n\n```go\nfunc RespErr[T any](err error) wshrpc.RespOrErrorUnion[T]\n```\n\n```go\nfunc RunWshRpcOverListener(listener net.Listener, readCallback func())\n```\n\n```go\nfunc SendErrCh[T any](err error) \u003c-chan wshrpc.RespOrErrorUnion[T]\n```\n\n```go\nfunc ValidateAndExtractRpcContextFromToken(tokenStr string) (*wshrpc.RpcContext, error)\n```\n\n## Types\n\n```go\ntype AbstractRpcClient interface {\n\tGetPeerInfo() string\n\tSendRpcMessage(msg []byte, ingressLinkId baseds.LinkId, debugStr string) bool\n\tRecvRpcMessage() ([]byte, bool) // blocking\n}\n```\n\n```go\ntype CommandHandlerFnType = func(*RpcResponseHandler) bool\n```\nreturns true if handler is complete, false for an async handler\n\n```go\ntype EventListener struct {\n\tLock      *sync.Mutex\n\tListeners map[string][]singleListener\n}\n```\n\n```go\nfunc MakeEventListener() *EventListener\n```\n\n```go\nfunc (el *EventListener) On(eventName string, fn func(*wps.WaveEvent)) string\n```\n\n```go\nfunc (el *EventListener) RecvEvent(e *wps.WaveEvent)\n```\n\n```go\nfunc (el *EventListener) Unregister(eventName string, id string)\n```\n\n```go\ntype PtyBuffer struct {\n\tCVar        *sync.Cond\n\tDataBuf     *bytes.Buffer\n\tEscMode     string\n\tEscSeqBuf   []byte\n\tOSCPrefix   string\n\tInputReader io.Reader\n\tMessageCh   chan baseds.RpcInputChType\n\tAtEOF       bool\n\tErr         error\n}\n```\n\n```go\nfunc MakePtyBuffer(oscPrefix string, input io.Reader, messageCh chan baseds.RpcInputChType) *PtyBuffer\n```\ncloses messageCh when input is closed (or error)\n\n```go\nfunc (b *PtyBuffer) Read(p []byte) (n int, err error)\n```\n\n```go\ntype ResponseFnType = func(any) error\n```\n\n```go\ntype RpcMessage struct {\n\tCommand  string `json:\"command,omitempty\"`\n\tReqId    string `json:\"reqid,omitempty\"`\n\tResId    string `json:\"resid,omitempty\"`\n\tTimeout  int64  `json:\"timeout,omitempty\"`\n\tRoute    string `json:\"route,omitempty\"`  // to route/forward requests to alternate servers\n\tSource   string `json:\"source,omitempty\"` // source route id\n\tCont     bool   `json:\"cont,omitempty\"`   // flag if additional requests/responses are forthcoming\n\tCancel   bool   `json:\"cancel,omitempty\"` // used to cancel a streaming request or response (sent from the side that is not streaming)\n\tError    string `json:\"error,omitempty\"`\n\tDataType string `json:\"datatype,omitempty\"`\n\tData     any    `json:\"data,omitempty\"`\n}\n```\n\n```go\nfunc (r *RpcMessage) IsRpcRequest() bool\n```\n\n```go\nfunc (r *RpcMessage) Validate() error\n```\n\n```go\ntype RpcRequestHandler struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (handler *RpcRequestHandler) Context() context.Context\n```\n\n```go\nfunc (handler *RpcRequestHandler) NextResponse() (any, error)\n```\n\n```go\nfunc (handler *RpcRequestHandler) ResponseDone() bool\n```\n\n```go\nfunc (handler *RpcRequestHandler) SendCancel(ctx context.Context) error\n```\n\n```go\ntype RpcResponseHandler struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc GetRpcResponseHandlerFromContext(ctx context.Context) *RpcResponseHandler\n```\n\n```go\nfunc (handler *RpcResponseHandler) Context() context.Context\n```\n\n```go\nfunc (handler *RpcResponseHandler) Finalize()\n```\nif async, caller must call finalize\n\n```go\nfunc (handler *RpcResponseHandler) GetCommand() string\n```\n\n```go\nfunc (handler *RpcResponseHandler) GetCommandRawData() any\n```\n\n```go\nfunc (handler *RpcResponseHandler) GetIngressLinkId() baseds.LinkId\n```\n\n```go\nfunc (handler *RpcResponseHandler) GetRpcContext() wshrpc.RpcContext\n```\n\n```go\nfunc (handler *RpcResponseHandler) GetSource() string\n```\n\n```go\nfunc (handler *RpcResponseHandler) IsCanceled() bool\n```\n\n```go\nfunc (handler *RpcResponseHandler) IsDone() bool\n```\n\n```go\nfunc (handler *RpcResponseHandler) NeedsResponse() bool\n```\n\n```go\nfunc (handler *RpcResponseHandler) SendMessage(msg string)\n```\n\n```go\nfunc (handler *RpcResponseHandler) SendResponse(data any, done bool) error\n```\n\n```go\nfunc (handler *RpcResponseHandler) SendResponseError(err error)\n```\n\n```go\ntype ServerImpl interface {\n\tWshServerImpl()\n}\n```\n\n```go\ntype WriteFlusher interface {\n\tWrite([]byte) (int, error)\n\tFlush() error\n}\n```\n\n```go\ntype WshRouter struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nvar DefaultRouter *WshRouter\n```\n\n```go\nfunc NewWshRouter() *WshRouter\n```\n\n```go\nfunc (router *WshRouter) GetControlRpc() *WshRpc\n```\n\n```go\nfunc (router *WshRouter) GetLinkIdForRoute(routeId string) baseds.LinkId\n```\n\n```go\nfunc (router *WshRouter) IsRootRouter() bool\n```\n\n```go\nfunc (router *WshRouter) RegisterTrustedLeaf(rpc AbstractRpcClient, routeId string) (baseds.LinkId, error)\n```\nonly for leaves\n\n```go\nfunc (router *WshRouter) RegisterTrustedRouter(rpc AbstractRpcClient) baseds.LinkId\n```\nonly for routers\n\n```go\nfunc (router *WshRouter) RegisterUntrustedLink(client AbstractRpcClient) baseds.LinkId\n```\n\n```go\nfunc (router *WshRouter) RegisterUpstream(rpc AbstractRpcClient) baseds.LinkId\n```\n\n```go\nfunc (router *WshRouter) SendEvent(routeId string, event wps.WaveEvent)\n```\n\n```go\nfunc (router *WshRouter) SetAsRootRouter()\n```\n\n```go\nfunc (router *WshRouter) UnregisterLink(linkId baseds.LinkId)\n```\n\n```go\nfunc (router *WshRouter) WaitForRegister(ctx context.Context, routeId string) error\n```\n\n```go\ntype WshRouterControlImpl struct {\n\tRouter *WshRouter\n}\n```\n\n```go\nfunc (impl *WshRouterControlImpl) AuthenticateCommand(ctx context.Context, data string) (wshrpc.CommandAuthenticateRtnData, error)\n```\n\n```go\nfunc (impl *WshRouterControlImpl) AuthenticateJobManagerCommand(ctx context.Context, data wshrpc.CommandAuthenticateJobManagerData) error\n```\n\n```go\nfunc (impl *WshRouterControlImpl) AuthenticateJobManagerVerifyCommand(ctx context.Context, data wshrpc.CommandAuthenticateJobManagerData) error\n```\n\n```go\nfunc (impl *WshRouterControlImpl) AuthenticateTokenCommand(ctx context.Context, data wshrpc.CommandAuthenticateTokenData) (wshrpc.CommandAuthenticateRtnData, error)\n```\n\n```go\nfunc (impl *WshRouterControlImpl) AuthenticateTokenVerifyCommand(ctx context.Context, data wshrpc.CommandAuthenticateTokenData) (wshrpc.CommandAuthenticateRtnData, error)\n```\n\n```go\nfunc (impl *WshRouterControlImpl) ControlGetRouteIdCommand(ctx context.Context) (string, error)\n```\n\n```go\nfunc (impl *WshRouterControlImpl) RouteAnnounceCommand(ctx context.Context) error\n```\n\n```go\nfunc (impl *WshRouterControlImpl) RouteUnannounceCommand(ctx context.Context) error\n```\n\n```go\nfunc (impl *WshRouterControlImpl) SetPeerInfoCommand(ctx context.Context, peerInfo string) error\n```\n\n```go\nfunc (impl *WshRouterControlImpl) WshServerImpl()\n```\n\n```go\ntype WshRpc struct {\n\tLock               *sync.Mutex\n\tInputCh            chan baseds.RpcInputChType\n\tOutputCh           chan []byte\n\tCtxDoneCh          chan string // for context cancellation, value is ResId\n\tRpcContext         *atomic.Pointer[wshrpc.RpcContext]\n\tRpcMap             map[string]*rpcData\n\tServerImpl         ServerImpl\n\tEventListener      *EventListener\n\tResponseHandlerMap map[string]*RpcResponseHandler // reqId =\u003e handler\n\tStreamBroker       *streamclient.Broker\n\tDebug              bool\n\tDebugName          string\n\tServerDone         bool\n}\n```\n\n```go\nfunc GetWshRpcFromContext(ctx context.Context) *WshRpc\n```\n\n```go\nfunc MakeWshRpc(rpcCtx wshrpc.RpcContext, serverImpl ServerImpl, debugName string) *WshRpc\n```\n\n```go\nfunc MakeWshRpcWithChannels(inputCh chan baseds.RpcInputChType, outputCh chan []byte, rpcCtx wshrpc.RpcContext, serverImpl ServerImpl, debugName string) *WshRpc\n```\ncloses outputCh when inputCh is closed/done\n\n```go\nfunc SetupConnRpcClient(conn net.Conn, serverImpl ServerImpl, debugStr string) (*WshRpc, chan error, error)\n```\n\n```go\nfunc SetupDomainSocketRpcClient(sockName string, serverImpl ServerImpl, debugName string) (*WshRpc, error)\n```\n\n```go\nfunc SetupPacketRpcClient(input io.Reader, output io.Writer, serverImpl ServerImpl, debugStr string) (*WshRpc, chan []byte)\n```\n\n```go\nfunc (w *WshRpc) GetPeerInfo() string\n```\n\n```go\nfunc (w *WshRpc) GetRpcContext() wshrpc.RpcContext\n```\n\n```go\nfunc (w *WshRpc) IsServerDone() bool\n```\n\n```go\nfunc (w *WshRpc) RecvRpcMessage() ([]byte, bool)\n```\n\n```go\nfunc (w *WshRpc) SendCommand(command string, data any, opts *wshrpc.RpcOpts) error\n```\nno response\n\n```go\nfunc (w *WshRpc) SendComplexRequest(command string, data any, opts *wshrpc.RpcOpts) (rtnHandler *RpcRequestHandler, rtnErr error)\n```\n\n```go\nfunc (w *WshRpc) SendRpcMessage(msg []byte, ingressLinkId baseds.LinkId, debugStr string) bool\n```\n\n```go\nfunc (w *WshRpc) SendRpcRequest(command string, data any, opts *wshrpc.RpcOpts) (any, error)\n```\nsingle response\n\n```go\nfunc (w *WshRpc) SetRpcContext(ctx wshrpc.RpcContext)\n```\n\n```go\nfunc (w *WshRpc) SetServerImpl(serverImpl ServerImpl)\n```\n\n```go\ntype WshRpcProxy struct {\n\tLock         *sync.Mutex\n\tRpcContext   *wshrpc.RpcContext\n\tToRemoteCh   chan []byte\n\tFromRemoteCh chan baseds.RpcInputChType\n\tPeerInfo     string\n}\n```\n\n```go\nfunc MakeRpcProxy(peerInfo string) *WshRpcProxy\n```\n\n```go\nfunc MakeRpcProxyWithSize(peerInfo string, inputChSize int, outputChSize int) *WshRpcProxy\n```\n\n```go\nfunc (p *WshRpcProxy) GetPeerInfo() string\n```\n\n```go\nfunc (p *WshRpcProxy) RecvRpcMessage() ([]byte, bool)\n```\n\n```go\nfunc (p *WshRpcProxy) SendRpcMessage(msg []byte, ingressLinkId baseds.LinkId, debugStr string) bool\n```\n\n```go\nfunc (p *WshRpcProxy) SetPeerInfo(peerInfo string)\n```\n\n```go\ntype WshRpcStreamClientAdapter struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc AdaptWshRpc(rpc *WshRpc) *WshRpcStreamClientAdapter\n```\n\n```go\nfunc (a *WshRpcStreamClientAdapter) StreamDataAckCommand(data wshrpc.CommandStreamAckData, opts *wshrpc.RpcOpts) error\n```\n\n```go\nfunc (a *WshRpcStreamClientAdapter) StreamDataCommand(data wshrpc.CommandStreamData, opts *wshrpc.RpcOpts) error\n```\n\n","path":"github.com/wavetermdev/waveterm/pkg/wshutil","name":"wshutil","synopsis":"","isRedistributable":true}
