Documentation
¶
Index ¶
- Constants
- func Preallocate()
- func ReceiveBinaryFrame(relay io.Reader, fr *Frame) error
- func ReceiveFrame(relay io.Reader, fr *Frame) error
- type Frame
- func (*Frame) AppendOptions(header *[]byte, options []byte)
- func (f *Frame) Bytes() []byte
- func (f *Frame) Header() []byte
- func (f *Frame) HeaderPtr() *[]byte
- func (*Frame) IsStop(header []byte) bool
- func (*Frame) IsStream(header []byte) bool
- func (f *Frame) Payload() []byte
- func (f *Frame) ReadFlags() byte
- func (*Frame) ReadHL(header []byte) byte
- func (f *Frame) ReadOptions(header []byte) []uint32
- func (*Frame) ReadPayloadLen(header []byte) uint32
- func (*Frame) ReadVersion(header []byte) byte
- func (f *Frame) Reset()
- func (*Frame) SetStopBit(header []byte)
- func (*Frame) SetStreamFlag(header []byte)
- func (*Frame) VerifyCRC(header []byte) bool
- func (*Frame) WriteCRC(header []byte)
- func (*Frame) WriteFlags(header []byte, flags ...byte)
- func (f *Frame) WriteOptions(header *[]byte, options ...uint32)
- func (f *Frame) WritePayload(data []byte)
- func (*Frame) WritePayloadLen(header []byte, payloadLen uint32)
- func (*Frame) WriteVersion(header []byte, version byte)
- type Pipe
- type Transfer
- type TransferImp
Constants ¶
const ( OneMB uint32 = 1024 * 1024 * 1 FiveMB uint32 = 1024 * 1024 * 5 TenMB uint32 = 1024 * 1024 * 10 )
const ( CONTROL byte = 0x01 CodecRaw byte = 0x04 CodecJSON byte = 0x08 CodecMsgpack byte = 0x10 CodecGob byte = 0x20 ERROR byte = 0x40 CodecProto byte = 0x80 CodeBinary byte = 0x02 // Version1 byte Version1 byte = 0x01 // STREAM bit STREAM byte = 0x01 // STOP command STOP byte = 0x02 )
BYTE flags, it means, that we can set multiply flags from this group using bitwise OR For example CONTEXT_SEPARATOR | CodecRaw
const OptionsMaxSize = 40
OptionsMaxSize represents header's options maximum size
const WORD = 4
WORD represents 32bit word
Variables ¶
This section is empty.
Functions ¶
func Preallocate ¶
func Preallocate()
Types ¶
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame defines new user level package format.
func NewFrame ¶
func NewFrame() *Frame
NewFrame initializes new frame with 12-byte header and 100-byte reserved space for the payload
func ReadFrame ¶
ReadFrame produces Frame from the RAW bytes first 12 bytes will be a header the rest - payload
func (*Frame) AppendOptions ¶
AppendOptions appends options to the header
func (*Frame) ReadHL ¶
ReadHL The lower 4 bits of the 0th octet occupies our header len data. We should erase upper 4 bits, which contain information about Version To erase, we are applying bitwise AND to the upper 4 bits and returning result
func (*Frame) ReadOptions ¶
ReadOptions f.readHL() - 2 needed to know actual options size we know, that 2 WORDS is minimal header len extra WORDS will add extra 32bits to the options (4 bytes) cannot inline, cost 117 vs 80
func (*Frame) ReadPayloadLen ¶
ReadPayloadLen LE format used to write Payload Using 4 bytes (2,3,4,5 bytes in the header)
func (*Frame) ReadVersion ¶
ReadVersion ... To read version, we should return our 4 upper bits to their original place 1111_0000 -> 0000_1111 (15)
func (*Frame) SetStopBit ¶
func (*Frame) SetStreamFlag ¶
func (*Frame) VerifyCRC ¶
VerifyCRC ... Reading info from 6th byte and verifying it with calculated in-place. Should be equal. If not - drop the frame as incorrect.
func (*Frame) WriteCRC ¶
WriteCRC will calculate and write CRC32 4-bytes it to the 6th byte (7th reserved)
func (*Frame) WriteFlags ¶
func (*Frame) WriteOptions ¶
WriteOptions Options slice len should not be more than 10 (40 bytes) we need a pointer to the header because we are reallocating the slice
func (*Frame) WritePayloadLen ¶
WritePayloadLen LE format used to write Payload Using 4 bytes (2,3,4,5 bytes in the header)
func (*Frame) WriteVersion ¶
WriteVersion To write version, we should do the following: 1. For example, we have version 15 it's 0000_1111 (1 byte) 2. We should shift 4 lower bits to upper and write that to the 0th byte 3. The 0th byte should become 1111_0000, but it's not 240, it's only 15, because version only 4 bits len
type Pipe ¶
type Pipe struct {
// contains filtered or unexported fields
}
Pipe ... PipeRelay communicate with underlying process using standard streams (STDIN, STDOUT). Attention, use TCP alternative for Windows as more reliable option. This Pipe closes automatically with the process.
func NewPipeRelay ¶
func NewPipeRelay(in io.ReadCloser, out io.WriteCloser) *Pipe
NewPipeRelay creates new pipe based data Pipe.
type Transfer ¶
type Transfer interface { // Send signed (prefixed) data to PHP process. Send(frame *Frame) error // Receive data from the underlying process and returns associated prefix or error. Receive(frame *Frame) error // Close the connection. Close() error }
Relay provide IPC over signed payloads.
type TransferImp ¶
type TransferImp struct {
// contains filtered or unexported fields
}
TransferImp communicates with underlying process using sockets (TPC or Unix).
func NewTransferImp ¶
func NewTransferImp(rwc io.ReadWriteCloser) *TransferImp
NewSocketRelay creates new socket based data relay.
func (*TransferImp) Receive ¶
func (rl *TransferImp) Receive(frame *Frame) error
Receive data from the underlying process and returns associated prefix or error.
func (*TransferImp) Send ¶
func (rl *TransferImp) Send(frame *Frame) error
Send signed (prefixed) data to PHP process.