Skip to content

Commit 90bebb4

Browse files
committed
decimal: fix godoc
The patch fixes markdown of Decimal.UnmarshalMsgpack method in godoc. It also makes the package description less confusing, removes duplication. Closes #201
1 parent d955230 commit 90bebb4

File tree

2 files changed

+42
-45
lines changed

2 files changed

+42
-45
lines changed

decimal/bcd.go

-42
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,3 @@
1-
// Package decimal implements methods to encode and decode BCD.
2-
//
3-
// BCD (Binary-Coded Decimal) is a sequence of bytes representing decimal
4-
// digits of the encoded number (each byte has two decimal digits each encoded
5-
// using 4-bit nibbles), so byte >> 4 is the first digit and byte & 0x0f is the
6-
// second digit. The leftmost digit in the array is the most significant. The
7-
// rightmost digit in the array is the least significant.
8-
//
9-
// The first byte of the BCD array contains the first digit of the number,
10-
// represented as follows:
11-
//
12-
// | 4 bits | 4 bits |
13-
// = 0x = the 1st digit
14-
//
15-
// (The first nibble contains 0 if the decimal number has an even number of
16-
// digits). The last byte of the BCD array contains the last digit of the
17-
// number and the final nibble, represented as follows:
18-
//
19-
// | 4 bits | 4 bits |
20-
// = the last digit = nibble
21-
//
22-
// The final nibble represents the number's sign: 0x0a, 0x0c, 0x0e, 0x0f stand
23-
// for plus, 0x0b and 0x0d stand for minus.
24-
//
25-
// Examples:
26-
//
27-
// The decimal -12.34 will be encoded as 0xd6, 0x01, 0x02, 0x01, 0x23, 0x4d:
28-
//
29-
// | MP_EXT (fixext 4) | MP_DECIMAL | scale | 1 | 2,3 | 4 (minus) |
30-
// | 0xd6 | 0x01 | 0x02 | 0x01 | 0x23 | 0x4d |
31-
//
32-
// The decimal 0.000000000000000000000000000000000010 will be encoded as
33-
// 0xc7, 0x03, 0x01, 0x24, 0x01, 0x0c:
34-
//
35-
// | MP_EXT (ext 8) | length | MP_DECIMAL | scale | 1 | 0 (plus) |
36-
// | 0xc7 | 0x03 | 0x01 | 0x24 | 0x01 | 0x0c |
37-
//
38-
// See also:
39-
//
40-
// * MessagePack extensions https://www.tarantool.io/en/doc/latest/dev_guide/internals/msgpack_extensions/
41-
//
42-
// * An implementation in C language https://github.com/tarantool/decNumber/blob/master/decPacked.c
431
package decimal
442

453
import (

decimal/decimal.go

+42-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
// Package decimal with support of Tarantool's decimal data type.
22
//
3+
// The package implements methods to encode and decode BCD.
4+
//
5+
// BCD (Binary-Coded Decimal) is a sequence of bytes representing decimal
6+
// digits of the encoded number (each byte has two decimal digits each encoded
7+
// using 4-bit nibbles), so byte >> 4 is the first digit and byte & 0x0f is the
8+
// second digit. The leftmost digit in the array is the most significant. The
9+
// rightmost digit in the array is the least significant.
10+
//
11+
// The first byte of the BCD array contains the first digit of the number,
12+
// represented as follows:
13+
//
14+
// | 4 bits | 4 bits |
15+
// = 0x = the 1st digit
16+
//
17+
// (The first nibble contains 0 if the decimal number has an even number of
18+
// digits). The last byte of the BCD array contains the last digit of the
19+
// number and the final nibble, represented as follows:
20+
//
21+
// | 4 bits | 4 bits |
22+
// = the last digit = nibble
23+
//
24+
// The final nibble represents the number's sign: 0x0a, 0x0c, 0x0e, 0x0f stand
25+
// for plus, 0x0b and 0x0d stand for minus.
26+
//
27+
// Examples:
28+
//
29+
// The decimal -12.34 will be encoded as 0xd6, 0x01, 0x02, 0x01, 0x23, 0x4d:
30+
//
31+
// | MP_EXT (fixext 4) | MP_DECIMAL | scale | 1 | 2,3 | 4 (minus) |
32+
// | 0xd6 | 0x01 | 0x02 | 0x01 | 0x23 | 0x4d |
33+
//
34+
// The decimal 0.000000000000000000000000000000000010 will be encoded as
35+
// 0xc7, 0x03, 0x01, 0x24, 0x01, 0x0c:
36+
//
37+
// | MP_EXT (ext 8) | length | MP_DECIMAL | scale | 1 | 0 (plus) |
38+
// | 0xc7 | 0x03 | 0x01 | 0x24 | 0x01 | 0x0c |
39+
//
340
// Decimal data type supported in Tarantool since 2.2.
441
//
542
// Since: 1.7.0
@@ -13,6 +50,8 @@
1350
// * Tarantool issue for support decimal type https://github.com/tarantool/tarantool/issues/692
1451
//
1552
// * Tarantool module decimal https://www.tarantool.io/en/doc/latest/reference/reference_lua/decimal/
53+
//
54+
// * An implementation in C language https://github.com/tarantool/decNumber/blob/master/decPacked.c
1655
package decimal
1756

1857
import (
@@ -83,9 +122,9 @@ func (decNum *Decimal) MarshalMsgpack() ([]byte, error) {
83122
// buffer length is not fixed and encoded by a number in a separate
84123
// field:
85124
//
86-
// +--------+-------------------+------------+===============+
87-
// | MP_EXT | length (optional) | MP_DECIMAL | PackedDecimal |
88-
// +--------+-------------------+------------+===============+
125+
// +--------+-------------------+------------+===============+
126+
// | MP_EXT | length (optional) | MP_DECIMAL | PackedDecimal |
127+
// +--------+-------------------+------------+===============+
89128
func (decNum *Decimal) UnmarshalMsgpack(b []byte) error {
90129
digits, err := decodeStringFromBCD(b)
91130
if err != nil {

0 commit comments

Comments
 (0)