FreeRDP
TestBitStream.c
1 
2 #include <winpr/crt.h>
3 #include <winpr/print.h>
4 #include <winpr/stream.h>
5 #include <winpr/bitstream.h>
6 
7 static void BitStrGen(void)
8 {
9  char str[64] = { 0 };
10 
11  for (DWORD i = 0; i < 256;)
12  {
13  printf("\t");
14 
15  for (DWORD j = 0; j < 4; j++)
16  {
17  if (0)
18  {
19  /* Least Significant Bit First */
20  str[0] = (i & (1 << 7)) ? '1' : '0';
21  str[1] = (i & (1 << 6)) ? '1' : '0';
22  str[2] = (i & (1 << 5)) ? '1' : '0';
23  str[3] = (i & (1 << 4)) ? '1' : '0';
24  str[4] = (i & (1 << 3)) ? '1' : '0';
25  str[5] = (i & (1 << 2)) ? '1' : '0';
26  str[6] = (i & (1 << 1)) ? '1' : '0';
27  str[7] = (i & (1 << 0)) ? '1' : '0';
28  str[8] = '\0';
29  }
30  else
31  {
32  /* Most Significant Bit First */
33  str[7] = (i & (1 << 7)) ? '1' : '0';
34  str[6] = (i & (1 << 6)) ? '1' : '0';
35  str[5] = (i & (1 << 5)) ? '1' : '0';
36  str[4] = (i & (1 << 4)) ? '1' : '0';
37  str[3] = (i & (1 << 3)) ? '1' : '0';
38  str[2] = (i & (1 << 2)) ? '1' : '0';
39  str[1] = (i & (1 << 1)) ? '1' : '0';
40  str[0] = (i & (1 << 0)) ? '1' : '0';
41  str[8] = '\0';
42  }
43 
44  printf("\"%s\",%s", str, j == 3 ? "" : " ");
45  i++;
46  }
47 
48  printf("\n");
49  }
50 }
51 
52 int TestBitStream(int argc, char* argv[])
53 {
54  wBitStream* bs = NULL;
55  BYTE buffer[1024] = { 0 };
56 
57  WINPR_UNUSED(argc);
58  WINPR_UNUSED(argv);
59 
60  bs = BitStream_New();
61  if (!bs)
62  return 1;
63  BitStream_Attach(bs, buffer, sizeof(buffer));
64  BitStream_Write_Bits(bs, 0xAF, 8); /* 11110101 */
65  BitStream_Write_Bits(bs, 0xF, 4); /* 1111 */
66  BitStream_Write_Bits(bs, 0xA, 4); /* 0101 */
67  BitStream_Flush(bs);
68  BitDump(__func__, WLOG_INFO, buffer, bs->position, BITDUMP_MSB_FIRST);
69  BitStream_Write_Bits(bs, 3, 2); /* 11 */
70  BitStream_Write_Bits(bs, 0, 3); /* 000 */
71  BitStream_Write_Bits(bs, 0x2D, 6); /* 101101 */
72  BitStream_Write_Bits(bs, 0x19, 5); /* 11001 */
73  // BitStream_Flush(bs); /* flush should be done automatically here (32 bits written) */
74  BitDump(__func__, WLOG_INFO, buffer, bs->position, BITDUMP_MSB_FIRST);
75  BitStream_Write_Bits(bs, 3, 2); /* 11 */
76  BitStream_Flush(bs);
77  BitDump(__func__, WLOG_INFO, buffer, bs->position, BITDUMP_MSB_FIRST);
78  BitStream_Write_Bits(bs, 00, 2); /* 00 */
79  BitStream_Write_Bits(bs, 0xF, 4); /* 1111 */
80  BitStream_Write_Bits(bs, 0, 20);
81  BitStream_Write_Bits(bs, 0xAFF, 12); /* 111111110101 */
82  BitStream_Flush(bs);
83  BitDump(__func__, WLOG_INFO, buffer, bs->position, BITDUMP_MSB_FIRST);
84  BitStream_Free(bs);
85  return 0;
86 }