Break out encodeMessageA
This commit is contained in:
parent
68961f8ad8
commit
dc560075d7
23
metadapta.go
23
metadapta.go
@ -79,16 +79,7 @@ func (this *a) unlistTransactionSafe(id int64) {
|
|||||||
func (this *a) sendMessageSafe(trans int64, method uint16, data []byte) error {
|
func (this *a) sendMessageSafe(trans int64, method uint16, data []byte) error {
|
||||||
this.sendLock.Lock()
|
this.sendLock.Lock()
|
||||||
defer this.sendLock.Lock()
|
defer this.sendLock.Lock()
|
||||||
|
return encodeMessageA(this.underlying, trans, method, data)
|
||||||
buffer := make([]byte, 8 + len(data))
|
|
||||||
tape.EncodeI64(buffer[:4], trans)
|
|
||||||
tape.EncodeI16(buffer[4:6], method)
|
|
||||||
length, ok := tape.U16CastSafe(len(data))
|
|
||||||
if !ok { return ErrPayloadTooLarge }
|
|
||||||
tape.EncodeI16(data[6:8], length)
|
|
||||||
copy(buffer[8:], data)
|
|
||||||
_, err := this.underlying.Write(buffer)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *a) receive() {
|
func (this *a) receive() {
|
||||||
@ -198,6 +189,18 @@ func decodeMessageA(reader io.Reader) (int64, uint16, []byte, error) {
|
|||||||
return transID, method, payloadBuffer, nil
|
return transID, method, payloadBuffer, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func encodeMessageA(writer io.Writer, trans int64, method uint16, data []byte) error {
|
||||||
|
buffer := make([]byte, 8 + len(data))
|
||||||
|
tape.EncodeI64(buffer[:4], trans)
|
||||||
|
tape.EncodeI16(buffer[4:6], method)
|
||||||
|
length, ok := tape.U16CastSafe(len(data))
|
||||||
|
if !ok { return ErrPayloadTooLarge }
|
||||||
|
tape.EncodeI16(data[6:8], length)
|
||||||
|
copy(buffer[8:], data)
|
||||||
|
_, err := writer.Write(buffer)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func partyFromTransID(id int64) Party {
|
func partyFromTransID(id int64) Party {
|
||||||
return id > 0
|
return id > 0
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user