complete rewrite to grpc
This commit is contained in:
@@ -14,6 +14,22 @@ import (
|
||||
|
||||
type CartId [16]byte
|
||||
|
||||
// String returns the cart id as a trimmed UTF-8 string (trailing zero bytes removed).
|
||||
func (id CartId) String() string {
|
||||
n := 0
|
||||
for n < len(id) && id[n] != 0 {
|
||||
n++
|
||||
}
|
||||
return string(id[:n])
|
||||
}
|
||||
|
||||
// ToCartId converts an arbitrary string to a fixed-size CartId (truncating or padding with zeros).
|
||||
func ToCartId(s string) CartId {
|
||||
var id CartId
|
||||
copy(id[:], []byte(s))
|
||||
return id
|
||||
}
|
||||
|
||||
func (id CartId) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(id.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user