kinetic-c  v0.12.0
Seagate Kinetic Protocol Client Library for C
kinetic_nbo.c
Go to the documentation of this file.
1 /*
2 * kinetic-c
3 * Copyright (C) 2015 Seagate Technology.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20 
21 #include "kinetic_nbo.h"
22 
23 static uint64_t KineticNBO_SwapByteOrder(uint8_t* pByte, size_t len)
24 {
25  uint64_t swapped = 0u;
26  for (size_t i = 0; i < len; i++) {
27  swapped = (swapped << 8) | pByte[i];
28  }
29  return swapped;
30 }
31 
32 uint32_t KineticNBO_FromHostU32(uint32_t valueHost)
33 {
34  return (uint32_t)KineticNBO_SwapByteOrder(
35  (uint8_t*)&valueHost, sizeof(uint32_t));
36 }
37 
38 uint32_t KineticNBO_ToHostU32(uint32_t valueNBO)
39 {
40  return (uint32_t)KineticNBO_SwapByteOrder(
41  (uint8_t*)&valueNBO, sizeof(uint32_t));
42 }
43 
44 uint64_t KineticNBO_FromHostU64(uint64_t valueHost)
45 {
47  (uint8_t*)&valueHost, sizeof(uint64_t));
48 }
49 
50 uint64_t KineticNBO_ToHostU64(uint64_t valueNBO)
51 {
53  (uint8_t*)&valueNBO, sizeof(uint64_t));
54 }
uint64_t KineticNBO_FromHostU64(uint64_t valueHost)
Definition: kinetic_nbo.c:44
uint32_t KineticNBO_FromHostU32(uint32_t valueHost)
Definition: kinetic_nbo.c:32
uint64_t KineticNBO_ToHostU64(uint64_t valueNBO)
Definition: kinetic_nbo.c:50
static uint64_t KineticNBO_SwapByteOrder(uint8_t *pByte, size_t len)
Definition: kinetic_nbo.c:23
uint32_t KineticNBO_ToHostU32(uint32_t valueNBO)
Definition: kinetic_nbo.c:38