jsonbuffer

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2019 License: MPL-2.0-no-copyleft-exception Imports: 4 Imported by: ? 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 jsonbuffer implements a stream protocol using JSON blobs as segments in the buffer, with a type and envelope.

Each message is sent as JSON (see the Message struct) and contains a type and payload. The type determines how the payload is handled; but arguably what happens as a result of that belongs to the client.

There is also a javascript client for this in the ci-ui repository.

Index

Constants

View Source
const (
	// TypeMessage is a message and the payload is the message we're trying to send.
	TypeMessage = "message"
	// TypeError is an error and the payload is the error text.
	TypeError = "error"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Type    string `json:"type"`
	Payload string `json:"payload"`
}

Message is the websocket message transmitted.

type Wrapper

type Wrapper struct {
	io.Writer
	io.Reader
	// contains filtered or unexported fields
}

Wrapper is a wrapper for io.Reader that lets us power it via protocol through our client.

func NewWrapper

func NewWrapper(rw io.ReadWriter) *Wrapper

NewWrapper creates a Wrapper from a pre-established connection.

func (*Wrapper) Read

func (w *Wrapper) Read(buf []byte) (int, error)

Read conforms to the io.Reader interface. If it cannot fill buf with the payload, it will keep the buffer for the next read call.

func (*Wrapper) Recv

func (w *Wrapper) Recv() (string, error)

Recv reads a single message from the reader and returns it. If the type is message, it returns the payload, otherwise if it hits EOF it will return ErrEOF; on any error return it returns the error.

func (*Wrapper) Send

func (w *Wrapper) Send(message string) error

Send sends a message by writing through the Wrapper. The outgoing message will be of type websocket.TypeMessage.

func (*Wrapper) SendError

func (w *Wrapper) SendError(err error) error

SendError is like Send, but for errors.

func (*Wrapper) Write

func (w *Wrapper) Write(buf []byte) (int, error)

Write is Send that conforms to the io.Writer spec. Each buffer will be sent as a single Message.

Jump to

Keyboard shortcuts

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