From c748ca22238c5cc45036c5d49dd59f7b9c977db0 Mon Sep 17 00:00:00 2001 From: "sashakoshka@tebibyte.media" Date: Sun, 19 Jan 2025 14:21:58 -0500 Subject: [PATCH] Fix transaction ID size --- design/protocol.md | 2 +- metadapta.go | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/design/protocol.md b/design/protocol.md index 3424a6a..d33113c 100644 --- a/design/protocol.md +++ b/design/protocol.md @@ -136,7 +136,7 @@ Internet. ### METADAPT-A METADAPT-A requires a transport which offers a single full-duplex data stream that persists for the duration of the connection. All transactions are -multiplexed onto this single stream. Each MMB contains a 8-octet long header, +multiplexed onto this single stream. Each MMB contains a 12-octet long header, with the transaction ID, then the method, and then the payload size (in octets). The transaction ID is encoded as an I64, and the method and payload size are both encoded as U16s. The remainder of the message is the payload. Since each diff --git a/metadapta.go b/metadapta.go index 467c7f5..885a23f 100644 --- a/metadapta.go +++ b/metadapta.go @@ -174,14 +174,14 @@ type incomingMessage struct { } func decodeMessageA(reader io.Reader) (int64, uint16, []byte, error) { - headerBuffer := [8]byte { } + headerBuffer := [12]byte { } _, err := io.ReadFull(reader, headerBuffer[:]) if err != nil { return 0, 0, nil, err } - transID, err := tape.DecodeI64[int64](headerBuffer[:4]) + transID, err := tape.DecodeI64[int64](headerBuffer[:8]) if err != nil { return 0, 0, nil, err } - method, err := tape.DecodeI16[uint16](headerBuffer[4:6]) + method, err := tape.DecodeI16[uint16](headerBuffer[8:10]) if err != nil { return 0, 0, nil, err } - length, err := tape.DecodeI16[uint16](headerBuffer[6:8]) + length, err := tape.DecodeI16[uint16](headerBuffer[10:12]) if err != nil { return 0, 0, nil, err } payloadBuffer := make([]byte, int(length)) _, err = io.ReadFull(reader, payloadBuffer) @@ -190,13 +190,13 @@ func decodeMessageA(reader io.Reader) (int64, uint16, []byte, error) { } 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) + buffer := make([]byte, 12 + len(data)) + tape.EncodeI64(buffer[:8], trans) + tape.EncodeI16(buffer[8:10], method) length, ok := tape.U16CastSafe(len(data)) if !ok { return ErrPayloadTooLarge } - tape.EncodeI16(data[6:8], length) - copy(buffer[8:], data) + tape.EncodeI16(data[10:12], length) + copy(buffer[12:], data) _, err := writer.Write(buffer) return err }