Skip to content

Commit

Permalink
fixed character count
Browse files Browse the repository at this point in the history
  • Loading branch information
aslanyanhaik committed Apr 12, 2020
1 parent 55684f2 commit b08a752
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Sources/Internal/RCBitCoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ extension RCBitCoder {
//adding staring character index and filling with special indexes
indexes.insert(configuration.characters.firstIndex(of: configuration.version.startingCharacter)!, at: 0)
let emptyIndexes = configuration.version.emptyCharacters.map({configuration.characters.firstIndex(of: $0)!})
let randomBytes = (0..<configuration.maxMessageCount).map({_ in emptyIndexes[Int.random(in: 0..<emptyIndexes.count)]})
let randomBytes = (0...configuration.maxMessageCount).map({_ in emptyIndexes[Int.random(in: 0..<emptyIndexes.count)]})
indexes.append(contentsOf: randomBytes)
indexes = Array(indexes.prefix(configuration.maxMessageCount))
indexes = Array(indexes.prefix(configuration.maxMessageCount + 1))
//encoding into bits
let encodedBits = indexes.map { byte -> [RCBit] in
var stringValue = String(repeating: "0", count: configuration.bitesPerSymbol)
Expand Down Expand Up @@ -96,7 +96,7 @@ extension RCBitCoder {
//mapping to custom size byte
let bytes = stride(from: 0, to: dataBits.count, by: configuration.bitesPerSymbol).map {
Array(dataBits[$0 ..< min($0 + configuration.bitesPerSymbol, dataBits.count)])
}.prefix(configuration.maxMessageCount)
}.prefix(configuration.maxMessageCount + 1)
//converting binary into decimal
let indexes = bytes.map({ bits in
return bits.reduce(0) { accumulated, current in
Expand Down
2 changes: 1 addition & 1 deletion Sources/Public/RCCoderConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public struct RCCoderConfiguration {
charactersArray.append(contentsOf: version.emptyCharacters)
self.characters = charactersArray
self.bitesPerSymbol = String(charactersArray.count - 1, radix: 2).count
self.maxMessageCount = version.maxBitesPerSection * 3 / bitesPerSymbol
self.maxMessageCount = version.maxBitesPerSection * 3 / bitesPerSymbol - 1
}

func validate(_ text: String) -> Bool {
Expand Down

0 comments on commit b08a752

Please sign in to comment.