[#265] proto: Implement functions for double (float64) protobuf data type
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
101d14d405
commit
0cbb8d0913
4 changed files with 95 additions and 21 deletions
|
@ -8,6 +8,7 @@ package proto
|
|||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"math"
|
||||
"math/bits"
|
||||
"reflect"
|
||||
)
|
||||
|
@ -360,3 +361,26 @@ func Fixed64Size(fNum int, v uint64) int {
|
|||
|
||||
return VarUIntSize(uint64(prefix)) + 8
|
||||
}
|
||||
|
||||
func Float64Marshal(field int, buf []byte, v float64) (int, error) {
|
||||
if v == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
prefix := field<<3 | 1
|
||||
|
||||
i := binary.PutUvarint(buf, uint64(prefix))
|
||||
binary.LittleEndian.PutUint64(buf[i:], math.Float64bits(v))
|
||||
|
||||
return i + 8, nil
|
||||
}
|
||||
|
||||
func Float64Size(fNum int, v float64) int {
|
||||
if v == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
prefix := fNum<<3 | 1
|
||||
|
||||
return VarUIntSize(uint64(prefix)) + 8
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue