Skip to content

Commit

Permalink
Clean up & support for NextType
Browse files Browse the repository at this point in the history
  • Loading branch information
klauspost committed Oct 29, 2024
1 parent 1e1e78e commit cf97edd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions msgp/json_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func writeNext(w jsWriter, msg []byte, scratch []byte, depth int) ([]byte, []byt
if err != nil {
return nil, scratch, err
}
if et == TimeExtension {
if et == TimeExtension || et == MsgTimeExtension {
t = TimeType
}
}
Expand Down Expand Up @@ -276,7 +276,7 @@ func rwExtensionBytes(w jsWriter, msg []byte, scratch []byte, depth int) ([]byte
}

// if it's time.Time
if et == TimeExtension {
if et == TimeExtension || et == MsgTimeExtension {
var tm time.Time
tm, msg, err = ReadTimeBytes(msg)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions msgp/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (m *Reader) NextType() (Type, error) {
return Complex64Type, nil
case Complex128Extension:
return Complex128Type, nil
case TimeExtension:
case TimeExtension, MsgTimeExtension:
return TimeType, nil
}
}
Expand Down Expand Up @@ -1287,7 +1287,7 @@ func (m *Reader) ReadTime() (t time.Time, err error) {
t = time.Unix(sec, int64(nsec)).Local()
_, err = m.R.Skip(15)
return
case -1:
case MsgTimeExtension:
switch length {
case 4, 8, 12:
var tmp [12]byte
Expand Down
4 changes: 2 additions & 2 deletions msgp/read_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NextType(b []byte) Type {
tp = int8(b[spec.size-1])
}
switch tp {
case TimeExtension:
case TimeExtension, MsgTimeExtension:
return TimeType
case Complex128Extension:
return Complex128Type
Expand Down Expand Up @@ -1094,7 +1094,7 @@ func ReadTimeBytes(b []byte) (t time.Time, o []byte, err error) {
sec, nsec := getUnix(b)
t = time.Unix(sec, int64(nsec)).Local()
return
case -1:
case MsgTimeExtension:
switch len(b) {
case 4:
t = time.Unix(int64(binary.BigEndian.Uint32(b)), 0).Local()
Expand Down

0 comments on commit cf97edd

Please sign in to comment.