github.com/pion/dtls/v2@v2.2.12/internal/util/util.go (about) 1 // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> 2 // SPDX-License-Identifier: MIT 3 4 // Package util contains small helpers used across the repo 5 package util 6 7 import ( 8 "encoding/binary" 9 ) 10 11 // BigEndianUint24 returns the value of a big endian uint24 12 func BigEndianUint24(raw []byte) uint32 { 13 if len(raw) < 3 { 14 return 0 15 } 16 17 rawCopy := make([]byte, 4) 18 copy(rawCopy[1:], raw) 19 return binary.BigEndian.Uint32(rawCopy) 20 } 21 22 // PutBigEndianUint24 encodes a uint24 and places into out 23 func PutBigEndianUint24(out []byte, in uint32) { 24 tmp := make([]byte, 4) 25 binary.BigEndian.PutUint32(tmp, in) 26 copy(out, tmp[1:]) 27 } 28 29 // PutBigEndianUint48 encodes a uint64 and places into out 30 func PutBigEndianUint48(out []byte, in uint64) { 31 tmp := make([]byte, 8) 32 binary.BigEndian.PutUint64(tmp, in) 33 copy(out, tmp[2:]) 34 } 35 36 // Max returns the larger value 37 func Max(a, b int) int { 38 if a > b { 39 return a 40 } 41 return b 42 }