frame

package
v0.0.0-...-b44964e Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: Apache-2.0 Imports: 7 Imported by: 3

Documentation

Overview

Copyright (c) 2014-2019 Cesanta Software Limited All rights reserved

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2014-2019 Cesanta Software Limited All rights reserved

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCommandUID

func CreateCommandUID() int64

CreateCommandUID creates a unique UID for commands.

func MarshalJSON

func MarshalJSON(f *Frame) ([]byte, error)

func NewLimitedWriter

func NewLimitedWriter(w io.Writer, limit int) io.Writer

New returns a new limited writer.

A limited writer will return error after writing limit bytes.

Types

type Command

type Command struct {
	Cmd  string          `json:"cmd"`
	ID   int64           `json:"id,omitempty"`
	Args json.RawMessage `json:"args,omitempty"`

	Auth *FrameAuth `json:"auth,omitempty"`

	// Timestamp (as number of seconds since Epoch) of when the command result is no longer relevant.
	Deadline int64 `json:"deadline,omitempty"`

	// Number of seconds after reception of the command after when the command result is no longer relevant.
	Timeout int64 `json:"timeout,omitempty"`

	Trace *Trace `json:"trace,omitempty"`
}

func NewCommandFromFrame

func NewCommandFromFrame(f *Frame) *Command

func (Command) String

func (c Command) String() string

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message,omitempty"`
}

type Frame

type Frame struct {
	// Version denotes the protocol version in use. Must be set to 1.
	Version int `json:"v,omitempty"`

	// Src is the ID of the sender.
	Src string `json:"src,omitempty"`

	// Dst is the ID of the recipient.
	Dst string `json:"dst,omitempty"`

	// Key should contains pre-shared key if client certificates are not used.
	Key string `json:"key,omitempty"`

	// Tag, if present, should be copied verbatim to the response frame.
	Tag string `json:"tag,omitempty"`

	ID int64 `json:"id,omitempty"`

	// Request
	Method string          `json:"method,omitempty"`
	Params json.RawMessage `json:"params,omitempty"`
	// Timestamp (as number of seconds since Epoch) of when the command result is no longer relevant.
	Deadline int64 `json:"deadline,omitempty"`
	// Number of seconds after reception of the command after when the command result is no longer relevant.
	Timeout int64 `json:"timeout,omitempty"`

	// Response
	Result json.RawMessage `json:"result,omitempty"`
	Error  *Error          `json:"error,omitempty"`

	Trace *Trace `json:"trace,omitempty"`

	Auth *FrameAuth `json:"auth,omitempty"`

	// Size hint, if present, gives approximate size of the frame in memory.
	SizeHint int `json:"-"`

	// Send no response to this frame
	NoResponse bool `json:"nr,omitempty"`

	DeprecatedArgs json.RawMessage `json:"args,omitempty"`
}

Frame is a basic data structure that contains request or response.

func NewRequestFrame

func NewRequestFrame(src string, dst string, key string, cmd *Command, compatArgs bool) *Frame

func NewResponseFrame

func NewResponseFrame(src string, dst string, key string, resp *Response) *Frame

func (*Frame) IsRequest

func (f *Frame) IsRequest() bool

func (*Frame) String

func (f *Frame) String() string

type FrameAuth

type FrameAuth struct {
	Realm     string `json:"realm"`
	Username  string `json:"username"`
	Nonce     int    `json:"nonce"`
	CNonce    int    `json:"cnonce"`
	Algorithm string `json:"algorithm,omitempty"`
	Response  string `json:"response"`
	Opaque    string `json:"opaque,omitempty"`
}

type Response

type Response struct {
	ID int64 `json:"id"`

	// Status code. Non-zero value means error.
	Status int `json:"status"`

	// Human-readable explanation of an error, if any.
	StatusMsg string `json:"status_msg,omitempty"`

	// Application defined response payload
	Response json.RawMessage `json:"resp,omitempty"`
}

func NewResponseFromFrame

func NewResponseFromFrame(f *Frame) *Response

func (Response) String

func (r Response) String() string

type Trace

type Trace struct {
	// Dapper trace ID
	TraceID int64 `json:"id,omitempty"`
	// Dapper span ID
	SpanID int64 `json:"span,omitempty"`
}

Trace groups optional call tracing info.

Jump to

Keyboard shortcuts

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