Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve comments for encodeBigInt and decodeBigInt #757

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/debezium/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/artie-labs/transfer/lib/typing/decimal"
)

// encodeBigInt encodes a [big.Int] into a byte slice using two's complement.
// encodeBigInt encodes a [big.Int] into a big-endian byte slice using two's complement.
func encodeBigInt(value *big.Int) []byte {
data := value.Bytes() // [Bytes] returns the absolute value of the number.

Expand All @@ -17,8 +17,8 @@ func encodeBigInt(value *big.Int) []byte {
}

if data[0] >= 0x80 {
// If the first bit is already set then it is a significant bit and we need to prepend an additional byte
// so that the first bit can safely be used to indicate whether the number is positive or negative.
// If the leftmost bit is already set then it is a significant bit and we need to prepend an additional byte
// so that the leftmost bit can safely be used to indicate whether the number is positive or negative.
data = slices.Concat([]byte{0x00}, data)
}

Expand All @@ -40,7 +40,7 @@ func encodeBigInt(value *big.Int) []byte {
return data
}

// decodeBigInt decodes a [big.Int] from a byte slice that has been encoded using two's complement.
// decodeBigInt decodes a [big.Int] from a big-endian byte slice that has been encoded using two's complement.
func decodeBigInt(data []byte) *big.Int {
bigInt := new(big.Int)

Expand Down