1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
-
-
- #import "ZXAztecBinaryShiftToken.h"
- #import "ZXBitArray.h"
- #import "ZXByteArray.h"
-
- @interface ZXAztecBinaryShiftToken ()
-
- @property (nonatomic, assign, readonly) int16_t binaryShiftStart;
- @property (nonatomic, assign, readonly) int16_t binaryShiftByteCount;
-
- @end
-
- @implementation ZXAztecBinaryShiftToken
-
- - (id)initWithPrevious:(ZXAztecToken *)previous binaryShiftStart:(int)binaryShiftStart binaryShiftByteCount:(int)binaryShiftByteCount {
- if (self = [super initWithPrevious:previous]) {
- _binaryShiftStart = (int16_t) binaryShiftStart;
- _binaryShiftByteCount = (int16_t) binaryShiftByteCount;
- }
-
- return self;
- }
-
- - (void)appendTo:(ZXBitArray *)bitArray text:(ZXByteArray *)text {
- for (int i = 0; i < self.binaryShiftByteCount; i++) {
- if (i == 0 || (i == 31 && self.binaryShiftByteCount <= 62)) {
-
-
- [bitArray appendBits:31 numBits:5];
- if (self.binaryShiftByteCount > 62) {
- [bitArray appendBits:self.binaryShiftByteCount - 31 numBits:16];
- } else if (i == 0) {
-
- [bitArray appendBits:MIN(self.binaryShiftByteCount, 31) numBits:5];
- } else {
-
- [bitArray appendBits:self.binaryShiftByteCount - 31 numBits:5];
- }
- }
- [bitArray appendBits:text.array[self.binaryShiftStart + i] numBits:8];
- }
- }
-
- @end
|