// Copyright 2016 CodisLabs. All Rights Reserved. // Licensed under the MIT (MIT-LICENSE.txt) license. package backlog import ( "os" "sync" "github.com/CodisLabs/redis-port/pkg/libs/errors" ) var ( ErrClosedBacklog = errors.New("closed backlog") ErrInvalidOffset = errors.New("invalid offset") ) type buffer interface { readSomeAt(b []byte, rpos uint64) (int, error) writeSome(b []byte) (int, error) dataRange() (rpos, wpos uint64) close() error } type Backlog struct { wl sync.Mutex mu sync.Mutex err error
const ( B = 1 << (10 * iota) KB MB GB TB PB ) var ( BytesizeRegexp = regexp.MustCompile(`(?i)^\s*(\-?[\d\.]+)\s*([KMGTP]?B|[BKMGTP]|)\s*$`) digitsRegexp = regexp.MustCompile(`^\-?\d+$`) ) var ( ErrBadBytesize = errors.New("invalid byte size") ErrBadBytesizeUnit = errors.New("invalid byte size unit") ) func Parse(s string) (int64, error) { if !BytesizeRegexp.MatchString(s) { return 0, errors.Trace(ErrBadBytesize) } subs := BytesizeRegexp.FindStringSubmatch(s) if len(subs) != 3 { return 0, errors.Trace(ErrBadBytesize) } size := int64(0) switch strings.ToUpper(string(subs[2])) {
// Licensed under the MIT (MIT-LICENSE.txt) license. package redis import ( "bufio" "bytes" "io" "strconv" "github.com/CodisLabs/redis-port/pkg/libs/errors" "github.com/CodisLabs/redis-port/pkg/libs/log" ) var ( ErrBadRespCRLFEnd = errors.New("bad resp CRLF end") ErrBadRespBytesLen = errors.New("bad resp bytes len") ErrBadRespArrayLen = errors.New("bad resp array len") ) type decoder struct { r *bufio.Reader } func Decode(r *bufio.Reader) (Resp, error) { d := &decoder{r} return d.decodeResp(0) } func MustDecode(r *bufio.Reader) Resp { resp, err := Decode(r)