diff options
author | dotnet-bot <dotnet-bot@microsoft.com> | 2015-01-30 14:14:42 -0800 |
---|---|---|
committer | dotnet-bot <dotnet-bot@microsoft.com> | 2015-01-30 14:14:42 -0800 |
commit | ef1e2ab328087c61a6878c1e84f4fc5d710aebce (patch) | |
tree | dee1bbb89e9d722e16b0d1485e3cdd1b6c8e2cfa /src/vm/decodemd.h | |
download | coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.gz coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.bz2 coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.zip |
Initial commit to populate CoreCLR repo
[tfs-changeset: 1407945]
Diffstat (limited to 'src/vm/decodemd.h')
-rw-r--r-- | src/vm/decodemd.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/vm/decodemd.h b/src/vm/decodemd.h new file mode 100644 index 0000000000..c76bdddb53 --- /dev/null +++ b/src/vm/decodemd.h @@ -0,0 +1,80 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license 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 +#ifndef BINDER +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 // !BINDER +#endif // __DECODEMD_H__ |