diff options
author | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
---|---|---|
committer | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
commit | 15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (patch) | |
tree | 255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/ulikunitz/xz/lzma/directcodec.go | |
parent | 07971ca38143c5faf951d152fba370ddcbe26ad5 (diff) | |
download | terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.gz terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.zst terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.zip |
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
Updated via: go get github.com/hashicorp/terraform@sdk-v0.11-with-go-modules and go mod tidy
Diffstat (limited to 'vendor/github.com/ulikunitz/xz/lzma/directcodec.go')
-rw-r--r-- | vendor/github.com/ulikunitz/xz/lzma/directcodec.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/github.com/ulikunitz/xz/lzma/directcodec.go b/vendor/github.com/ulikunitz/xz/lzma/directcodec.go new file mode 100644 index 0000000..e08eb98 --- /dev/null +++ b/vendor/github.com/ulikunitz/xz/lzma/directcodec.go | |||
@@ -0,0 +1,49 @@ | |||
1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | package lzma | ||
6 | |||
7 | import "fmt" | ||
8 | |||
9 | // directCodec allows the encoding and decoding of values with a fixed number | ||
10 | // of bits. The number of bits must be in the range [1,32]. | ||
11 | type directCodec byte | ||
12 | |||
13 | // makeDirectCodec creates a directCodec. The function panics if the number of | ||
14 | // bits is not in the range [1,32]. | ||
15 | func makeDirectCodec(bits int) directCodec { | ||
16 | if !(1 <= bits && bits <= 32) { | ||
17 | panic(fmt.Errorf("bits=%d out of range", bits)) | ||
18 | } | ||
19 | return directCodec(bits) | ||
20 | } | ||
21 | |||
22 | // Bits returns the number of bits supported by this codec. | ||
23 | func (dc directCodec) Bits() int { | ||
24 | return int(dc) | ||
25 | } | ||
26 | |||
27 | // Encode uses the range encoder to encode a value with the fixed number of | ||
28 | // bits. The most-significant bit is encoded first. | ||
29 | func (dc directCodec) Encode(e *rangeEncoder, v uint32) error { | ||
30 | for i := int(dc) - 1; i >= 0; i-- { | ||
31 | if err := e.DirectEncodeBit(v >> uint(i)); err != nil { | ||
32 | return err | ||
33 | } | ||
34 | } | ||
35 | return nil | ||
36 | } | ||
37 | |||
38 | // Decode uses the range decoder to decode a value with the given number of | ||
39 | // given bits. The most-significant bit is decoded first. | ||
40 | func (dc directCodec) Decode(d *rangeDecoder) (v uint32, err error) { | ||
41 | for i := int(dc) - 1; i >= 0; i-- { | ||
42 | x, err := d.DirectDecodeBit() | ||
43 | if err != nil { | ||
44 | return 0, err | ||
45 | } | ||
46 | v = (v << 1) | x | ||
47 | } | ||
48 | return v, nil | ||
49 | } | ||