libnjb: /usr/obj/ports/libnjb-2.2.7/libnjb-2.2.7/src/byteorder.c File Reference

libnjb 2.2.7

- Main Page
- Modules
- Data Structures
- Files
- Examples

- File List
- Globals

Functions
byteorder.c File Reference
`#include "libnjb.h"`
`#include "byteorder.h"`

## Functions
u_int64_t | njb1_bytes_to_64bit (unsigned char *dp)
void | from_64bit_to_njb1_bytes (u_int64_t val, unsigned char *dp)
u_int32_t | njb1_bytes_to_32bit (unsigned char *dp)
u_int32_t | njb3_bytes_to_32bit (unsigned char *dp)
void | from_32bit_to_njb1_bytes (u_int32_t val, unsigned char *dp)
void | from_32bit_to_njb3_bytes (u_int32_t val, unsigned char *dp)
u_int16_t | njb1_bytes_to_16bit (unsigned char *dp)
u_int16_t | njb3_bytes_to_16bit (unsigned char *dp)
void | from_16bit_to_njb1_bytes (u_int16_t val, unsigned char *dp)
void | from_16bit_to_njb3_bytes (u_int16_t val, unsigned char *dp)
u_int16_t | get_msw (u_int32_t word)
u_int16_t | get_lsw (u_int32_t word)
u_int64_t | make64 (u_int32_t msdw, u_int32_t lsdw)
void | split64 (u_int64_t num, u_int32_t *msdw, u_int32_t *lsdw)

## Detailed Description

We want libnjb to be "endianness agnostic" i.e. the byte-ordering of the libnjb host platform shall not affect its functionality. These routines are written using shifting and byte operations that will produce the same result regardless of whether the host platform is little-endian, big-endian or even mixed-endian.

NJB1 and the "series 3 family" (NJB2, NJB3, NJB Zen, NJB Zen 2.0) have different byte ordering. NJB1 is essentially big-endian, and the series 3 family little-endian. The terminology could be confusing, so we refer to the different endiannesses as "njb1-endian" and "njb3-endian".

## Function Documentation

void from_16bit_to_njb1_bytes | ( | u_int16_t | val,
|  | unsigned char * | dp
| ) |  |

This function will write the `u_int16_t` of the host platform, `val` as 2 NJB1-endian bytes beginning at the first byte in the byte array pointed to by `*dp`.

Parameters

  val | the unsigned 16 bit integer to convert to bytes
  dp | a pointer to the byte array (of atleast 2 bytes) that shall hold the resulting bytes

Referenced by datafile_pack(), songid_pack(), and time_pack().

void from_16bit_to_njb3_bytes | ( | u_int16_t | val,
|  | unsigned char * | dp
| ) |  |

This function will write the `u_int16_t` of the host platform, `val` as 2 series 3-endian bytes beginning at the first byte in the byte array pointed to by `*dp`.

Parameters

  val | the unsigned 16 bit integer to convert to bytes
  dp | a pointer to the byte array (of atleast 2 bytes) that shall hold the resulting bytes

Referenced by datafile_pack3(), new_folder_pack3(), njb3_add_multiple_tracks_to_playlist(), njb3_control_eax_processor(), njb3_create_playlist(), njb3_set_bitmap(), njb3_update_16bit_frame(), njb3_update_string_frame(), and songid_pack3().

void from_32bit_to_njb1_bytes | ( | u_int32_t | val,
|  | unsigned char * | dp
| ) |  |

This function will write the `u_int32_t` of the host platform, `val` as 4 NJB1-endian bytes beginning at the first byte in the byte array pointed to by `*dp`.

Parameters

  val | the unsigned 32 bit integer to convert to bytes
  dp | a pointer to the byte array (of atleast 4 bytes) that shall hold the resulting bytes

Referenced by njb_read_eaxtypes(), njb_receive_file_block(), and songid_pack().

void from_32bit_to_njb3_bytes | ( | u_int32_t | val,
|  | unsigned char * | dp
| ) |  |

This function will write the `u_int32_t` of the host platform, `val` as 4 series 3-endian bytes beginning at the first byte in the byte array pointed to by `*dp`.

Parameters

  val | the unsigned 32 bit integer to convert to bytes
  dp | a pointer to the byte array (of atleast 4 bytes) that shall hold the resulting bytes

Referenced by datafile_pack3(), new_folder_pack3(), njb3_add_multiple_tracks_to_playlist(), njb3_announce_firmware(), njb3_request_file_chunk(), njb3_set_bitmap(), njb3_update_16bit_frame(), njb3_update_string_frame(), njb3_update_tag(), and songid_pack3().

