diff --git a/kv/ArrayCodec.go b/kv/ArrayCodec.go index 3516dda..227ad87 100644 --- a/kv/ArrayCodec.go +++ b/kv/ArrayCodec.go @@ -21,10 +21,10 @@ func ArrayCodec[V any](codec Codec[io.Reader, V]) Codec[[]byte, []V] { return &arrayCodec[V]{codec: codec} } -func (a *arrayCodec[V]) encode(v2 []V) []byte { +func (a *arrayCodec[V]) Encode(v2 []V) []byte { var bs []byte for _, v := range v2 { - encode := a.codec.encode(v) + encode := a.codec.Encode(v) all, err := io.ReadAll(encode) if err != nil { panic(exceptions.Package(err)) @@ -36,7 +36,7 @@ func (a *arrayCodec[V]) encode(v2 []V) []byte { return bs } -func (a *arrayCodec[V]) decode(v1 []byte) []V { +func (a *arrayCodec[V]) Decode(v1 []byte) []V { if len(v1) == 0 { return []V{} } @@ -48,7 +48,7 @@ func (a *arrayCodec[V]) decode(v1 []byte) []V { for func() bool { defer recover() - v := a.codec.decode(reader) + v := a.codec.Decode(reader) values = append(values, v) return reader.Len() > 0 diff --git a/kv/BoolCodec.go b/kv/BoolCodec.go index 5a493ba..149d3f6 100644 --- a/kv/BoolCodec.go +++ b/kv/BoolCodec.go @@ -15,7 +15,7 @@ var ( BoolToByteCodec Codec[[]byte, bool] = &boolCodec{} ) -func (b *boolCodec) encode(v2 bool) []byte { +func (b *boolCodec) Encode(v2 bool) []byte { if v2 { return TrueBytes } else { @@ -23,7 +23,7 @@ func (b *boolCodec) encode(v2 bool) []byte { } } -func (b *boolCodec) decode(v1 []byte) bool { +func (b *boolCodec) Decode(v1 []byte) bool { if len(v1) == 0 { return false } diff --git a/kv/ChainCodec.go b/kv/ChainCodec.go index d83e6c8..04b9497 100644 --- a/kv/ChainCodec.go +++ b/kv/ChainCodec.go @@ -17,10 +17,10 @@ func ChainCodec[V1, V2, V3 any](codec1 Codec[V2, V3], codec2 Codec[V1, V2]) Code } } -func (c *chainCodec[V1, V2, V3]) encode(v2 V3) V1 { - return c.codec2.encode(c.codec1.encode(v2)) +func (c *chainCodec[V1, V2, V3]) Encode(v2 V3) V1 { + return c.codec2.Encode(c.codec1.Encode(v2)) } -func (c *chainCodec[V1, V2, V3]) decode(v1 V1) V3 { - return c.codec1.decode(c.codec2.decode(v1)) +func (c *chainCodec[V1, V2, V3]) Decode(v1 V1) V3 { + return c.codec1.Decode(c.codec2.Decode(v1)) } diff --git a/kv/NumberCodec.go b/kv/NumberCodec.go index e61cefc..7843b0e 100644 --- a/kv/NumberCodec.go +++ b/kv/NumberCodec.go @@ -73,11 +73,11 @@ var ( ByteToComplex128Codec = InvertCodec[complex128, []byte](&complex128ToByteCodec{}) ) -func (u *int8ToByteCodec) encode(v2 int8) []byte { +func (u *int8ToByteCodec) Encode(v2 int8) []byte { return []byte{byte(v2)} } -func (u *int8ToByteCodec) decode(v1 []byte) int8 { +func (u *int8ToByteCodec) Decode(v1 []byte) int8 { if len(v1) == 0 { return 0 } @@ -85,11 +85,11 @@ func (u *int8ToByteCodec) decode(v1 []byte) int8 { return int8(v1[0]) } -func (u *int16ToByteCodec) encode(v2 int16) []byte { +func (u *int16ToByteCodec) Encode(v2 int16) []byte { return binary.BigEndian.AppendUint16(nil, uint16(v2)) } -func (u *int16ToByteCodec) decode(v1 []byte) int16 { +func (u *int16ToByteCodec) Decode(v1 []byte) int16 { if len(v1) == 0 { return 0 } @@ -97,11 +97,11 @@ func (u *int16ToByteCodec) decode(v1 []byte) int16 { return int16(binary.BigEndian.Uint16(v1)) } -func (u *int32ToByteCodec) encode(v2 int32) []byte { +func (u *int32ToByteCodec) Encode(v2 int32) []byte { return binary.BigEndian.AppendUint32(nil, uint32(v2)) } -func (u *int32ToByteCodec) decode(v1 []byte) int32 { +func (u *int32ToByteCodec) Decode(v1 []byte) int32 { if len(v1) == 0 { return 0 } @@ -109,11 +109,11 @@ func (u *int32ToByteCodec) decode(v1 []byte) int32 { return int32(binary.BigEndian.Uint32(v1)) } -func (u *int64ToByteCodec) encode(v2 int64) []byte { +func (u *int64ToByteCodec) Encode(v2 int64) []byte { return binary.BigEndian.AppendUint64(nil, uint64(v2)) } -func (u *int64ToByteCodec) decode(v1 []byte) int64 { +func (u *int64ToByteCodec) Decode(v1 []byte) int64 { if len(v1) == 0 { return 0 } @@ -121,11 +121,11 @@ func (u *int64ToByteCodec) decode(v1 []byte) int64 { return int64(binary.BigEndian.Uint64(v1)) } -func (u *uint8ToByteCodec) encode(v2 uint8) []byte { +func (u *uint8ToByteCodec) Encode(v2 uint8) []byte { return []byte{v2} } -func (u *uint8ToByteCodec) decode(v1 []byte) uint8 { +func (u *uint8ToByteCodec) Decode(v1 []byte) uint8 { if len(v1) == 0 { return 0 } @@ -133,11 +133,11 @@ func (u *uint8ToByteCodec) decode(v1 []byte) uint8 { return v1[0] } -func (u *uint16ToByteCodec) encode(v2 uint16) []byte { +func (u *uint16ToByteCodec) Encode(v2 uint16) []byte { return binary.BigEndian.AppendUint16(nil, v2) } -func (u *uint16ToByteCodec) decode(v1 []byte) uint16 { +func (u *uint16ToByteCodec) Decode(v1 []byte) uint16 { if len(v1) == 0 { return 0 } @@ -145,11 +145,11 @@ func (u *uint16ToByteCodec) decode(v1 []byte) uint16 { return binary.BigEndian.Uint16(v1) } -func (u *uint32ToByteCodec) encode(v2 uint32) []byte { +func (u *uint32ToByteCodec) Encode(v2 uint32) []byte { return binary.BigEndian.AppendUint32(nil, v2) } -func (u *uint32ToByteCodec) decode(v1 []byte) uint32 { +func (u *uint32ToByteCodec) Decode(v1 []byte) uint32 { if len(v1) == 0 { return 0 } @@ -157,11 +157,11 @@ func (u *uint32ToByteCodec) decode(v1 []byte) uint32 { return binary.BigEndian.Uint32(v1) } -func (u *uint64ToByteCodec) encode(v2 uint64) []byte { +func (u *uint64ToByteCodec) Encode(v2 uint64) []byte { return binary.BigEndian.AppendUint64(nil, v2) } -func (u *uint64ToByteCodec) decode(v1 []byte) uint64 { +func (u *uint64ToByteCodec) Decode(v1 []byte) uint64 { if len(v1) == 0 { return 0 } @@ -169,11 +169,11 @@ func (u *uint64ToByteCodec) decode(v1 []byte) uint64 { return binary.BigEndian.Uint64(v1) } -func (u *float32ToByteCodec) encode(v2 float32) []byte { +func (u *float32ToByteCodec) Encode(v2 float32) []byte { return binary.BigEndian.AppendUint32(nil, *(*uint32)(unsafe.Pointer(&v2))) } -func (u *float32ToByteCodec) decode(v1 []byte) float32 { +func (u *float32ToByteCodec) Decode(v1 []byte) float32 { if len(v1) == 0 { return 0 } @@ -182,11 +182,11 @@ func (u *float32ToByteCodec) decode(v1 []byte) float32 { return *(*float32)(unsafe.Pointer(&u2)) } -func (u *float64ToByteCodec) encode(v2 float64) []byte { +func (u *float64ToByteCodec) Encode(v2 float64) []byte { return binary.BigEndian.AppendUint64(nil, *(*uint64)(unsafe.Pointer(&v2))) } -func (u *float64ToByteCodec) decode(v1 []byte) float64 { +func (u *float64ToByteCodec) Decode(v1 []byte) float64 { if len(v1) == 0 { return 0 } @@ -195,11 +195,11 @@ func (u *float64ToByteCodec) decode(v1 []byte) float64 { return *(*float64)(unsafe.Pointer(&u2)) } -func (u *complex64ToByteCodec) encode(v2 complex64) []byte { +func (u *complex64ToByteCodec) Encode(v2 complex64) []byte { return binary.BigEndian.AppendUint64(nil, *(*uint64)(unsafe.Pointer(&v2))) } -func (u *complex64ToByteCodec) decode(v1 []byte) complex64 { +func (u *complex64ToByteCodec) Decode(v1 []byte) complex64 { if len(v1) == 0 { return 0 } @@ -208,7 +208,7 @@ func (u *complex64ToByteCodec) decode(v1 []byte) complex64 { return *(*complex64)(unsafe.Pointer(&u2)) } -func (u *complex128ToByteCodec) encode(v2 complex128) []byte { +func (u *complex128ToByteCodec) Encode(v2 complex128) []byte { r := real(v2) i := imag(v2) @@ -220,7 +220,7 @@ func (u *complex128ToByteCodec) encode(v2 complex128) []byte { return bytes } -func (u *complex128ToByteCodec) decode(v1 []byte) complex128 { +func (u *complex128ToByteCodec) Decode(v1 []byte) complex128 { if len(v1) == 0 { return 0 } diff --git a/kv/ProtoCodec.go b/kv/ProtoCodec.go index a987b27..6eccbb5 100644 --- a/kv/ProtoCodec.go +++ b/kv/ProtoCodec.go @@ -23,7 +23,7 @@ func ProtoDeCodec[V proto.Message](emptyMessage func() V) Codec[V, []byte] { return InvertCodec(ProtoCodec(emptyMessage)) } -func (p *protoToByteCodec[V]) encode(v2 V) []byte { +func (p *protoToByteCodec[V]) Encode(v2 V) []byte { bytes, err := proto.Marshal(v2) if err == nil { panic(exceptions.Package(err)) @@ -32,7 +32,7 @@ func (p *protoToByteCodec[V]) encode(v2 V) []byte { return bytes } -func (p *protoToByteCodec[V]) decode(v1 []byte) V { +func (p *protoToByteCodec[V]) Decode(v1 []byte) V { message := p.emptyMessage() if err := proto.Unmarshal(v1, message); err != nil { panic(exceptions.Package(err)) diff --git a/kv/ReaderCodec.go b/kv/ReaderCodec.go index 1f1f5bb..245e58d 100644 --- a/kv/ReaderCodec.go +++ b/kv/ReaderCodec.go @@ -40,7 +40,7 @@ func FixedLengthCodec(frameLength uint32) Codec[io.Reader, []byte] { } func (r *readerCodec[V]) encode(v2 V) io.Reader { - return bytes.NewReader(r.codec.encode(v2)) + return bytes.NewReader(r.codec.Encode(v2)) } func (r *readerCodec[V]) decode(v1 io.Reader) V { @@ -49,7 +49,7 @@ func (r *readerCodec[V]) decode(v1 io.Reader) V { panic(exceptions.Package(err)) } - return r.codec.decode(all) + return r.codec.Decode(all) } func (f *fixedLengthCodec) encode(v2 []byte) io.Reader { diff --git a/kv/StringCodec.go b/kv/StringCodec.go index 420b538..8c0be20 100644 --- a/kv/StringCodec.go +++ b/kv/StringCodec.go @@ -13,11 +13,11 @@ var ( ByteToStringCodec = InvertCodec[string, []byte](&stringToByteCodec{}) ) -func (s *stringToByteCodec) encode(v2 string) []byte { +func (s *stringToByteCodec) Encode(v2 string) []byte { return []byte(v2) } -func (s *stringToByteCodec) decode(v1 []byte) string { +func (s *stringToByteCodec) Decode(v1 []byte) string { if len(v1) == 0 { return "" } diff --git a/kv/codec.go b/kv/codec.go index e9999d3..916038e 100644 --- a/kv/codec.go +++ b/kv/codec.go @@ -8,8 +8,8 @@ import ( type ( Codec[V1, V2 any] interface { lang.Object - encode(v2 V2) V1 - decode(v1 V1) V2 + Encode(v2 V2) V1 + Decode(v1 V1) V2 } codecStore[K1, K2, V1, V2 any] struct { @@ -74,28 +74,28 @@ func VCodecStore[K, V1, V2 any]( } func (c *codecStore[K1, K2, V1, V2]) Put(key K2, value V2) exceptions.Exception { - return c.kvs.Put(c.kCodec.encode(key), c.vCodec.encode(value)) + return c.kvs.Put(c.kCodec.Encode(key), c.vCodec.Encode(value)) } func (c *codecStore[K1, K2, V1, V2]) Get(key K2) (V2, exceptions.Exception) { - value, exception := c.kvs.Get(c.kCodec.encode(key)) + value, exception := c.kvs.Get(c.kCodec.Encode(key)) if exception != nil { return lang.Nil[V2](), exception } - return c.vCodec.decode(value), nil + return c.vCodec.Decode(value), nil } func (c *kCodecStore[K1, K2, V]) Put(key K2, value V) exceptions.Exception { - return c.kvs.Put(c.codec.encode(key), value) + return c.kvs.Put(c.codec.Encode(key), value) } func (c *kCodecStore[K1, K2, V]) Get(key K2) (V, exceptions.Exception) { - return c.kvs.Get(c.codec.encode(key)) + return c.kvs.Get(c.codec.Encode(key)) } func (c *vCodecStore[K, V1, V2]) Put(key K, value V2) exceptions.Exception { - return c.kvs.Put(key, c.codec.encode(value)) + return c.kvs.Put(key, c.codec.Encode(value)) } func (c *vCodecStore[K, V1, V2]) Get(key K) (V2, exceptions.Exception) { @@ -104,13 +104,13 @@ func (c *vCodecStore[K, V1, V2]) Get(key K) (V2, exceptions.Exception) { return lang.Nil[V2](), exception } - return c.codec.decode(get), nil + return c.codec.Decode(get), nil } -func (i *invertCodec[V1, V2]) encode(v2 V2) V1 { - return i.codec.decode(v2) +func (i *invertCodec[V1, V2]) Encode(v2 V2) V1 { + return i.codec.Decode(v2) } -func (i *invertCodec[V1, V2]) decode(v1 V1) V2 { - return i.codec.encode(v1) +func (i *invertCodec[V1, V2]) Decode(v1 V1) V2 { + return i.codec.Encode(v1) }