github.com/lirm/aeron-go@v0.0.0-20230415210743-920325491dc4/aeron/util/version.go (about)

     1  /*
     2  Copyright 2016 Stanislav Liberman
     3  Copyright 2020 Evan Wies
     4  
     5  Licensed under the Apache License, Version 2.0 (the "License");
     6  you may not use this file except in compliance with the License.
     7  You may obtain a copy of the License at
     8  
     9  http://www.apache.org/licenses/LICENSE-2.0
    10  
    11  Unless required by applicable law or agreed to in writing, software
    12  distributed under the License is distributed on an "AS IS" BASIS,
    13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  See the License for the specific language governing permissions and
    15  limitations under the License.
    16  */
    17  
    18  package util
    19  
    20  import "fmt"
    21  
    22  func SemanticVersionCompose(major uint8, minor uint8, patch uint8) uint32 {
    23  	return (uint32(major) << 16) | (uint32(minor) << 8) | uint32(patch)
    24  }
    25  
    26  func SemanticVersionMajor(version uint32) uint8 {
    27  	return uint8((version >> 16) & 0xFF)
    28  }
    29  
    30  func SemanticVersionMinor(version uint32) uint8 {
    31  	return uint8((version >> 8) & 0xFF)
    32  }
    33  
    34  func SemanticVersionPatch(version uint32) uint8 {
    35  	return uint8(version & 0xFF)
    36  }
    37  
    38  func SemanticVersionToString(version uint32) string {
    39  	return fmt.Sprintf("%d.%d.%d",
    40  		SemanticVersionMajor(version),
    41  		SemanticVersionMinor(version),
    42  		SemanticVersionPatch(version))
    43  }