MCPcopy
hub / github.com/TarsCloud/TarsGo / ReadFloat64

Method ReadFloat64

tars/protocol/codec/codec.go:806–834  ·  view source on GitHub ↗

ReadFloat64 reads the float64 value for the tag and the require or optional sign.

(data *float64, tag byte, require bool)

Source from the content-addressed store, hash-verified

804
805// ReadFloat64 reads the float64 value for the tag and the require or optional sign.
806func (b *Reader) ReadFloat64(data *float64, tag byte, require bool) error {
807 have, ty, err := b.SkipToNoCheck(tag, require)
808 if err != nil {
809 return err
810 }
811 if !have {
812 return nil
813 }
814
815 switch ty {
816 case ZeroTag:
817 *data = 0
818 case FLOAT:
819 var tmp uint32
820 err = bReadU32(b.buf, &tmp)
821 *data = float64(math.Float32frombits(tmp))
822 case DOUBLE:
823 var tmp uint64
824 err = bReadU64(b.buf, &tmp)
825 *data = math.Float64frombits(tmp)
826 default:
827 return fmt.Errorf("read 'double' type mismatch, tag:%d, get type:%s", tag, getTypeStr(int(ty)))
828 }
829
830 if err != nil {
831 err = fmt.Errorf("read 'float64' tag:%d error:%v", tag, err)
832 }
833 return err
834}
835
836// ReadString reads the string value for the tag and the require or optional sign.
837func (b *Reader) ReadString(data *string, tag byte, require bool) error {

Callers 2

TestBuffer_float64Function · 0.80
getBaseMethod · 0.80

Calls 5

SkipToNoCheckMethod · 0.95
bReadU32Function · 0.85
bReadU64Function · 0.85
getTypeStrFunction · 0.85
ErrorfMethod · 0.45

Tested by 1

TestBuffer_float64Function · 0.64