Fix transaction ID size
This commit is contained in:
		
							parent
							
								
									dc560075d7
								
							
						
					
					
						commit
						c748ca2223
					
				| @ -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 | ||||
|  | ||||
							
								
								
									
										18
									
								
								metadapta.go
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								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 | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user