proto

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CommandVersion sends the version of the fossil protocol supported to the server / client
	CommandVersion = "VERSION"
	// CommandList sets the current database context
	CommandList = "LIST"
	// CommandUse sets the current database context
	CommandUse = "USE"
	// CommandError sends an error code and a message to the client
	CommandError = "ERR"
	// CommandOk is used to respond to generic actions
	CommandOk = "OK"
	// CommandStats retrieves the current database stats
	CommandStats = "STATS"
	// CommandQuery executes a query on the current database
	CommandQuery = "QUERY"
	// CommandAppend appends data to the current database
	CommandAppend = "APPEND"
	// CommandCreate is used to create topics (but could be used for other purposes in the future)
	CommandCreate = "CREATE"
)
View Source
var (
	Version                      = "v1.0.0"
	MessageOk                    = NewMessageWithType(CommandOk, OkResponse{Code: 200, Message: "Ok"})
	MessageOkDatabaseChanged     = NewMessageWithType(CommandOk, OkResponse{Code: 201, Message: "database changed"})
	MessageError                 = NewMessageWithType(CommandError, ErrResponse{Code: 500})
	MessageErrorCommandNotFound  = NewMessageWithType(CommandError, ErrResponse{Code: 501, Err: fmt.Errorf("command not found")})
	MessageErrorMalformedMessage = NewMessageWithType(CommandError, ErrResponse{Code: 502, Err: fmt.Errorf("malformed message")})
	MessageErrorUnmarshaling     = NewMessageWithType(CommandError, ErrResponse{Code: 506, Err: fmt.Errorf("error unmarshaling")})
	MessageErrorUnknownDb        = NewMessageWithType(CommandList, ListRequest{})

	MessageList = NewMessageWithType(CommandError, ErrResponse{Code: 505})
)
View Source
var Protocol = "fossil"

Functions

func Marshal

func Marshal(t Marshaler) ([]byte, error)

func Unmarshal

func Unmarshal(b []byte, t Unmarshaler) error

Types

type AppendRequest

type AppendRequest struct {
	Topic string
	Data  []byte
}

func (AppendRequest) Marshal

func (rq AppendRequest) Marshal() ([]byte, error)

Marshal ...

func (*AppendRequest) Unmarshal

func (rq *AppendRequest) Unmarshal(b []byte) error

Unmarshal ...

type ConnectionString

type ConnectionString struct {
	Local    bool
	Address  string
	Database string
}

func ParseConnectionString

func ParseConnectionString(connStr string) (ConnectionString, error)

ParseConnectionString takes a connection string and parses it into the parts the application needs to make a connection. This function will always parse, even horribly malformed connection strings. It will only return an error if the protocol is not "fossil" or "file"

Formats:

./path/to/local/db
file://./path/to/local/db
fossil://<host:port>[/<db_name>]

type CreateTopicRequest added in v0.2.0

type CreateTopicRequest struct {
	Topic  string
	Schema string
}

func (CreateTopicRequest) Marshal added in v0.2.0

func (rq CreateTopicRequest) Marshal() ([]byte, error)

Marshal ...

func (*CreateTopicRequest) Unmarshal added in v0.2.0

func (rq *CreateTopicRequest) Unmarshal(b []byte) error

Unmarshal ...

type ErrResponse

type ErrResponse struct {
	Code uint32 `json:"code"`
	Err  error  `json:"error"`
}

func (ErrResponse) Headers added in v0.2.0

func (v ErrResponse) Headers() []string

func (ErrResponse) Marshal

func (rq ErrResponse) Marshal() ([]byte, error)

Marshal ...

func (*ErrResponse) Unmarshal

func (rq *ErrResponse) Unmarshal(b []byte) error

Unmarshal ...

func (ErrResponse) Values added in v0.2.0

func (v ErrResponse) Values() [][]string

type ListRequest

type ListRequest struct {
	Object string
}

func (ListRequest) Marshal

func (rq ListRequest) Marshal() ([]byte, error)

Marshal ...

func (*ListRequest) Unmarshal

func (rq *ListRequest) Unmarshal(b []byte) error

Unmarshal ...

type ListResponse

type ListResponse struct {
	ObjectList []string `json:"results"`
}

func (ListResponse) Headers added in v0.2.0

func (v ListResponse) Headers() []string

func (ListResponse) Marshal

func (rq ListResponse) Marshal() ([]byte, error)

Marshal ...

func (*ListResponse) Unmarshal

func (rq *ListResponse) Unmarshal(b []byte) error

Unmarshal ...

func (ListResponse) Values added in v0.2.0

func (v ListResponse) Values() [][]string

type Marshaler

type Marshaler interface {
	Marshal() ([]byte, error)
}

type Message

type Message interface {
	Marshal() ([]byte, error)
	Unmarshal(r io.Reader) error
	Command() string
	Data() []byte
	MarshalZerologObject(e *zerolog.Event)
}

func NewMessage

