Skip to content

Commit

Permalink
Refactor to improve readability and maintainability
Browse files Browse the repository at this point in the history
Refactoring includes:
- Improve function names.
- Extract decoding to Unmarshaler to a separate function.
- Extract snippets to inline functions.
- Scan nested CBOR tag numbers to avoid recursion during data validation.
  • Loading branch information
fxamacker committed Dec 17, 2019
1 parent 4c88141 commit d2d6a95
Show file tree
Hide file tree
Showing 6 changed files with 300 additions and 272 deletions.
6 changes: 3 additions & 3 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ func getEncodingStructType(t reflect.Type) encodingStructType {
break
}
if nameAsInt >= 0 {
encodeTypeAndAdditionalValue(e, byte(cborTypePositiveInt), uint64(nameAsInt))
encodeHead(e, byte(cborTypePositiveInt), uint64(nameAsInt))
} else {
n := nameAsInt*(-1) - 1
encodeTypeAndAdditionalValue(e, byte(cborTypeNegativeInt), uint64(n))
encodeHead(e, byte(cborTypeNegativeInt), uint64(n))
}
flds[i].cborName = make([]byte, e.Len())
copy(flds[i].cborName, e.Bytes())
e.Reset()
} else {
encodeTypeAndAdditionalValue(e, byte(cborTypeTextString), uint64(len(flds[i].name)))
encodeHead(e, byte(cborTypeTextString), uint64(len(flds[i].name)))
flds[i].cborName = make([]byte, e.Len()+len(flds[i].name))
n := copy(flds[i].cborName, e.Bytes())
copy(flds[i].cborName[n:], flds[i].name)
Expand Down
Loading

0 comments on commit d2d6a95

Please sign in to comment.