blob: e6c6145bc0e6870d3e7632bdff7cbf2dcb9de9b8 (
plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#ifndef __DECODEMD_H__
#define __DECODEMD_H__
// --------------------------------------------------------
// This is used to decode a bitstream encoding
class Decoder
{
public:
Decoder();
Decoder(PTR_BYTE bytes);
void Init(PTR_BYTE bytes);
unsigned Next();
signed NextSigned();
PTR_BYTE End();
// --------------------------------------------------------
// This structures contains the state of the FSM
struct Decode
{
const BYTE* decoded; //the already decoded values
unsigned next; //what to do when no more decoded values
};
private:
// --------------------------------------------------------
// This is used to access nibbles from a byte stream.
class Nibbles
{
friend class Decoder;
public:
void SetContents(PTR_BYTE bytes);
BYTE Next();
BYTE Read();
unsigned Bits(unsigned number);
private:
PTR_BYTE data;
BYTE nibbles[2];
unsigned next;
};
Decode state;
Nibbles data;
};
// --------------------------------------------------------
// This is used to encode a bitstream encoding
class Encoder
{
public:
Encoder(BYTE *buffer);
void ContainsNegatives(BOOL b);
void EncodeSigned(signed value);
void Encode(unsigned value);
void Encode(signed value, BOOL isSigned);
void Add(unsigned value, unsigned length);
void Add64(unsigned __int64 value, unsigned length);
void Done();
unsigned Contents(BYTE** contents);
unsigned Length();
private:
BYTE* buffer;
BYTE encoding;
unsigned unusedBits;
BOOL done;
BOOL signedNumbers;
unsigned index;
};
#endif // __DECODEMD_H__
|