func NewMessage(cmd string, data []byte) Message

func NewMessageWithType

func NewMessageWithType(cmd string, t Marshaler) Message

func ReadMessageFull

func ReadMessageFull(r io.Reader) (Message, error)

type OkResponse

type OkResponse struct {
	Code    uint32 `json:"code"`
	Message string `json:"message"`
}

func (OkResponse) Headers added in v0.2.0

func (v OkResponse) Headers() []string

func (OkResponse) Marshal

func (rq OkResponse) Marshal() ([]byte, error)

Marshal ...

func (*OkResponse) Unmarshal

func (rq *OkResponse) Unmarshal(b []byte) error

Unmarshal ...

func (OkResponse) Values added in v0.2.0

func (v OkResponse) Values() [][]string

type Printable added in v0.2.0

type Printable interface {
	Headers() []string
	Values() [][]string
}

type QueryRequest

type QueryRequest struct {
	Query string
}

func (QueryRequest) Marshal

func (rq QueryRequest) Marshal() ([]byte, error)

Marshal ...

func (*QueryRequest) Unmarshal

func (rq *QueryRequest) Unmarshal(b []byte) error

Unmarshal ...

type QueryResponse

type QueryResponse struct {
	Results database.Entries `json:"results"`
}

func (QueryResponse) Headers added in v0.2.0

func (v QueryResponse) Headers() []string

func (QueryResponse) Marshal

func (rq QueryResponse) Marshal() ([]byte, error)

Marshal ...

func (*QueryResponse) Unmarshal

func (rq *QueryResponse) Unmarshal(b []byte) error

Unmarshal ...

func (QueryResponse) Values added in v0.2.0

func (v QueryResponse) Values() [][]string

type Request

type Request struct {
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(msg Message, db *database.Database) *Request

NewRequest creates a new request from the line message and the current client state

func (*Request) Command

func (r *Request) Command() string

Command retrieves the command from the request

func (*Request) Data

func (r *Request) Data() []byte

Data retrieves the data portion of the line message

func (*Request) Database

func (r *Request) Database() *database.Database

Database retrieves the current database handle

type ResponseWriter

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

func NewResponseWriter

func NewResponseWriter(w io.Writer) ResponseWriter

NewResponseWriter ...

func (ResponseWriter) Write

func (rw ResponseWriter) Write(b []byte) (int, error)

func (ResponseWriter) WriteMessage

func (rw ResponseWriter) WriteMessage(t Marshaler) (int, error)

type StatsRequest

type StatsRequest struct {
	Database string
}

func (StatsRequest) Marshal

func (rq StatsRequest) Marshal() ([]byte, error)

Marshal ...

func (*StatsRequest) Unmarshal

func (rq *StatsRequest) Unmarshal(b []byte) error

Unmarshal ...

type StatsResponse

type StatsResponse struct {
	AllocHeap uint64        `json:"alloc_heap"`
	TotalMem  uint64        `json:"total_mem"`
	Uptime    time.Duration `json:"uptime"`
	Segments  int           `json:"segments"`
	Topics    int           `json:"topics"`
}

func (StatsResponse) Headers added in v0.2.0

func (v StatsResponse) Headers() []string

func (StatsResponse) Marshal

func (rq StatsResponse) Marshal() ([]byte, error)

Marshal ...

func (*StatsResponse) Unmarshal

func (rq *StatsResponse) Unmarshal(b []byte) error

Unmarshal ...

func (StatsResponse) Values added in v0.2.0

func (v StatsResponse) Values() [][]string

type Unmarshaler

type Unmarshaler interface {
	Unmarshal([]byte) error
}

type UseRequest

type UseRequest struct {
	DbName string
}

func (UseRequest) Marshal

func (rq UseRequest) Marshal() ([]byte, error)

Marshal ...

func (*UseRequest) Unmarshal

func (rq *UseRequest) Unmarshal(b []byte) error

Unmarshal ...

type VersionRequest

type VersionRequest struct {
	Version string
}

func (VersionRequest) Marshal

func (v VersionRequest) Marshal() ([]byte, error)

Marshal a VersionRequest. We don't actually use the specified version, and instead rely on the Version variable above

func (*VersionRequest) Unmarshal

func (v *VersionRequest) Unmarshal(b []byte) error

Unmarshal ...

type VersionResponse

type VersionResponse struct {
	Code    uint32 `json:"code"`
	Version string `json:"version"`
}

func (VersionResponse) Headers added in v0.2.0

func (v VersionResponse) Headers() []string

func (VersionResponse) Marshal

func (v VersionResponse) Marshal() ([]byte, error)

Marshal a VersionResponse. As with VersionRequest, we override the version specified in the supplied VersionResponse.

func (*VersionResponse) Unmarshal

func (v *VersionResponse) Unmarshal(b []byte) error

Unmarshal ...

func (VersionResponse) Values added in v0.2.0

func (v VersionResponse) Values() [][]string

Jump to

Keyboard shortcuts

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