Skip to content

Commit e948683

Browse files
committed
doc: fix markdown for the decimal subpackage
The patch hides the implementation details of the Decimal type from documentation. It provides comments for Decimal.MarshalMsgpack and Decimal.UnmarshalMsgpack. Closes #201
1 parent ab1fb93 commit e948683

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1818

1919
### Fixed
2020

21+
- Markdown of documentation for the decimal subpackage (#201)
22+
2123
## [1.7.0] - 2022-08-02
2224

2325
### Added

decimal/bcd.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package decimal
2+
13
// Package decimal implements methods to encode and decode BCD.
24
//
35
// BCD (Binary-Coded Decimal) is a sequence of bytes representing decimal
@@ -26,21 +28,20 @@
2628
//
2729
// The decimal -12.34 will be encoded as 0xd6, 0x01, 0x02, 0x01, 0x23, 0x4d:
2830
//
29-
// | MP_EXT (fixext 4) | MP_DECIMAL | scale | 1 | 2,3 | 4 (minus) |
30-
// | 0xd6 | 0x01 | 0x02 | 0x01 | 0x23 | 0x4d |
31+
// | MP_EXT (fixext 4) | MP_DECIMAL | scale | 1 | 2,3 | 4 (minus) |
32+
// | 0xd6 | 0x01 | 0x02 | 0x01 | 0x23 | 0x4d |
3133
//
3234
// The decimal 0.000000000000000000000000000000000010 will be encoded as
3335
// 0xc7, 0x03, 0x01, 0x24, 0x01, 0x0c:
3436
//
35-
// | MP_EXT (ext 8) | length | MP_DECIMAL | scale | 1 | 0 (plus) |
36-
// | 0xc7 | 0x03 | 0x01 | 0x24 | 0x01 | 0x0c |
37+
// | MP_EXT (ext 8) | length | MP_DECIMAL | scale | 1 | 0 (plus) |
38+
// | 0xc7 | 0x03 | 0x01 | 0x24 | 0x01 | 0x0c |
3739
//
3840
// See also:
3941
//
4042
// * MessagePack extensions https://www.tarantool.io/en/doc/latest/dev_guide/internals/msgpack_extensions/
4143
//
4244
// * An implementation in C language https://github.com/tarantool/decNumber/blob/master/decPacked.c
43-
package decimal
4445

4546
import (
4647
"fmt"

decimal/decimal.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func NewDecimalFromString(src string) (result *Decimal, err error) {
5555
return
5656
}
5757

58+
// MarshalMsgpack serializes the Decimal into a MessagePack representation.
5859
func (decNum *Decimal) MarshalMsgpack() ([]byte, error) {
5960
one := decimal.NewFromInt(1)
6061
maxSupportedDecimal := decimal.New(1, DecimalPrecision).Sub(one) // 10^DecimalPrecision - 1
@@ -74,15 +75,17 @@ func (decNum *Decimal) MarshalMsgpack() ([]byte, error) {
7475
return bcdBuf, nil
7576
}
7677

77-
// Decimal values can be encoded to fixext MessagePack, where buffer
78-
// has a fixed length encoded by first byte, and ext MessagePack, where
79-
// buffer length is not fixed and encoded by a number in a separate
80-
// field:
81-
//
82-
// +--------+-------------------+------------+===============+
83-
// | MP_EXT | length (optional) | MP_DECIMAL | PackedDecimal |
84-
// +--------+-------------------+------------+===============+
78+
// UnmarshalMsgpack deserializes a Decimal value from a MessagePack
79+
// representation.
8580
func (decNum *Decimal) UnmarshalMsgpack(b []byte) error {
81+
// Decimal values can be encoded to fixext MessagePack, where buffer
82+
// has a fixed length encoded by first byte, and ext MessagePack, where
83+
// buffer length is not fixed and encoded by a number in a separate
84+
// field:
85+
//
86+
// +--------+-------------------+------------+===============+
87+
// | MP_EXT | length (optional) | MP_DECIMAL | PackedDecimal |
88+
// +--------+-------------------+------------+===============+
8689
digits, err := decodeStringFromBCD(b)
8790
if err != nil {
8891
return fmt.Errorf("msgpack: can't decode string from BCD buffer (%x): %w", b, err)

0 commit comments

Comments
 (0)