lisette-stdlib 0.2.13

Little language inspired by Rust that compiles to Go
Documentation
// Generated by Lisette bindgen
// Source: net/rpc (Go stdlib)
// Go: 1.25.10
// Lisette: 0.2.1

import "go:io"
import "go:net"
import "go:net/http"

/// Accept accepts connections on the listener and serves requests
/// to [DefaultServer] for each incoming connection.
/// Accept blocks; the caller typically invokes it in a go statement.
pub fn Accept(lis: net.Listener)

/// Dial connects to an RPC server at the specified network address.
pub fn Dial(network: string, address: string) -> Result<Ref<Client>, error>

/// DialHTTP connects to an HTTP RPC server at the specified network address
/// listening on the default HTTP RPC path.
pub fn DialHTTP(network: string, address: string) -> Result<Ref<Client>, error>

/// DialHTTPPath connects to an HTTP RPC server
/// at the specified network address and path.
pub fn DialHTTPPath(network: string, address: string, path: string) -> Result<Ref<Client>, error>

/// HandleHTTP registers an HTTP handler for RPC messages to [DefaultServer]
/// on [DefaultRPCPath] and a debugging handler on [DefaultDebugPath].
/// It is still necessary to invoke [http.Serve](), typically in a go statement.
pub fn HandleHTTP()

/// NewClient returns a new [Client] to handle requests to the
/// set of services at the other end of the connection.
/// It adds a buffer to the write side of the connection so
/// the header and payload are sent as a unit.
/// 
/// The read and write halves of the connection are serialized independently,
/// so no interlocking is required. However each half may be accessed
/// concurrently so the implementation of conn should protect against
/// concurrent reads or concurrent writes.
pub fn NewClient(conn: io.ReadWriteCloser) -> Ref<Client>

/// NewClientWithCodec is like [NewClient] but uses the specified
/// codec to encode requests and decode responses.
pub fn NewClientWithCodec(codec: ClientCodec) -> Ref<Client>

/// NewServer returns a new [Server].
pub fn NewServer() -> Ref<Server>

/// Register publishes the receiver's methods in the [DefaultServer].
pub fn Register(rcvr: Unknown) -> Result<(), error>

/// RegisterName is like [Register] but uses the provided name for the type
/// instead of the receiver's concrete type.
pub fn RegisterName(name: string, rcvr: Unknown) -> Result<(), error>

/// ServeCodec is like [ServeConn] but uses the specified codec to
/// decode requests and encode responses.
pub fn ServeCodec(codec: ServerCodec)

/// ServeConn runs the [DefaultServer] on a single connection.
/// ServeConn blocks, serving the connection until the client hangs up.
/// The caller typically invokes ServeConn in a go statement.
/// ServeConn uses the gob wire format (see package gob) on the
/// connection. To use an alternate codec, use [ServeCodec].
/// See [NewClient]'s comment for information about concurrent access.
pub fn ServeConn(conn: io.ReadWriteCloser)

/// ServeRequest is like [ServeCodec] but synchronously serves a single request.
/// It does not close the codec upon completion.
pub fn ServeRequest(codec: ServerCodec) -> Result<(), error>

/// Call represents an active RPC.
pub struct Call {
  pub ServiceMethod: string,
  pub Args: Unknown,
  pub Reply: Unknown,
  pub Error: error,
  pub Done: Channel<Ref<Call>>,
}

/// Client represents an RPC Client.
/// There may be multiple outstanding Calls associated
/// with a single Client, and a Client may be used by
/// multiple goroutines simultaneously.
pub type Client

/// A ClientCodec implements writing of RPC requests and
/// reading of RPC responses for the client side of an RPC session.
/// The client calls [ClientCodec.WriteRequest] to write a request to the connection
/// and calls [ClientCodec.ReadResponseHeader] and [ClientCodec.ReadResponseBody] in pairs
/// to read responses. The client calls [ClientCodec.Close] when finished with the
/// connection. ReadResponseBody may be called with a nil
/// argument to force the body of the response to be read and then
/// discarded.
/// See [NewClient]'s comment for information about concurrent access.
pub interface ClientCodec {
  fn Close() -> Result<(), error>
  fn ReadResponseBody(any: Unknown) -> Result<(), error>
  fn ReadResponseHeader(response: Ref<Response>) -> Result<(), error>
  fn WriteRequest(request: Ref<Request>, any: Unknown) -> Result<(), error>
}

/// Request is a header written before every RPC call. It is used internally
/// but documented here as an aid to debugging, such as when analyzing
/// network traffic.
pub struct Request {
  pub ServiceMethod: string,
  pub Seq: uint64,
}

/// Response is a header written before every RPC return. It is used internally
/// but documented here as an aid to debugging, such as when analyzing
/// network traffic.
pub struct Response {
  pub ServiceMethod: string,
  pub Seq: uint64,
  pub Error: string,
}

