types

package
v0.0.0-...-0807a26 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: BSD-3-Clause Imports: 5 Imported by: 8

Documentation

Index

Constants

View Source
const (
	// MAX_JSON_SIZE is the limit on the size of JSON produced by a single fiddle run.
	MAX_JSON_SIZE = 100 * 1024 * 1024

	MAX_CODE_SIZE = 128 * 1024

	DefaultAnimationDuration = 2 // seconds
)

Variables

View Source
var (
	AllStates = []State{IDLE, WRITING, COMPILING, RUNNING, ERROR}
)

Functions

This section is empty.

Types

type BulkRequest

type BulkRequest map[string]*FiddleContext

type BulkResponse

type BulkResponse map[string]*RunResults

type Compile

type Compile struct {
	Errors string `json:"errors"`
	Output string `json:"output"` // Compiler output.
}

Compile contains the output from compiling the user's fiddle.

type CompileError

type CompileError struct {
	Text string `json:"text"`
	Line int    `json:"line"`
	Col  int    `json:"col"`
}

CompileError is a single line of compiler error output, along with the line and column that the error occurred at.

type Execute

type Execute struct {
	Errors string `json:"errors"`
	Output Output `json:"output"`
}

Execute contains the output from running the compiled fiddle.

type FiddleContext

type FiddleContext struct {
	Version   string  `json:"version"`    // The version of Skia that fiddle is running.
	Sources   string  `json:"sources"`    // All the source image ids serialized as a JSON array.
	Hash      string  `json:"fiddlehash"` // Can be the fiddle hash or the fiddle name.
	Code      string  `json:"code"`
	Name      string  `json:"name"`      // In a request can be the name to create for this fiddle.
	Overwrite bool    `json:"overwrite"` // In a request, should a name be overwritten if it already exists.
	Fast      bool    `json:"fast"`      // Fast, don't compile and run if a fiddle with this hash has already been compiled and run.
	Options   Options `json:"options"`
}

FiddleContext is the structure we use for expanding the index.html template.

It is also used (without the Hash) as the incoming JSON request to /_/run.

type FiddlerMainResponse

type FiddlerMainResponse struct {
	State   State  `json:"state"`
	Version string `json:"version"` // Skia Git Hash
}

FiddlerMainResponse is the JSON that fiddler responds with for a request to "/".

type Options

type Options struct {
	Width                int     `json:"width"`
	Height               int     `json:"height"`
	Source               int     `json:"source"`
	SourceMipMap         bool    `json:"source_mipmap"`
	SRGB                 bool    `json:"srgb"`
	F16                  bool    `json:"f16"`
	TextOnly             bool    `json:"textOnly"`
	Animated             bool    `json:"animated"`
	Duration             float64 `json:"duration"`
	OffScreen            bool    `json:"offscreen"`
	OffScreenWidth       int     `json:"offscreen_width"`
	OffScreenHeight      int     `json:"offscreen_height"`
	OffScreenSampleCount int     `json:"offscreen_sample_count"`
	OffScreenTexturable  bool    `json:"offscreen_texturable"`
	OffScreenMipMap      bool    `json:"offscreen_mipmap"`
}

Options are the users options they can select when running a fiddle that will cause it to produce different output.

If new fields are added make sure to update ComputeHash and go/store.

func (*Options) ComputeHash

func (o *Options) ComputeHash(code string) (string, error)

ComputeHash calculates the fiddleHash for the given code and options.

It might seem a little odd to have this as a member function of Options, but it's more likely to get updated if Options ever gets changed.

The hash computation is a bit convoluted because it needs to be backward compatible with the original version of fiddle so URLs don't break.

type Output

type Output struct {
	Raster         string `json:"Raster"`
	Gpu            string `json:"Gpu"`
	Pdf            string `json:"Pdf"`
	Skp            string `json:"Skp"`
	Text           string `json:"Text"`
	AnimatedRaster string `json:"AnimatedRaster"`
	AnimatedGpu    string `json:"AnimatedGpu"`
	GLInfo         string `json:"GLInfo"`
}

Output contains the base64 encoded files for each of the output types.

type Result

type Result struct {
	Errors  string  `json:"errors"`
	Compile Compile `json:"compile"`
	Execute Execute `json:"execute"`
}

Result is the JSON output format from fiddle_run.

type RunResults

type RunResults struct {
	CompileErrors []CompileError `json:"compile_errors"`
	RunTimeError  string         `json:"runtime_error"`
	FiddleHash    string         `json:"fiddleHash"`
	Text          string         `json:"text"`
}

RunResults is the results we serialize to JSON as the results from a run.

type State

type State string

State is the state of a fiddler.

const (
	IDLE      State = "idle"
	WRITING   State = "writing"
	COMPILING State = "compiling"
	RUNNING   State = "running"
	ERROR     State = "error"
)

Jump to

Keyboard shortcuts

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