void from_64bit_to_njb1_bytes | ( | u_int64_t | val,
|  | unsigned char * | dp
| ) |  |

This function will write the `u_int64_t` of the host platform, `val` as NJB1-endian bytes beginning at the first byte in the byte array pointed to by `*dp`.

Parameters

  val | the unsigned 64 bit integer to convert to bytes
  dp | a pointer to the byte array (of atleast 8 bytes) that shall hold the resulting bytes

Referenced by datafile_pack(), and njb_set_library_counter().

u_int16_t get_lsw | ( | u_int32_t | word | ) |

This simply extract the least significant 16 bit parts of a 32 bit word.

Parameters

  word | the 32 bit word to get the least significant 16 bits for

Returns
  the least significant 16 bits as a 16 bit unsigned integer

u_int16_t get_msw | ( | u_int32_t | word | ) |

This simply extract the most significant 16 bit parts of a 32 bit word.

Parameters

  word | the 32 bit word to get the most significant 16 bits for

Returns
  the most significant 16 bits as a 16 bit unsigned integer

u_int64_t make64 | ( | u_int32_t | msdw,
|  | u_int32_t | lsdw
| ) |  |

Create a 64 bit unsigned integer from two 32 bit integers representing the most/least significant part of it.

Parameters

  msdw | the most significant 32 bits
  lsdw | the least significant 32 bits

Returns
  a 64 bit unsigned integer made by joining the two parts

u_int16_t njb1_bytes_to_16bit | ( | unsigned char * | dp | ) |

This function will take 2 bytes from the NJB1-endian byte array pointed to by `*dp` and transform it to `a u_int16_t` unsigned 16 bit integer on the host platform.

Parameters

  dp | a pointer to the 2 raw bytes in NJB1 endianness to convert

Returns
  an unsigned 16 bit integer

Referenced by datafile_unpack(), eax_unpack(), playlist_unpack(), songid_unpack(), and time_unpack().

u_int32_t njb1_bytes_to_32bit | ( | unsigned char * | dp | ) |

This function will take 4 bytes from the NJB1-endian byte array pointed to by `*dp` and transform it to a `u_int32_t` on the host platform.

Parameters

  dp | a pointer to the 4 raw bytes in NJB1 endianness to convert

Returns
  an unsigned 32 bit integer

Referenced by njb_get_datafile_header(), njb_get_playlist_header(), njb_get_track_tag_header(), njb_read_eaxtypes(), playlist_unpack(), and songid_unpack().

u_int64_t njb1_bytes_to_64bit | ( | unsigned char * | dp | ) |

This function will take 8 bytes from the njb1-endian byte array pointed to by `*dp` and transform it to a `u_int64_t` on the host platform.

Parameters

  dp | a pointer to the 8 raw bytes in NJB1 endianness to convert

Returns
  an unsigned 64 bit integer

Referenced by datafile_unpack(), njb_get_disk_usage(), and njb_get_library_counter().

u_int16_t njb3_bytes_to_16bit | ( | unsigned char * | dp | ) |

This function will take 2 bytes from the series 3-endian byte array pointed to by `*dp` and transform it to `a u_int16_t` unsigned 16 bit integer on the host platform.

Parameters

  dp | a pointer to the 2 raw bytes in series 3 endianness to convert

Returns
  an unsigned 16 bit integer

Referenced by njb3_add_multiple_tracks_to_playlist(), njb3_create_playlist(), njb3_get_codecs(), njb3_power_status(), and njb3_request_file_chunk().

u_int32_t njb3_bytes_to_32bit | ( | unsigned char * | dp | ) |

This function will take 4 bytes from the series 3-endian byte array pointed to by `*dp` and transform it to a `u_int32_t` on the host platform.

Parameters

  dp | a pointer to the 4 raw bytes in series 3 endianness to convert

Returns
  an unsigned 32 bit integer

Referenced by njb3_add_multiple_tracks_to_playlist(), njb3_create_playlist(), and njb3_request_file_chunk().

void split64 | ( | u_int64_t | num,
|  | u_int32_t * | msdw,
|  | u_int32_t * | lsdw
| ) |  |

Split a 64 bit unsigned integer into two unsigned 32 bit integer representing the most/least significant 32 bits of the incoming 64 bit integer.

Parameters

  num | the 64 bit integer to split
  msdw | a pointer to the 32 bit integer that shall hold the most significant 32 bits of the 64 bit integer
  lsdw | a pointer to the 32 bit integer that shall hold the least significant 32 bits of the 64 bit integer