Developing lightweight computation at the DSG edge

Commit f20c5a3c authored by Mathias Weber's avatar Mathias Weber
Browse files

de- and encoding for remaining messages

parent a49f0a4e
......@@ -34,20 +34,72 @@ func readMsgRaw(reader io.Reader) (data []byte, err error) {
return
}
func (op *ApbReadObjects) encode(writer io.Writer) (err error) {
return encodeMsg(op, 116, writer)
}
func (op *ApbUpdateObjects) encode(writer io.Writer) (err error) {
return encodeMsg(op, 118, writer)
}
func (op *ApbStartTransaction) encode(writer io.Writer) (err error) {
msg, err := proto.Marshal(op)
return encodeMsg(op, 119, writer)
}
func (op *ApbAbortTransaction) encode(writer io.Writer) (err error) {
return encodeMsg(op, 120, writer)
}
func (op *ApbCommitTransaction) encode(writer io.Writer) (err error) {
return encodeMsg(op, 121, writer)
}
func (op *ApbStaticUpdateObjects) encode(writer io.Writer) (err error) {
return encodeMsg(op, 122, writer)
}
func (op *ApbStaticReadObjects) encode(writer io.Writer) (err error) {
return encodeMsg(op, 123, writer)
}
func encodeMsg(message proto.Message, msgCode byte, writer io.Writer) (err error) {
msg, err := proto.Marshal(message)
if err != nil {
return
}
msgsize := len(msg)
buf := make([]byte, 5)
binary.BigEndian.PutUint32(buf[0:4], uint32(msgsize))
buf[5] = 119
buf[5] = msgCode
writer.Write(buf)
writer.Write(msg)
return nil
}
func decodeOperationResp(reader io.Reader) (op *ApbOperationResp, err error) {
data, err := readMsgRaw(reader)
if err != nil {
return
}
switch data[0] {
case 0:
// error
err = decodeError(data[1:])
return
case 111:
// transaction response
resp := &ApbOperationResp{}
err = proto.Unmarshal(data[1:], resp)
if err != nil {
return
}
op = resp
return
}
err = fmt.Errorf("invalid message code: %d", data[0])
return
}
func decodeStartTransactionResp(reader io.Reader) (op *ApbStartTransactionResp, err error) {
data, err := readMsgRaw(reader)
if err != nil {
......@@ -72,6 +124,79 @@ func decodeStartTransactionResp(reader io.Reader) (op *ApbStartTransactionResp,
return
}
func decodeReadObjectsResp(reader io.Reader) (op *ApbReadObjectsResp, err error) {
data, err := readMsgRaw(reader)
if err != nil {
return
}
switch data[0] {
case 0:
// error
err = decodeError(data[1:])
return
case 126:
// transaction response
resp := &ApbReadObjectsResp{}
err = proto.Unmarshal(data[1:], resp)
if err != nil {
return
}
op = resp
return
}
err = fmt.Errorf("invalid message code: %d", data[0])
return
}
func decodeCommitResp(reader io.Reader) (op *ApbCommitResp, err error) {
data, err := readMsgRaw(reader)
if err != nil {
return
}
switch data[0] {
case 0:
// error
err = decodeError(data[1:])
return
case 127:
// transaction response
resp := &ApbCommitResp{}
err = proto.Unmarshal(data[1:], resp)
if err != nil {
return
}
op = resp
return
}
err = fmt.Errorf("invalid message code: %d", data[0])
return
}
func decodeStaticReadObjectsResp(reader io.Reader) (op *ApbStaticReadObjectsResp, err error) {
data, err := readMsgRaw(reader)
if err != nil {
return
}
switch data[0] {
case 0:
// error
err = decodeError(data[1:])
return
case 128:
// transaction response
resp := &ApbStaticReadObjectsResp{}
err = proto.Unmarshal(data[1:], resp)
if err != nil {
return
}
op = resp
return
}
err = fmt.Errorf("invalid message code: %d", data[0])
return
}
func decodeError(data []byte) (err error) {
resp := &ApbErrorResp{}
err = proto.Unmarshal(data, resp)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment