proto

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2022 License: BSD-2-Clause Imports: 9 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"
)
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

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 panic if a protocol is specified and it is != 'fossil'. Format:

[fossil://]<host:port|local>[/<db_name>]

type ErrResponse

type ErrResponse struct {
	Code uint32
	Err  error
}

func (ErrResponse) Marshal

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

Marshal ...

func (*ErrResponse) Unmarshal

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

Unmarshal ...

type ListRequest

type ListRequest struct {
}

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 {
	DatabaseList []string
}

func (ListResponse) Marshal

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

Marshal ...

func (*ListResponse) Unmarshal

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

Unmarshal ...

type Marshaler

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

type Message

type Message struct {
	Command string
	Data    []byte
}

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)

func (Message) Marshal

func (m Message) Marshal() ([]byte, error)

func (Message) MarshalZerologObject

func (m Message) MarshalZerologObject(e *zerolog.Event)

func (*Message) Unmarshal

func (m *Message) Unmarshal(r io.Reader) error

type OkResponse

type OkResponse struct {
	Code    uint32
	Message string
}

func (OkResponse) Marshal

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

Marshal ...

func (*OkResponse) Unmarshal

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

Unmarshal ...

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
}

func (QueryResponse) Marshal

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

Marshal ...

func (*QueryResponse) Unmarshal

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

Unmarshal ...

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
	TotalMem  uint64
	Uptime    time.Duration
	Segments  int
}

func (StatsResponse) Marshal

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

Marshal ...

func (*StatsResponse) Unmarshal

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

Unmarshal ...

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
	Version 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 ...

Jump to

Keyboard shortcuts

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