1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5
6
7#ifndef __DECODEMD_H__
8#define __DECODEMD_H__
9
10// --------------------------------------------------------
11// This is used to decode a bitstream encoding
12
13class Decoder
14{
15public:
16 Decoder();
17 Decoder(PTR_BYTE bytes);
18 void Init(PTR_BYTE bytes);
19 unsigned Next();
20 signed NextSigned();
21 PTR_BYTE End();
22
23 // --------------------------------------------------------
24 // This structures contains the state of the FSM
25
26 struct Decode
27 {
28 const BYTE* decoded; //the already decoded values
29 unsigned next; //what to do when no more decoded values
30 };
31
32private:
33 // --------------------------------------------------------
34 // This is used to access nibbles from a byte stream.
35
36 class Nibbles
37 {
38 friend class Decoder;
39 public:
40 void SetContents(PTR_BYTE bytes);
41 BYTE Next();
42 BYTE Read();
43 unsigned Bits(unsigned number);
44 private:
45 PTR_BYTE data;
46 BYTE nibbles[2];
47 unsigned next;
48 };
49
50 Decode state;
51 Nibbles data;
52};
53
54// --------------------------------------------------------
55// This is used to encode a bitstream encoding
56class Encoder
57{
58public:
59 Encoder(BYTE *buffer);
60 void ContainsNegatives(BOOL b);
61 void EncodeSigned(signed value);
62 void Encode(unsigned value);
63 void Encode(signed value, BOOL isSigned);
64 void Add(unsigned value, unsigned length);
65 void Add64(unsigned __int64 value, unsigned length);
66 void Done();
67 unsigned Contents(BYTE** contents);
68 unsigned Length();
69private:
70 BYTE* buffer;
71 BYTE encoding;
72 unsigned unusedBits;
73 BOOL done;
74 BOOL signedNumbers;
75 unsigned index;
76};
77#endif // __DECODEMD_H__
78