github.com/lirm/aeron-go@v0.0.0-20230415210743-920325491dc4/aeron/logbuffer/FrameDescriptor.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 logbuffer 18 19 import ( 20 "github.com/lirm/aeron-go/aeron/atomic" 21 ) 22 23 const ( 24 // FrameAlignment frame alignment 25 FrameAlignment int32 = 32 26 ) 27 28 func flagsOffset(frameOffset int32) int32 { 29 return frameOffset + DataFrameHeader.FlagsFieldOffset 30 } 31 32 func lengthOffset(frameOffset int32) int32 { 33 return frameOffset + DataFrameHeader.FrameLengthFieldOffset 34 } 35 36 func termIdOffset(frameOffset int32) int32 { 37 return frameOffset + DataFrameHeader.TermIDFieldOffset 38 } 39 40 func sessionIdOffset(frameOffset int32) int32 { 41 return frameOffset + DataFrameHeader.SessionIDFieldOffset 42 } 43 44 func streamIdOffset(frameOffset int32) int32 { 45 return frameOffset + DataFrameHeader.StreamIDFieldOffset 46 } 47 48 func ComputeMaxMessageLength(capacity int32) int32 { 49 return capacity / 8 50 } 51 52 func typeOffset(frameOffset int32) int32 { 53 return frameOffset + DataFrameHeader.TypeFieldOffset 54 } 55 56 func reservedValueOffset(frameOffset int32) int32 { 57 return frameOffset + DataFrameHeader.ReservedValueFieldOffset 58 } 59 60 func GetFlags(logBuffer *atomic.Buffer, frameOffset int32) uint8 { 61 offset := flagsOffset(frameOffset) 62 return logBuffer.GetUInt8(offset) 63 } 64 65 func GetTermId(logBuffer *atomic.Buffer, frameOffset int32) int32 { 66 offset := termIdOffset(frameOffset) 67 return logBuffer.GetInt32Volatile(offset) 68 } 69 70 func GetSessionId(logBuffer *atomic.Buffer, frameOffset int32) int32 { 71 offset := sessionIdOffset(frameOffset) 72 return logBuffer.GetInt32Volatile(offset) 73 } 74 75 func GetStreamId(logBuffer *atomic.Buffer, frameOffset int32) int32 { 76 offset := streamIdOffset(frameOffset) 77 return logBuffer.GetInt32Volatile(offset) 78 } 79 80 func GetFrameLength(logBuffer *atomic.Buffer, frameOffset int32) int32 { 81 offset := lengthOffset(frameOffset) 82 return logBuffer.GetInt32Volatile(offset) 83 } 84 85 func GetReservedValue(logBuffer *atomic.Buffer, frameOffset int32) int64 { 86 offset := reservedValueOffset(frameOffset) 87 return logBuffer.GetInt64Volatile(offset) 88 } 89 90 func SetFrameLength(logBuffer *atomic.Buffer, frameOffset int32, frameLength int32) { 91 logBuffer.PutInt32Ordered(lengthOffset(frameOffset), frameLength) 92 } 93 94 func IsPaddingFrame(logBuffer *atomic.Buffer, frameOffset int32) bool { 95 return logBuffer.GetUInt16(typeOffset(frameOffset)) == DataFrameHeader.TypePad 96 } 97 98 func SetFrameType(logBuffer *atomic.Buffer, frameOffset int32, typ uint16) { 99 logBuffer.PutUInt16(typeOffset(frameOffset), typ) 100 } 101 102 func FrameFlags(logBuffer *atomic.Buffer, frameOffset int32, flags uint8) { 103 logBuffer.PutUInt8(flagsOffset(frameOffset), flags) 104 }