github.com/lirm/aeron-go@v0.0.0-20230415210743-920325491dc4/aeron/ringbuffer/recorddesc.go (about) 1 /* 2 Copyright 2016 Stanislav Liberman 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package rb 18 19 import ( 20 "fmt" 21 22 "github.com/lirm/aeron-go/aeron/util" 23 ) 24 25 var RecordDescriptor = struct { 26 HeaderLength int32 27 RecordAlignment int32 28 PaddingMsgTypeID int32 29 LengthOffset int32 30 TypeOffset int32 31 }{ 32 util.SizeOfInt32 * 2, 33 util.SizeOfInt32 * 2, 34 -1, 35 0, 36 4, 37 } 38 39 func LengthOffset(recordOffset int32) int32 { 40 return recordOffset 41 } 42 43 func TypeOffset(recordOffset int32) int32 { 44 return recordOffset + util.SizeOfInt32 45 } 46 47 func EncodedMsgOffset(recordOffset int32) int32 { 48 return recordOffset + RecordDescriptor.HeaderLength 49 } 50 51 func makeHeader(length, msgTypeID int32) int64 { 52 return ((int64(msgTypeID) & 0xFFFFFFFF) << 32) | (int64(length) & 0xFFFFFFFF) 53 } 54 55 func checkMsgTypeID(msgTypeID int32) { 56 if msgTypeID < 1 { 57 panic(fmt.Sprintf("Message type id must be greater than zero, msgTypeId=%d", msgTypeID)) 58 } 59 }