Skip to content

Commit

Permalink
simplify codeman api
Browse files Browse the repository at this point in the history
  • Loading branch information
xgzlucario committed Jan 26, 2024
1 parent 5c84dcb commit 33bf29a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
6 changes: 4 additions & 2 deletions codeman/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ func (s *Codec) Float(f float64) *Codec {
}

func (s *Codec) StrSlice(v []string) *Codec {
return s.format(formatStrSlice(v))
s.b = append(s.b, formatStrSlice(v)...)
return s
}

func (s *Codec) Uint32Slice(v []uint32) *Codec {
return s.format(formatNumberSlice(v))
s.b = append(s.b, formatNumberSlice(v)...)
return s
}

// format uses variable-length encoding of incoming bytes.
Expand Down
23 changes: 6 additions & 17 deletions codeman/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,17 @@ func (s *Reader) Str() string {
}

func (s *Reader) StrSlice() []string {
r := s.read()
length, n := binary.Uvarint(r)
r = r[n:]
data := make([]string, 0, length)
for i := uint64(0); i < length; i++ {
klen, n := binary.Uvarint(r)
r = r[n:]
data = append(data, string(r[:klen]))
r = r[klen:]
data := make([]string, s.readVarint())
for i := range data {
data[i] = s.Str()
}
return data
}

func (s *Reader) Uint32Slice() []uint32 {
r := s.read()
length, n := binary.Uvarint(r)
r = r[n:]
data := make([]uint32, 0, length)
for i := uint64(0); i < length; i++ {
k, n := binary.Uvarint(r)
r = r[n:]
data = append(data, uint32(k))
data := make([]uint32, s.readVarint())
for i := range data {
data[i] = s.Uint32()
}
return data
}
Expand Down

0 comments on commit 33bf29a

Please sign in to comment.