File: igtl_string.c

package info (click to toggle)
openigtlink 3.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,080 kB
  • sloc: cpp: 20,076; ansic: 6,704; sh: 227; perl: 74; makefile: 46
file content (58 lines) | stat: -rw-r--r-- 1,519 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*=========================================================================

  Program:   The OpenIGTLink Library
  Language:  C
  Web page:  http://openigtlink.org/

  Copyright (c) Insight Software Consortium. All rights reserved.

  This software is distributed WITHOUT ANY WARRANTY; without even
  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#include <string.h>
#include <math.h>

#include "igtl_string.h"
#include "igtl_util.h"

igtl_uint32 igtl_export igtl_string_get_string_length(igtl_string_header * header)
{
 
  igtl_uint32 length;
  length = (igtl_uint32)(header->length);
  
  return length;
}


void igtl_export igtl_string_convert_byte_order(igtl_string_header* header)
{

  if (igtl_is_little_endian()) 
    {
    header->encoding = BYTE_SWAP_INT16(header->encoding);
    header->length   = BYTE_SWAP_INT16(header->length);
    }
}


igtl_uint64 igtl_export igtl_string_get_crc(igtl_string_header * header, void* string)
{
  igtl_uint64   crc;
  igtl_uint64   string_length;

  /* convert byte order to get string length */
  igtl_string_convert_byte_order(header);
  string_length = (igtl_uint32)(header->length);
  igtl_string_convert_byte_order(header);

  crc = crc64(0, 0, 0);
  crc = crc64((unsigned char*) header, IGTL_STRING_HEADER_SIZE, crc);
  crc = crc64((unsigned char*) string, (int)string_length, crc);

  return crc;
}