Skip to content

Commit

Permalink
int
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaydubina committed Mar 24, 2023
1 parent a2919b8 commit a284c7e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions marshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func (s *Marshaler) MarshalTo(w io.Writer, v any) error {
return errors.Join(s.err...)
}

// go-yaml decodes YAML numbers into different numeric Go types,
// as opposed to encoding/json decoding always to float64.
func (s *Marshaler) marshal(v any) {
if v == nil {
s.write(s.Null(s.key))
Expand All @@ -71,6 +73,16 @@ func (s *Marshaler) marshal(v any) {
s.write(s.Bool(s.key, q))
case string:
s.write(s.String(s.key, tryEscapeString(q)))
case int:
s.write(s.Number(s.key, float64(q), strconv.Itoa(q)))
case int64:
s.write(s.Number(s.key, float64(q), strconv.Itoa(int(q))))
case uint:
s.write(s.Number(s.key, float64(q), strconv.Itoa(int(q))))
case uint64:
s.write(s.Number(s.key, float64(q), strconv.Itoa(int(q))))
case float32:
s.write(s.Number(s.key, float64(q), strconv.FormatFloat(float64(q), 'f', -1, 32)))
case float64:
s.write(s.Number(s.key, q, strconv.FormatFloat(q, 'f', -1, 64)))
case map[string]any:
Expand Down

0 comments on commit a284c7e

Please sign in to comment.