blob: 962a895a6c5b1f3e62e8b59b3862c4b576145847 [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file was auto-generated by the vanadium vdl tool.
// Source: p2b.vdl
// Package vdl is an example of a Vanadium service for
// streaming data from a pipe to a browser, which can visualize this
// data.
package vdl
import (
"io"
"v.io/v23"
"v.io/v23/context"
"v.io/v23/rpc"
"v.io/v23/vom"
)
func __VDLEnsureNativeBuilt_p2b() {
}
// ViewerClientMethods is the client interface
// containing Viewer methods.
//
// Viewer allows clients to stream data to it and to request a
// particular viewer to format and display the data.
type ViewerClientMethods interface {
// Pipe creates a bidirectional pipe between client and viewer
// service, returns total number of bytes received by the service
// after streaming ends
Pipe(*context.T, ...rpc.CallOpt) (ViewerPipeClientCall, error)
}
// ViewerClientStub adds universal methods to ViewerClientMethods.
type ViewerClientStub interface {
ViewerClientMethods
rpc.UniversalServiceMethods
}
// ViewerClient returns a client stub for Viewer.
func ViewerClient(name string) ViewerClientStub {
return implViewerClientStub{name}
}
type implViewerClientStub struct {
name string
}
func (c implViewerClientStub) Pipe(ctx *context.T, opts ...rpc.CallOpt) (ocall ViewerPipeClientCall, err error) {
var call rpc.ClientCall
if call, err = v23.GetClient(ctx).StartCall(ctx, c.name, "Pipe", nil, opts...); err != nil {
return
}
ocall = &implViewerPipeClientCall{ClientCall: call}
return
}
// ViewerPipeClientStream is the client stream for Viewer.Pipe.
type ViewerPipeClientStream interface {
// SendStream returns the send side of the Viewer.Pipe client stream.
SendStream() interface {
// Send places the item onto the output stream. Returns errors
// encountered while sending, or if Send is called after Close or
// the stream has been canceled. Blocks if there is no buffer
// space; will unblock when buffer space is available or after
// the stream has been canceled.
Send(item []byte) error
// Close indicates to the server that no more items will be sent;
// server Recv calls will receive io.EOF after all sent items.
// This is an optional call - e.g. a client might call Close if it
// needs to continue receiving items from the server after it's
// done sending. Returns errors encountered while closing, or if
// Close is called after the stream has been canceled. Like Send,
// blocks if there is no buffer space available.
Close() error
}
}
// ViewerPipeClientCall represents the call returned from Viewer.Pipe.
type ViewerPipeClientCall interface {
ViewerPipeClientStream
// Finish performs the equivalent of SendStream().Close, then blocks until
// the server is done, and returns the positional return values for the call.
//
// Finish returns immediately if the call has been canceled; depending on the
// timing the output could either be an error signaling cancelation, or the
// valid positional return values from the server.
//
// Calling Finish is mandatory for releasing stream resources, unless the call
// has been canceled or any of the other methods return an error. Finish should
// be called at most once.
Finish() (*vom.RawBytes, error)
}
type implViewerPipeClientCall struct {
rpc.ClientCall
}
func (c *implViewerPipeClientCall) SendStream() interface {
Send(item []byte) error
Close() error
} {
return implViewerPipeClientCallSend{c}
}
type implViewerPipeClientCallSend struct {
c *implViewerPipeClientCall
}
func (c implViewerPipeClientCallSend) Send(item []byte) error {
return c.c.Send(item)
}
func (c implViewerPipeClientCallSend) Close() error {
return c.c.CloseSend()
}
func (c *implViewerPipeClientCall) Finish() (o0 *vom.RawBytes, err error) {
err = c.ClientCall.Finish(&o0)
return
}
// ViewerServerMethods is the interface a server writer
// implements for Viewer.
//
// Viewer allows clients to stream data to it and to request a
// particular viewer to format and display the data.
type ViewerServerMethods interface {
// Pipe creates a bidirectional pipe between client and viewer
// service, returns total number of bytes received by the service
// after streaming ends
Pipe(*context.T, ViewerPipeServerCall) (*vom.RawBytes, error)
}
// ViewerServerStubMethods is the server interface containing
// Viewer methods, as expected by rpc.Server.
// The only difference between this interface and ViewerServerMethods
// is the streaming methods.
type ViewerServerStubMethods interface {
// Pipe creates a bidirectional pipe between client and viewer
// service, returns total number of bytes received by the service
// after streaming ends
Pipe(*context.T, *ViewerPipeServerCallStub) (*vom.RawBytes, error)
}
// ViewerServerStub adds universal methods to ViewerServerStubMethods.
type ViewerServerStub interface {
ViewerServerStubMethods
// Describe the Viewer interfaces.
Describe__() []rpc.InterfaceDesc
}
// ViewerServer returns a server stub for Viewer.
// It converts an implementation of ViewerServerMethods into
// an object that may be used by rpc.Server.
func ViewerServer(impl ViewerServerMethods) ViewerServerStub {
stub := implViewerServerStub{
impl: impl,
}
// Initialize GlobState; always check the stub itself first, to handle the
// case where the user has the Glob method defined in their VDL source.
if gs := rpc.NewGlobState(stub); gs != nil {
stub.gs = gs
} else if gs := rpc.NewGlobState(impl); gs != nil {
stub.gs = gs
}
return stub
}
type implViewerServerStub struct {
impl ViewerServerMethods
gs *rpc.GlobState
}
func (s implViewerServerStub) Pipe(ctx *context.T, call *ViewerPipeServerCallStub) (*vom.RawBytes, error) {
return s.impl.Pipe(ctx, call)
}
func (s implViewerServerStub) Globber() *rpc.GlobState {
return s.gs
}
func (s implViewerServerStub) Describe__() []rpc.InterfaceDesc {
return []rpc.InterfaceDesc{ViewerDesc}
}
// ViewerDesc describes the Viewer interface.
var ViewerDesc rpc.InterfaceDesc = descViewer
// descViewer hides the desc to keep godoc clean.
var descViewer = rpc.InterfaceDesc{
Name: "Viewer",
PkgPath: "v.io/x/p2b/vdl",
Doc: "// Viewer allows clients to stream data to it and to request a\n// particular viewer to format and display the data.",
Methods: []rpc.MethodDesc{
{
Name: "Pipe",
Doc: "// Pipe creates a bidirectional pipe between client and viewer\n// service, returns total number of bytes received by the service\n// after streaming ends",
OutArgs: []rpc.ArgDesc{
{"", ``}, // *vom.RawBytes
},
},
},
}
// ViewerPipeServerStream is the server stream for Viewer.Pipe.
type ViewerPipeServerStream interface {
// RecvStream returns the receiver side of the Viewer.Pipe server stream.
RecvStream() interface {
// Advance stages an item so that it may be retrieved via Value. Returns
// true iff there is an item to retrieve. Advance must be called before
// Value is called. May block if an item is not available.
Advance() bool
// Value returns the item that was staged by Advance. May panic if Advance
// returned false or was not called. Never blocks.
Value() []byte
// Err returns any error encountered by Advance. Never blocks.
Err() error
}
}
// ViewerPipeServerCall represents the context passed to Viewer.Pipe.
type ViewerPipeServerCall interface {
rpc.ServerCall
ViewerPipeServerStream
}
// ViewerPipeServerCallStub is a wrapper that converts rpc.StreamServerCall into
// a typesafe stub that implements ViewerPipeServerCall.
type ViewerPipeServerCallStub struct {
rpc.StreamServerCall
valRecv []byte
errRecv error
}
// Init initializes ViewerPipeServerCallStub from rpc.StreamServerCall.
func (s *ViewerPipeServerCallStub) Init(call rpc.StreamServerCall) {
s.StreamServerCall = call
}
// RecvStream returns the receiver side of the Viewer.Pipe server stream.
func (s *ViewerPipeServerCallStub) RecvStream() interface {
Advance() bool
Value() []byte
Err() error
} {
return implViewerPipeServerCallRecv{s}
}
type implViewerPipeServerCallRecv struct {
s *ViewerPipeServerCallStub
}
func (s implViewerPipeServerCallRecv) Advance() bool {
s.s.errRecv = s.s.Recv(&s.s.valRecv)
return s.s.errRecv == nil
}
func (s implViewerPipeServerCallRecv) Value() []byte {
return s.s.valRecv
}
func (s implViewerPipeServerCallRecv) Err() error {
if s.s.errRecv == io.EOF {
return nil
}
return s.s.errRecv
}