You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package supports the two latest Go versions. With that in mind, interpretation of raw byte buffers as integer types can be simplified with the usage of generics, thereby reducing the verbosity of the nlenc package. This change is backwards-compatible with the currently exposed API. What do you think?
// Int returns the contents of raw as an integer as specified by T// Int panics if the raw data is not the exact length as the compile-time// length of TfuncInt[T constraints.Integer](raw []byte) (iT) {
rawLen:=len(raw)
ifcompLen:=int(unsafe.Sizeof(i)); compLen!=rawLen {
panic(fmt.Sprintf(
"unexpected byte slice length when decoding integer: %d",
rawLen,
))
}
return*(*T)(unsafe.Pointer(&raw[0]))
}
// PutInt puts an integer into the contents of raw// PutInt panics if the byte slice is not the exact length as the compile-time// length of TfuncPutInt[T constraints.Integer](raw []byte, iT) {
rawLen:=len(raw)
ifcompLen:=int(unsafe.Sizeof(i)); compLen!=rawLen {
panic(fmt.Sprintf(
"unexpected byte slice length when encoding integer: %d",
rawLen,
))
}
*(*T)(unsafe.Pointer(&raw[0])) =i
}
The text was updated successfully, but these errors were encountered:
This package supports the two latest Go versions. With that in mind, interpretation of raw byte buffers as integer types can be simplified with the usage of generics, thereby reducing the verbosity of the
nlenc
package. This change is backwards-compatible with the currently exposed API. What do you think?The text was updated successfully, but these errors were encountered: