docs(collections): add comments for funcs (#22214)
This commit is contained in:
parent
db6a8352c3
commit
63b1652d98
@ -106,6 +106,8 @@ type quadKeyCodec[K1, K2, K3, K4 any] struct {
|
||||
|
||||
type jsonQuadKey [4]json.RawMessage
|
||||
|
||||
|
||||
// EncodeJSON encodes Quads to json
|
||||
func (t quadKeyCodec[K1, K2, K3, K4]) EncodeJSON(value Quad[K1, K2, K3, K4]) ([]byte, error) {
|
||||
json1, err := t.keyCodec1.EncodeJSON(*value.k1)
|
||||
if err != nil {
|
||||
@ -130,6 +132,7 @@ func (t quadKeyCodec[K1, K2, K3, K4]) EncodeJSON(value Quad[K1, K2, K3, K4]) ([]
|
||||
return json.Marshal(jsonQuadKey{json1, json2, json3, json4})
|
||||
}
|
||||
|
||||
// DecodeJSON decodes json to Quads
|
||||
func (t quadKeyCodec[K1, K2, K3, K4]) DecodeJSON(b []byte) (Quad[K1, K2, K3, K4], error) {
|
||||
var jsonKey jsonQuadKey
|
||||
err := json.Unmarshal(b, &jsonKey)
|
||||
@ -160,6 +163,7 @@ func (t quadKeyCodec[K1, K2, K3, K4]) DecodeJSON(b []byte) (Quad[K1, K2, K3, K4]
|
||||
return Join4(key1, key2, key3, key4), nil
|
||||
}
|
||||
|
||||
// Stringify converts Quads to string
|
||||
func (t quadKeyCodec[K1, K2, K3, K4]) Stringify(key Quad[K1, K2, K3, K4]) string {
|
||||
b := new(strings.Builder)
|
||||
b.WriteByte('(')
|
||||
@ -206,6 +210,7 @@ func (t quadKeyCodec[K1, K2, K3, K4]) KeyType() string {
|
||||
return fmt.Sprintf("Quad[%s,%s,%s,%s]", t.keyCodec1.KeyType(), t.keyCodec2.KeyType(), t.keyCodec3.KeyType(), t.keyCodec4.KeyType())
|
||||
}
|
||||
|
||||
|
||||
func (t quadKeyCodec[K1, K2, K3, K4]) Encode(buffer []byte, key Quad[K1, K2, K3, K4]) (int, error) {
|
||||
writtenTotal := 0
|
||||
if key.k1 != nil {
|
||||
@ -239,6 +244,7 @@ func (t quadKeyCodec[K1, K2, K3, K4]) Encode(buffer []byte, key Quad[K1, K2, K3,
|
||||
return writtenTotal, nil
|
||||
}
|
||||
|
||||
|
||||
func (t quadKeyCodec[K1, K2, K3, K4]) Decode(buffer []byte) (int, Quad[K1, K2, K3, K4], error) {
|
||||
readTotal := 0
|
||||
read, key1, err := t.keyCodec1.DecodeNonTerminal(buffer)
|
||||
|
||||
@ -85,6 +85,7 @@ type tripleKeyCodec[K1, K2, K3 any] struct {
|
||||
|
||||
type jsonTripleKey [3]json.RawMessage
|
||||
|
||||
// EncodeJSON convert triple keys to json
|
||||
func (t tripleKeyCodec[K1, K2, K3]) EncodeJSON(value Triple[K1, K2, K3]) ([]byte, error) {
|
||||
json1, err := t.keyCodec1.EncodeJSON(*value.k1)
|
||||
if err != nil {
|
||||
@ -104,6 +105,7 @@ func (t tripleKeyCodec[K1, K2, K3]) EncodeJSON(value Triple[K1, K2, K3]) ([]byte
|
||||
return json.Marshal(jsonTripleKey{json1, json2, json3})
|
||||
}
|
||||
|
||||
// DecodeJSON convert json to triple keys
|
||||
func (t tripleKeyCodec[K1, K2, K3]) DecodeJSON(b []byte) (Triple[K1, K2, K3], error) {
|
||||
var jsonKey jsonTripleKey
|
||||
err := json.Unmarshal(b, &jsonKey)
|
||||
@ -129,6 +131,7 @@ func (t tripleKeyCodec[K1, K2, K3]) DecodeJSON(b []byte) (Triple[K1, K2, K3], er
|
||||
return Join3(key1, key2, key3), nil
|
||||
}
|
||||
|
||||
// Stringify convert triple keys to string
|
||||
func (t tripleKeyCodec[K1, K2, K3]) Stringify(key Triple[K1, K2, K3]) string {
|
||||
b := new(strings.Builder)
|
||||
b.WriteByte('(')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user