Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up & support for NextType
Browse files Browse the repository at this point in the history
klauspost committed Oct 29, 2024

Verified

This commit was signed with the committer’s verified signature.
d3adb5 d3adb5
1 parent 1e1e78e commit cf97edd
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
@@ -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
}
}
@@ -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 {
4 changes: 2 additions & 2 deletions msgp/read.go
Original file line number Diff line number Diff line change
@@ -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
}
}
@@ -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
4 changes: 2 additions & 2 deletions msgp/read_bytes.go
Original file line number Diff line number Diff line change
@@ -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
@@ -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()

0 comments on commit cf97edd

Please sign in to comment.