protocol

package module
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: GPL-3.0 Imports: 4 Imported by: 0

README

TouHou.FM Radio Protocol Library

This module contains helpers to interface with the inter-service communication protocol.

Tests

In order to run the tests, run:

make test

It will generate a JUnit style report.xml

Documentation

Overview

Package protocol implements the protocol decoding, encoding of the go.touhou.fm/radio/server players

Messages

The protocol consists of several messages that are sent between the different services:

Basic:

Want        sent from the player to request new songs
Skip        sent from a controller to skip a song
Status      sent from a controller to ask for current status
Quit        sent from a controller to stop the service gracefully

Loading:

Next        sent from a controller to load a song
Loaded      sent from the player to indicate the song has been loaded
Playing     sent from the server to indicate the song has begun playing
Stopped     sent from the server to indicate the song has stopped playing

Meta:

Meta        sent from a controller to update the metadata broadcast by the player

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidType = errors.New("invalid type")

ErrInvalidType is returned when a message is not understood

Functions

This section is empty.

Types

type Loaded

type Loaded struct {
	// The deck number the song has been loaded in
	Deck int
	// The song that has been loaded
	Song
}

Loaded describes a message that indicates a song has been loaded

The player will send this message to indicate to a controller that the song has been loaded. This will be sent regardless of whether it can play it. If the song cannot be played, the player will send a Want message as soon as it fails to load it.

Sending Status will also yield Loaded messages, 1 for each deck

func (*Loaded) Encode

func (p *Loaded) Encode(writer io.Writer) error

Encode implements the serialization of the Loaded message to json

type Message

type Message interface {
	Encode(writer io.Writer) error
}

Message is the interface that wraps the Encode method.

Encode serializes the message to a json string.

func Decode

func Decode(value *fastjson.Value) (Message, error)

Decode implements the decoding of a message from json. If the type defined in the json is not recognized, it will return protocol.ErrInvalidType

type Meta

type Meta map[string]string

Meta describes a message that indiates the metadata to broadcast to the listeners.

A controller can send this to provide additional information about the currently playing song like title, artist, circle, album, year, etc.

func (*Meta) Encode

func (p *Meta) Encode(writer io.Writer) error

Encode implements the serialization of the Meta message to json

type Next

type Next struct {
	// The Song to enqueue
	Song
}

Next describes a message that indicates to a player what song to add to the playlist

A controller should send this in response to a Want message. Depending on the targetted service, it may ignore or add this to the end of its queue. Player will ignore extra songs and Playlist will append extra songs to its playlist.

func (*Next) Encode

func (p *Next) Encode(writer io.Writer) error

Encode implements the serialization of the Next message to json

type Playing

type Playing transport

Playing describes a message that indicates a deck has begun playing

The player will send this message to indicate a previously loaded song has begun playback. The position will indicate the current position relative to the start at the time this message has been written

Sending Status will also yield Playing messages, 1 for each deck. Its Position value will in this case refers to the actual playback position at the time of reception of the Status message.

func (*Playing) Encode

func (p *Playing) Encode(writer io.Writer) error

Encode implements the serialization of the Playing message to json

type Quit

type Quit struct{}

Quit describes a message that requests the receiver to stop

A controller can send this to any service to cause it to stop its processing and gracefully exit

func (*Quit) Encode

func (q *Quit) Encode(writer io.Writer) error

Encode implements the serialization of the Quit message to json

type Skip

type Skip struct{}

Skip describes a message that requests a song to be skipped

A controller can send this to a player to cause the player to immediately switch to the next song

func (*Skip) Encode

func (p *Skip) Encode(writer io.Writer) error

Encode implements the serialization of the Skip message to json

type Song

type Song struct {
	// The relative path to the file
	File string
	// The starting position of the song in samples
	Start uint64
	// The ending position of the song in samples
	Stop uint64
}

Song stores the necessary information to identify a song for playback.

type Status

type Status struct{}

Status describes a message that requests the current status from the player

A controller can send this to a player to cause the player to resend its Loaded/Playing/Stopped messages.

func (*Status) Encode

func (s *Status) Encode(writer io.Writer) error

Encode implements the serialization of the Status message to json

type Stopped

type Stopped transport

Stopped describes a message that incidates a deck has stopped playing.

The player will send this message to indicate a previously loaded song has stopped playback. The position will indicate the current position relative to the start at the time this message has been written

Sending Status will also yield Stopped messages, 1 for each deck. Its Position value in this case refers to the actual playback position at the time of reception of the Status message.

func (*Stopped) Encode

func (p *Stopped) Encode(writer io.Writer) error

Encode implements the serialization of the Stopped message to json

type Type

type Type int

Type defines the allowed types for protocol messages

type Want

type Want struct{}

Want describes a message that requests a new song to be given

A player or playlist will send a Want message when it has no more items to play

func (*Want) Encode

func (p *Want) Encode(writer io.Writer) error

Encode implements the serialization of the Want message to json

Directories

Path Synopsis
Package channels provides the Producer, Consumer and Channels interfaces to be used for connecting producers and consumers together.
Package channels provides the Producer, Consumer and Channels interfaces to be used for connecting producers and consumers together.
Package consumer contains the Consumer protocol handler.
Package consumer contains the Consumer protocol handler.
Package producer contains the Producer protocol handler.
Package producer contains the Producer protocol handler.
Package util provides various utilities for the protocol
Package util provides various utilities for the protocol

Jump to

Keyboard shortcuts

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