/// Server represents an RPC Server.
pub type Server

/// A ServerCodec implements reading of RPC requests and writing of
/// RPC responses for the server side of an RPC session.
/// The server calls [ServerCodec.ReadRequestHeader] and [ServerCodec.ReadRequestBody] in pairs
/// to read requests from the connection, and it calls [ServerCodec.WriteResponse] to
/// write a response back. The server calls [ServerCodec.Close] when finished with the
/// connection. ReadRequestBody may be called with a nil
/// argument to force the body of the request to be read and discarded.
/// See [NewClient]'s comment for information about concurrent access.
pub interface ServerCodec {
  fn Close() -> Result<(), error>
  fn ReadRequestBody(any: Unknown) -> Result<(), error>
  fn ReadRequestHeader(request: Ref<Request>) -> Result<(), error>
  fn WriteResponse(response: Ref<Response>, any: Unknown) -> Result<(), error>
}

/// ServerError represents an error that has been returned from
/// the remote side of the RPC connection.
pub struct ServerError(string)

pub const DefaultDebugPath = "/debug/rpc"

pub const DefaultRPCPath = "/_goRPC_"

/// DefaultServer is the default instance of [*Server].
pub var DefaultServer: Ref<Server>

pub var ErrShutdown: error

impl Client {
  /// Call invokes the named function, waits for it to complete, and returns its error status.
  fn Call(
    self: Ref<Client>,
    serviceMethod: string,
    args: Unknown,
    reply: Unknown,
  ) -> Result<(), error>

  /// Close calls the underlying codec's Close method. If the connection is already
  /// shutting down, [ErrShutdown] is returned.
  #[allow(unused_result)]
  fn Close(self: Ref<Client>) -> Result<(), error>

  /// Go invokes the function asynchronously. It returns the [Call] structure representing
  /// the invocation. The done channel will signal when the call is complete by returning
  /// the same Call object. If done is nil, Go will allocate a new channel.
  /// If non-nil, done must be buffered or Go will deliberately crash.
  fn Go(
    self: Ref<Client>,
    serviceMethod: string,
    args: Unknown,
    reply: Unknown,
    done: Channel<Ref<Call>>,
  ) -> Ref<Call>
}

impl Server {
  /// Accept accepts connections on the listener and serves requests
  /// for each incoming connection. Accept blocks until the listener
  /// returns a non-nil error. The caller typically invokes Accept in a
  /// go statement.
  fn Accept(self: Ref<Server>, lis: net.Listener)

  /// HandleHTTP registers an HTTP handler for RPC messages on rpcPath,
  /// and a debugging handler on debugPath.
  /// It is still necessary to invoke [http.Serve](), typically in a go statement.
  fn HandleHTTP(self: Ref<Server>, rpcPath: string, debugPath: string)

  /// Register publishes in the server the set of methods of the
  /// receiver value that satisfy the following conditions:
  ///   - exported method of exported type
  ///   - two arguments, both of exported type
  ///   - the second argument is a pointer
  ///   - one return value, of type error
  /// 
  /// It returns an error if the receiver is not an exported type or has
  /// no suitable methods. It also logs the error using package log.
  /// The client accesses each method using a string of the form "Type.Method",
  /// where Type is the receiver's concrete type.
  fn Register(self: Ref<Server>, rcvr: Unknown) -> Result<(), error>

  /// RegisterName is like [Register] but uses the provided name for the type
  /// instead of the receiver's concrete type.
  fn RegisterName(self: Ref<Server>, name: string, rcvr: Unknown) -> Result<(), error>

  /// ServeCodec is like [ServeConn] but uses the specified codec to
  /// decode requests and encode responses.
  fn ServeCodec(self: Ref<Server>, codec: ServerCodec)

  /// ServeConn runs the server on a single connection.
  /// ServeConn blocks, serving the connection until the client hangs up.
  /// The caller typically invokes ServeConn in a go statement.
  /// ServeConn uses the gob wire format (see package gob) on the
  /// connection. To use an alternate codec, use [ServeCodec].
  /// See [NewClient]'s comment for information about concurrent access.
  fn ServeConn(self: Ref<Server>, conn: io.ReadWriteCloser)

  /// ServeHTTP implements an [http.Handler] that answers RPC requests.
  fn ServeHTTP(
    self: Ref<Server>,
    w: http.ResponseWriter,
    req: Ref<http.Request>,
  )

  /// ServeRequest is like [ServeCodec] but synchronously serves a single request.
  /// It does not close the codec upon completion.
  fn ServeRequest(self: Ref<Server>, codec: ServerCodec) -> Result<(), error>
}

impl ServerError {
  fn Error(self) -> string
}