Documentation ¶
Overview ¶
Pacakge jkprotocol implement jk protocol generate, parse and use.
Index ¶
- Constants
- func JKProtoV6Make(cmd string, resp bool, id string, data interface{}) (string, error)
- func JKProtoV6MakeKeepalive(id string) (string, error)
- func JKProtoV6MakeRegister(id string, data interface{}) (string, error)
- type JKDeviceInfo
- type JKFileTransfer
- type JKProtoInfo
- type JKProtoUp
- func (pup *JKProtoUp) JKProtoUpCommon(cmd string) ([]byte, error)
- func (pup *JKProtoUp) JKProtoUpInit(ack bool, length uint32, content []byte) ([]byte, error)
- func (pup *JKProtoUp) JKProtoUpKeepalive() ([]byte, error)
- func (pup *JKProtoUp) JKProtoUpParse(data []byte) error
- func (pup *JKProtoUp) JKProtoUpRegister() ([]byte, error)
- func (pup *JKProtoUp) JKProtoUpSeq() int
- func (pup *JKProtoUp) JKProtoUpSeqAdd(v int32) error
- type JKProtoV4
- func (p *JKProtoV4) Debug()
- func (p *JKProtoV4) GenerateBody(data string) (*JKProtoV4Body, error)
- func (p *JKProtoV4) GenerateBodyByte(data []byte) (*JKProtoV4Body, error)
- func (p *JKProtoV4) GenerateHeader(crypt uint, ack bool, length uint32) (*JKProtoV4Header, error)
- func (p *JKProtoV4) Parse(data []byte) error
- func (p *JKProtoV4) ToByte() ([]byte, error)
- type JKProtoV4Body
- type JKProtoV4Header
- type JKProtoV6
- func (p *JKProtoV6) JKProtoV6MakeCommon(cmd, id string, resp bool, data interface{}) (string, error)
- func (p *JKProtoV6) JKProtoV6MakeCommonResponse(data interface{}) (string, error)
- func (p *JKProtoV6) JKProtoV6MakeKeepaliveResponse() (string, error)
- func (p *JKProtoV6) JKProtoV6MakeTR(id string, resp bool, data interface{}) (string, error)
- type JKProtoV6Header
- type JKProtocol
- func (p *JKProtocol) Command() int
- func (p *JKProtocol) GenerateControlSaveFile(filename string, data string) string
- func (p *JKProtocol) GenerateNotifySaveFile(filename string) string
- func (p *JKProtocol) GenerateRegister(id string) string
- func (p *JKProtocol) GenerateResponseFail() string
- func (p *JKProtocol) GenerateResponseOK() string
- func (p *JKProtocol) ID() string
- func (p *JKProtocol) ParseFilename() string
- func (p *JKProtocol) ParseFilenameData() (string, string)
- func (p *JKProtocol) SubCommand() int
- type JKProtocolHead
- type JKProtocolWrap
- func (wrap *JKProtocolWrap) Keepalive(data string) (string, error)
- func (wrap *JKProtocolWrap) KeepaliveResponse(data string) (string, error)
- func (wrap *JKProtocolWrap) Leave(data string) (string, error)
- func (wrap *JKProtocolWrap) LeaveResponse(data string) (string, error)
- func (wrap *JKProtocolWrap) Parse(data string) (string, error)
- func (wrap *JKProtocolWrap) Register(data string) (string, error)
- func (wrap *JKProtocolWrap) RegisterResponse(data string) (string, error)
- type JK_P_DataWithHeader
- func (header *JK_P_DataWithHeader) Data() []byte
- func (header *JK_P_DataWithHeader) FromBytes(buf []byte) error
- func (h *JK_P_DataWithHeader) GetData() []byte
- func (header *JK_P_DataWithHeader) Header() *JK_P_Header
- func (h *JK_P_DataWithHeader) SetData(data []byte)
- func (h *JK_P_DataWithHeader) ToByte() []byte
- type JK_P_Header
- func (h *JK_P_Header) GetContinued() int
- func (h *JK_P_Header) GetLength() int
- func (h *JK_P_Header) GetMainCommand() int
- func (h *JK_P_Header) GetSequence() int
- func (h *JK_P_Header) GetSlaveCommand() int
- func (h *JK_P_Header) GetType() int
- func (h *JK_P_Header) GetVersions() string
- func (h *JK_P_Header) SetContinued(c int) error
- func (h *JK_P_Header) SetData(data []byte) *JK_P_DataWithHeader
- func (h *JK_P_Header) SetLength(length int) error
- func (h *JK_P_Header) SetMainCommand(mc int) error
- func (h *JK_P_Header) SetSequence(seq int) error
- func (h *JK_P_Header) SetSlaveCommand(sc int) error
- func (h *JK_P_Header) SetType(t int) error
- func (h *JK_P_Header) SetVersions(m, s, l int) error
- func (h *JK_P_Header) ToBytes() []byte
- type KFProtocol
- func (p *KFProtocol) GenerateData(dir bool) ([]byte, error)
- func (p *KFProtocol) GenerateDataText(dir bool) ([]byte, error)
- func (p *KFProtocol) Init()
- func (p *KFProtocol) SetCmd(cmd, subcmd uint, id []byte)
- func (p *KFProtocol) SetData(data []byte)
- func (p *KFProtocol) SetResponseCode(result bool, code int) error
- type KFProtocolBody
- type KFProtocolHeader
- type V5Base
- func (base *V5Base) GenCmd(cmd, subcmd string, resp bool, data string) (string, error)
- func (base *V5Base) Keepalive(data string) (string, error)
- func (base *V5Base) KeepaliveResponse(data string) (string, error)
- func (base *V5Base) Leave(data string) (string, error)
- func (base *V5Base) LeaveResponse(data string) (string, error)
- func (base *V5Base) Parse(data string) (interface{}, int, error)
- func (base *V5Base) Register(data string) (string, error)
- func (base *V5Base) RegisterReponse(data string) (string, error)
- type V5Body
- type V5Header
- type V5PreHeader
Constants ¶
const ( JK_P_HEADER_MARK_NAME = "JK" JK_P_HEADER_MAIN_VERSION = 0 JK_P_HEADER_SLAVE_VERSION = 1 JK_P_HEADER_LAST_VERSION = 0 )
Header const define
const ( JK_P_HEADER_TYPE_SEND = 0 JK_P_HEADER_TYPE_RESPONSE = 1 JK_P_HEADER_TYPE_NOTIFY = 2 )
Header main command type
const ( JK_P_HEADER_SINGLE = 0 JK_P_HEADER_CONTINUE = 1 )
const ( JK_P_CMD_DEVICE_CONNECT_QUERY = 1 JK_P_CMD_DEVICE_CONNECT_FILE_TRANSFER = 2 )
Header slave command depends on main command Device Connect
const ( JK_PROTOCOL_C_REGISTER = 1 << iota JK_PROTOCOL_C_LEAVE JK_PROTOCOL_C_KEEPALIVE )
const ( JK_PROTOCOL_VERSION_1 = 1 << iota JK_PROTOCOL_VERSION_2 JK_PROTOCOL_VERSION_3 JK_PROTOCOL_VERSION_4 JK_PROTOCOL_VERSION_5 )
const ( JKProtoV4CryptNone = 0 JKProtoV4CryptAES = 1 )
const ( JKP_V6_REGISTER_NAME = "Register" JKP_V6_KEEPALIVE_NAME = "Keepalive" // transfer content to other program JKP_V6_TR_NAME = "TR" )
const ( JK_PROTOCOL_CMD_REGISTER = 1 << iota JK_PROTOCOL_CMD_NOTIFY // 2 JK_PROTOCOL_CMD_CONTROL // 4 )
const ( KF_CMD_QUERY = 1 << iota KF_CMD_CONTROL KF_CMD_NOTIFY )
const ( KF_SUBCMD_REGISTER = 1 KF_SUBCMD_KEEPALIVE = 2 KF_SUBCMD_COMMAND = 0x100 // execute command KF_SUBCMD_FILE = 0x101 // Get file info (bidirectional) KF_SUBCMD_OFFLINE = 0x500 )
const (
JK_PROTOCOL_CMD_SAVEFILE = 1 << iota
)
const (
JK_P_CMD_DEVICE_CONNECT = 1
)
Header main command
const (
JK_P_HEADER_LENGTH = 20 // The header length is 20 bytes
)
Header const len define
const (
V5_VERSION = 0.1
)
Variables ¶
This section is empty.
Functions ¶
func JKProtoV6Make ¶
func JKProtoV6MakeKeepalive ¶
func JKProtoV6MakeRegister ¶
Types ¶
type JKDeviceInfo ¶
First query from other device contain information Response need.
func (*JKDeviceInfo) ToByte ¶
func (di *JKDeviceInfo) ToByte() []byte
type JKFileTransfer ¶
Used when need file transfer Use the addr and port to contact each other This will use tcp connect Response need.
func (*JKFileTransfer) ToByte ¶
func (ft *JKFileTransfer) ToByte() []byte
type JKProtoInfo ¶
type JKProtoUp ¶
type JKProtoUp struct { PType int // proto type Proto *JKProtoV4 Info JKProtoInfo }
func (*JKProtoUp) JKProtoUpCommon ¶
Command of register,...
func (*JKProtoUp) JKProtoUpInit ¶
Return bytes Generate command with protocol v4
func (*JKProtoUp) JKProtoUpKeepalive ¶
func (*JKProtoUp) JKProtoUpParse ¶
Parse bytes
func (*JKProtoUp) JKProtoUpRegister ¶
func (*JKProtoUp) JKProtoUpSeq ¶
Get last command's sequence
func (*JKProtoUp) JKProtoUpSeqAdd ¶
Auto add sequence, or set sequence
type JKProtoV4 ¶
type JKProtoV4 struct { Header JKProtoV4Header Body JKProtoV4Body }
func JKProtoV4New ¶
func (*JKProtoV4) GenerateBody ¶
func (p *JKProtoV4) GenerateBody(data string) (*JKProtoV4Body, error)
Set Body
func (*JKProtoV4) GenerateBodyByte ¶
func (p *JKProtoV4) GenerateBodyByte(data []byte) (*JKProtoV4Body, error)
func (*JKProtoV4) GenerateHeader ¶
Set header
type JKProtoV4Body ¶
type JKProtoV4Body struct {
Data []byte
}
type JKProtoV4Header ¶
type JKProtoV6 ¶
type JKProtoV6 struct { H JKProtoV6Header B interface{} }
func JKProtoV6Parse ¶
func (*JKProtoV6) JKProtoV6MakeCommon ¶
func (*JKProtoV6) JKProtoV6MakeCommonResponse ¶
func (*JKProtoV6) JKProtoV6MakeKeepaliveResponse ¶
type JKProtoV6Header ¶
type JKProtocol ¶
type JKProtocol struct {
// contains filtered or unexported fields
}
func NewJKProtocol ¶
func NewJKProtocol() *JKProtocol
func (*JKProtocol) Command ¶
func (p *JKProtocol) Command() int
func (*JKProtocol) GenerateControlSaveFile ¶
func (p *JKProtocol) GenerateControlSaveFile(filename string, data string) string
func (*JKProtocol) GenerateNotifySaveFile ¶
func (p *JKProtocol) GenerateNotifySaveFile(filename string) string
func (*JKProtocol) GenerateRegister ¶
func (p *JKProtocol) GenerateRegister(id string) string
func (*JKProtocol) GenerateResponseFail ¶
func (p *JKProtocol) GenerateResponseFail() string
func (*JKProtocol) GenerateResponseOK ¶
func (p *JKProtocol) GenerateResponseOK() string
func (*JKProtocol) ID ¶
func (p *JKProtocol) ID() string
func (*JKProtocol) ParseFilename ¶
func (p *JKProtocol) ParseFilename() string
func (*JKProtocol) ParseFilenameData ¶
func (p *JKProtocol) ParseFilenameData() (string, string)
func (*JKProtocol) SubCommand ¶
func (p *JKProtocol) SubCommand() int
type JKProtocolHead ¶
type JKProtocolHead struct {
// contains filtered or unexported fields
}
type JKProtocolWrap ¶
func NewJKProtocolWrap ¶
func NewJKProtocolWrap(ptype int) (*JKProtocolWrap, error)
func (*JKProtocolWrap) Keepalive ¶
func (wrap *JKProtocolWrap) Keepalive(data string) (string, error)
func (*JKProtocolWrap) KeepaliveResponse ¶
func (wrap *JKProtocolWrap) KeepaliveResponse(data string) (string, error)
func (*JKProtocolWrap) LeaveResponse ¶
func (wrap *JKProtocolWrap) LeaveResponse(data string) (string, error)
func (*JKProtocolWrap) Parse ¶
func (wrap *JKProtocolWrap) Parse(data string) (string, error)
Set cmd type for which command Give common response of the sender
func (*JKProtocolWrap) RegisterResponse ¶
func (wrap *JKProtocolWrap) RegisterResponse(data string) (string, error)
type JK_P_DataWithHeader ¶
type JK_P_DataWithHeader struct {
// contains filtered or unexported fields
}
func JKFromBytes ¶
func JKFromBytes(buf []byte) (*JK_P_DataWithHeader, error)
Parse buf out to DataWithHeader
func (*JK_P_DataWithHeader) Data ¶
func (header *JK_P_DataWithHeader) Data() []byte
Get data from dataWithHeader
func (*JK_P_DataWithHeader) FromBytes ¶
func (header *JK_P_DataWithHeader) FromBytes(buf []byte) error
func (*JK_P_DataWithHeader) Header ¶
func (header *JK_P_DataWithHeader) Header() *JK_P_Header
Get header from dataWithHeader
func (*JK_P_DataWithHeader) SetData ¶
func (h *JK_P_DataWithHeader) SetData(data []byte)
Change the data
func (*JK_P_DataWithHeader) ToByte ¶
func (h *JK_P_DataWithHeader) ToByte() []byte
type JK_P_Header ¶
type JK_P_Header struct {
// contains filtered or unexported fields
}
func JKGenearteHeaderSimpleNotify ¶
func JKGenearteHeaderSimpleNotify(seq, mCmd, sCmd int) *JK_P_Header
func JKGenerateHeaderSimple ¶
func JKGenerateHeaderSimple(seq, mCmd, sCmd int) *JK_P_Header
default version to use
func JKGenerateHeaderSimpleResponse ¶
func JKGenerateHeaderSimpleResponse(seq, mCmd, sCmd int) *JK_P_Header
func JKGenerateProtocolHeader ¶
func JKGenerateProtocolHeader(cmdType, cont, seq int, mCmd, sCmd int, length int) *JK_P_Header
GenerateProtocolHeader with args
func (*JK_P_Header) GetContinued ¶
func (h *JK_P_Header) GetContinued() int
func (*JK_P_Header) GetLength ¶
func (h *JK_P_Header) GetLength() int
func (*JK_P_Header) GetMainCommand ¶
func (h *JK_P_Header) GetMainCommand() int
func (*JK_P_Header) GetSequence ¶
func (h *JK_P_Header) GetSequence() int
func (*JK_P_Header) GetSlaveCommand ¶
func (h *JK_P_Header) GetSlaveCommand() int
func (*JK_P_Header) GetType ¶
func (h *JK_P_Header) GetType() int
func (*JK_P_Header) GetVersions ¶
func (h *JK_P_Header) GetVersions() string
func (*JK_P_Header) SetContinued ¶
func (h *JK_P_Header) SetContinued(c int) error
func (*JK_P_Header) SetData ¶
func (h *JK_P_Header) SetData(data []byte) *JK_P_DataWithHeader
Return a new pointer to the header with data and header
func (*JK_P_Header) SetLength ¶
func (h *JK_P_Header) SetLength(length int) error
func (*JK_P_Header) SetMainCommand ¶
func (h *JK_P_Header) SetMainCommand(mc int) error
func (*JK_P_Header) SetSequence ¶
func (h *JK_P_Header) SetSequence(seq int) error
func (*JK_P_Header) SetSlaveCommand ¶
func (h *JK_P_Header) SetSlaveCommand(sc int) error
func (*JK_P_Header) SetType ¶
func (h *JK_P_Header) SetType(t int) error
func (*JK_P_Header) SetVersions ¶
func (h *JK_P_Header) SetVersions(m, s, l int) error
func (*JK_P_Header) ToBytes ¶
func (h *JK_P_Header) ToBytes() []byte
Convert between header struct and []bytes
type KFProtocol ¶
type KFProtocol struct { Header KFProtocolHeader Body KFProtocolBody }
func KFProtocolParse ¶
func KFProtocolParse(data []byte) (*KFProtocol, error)
func KFProtocolParseText ¶
func KFProtocolParseText(data []byte) (*KFProtocol, error)
func NewKFProtocol ¶
func NewKFProtocol() *KFProtocol
func (*KFProtocol) GenerateData ¶
func (p *KFProtocol) GenerateData(dir bool) ([]byte, error)
func (*KFProtocol) GenerateDataText ¶
func (p *KFProtocol) GenerateDataText(dir bool) ([]byte, error)
func (*KFProtocol) Init ¶
func (p *KFProtocol) Init()
func (*KFProtocol) SetCmd ¶
func (p *KFProtocol) SetCmd(cmd, subcmd uint, id []byte)
func (*KFProtocol) SetData ¶
func (p *KFProtocol) SetData(data []byte)
func (*KFProtocol) SetResponseCode ¶
func (p *KFProtocol) SetResponseCode(result bool, code int) error
type KFProtocolBody ¶
type KFProtocolBody struct {
Data []byte
}
type KFProtocolHeader ¶
type V5Base ¶
type V5Base struct { PreHeader V5PreHeader `json:preheader` Header V5Header Body V5Body }