id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
18,200 | fagongzi/goetty | buf.go | Int2Bytes | func Int2Bytes(v int) []byte {
ret := make([]byte, 4)
Int2BytesTo(v, ret)
return ret
} | go | func Int2Bytes(v int) []byte {
ret := make([]byte, 4)
Int2BytesTo(v, ret)
return ret
} | [
"func",
"Int2Bytes",
"(",
"v",
"int",
")",
"[",
"]",
"byte",
"{",
"ret",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",
"Int2BytesTo",
"(",
"v",
",",
"ret",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // Int2Bytes int value to bytes array using big order | [
"Int2Bytes",
"int",
"value",
"to",
"bytes",
"array",
"using",
"big",
"order"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L70-L74 |
18,201 | fagongzi/goetty | buf.go | Int64ToBytesTo | func Int64ToBytesTo(v int64, ret []byte) {
ret[0] = byte(v >> 56)
ret[1] = byte(v >> 48)
ret[2] = byte(v >> 40)
ret[3] = byte(v >> 32)
ret[4] = byte(v >> 24)
ret[5] = byte(v >> 16)
ret[6] = byte(v >> 8)
ret[7] = byte(v)
} | go | func Int64ToBytesTo(v int64, ret []byte) {
ret[0] = byte(v >> 56)
ret[1] = byte(v >> 48)
ret[2] = byte(v >> 40)
ret[3] = byte(v >> 32)
ret[4] = byte(v >> 24)
ret[5] = byte(v >> 16)
ret[6] = byte(v >> 8)
ret[7] = byte(v)
} | [
"func",
"Int64ToBytesTo",
"(",
"v",
"int64",
",",
"ret",
"[",
"]",
"byte",
")",
"{",
"ret",
"[",
"0",
"]",
"=",
"byte",
"(",
"v",
">>",
"56",
")",
"\n",
"ret",
"[",
"1",
"]",
"=",
"byte",
"(",
"v",
">>",
"48",
")",
"\n",
"ret",
"[",
"2",
... | // Int64ToBytesTo int64 value to bytes array using big order | [
"Int64ToBytesTo",
"int64",
"value",
"to",
"bytes",
"array",
"using",
"big",
"order"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L77-L86 |
18,202 | fagongzi/goetty | buf.go | Uint64ToBytesTo | func Uint64ToBytesTo(v uint64, ret []byte) {
binary.BigEndian.PutUint64(ret, v)
} | go | func Uint64ToBytesTo(v uint64, ret []byte) {
binary.BigEndian.PutUint64(ret, v)
} | [
"func",
"Uint64ToBytesTo",
"(",
"v",
"uint64",
",",
"ret",
"[",
"]",
"byte",
")",
"{",
"binary",
".",
"BigEndian",
".",
"PutUint64",
"(",
"ret",
",",
"v",
")",
"\n",
"}"
] | // Uint64ToBytesTo uint64 value to bytes array using big order | [
"Uint64ToBytesTo",
"uint64",
"value",
"to",
"bytes",
"array",
"using",
"big",
"order"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L89-L91 |
18,203 | fagongzi/goetty | buf.go | Int64ToBytes | func Int64ToBytes(v int64) []byte {
ret := make([]byte, 8)
Int64ToBytesTo(v, ret)
return ret
} | go | func Int64ToBytes(v int64) []byte {
ret := make([]byte, 8)
Int64ToBytesTo(v, ret)
return ret
} | [
"func",
"Int64ToBytes",
"(",
"v",
"int64",
")",
"[",
"]",
"byte",
"{",
"ret",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"8",
")",
"\n",
"Int64ToBytesTo",
"(",
"v",
",",
"ret",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // Int64ToBytes int64 value to bytes array using big order | [
"Int64ToBytes",
"int64",
"value",
"to",
"bytes",
"array",
"using",
"big",
"order"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L94-L98 |
18,204 | fagongzi/goetty | buf.go | Uint32ToBytesTo | func Uint32ToBytesTo(v uint32, ret []byte) {
binary.BigEndian.PutUint32(ret, v)
} | go | func Uint32ToBytesTo(v uint32, ret []byte) {
binary.BigEndian.PutUint32(ret, v)
} | [
"func",
"Uint32ToBytesTo",
"(",
"v",
"uint32",
",",
"ret",
"[",
"]",
"byte",
")",
"{",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"ret",
",",
"v",
")",
"\n",
"}"
] | // Uint32ToBytesTo uint32 value to bytes array using big order | [
"Uint32ToBytesTo",
"uint32",
"value",
"to",
"bytes",
"array",
"using",
"big",
"order"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L101-L103 |
18,205 | fagongzi/goetty | buf.go | UInt32ToBytes | func UInt32ToBytes(v uint32) []byte {
ret := make([]byte, 4)
Uint32ToBytesTo(v, ret)
return ret
} | go | func UInt32ToBytes(v uint32) []byte {
ret := make([]byte, 4)
Uint32ToBytesTo(v, ret)
return ret
} | [
"func",
"UInt32ToBytes",
"(",
"v",
"uint32",
")",
"[",
"]",
"byte",
"{",
"ret",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",
"Uint32ToBytesTo",
"(",
"v",
",",
"ret",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // UInt32ToBytes uint32 value to bytes array using big order | [
"UInt32ToBytes",
"uint32",
"value",
"to",
"bytes",
"array",
"using",
"big",
"order"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L106-L110 |
18,206 | fagongzi/goetty | buf.go | Uint16ToBytesTo | func Uint16ToBytesTo(v uint16, ret []byte) {
binary.BigEndian.PutUint16(ret, v)
} | go | func Uint16ToBytesTo(v uint16, ret []byte) {
binary.BigEndian.PutUint16(ret, v)
} | [
"func",
"Uint16ToBytesTo",
"(",
"v",
"uint16",
",",
"ret",
"[",
"]",
"byte",
")",
"{",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"ret",
",",
"v",
")",
"\n",
"}"
] | // Uint16ToBytesTo uint16 value to bytes array using big order | [
"Uint16ToBytesTo",
"uint16",
"value",
"to",
"bytes",
"array",
"using",
"big",
"order"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L113-L115 |
18,207 | fagongzi/goetty | buf.go | UInt16ToBytes | func UInt16ToBytes(v uint16) []byte {
ret := make([]byte, 2)
Uint16ToBytesTo(v, ret)
return ret
} | go | func UInt16ToBytes(v uint16) []byte {
ret := make([]byte, 2)
Uint16ToBytesTo(v, ret)
return ret
} | [
"func",
"UInt16ToBytes",
"(",
"v",
"uint16",
")",
"[",
"]",
"byte",
"{",
"ret",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"2",
")",
"\n",
"Uint16ToBytesTo",
"(",
"v",
",",
"ret",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // UInt16ToBytes uint16 value to bytes array using big order | [
"UInt16ToBytes",
"uint16",
"value",
"to",
"bytes",
"array",
"using",
"big",
"order"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L118-L122 |
18,208 | fagongzi/goetty | buf.go | NewByteBufPool | func NewByteBufPool(capacity int, pool Pool) *ByteBuf {
return &ByteBuf{
capacity: capacity,
buf: pool.Alloc(capacity),
readerIndex: 0,
writerIndex: 0,
pool: pool,
}
} | go | func NewByteBufPool(capacity int, pool Pool) *ByteBuf {
return &ByteBuf{
capacity: capacity,
buf: pool.Alloc(capacity),
readerIndex: 0,
writerIndex: 0,
pool: pool,
}
} | [
"func",
"NewByteBufPool",
"(",
"capacity",
"int",
",",
"pool",
"Pool",
")",
"*",
"ByteBuf",
"{",
"return",
"&",
"ByteBuf",
"{",
"capacity",
":",
"capacity",
",",
"buf",
":",
"pool",
".",
"Alloc",
"(",
"capacity",
")",
",",
"readerIndex",
":",
"0",
",",... | // NewByteBufPool create a new bytebuf using a mem pool | [
"NewByteBufPool",
"create",
"a",
"new",
"bytebuf",
"using",
"a",
"mem",
"pool"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L149-L157 |
18,209 | fagongzi/goetty | buf.go | Release | func (b *ByteBuf) Release() {
b.pool.Free(b.buf)
b.buf = nil
} | go | func (b *ByteBuf) Release() {
b.pool.Free(b.buf)
b.buf = nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"Release",
"(",
")",
"{",
"b",
".",
"pool",
".",
"Free",
"(",
"b",
".",
"buf",
")",
"\n",
"b",
".",
"buf",
"=",
"nil",
"\n",
"}"
] | // Release release buf | [
"Release",
"release",
"buf"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L172-L175 |
18,210 | fagongzi/goetty | buf.go | Resume | func (b *ByteBuf) Resume(capacity int) {
b.buf = b.pool.Alloc(b.capacity)
} | go | func (b *ByteBuf) Resume(capacity int) {
b.buf = b.pool.Alloc(b.capacity)
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"Resume",
"(",
"capacity",
"int",
")",
"{",
"b",
".",
"buf",
"=",
"b",
".",
"pool",
".",
"Alloc",
"(",
"b",
".",
"capacity",
")",
"\n",
"}"
] | // Resume resume the buf | [
"Resume",
"resume",
"the",
"buf"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L178-L180 |
18,211 | fagongzi/goetty | buf.go | SetReaderIndex | func (b *ByteBuf) SetReaderIndex(newReaderIndex int) error {
if newReaderIndex < 0 || newReaderIndex > b.writerIndex {
return io.ErrShortBuffer
}
b.readerIndex = newReaderIndex
return nil
} | go | func (b *ByteBuf) SetReaderIndex(newReaderIndex int) error {
if newReaderIndex < 0 || newReaderIndex > b.writerIndex {
return io.ErrShortBuffer
}
b.readerIndex = newReaderIndex
return nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"SetReaderIndex",
"(",
"newReaderIndex",
"int",
")",
"error",
"{",
"if",
"newReaderIndex",
"<",
"0",
"||",
"newReaderIndex",
">",
"b",
".",
"writerIndex",
"{",
"return",
"io",
".",
"ErrShortBuffer",
"\n",
"}",
"\n",
... | // SetReaderIndex set the read index | [
"SetReaderIndex",
"set",
"the",
"read",
"index"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L188-L196 |
18,212 | fagongzi/goetty | buf.go | GetMarkedRemindData | func (b *ByteBuf) GetMarkedRemindData() []byte {
return b.buf[b.readerIndex:b.markedIndex]
} | go | func (b *ByteBuf) GetMarkedRemindData() []byte {
return b.buf[b.readerIndex:b.markedIndex]
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"GetMarkedRemindData",
"(",
")",
"[",
"]",
"byte",
"{",
"return",
"b",
".",
"buf",
"[",
"b",
".",
"readerIndex",
":",
"b",
".",
"markedIndex",
"]",
"\n",
"}"
] | // GetMarkedRemindData returns data in [readerIndex, markedIndex) | [
"GetMarkedRemindData",
"returns",
"data",
"in",
"[",
"readerIndex",
"markedIndex",
")"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L219-L221 |
18,213 | fagongzi/goetty | buf.go | SetWriterIndex | func (b *ByteBuf) SetWriterIndex(newWriterIndex int) error {
if newWriterIndex < b.readerIndex || newWriterIndex > b.Capacity() {
return io.ErrShortBuffer
}
b.writerIndex = newWriterIndex
return nil
} | go | func (b *ByteBuf) SetWriterIndex(newWriterIndex int) error {
if newWriterIndex < b.readerIndex || newWriterIndex > b.Capacity() {
return io.ErrShortBuffer
}
b.writerIndex = newWriterIndex
return nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"SetWriterIndex",
"(",
"newWriterIndex",
"int",
")",
"error",
"{",
"if",
"newWriterIndex",
"<",
"b",
".",
"readerIndex",
"||",
"newWriterIndex",
">",
"b",
".",
"Capacity",
"(",
")",
"{",
"return",
"io",
".",
"ErrSho... | // SetWriterIndex set the write index | [
"SetWriterIndex",
"set",
"the",
"write",
"index"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L224-L232 |
18,214 | fagongzi/goetty | buf.go | MarkN | func (b *ByteBuf) MarkN(n int) error {
return b.MarkIndex(b.readerIndex + n)
} | go | func (b *ByteBuf) MarkN(n int) error {
return b.MarkIndex(b.readerIndex + n)
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"MarkN",
"(",
"n",
"int",
")",
"error",
"{",
"return",
"b",
".",
"MarkIndex",
"(",
"b",
".",
"readerIndex",
"+",
"n",
")",
"\n",
"}"
] | // MarkN mark a index offset based by currently read index | [
"MarkN",
"mark",
"a",
"index",
"offset",
"based",
"by",
"currently",
"read",
"index"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L235-L237 |
18,215 | fagongzi/goetty | buf.go | MarkIndex | func (b *ByteBuf) MarkIndex(index int) error {
if index > b.Capacity() || index <= b.readerIndex {
return io.ErrShortBuffer
}
b.markedIndex = index
return nil
} | go | func (b *ByteBuf) MarkIndex(index int) error {
if index > b.Capacity() || index <= b.readerIndex {
return io.ErrShortBuffer
}
b.markedIndex = index
return nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"MarkIndex",
"(",
"index",
"int",
")",
"error",
"{",
"if",
"index",
">",
"b",
".",
"Capacity",
"(",
")",
"||",
"index",
"<=",
"b",
".",
"readerIndex",
"{",
"return",
"io",
".",
"ErrShortBuffer",
"\n",
"}",
"\n... | // MarkIndex mark a index | [
"MarkIndex",
"mark",
"a",
"index"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L240-L247 |
18,216 | fagongzi/goetty | buf.go | Skip | func (b *ByteBuf) Skip(n int) error {
if n > b.Readable() {
return io.ErrShortBuffer
}
b.readerIndex += n
return nil
} | go | func (b *ByteBuf) Skip(n int) error {
if n > b.Readable() {
return io.ErrShortBuffer
}
b.readerIndex += n
return nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"Skip",
"(",
"n",
"int",
")",
"error",
"{",
"if",
"n",
">",
"b",
".",
"Readable",
"(",
")",
"{",
"return",
"io",
".",
"ErrShortBuffer",
"\n",
"}",
"\n",
"b",
".",
"readerIndex",
"+=",
"n",
"\n",
"return",
... | // Skip skip bytes, after this option, read index will change to readerIndex+n | [
"Skip",
"skip",
"bytes",
"after",
"this",
"option",
"read",
"index",
"will",
"change",
"to",
"readerIndex",
"+",
"n"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L250-L257 |
18,217 | fagongzi/goetty | buf.go | ReadByte | func (b *ByteBuf) ReadByte() (byte, error) {
if b.Readable() == 0 {
return 0, nil
}
v := b.buf[b.readerIndex]
b.readerIndex++
return v, nil
} | go | func (b *ByteBuf) ReadByte() (byte, error) {
if b.Readable() == 0 {
return 0, nil
}
v := b.buf[b.readerIndex]
b.readerIndex++
return v, nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"ReadByte",
"(",
")",
"(",
"byte",
",",
"error",
")",
"{",
"if",
"b",
".",
"Readable",
"(",
")",
"==",
"0",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n",
"v",
":=",
"b",
".",
"buf",
"[",
"b",
".",
... | // ReadByte read a byte from buf
// return byte value, error | [
"ReadByte",
"read",
"a",
"byte",
"from",
"buf",
"return",
"byte",
"value",
"error"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L266-L274 |
18,218 | fagongzi/goetty | buf.go | ReadBytes | func (b *ByteBuf) ReadBytes(n int) (int, []byte, error) {
data := make([]byte, n)
n, err := b.Read(data)
return n, data, err
} | go | func (b *ByteBuf) ReadBytes(n int) (int, []byte, error) {
data := make([]byte, n)
n, err := b.Read(data)
return n, data, err
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"ReadBytes",
"(",
"n",
"int",
")",
"(",
"int",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
")",
"\n",
"n",
",",
"err",
":=",
"b",
".",
"Read",
... | // ReadBytes read bytes from buf
// It's will copy the data to a new byte arrary
// return readedBytesCount, byte array, error | [
"ReadBytes",
"read",
"bytes",
"from",
"buf",
"It",
"s",
"will",
"copy",
"the",
"data",
"to",
"a",
"new",
"byte",
"arrary",
"return",
"readedBytesCount",
"byte",
"array",
"error"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L289-L293 |
18,219 | fagongzi/goetty | buf.go | ReadAll | func (b *ByteBuf) ReadAll() (int, []byte, error) {
return b.ReadBytes(b.Readable())
} | go | func (b *ByteBuf) ReadAll() (int, []byte, error) {
return b.ReadBytes(b.Readable())
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"ReadAll",
"(",
")",
"(",
"int",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"b",
".",
"ReadBytes",
"(",
"b",
".",
"Readable",
"(",
")",
")",
"\n",
"}"
] | // ReadAll read all data from buf
// It's will copy the data to a new byte arrary
// return readedBytesCount, byte array, error | [
"ReadAll",
"read",
"all",
"data",
"from",
"buf",
"It",
"s",
"will",
"copy",
"the",
"data",
"to",
"a",
"new",
"byte",
"arrary",
"return",
"readedBytesCount",
"byte",
"array",
"error"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L298-L300 |
18,220 | fagongzi/goetty | buf.go | ReadMarkedBytes | func (b *ByteBuf) ReadMarkedBytes() (int, []byte, error) {
return b.ReadBytes(b.GetMarkedRemind())
} | go | func (b *ByteBuf) ReadMarkedBytes() (int, []byte, error) {
return b.ReadBytes(b.GetMarkedRemind())
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"ReadMarkedBytes",
"(",
")",
"(",
"int",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"b",
".",
"ReadBytes",
"(",
"b",
".",
"GetMarkedRemind",
"(",
")",
")",
"\n",
"}"
] | // ReadMarkedBytes read data from buf in the range [readerIndex, markedIndex) | [
"ReadMarkedBytes",
"read",
"data",
"from",
"buf",
"in",
"the",
"range",
"[",
"readerIndex",
"markedIndex",
")"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L303-L305 |
18,221 | fagongzi/goetty | buf.go | Read | func (b *ByteBuf) Read(p []byte) (n int, err error) {
if len(p) == 0 {
return 0, nil
}
size := len(p)
if len(p) > b.Readable() {
size = b.Readable()
}
n = copy(p, b.buf[b.readerIndex:b.readerIndex+size])
b.readerIndex += n
return n, nil
} | go | func (b *ByteBuf) Read(p []byte) (n int, err error) {
if len(p) == 0 {
return 0, nil
}
size := len(p)
if len(p) > b.Readable() {
size = b.Readable()
}
n = copy(p, b.buf[b.readerIndex:b.readerIndex+size])
b.readerIndex += n
return n, nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"p",
")",
"==",
"0",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n",
"size",
":=",
"len",
"... | // Read read bytes
// return readedBytesCount, byte array, error | [
"Read",
"read",
"bytes",
"return",
"readedBytesCount",
"byte",
"array",
"error"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L314-L327 |
18,222 | fagongzi/goetty | buf.go | ReadInt | func (b *ByteBuf) ReadInt() (int, error) {
if b.Readable() < 4 {
return 0, io.ErrShortBuffer
}
b.readerIndex += 4
return Byte2Int(b.buf[b.readerIndex-4 : b.readerIndex]), nil
} | go | func (b *ByteBuf) ReadInt() (int, error) {
if b.Readable() < 4 {
return 0, io.ErrShortBuffer
}
b.readerIndex += 4
return Byte2Int(b.buf[b.readerIndex-4 : b.readerIndex]), nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"ReadInt",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"b",
".",
"Readable",
"(",
")",
"<",
"4",
"{",
"return",
"0",
",",
"io",
".",
"ErrShortBuffer",
"\n",
"}",
"\n",
"b",
".",
"readerIndex",
"+="... | // ReadInt get int value from buf | [
"ReadInt",
"get",
"int",
"value",
"from",
"buf"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L330-L337 |
18,223 | fagongzi/goetty | buf.go | ReadUInt16 | func (b *ByteBuf) ReadUInt16() (uint16, error) {
if b.Readable() < 2 {
return 0, io.ErrShortBuffer
}
b.readerIndex += 2
return Byte2UInt16(b.buf[b.readerIndex-2 : b.readerIndex]), nil
} | go | func (b *ByteBuf) ReadUInt16() (uint16, error) {
if b.Readable() < 2 {
return 0, io.ErrShortBuffer
}
b.readerIndex += 2
return Byte2UInt16(b.buf[b.readerIndex-2 : b.readerIndex]), nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"ReadUInt16",
"(",
")",
"(",
"uint16",
",",
"error",
")",
"{",
"if",
"b",
".",
"Readable",
"(",
")",
"<",
"2",
"{",
"return",
"0",
",",
"io",
".",
"ErrShortBuffer",
"\n",
"}",
"\n",
"b",
".",
"readerIndex",
... | // ReadUInt16 get uint16 value from buf | [
"ReadUInt16",
"get",
"uint16",
"value",
"from",
"buf"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L340-L347 |
18,224 | fagongzi/goetty | buf.go | ReadUInt32 | func (b *ByteBuf) ReadUInt32() (uint32, error) {
if b.Readable() < 4 {
return 0, io.ErrShortBuffer
}
b.readerIndex += 4
return Byte2UInt32(b.buf[b.readerIndex-4 : b.readerIndex]), nil
} | go | func (b *ByteBuf) ReadUInt32() (uint32, error) {
if b.Readable() < 4 {
return 0, io.ErrShortBuffer
}
b.readerIndex += 4
return Byte2UInt32(b.buf[b.readerIndex-4 : b.readerIndex]), nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"ReadUInt32",
"(",
")",
"(",
"uint32",
",",
"error",
")",
"{",
"if",
"b",
".",
"Readable",
"(",
")",
"<",
"4",
"{",
"return",
"0",
",",
"io",
".",
"ErrShortBuffer",
"\n",
"}",
"\n",
"b",
".",
"readerIndex",
... | // ReadUInt32 get uint32 value from buf | [
"ReadUInt32",
"get",
"uint32",
"value",
"from",
"buf"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L350-L357 |
18,225 | fagongzi/goetty | buf.go | ReadInt64 | func (b *ByteBuf) ReadInt64() (int64, error) {
if b.Readable() < 8 {
return 0, io.ErrShortBuffer
}
b.readerIndex += 8
return Byte2Int64(b.buf[b.readerIndex-8 : b.readerIndex]), nil
} | go | func (b *ByteBuf) ReadInt64() (int64, error) {
if b.Readable() < 8 {
return 0, io.ErrShortBuffer
}
b.readerIndex += 8
return Byte2Int64(b.buf[b.readerIndex-8 : b.readerIndex]), nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"ReadInt64",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"b",
".",
"Readable",
"(",
")",
"<",
"8",
"{",
"return",
"0",
",",
"io",
".",
"ErrShortBuffer",
"\n",
"}",
"\n",
"b",
".",
"readerIndex",
... | // ReadInt64 get int64 value from buf | [
"ReadInt64",
"get",
"int64",
"value",
"from",
"buf"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L360-L367 |
18,226 | fagongzi/goetty | buf.go | ReadUInt64 | func (b *ByteBuf) ReadUInt64() (uint64, error) {
if b.Readable() < 8 {
return 0, io.ErrShortBuffer
}
b.readerIndex += 8
return Byte2UInt64(b.buf[b.readerIndex-8 : b.readerIndex]), nil
} | go | func (b *ByteBuf) ReadUInt64() (uint64, error) {
if b.Readable() < 8 {
return 0, io.ErrShortBuffer
}
b.readerIndex += 8
return Byte2UInt64(b.buf[b.readerIndex-8 : b.readerIndex]), nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"ReadUInt64",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"if",
"b",
".",
"Readable",
"(",
")",
"<",
"8",
"{",
"return",
"0",
",",
"io",
".",
"ErrShortBuffer",
"\n",
"}",
"\n",
"b",
".",
"readerIndex",
... | // ReadUInt64 get uint64 value from buf | [
"ReadUInt64",
"get",
"uint64",
"value",
"from",
"buf"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L370-L377 |
18,227 | fagongzi/goetty | buf.go | PeekInt | func (b *ByteBuf) PeekInt(offset int) (int, error) {
if b.Readable() < 4+offset {
return 0, io.ErrShortBuffer
}
start := b.readerIndex + offset
return Byte2Int(b.buf[start : start+4]), nil
} | go | func (b *ByteBuf) PeekInt(offset int) (int, error) {
if b.Readable() < 4+offset {
return 0, io.ErrShortBuffer
}
start := b.readerIndex + offset
return Byte2Int(b.buf[start : start+4]), nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"PeekInt",
"(",
"offset",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"b",
".",
"Readable",
"(",
")",
"<",
"4",
"+",
"offset",
"{",
"return",
"0",
",",
"io",
".",
"ErrShortBuffer",
"\n",
"}",
"\n... | // PeekInt get int value from buf based on currently read index, after read, read index not modifed | [
"PeekInt",
"get",
"int",
"value",
"from",
"buf",
"based",
"on",
"currently",
"read",
"index",
"after",
"read",
"read",
"index",
"not",
"modifed"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L380-L387 |
18,228 | fagongzi/goetty | buf.go | PeekByte | func (b *ByteBuf) PeekByte(offset int) (byte, error) {
if b.Readable() < offset || offset < 0 {
return 0, io.ErrShortBuffer
}
return b.buf[b.readerIndex+offset], nil
} | go | func (b *ByteBuf) PeekByte(offset int) (byte, error) {
if b.Readable() < offset || offset < 0 {
return 0, io.ErrShortBuffer
}
return b.buf[b.readerIndex+offset], nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"PeekByte",
"(",
"offset",
"int",
")",
"(",
"byte",
",",
"error",
")",
"{",
"if",
"b",
".",
"Readable",
"(",
")",
"<",
"offset",
"||",
"offset",
"<",
"0",
"{",
"return",
"0",
",",
"io",
".",
"ErrShortBuffer"... | // PeekByte get byte value from buf based on currently read index, after read, read index not modifed | [
"PeekByte",
"get",
"byte",
"value",
"from",
"buf",
"based",
"on",
"currently",
"read",
"index",
"after",
"read",
"read",
"index",
"not",
"modifed"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L390-L396 |
18,229 | fagongzi/goetty | buf.go | PeekN | func (b *ByteBuf) PeekN(offset int, n int) ([]byte, error) {
if b.Readable() < n+offset {
return nil, io.ErrShortBuffer
}
start := b.readerIndex + offset
return b.buf[start : start+n], nil
} | go | func (b *ByteBuf) PeekN(offset int, n int) ([]byte, error) {
if b.Readable() < n+offset {
return nil, io.ErrShortBuffer
}
start := b.readerIndex + offset
return b.buf[start : start+n], nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"PeekN",
"(",
"offset",
"int",
",",
"n",
"int",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"b",
".",
"Readable",
"(",
")",
"<",
"n",
"+",
"offset",
"{",
"return",
"nil",
",",
"io",
".",
... | // PeekN get bytes from buf based on currently read index, after read, read index not modifed | [
"PeekN",
"get",
"bytes",
"from",
"buf",
"based",
"on",
"currently",
"read",
"index",
"after",
"read",
"read",
"index",
"not",
"modifed"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L399-L406 |
18,230 | fagongzi/goetty | buf.go | Write | func (b *ByteBuf) Write(p []byte) (int, error) {
n := len(p)
b.Expansion(n)
copy(b.buf[b.writerIndex:], p)
b.writerIndex += n
return n, nil
} | go | func (b *ByteBuf) Write(p []byte) (int, error) {
n := len(p)
b.Expansion(n)
copy(b.buf[b.writerIndex:], p)
b.writerIndex += n
return n, nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"n",
":=",
"len",
"(",
"p",
")",
"\n",
"b",
".",
"Expansion",
"(",
"n",
")",
"\n",
"copy",
"(",
"b",
".",
"buf",
"[",
"b"... | // Write appends the contents of p to the buffer, growing the buffer as
// needed. | [
"Write",
"appends",
"the",
"contents",
"of",
"p",
"to",
"the",
"buffer",
"growing",
"the",
"buffer",
"as",
"needed",
"."
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L442-L448 |
18,231 | fagongzi/goetty | buf.go | WriteInt | func (b *ByteBuf) WriteInt(v int) (n int, err error) {
b.Expansion(4)
Int2BytesTo(v, b.buf[b.writerIndex:b.writerIndex+4])
b.writerIndex += 4
return 4, nil
} | go | func (b *ByteBuf) WriteInt(v int) (n int, err error) {
b.Expansion(4)
Int2BytesTo(v, b.buf[b.writerIndex:b.writerIndex+4])
b.writerIndex += 4
return 4, nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"WriteInt",
"(",
"v",
"int",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"b",
".",
"Expansion",
"(",
"4",
")",
"\n",
"Int2BytesTo",
"(",
"v",
",",
"b",
".",
"buf",
"[",
"b",
".",
"writerIndex",
... | // WriteInt write int value to buf using big order
// return write bytes count, error | [
"WriteInt",
"write",
"int",
"value",
"to",
"buf",
"using",
"big",
"order",
"return",
"write",
"bytes",
"count",
"error"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L452-L457 |
18,232 | fagongzi/goetty | buf.go | WriteUInt16 | func (b *ByteBuf) WriteUInt16(v uint16) (n int, err error) {
b.Expansion(2)
Uint16ToBytesTo(v, b.buf[b.writerIndex:b.writerIndex+2])
b.writerIndex += 2
return 2, nil
} | go | func (b *ByteBuf) WriteUInt16(v uint16) (n int, err error) {
b.Expansion(2)
Uint16ToBytesTo(v, b.buf[b.writerIndex:b.writerIndex+2])
b.writerIndex += 2
return 2, nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"WriteUInt16",
"(",
"v",
"uint16",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"b",
".",
"Expansion",
"(",
"2",
")",
"\n",
"Uint16ToBytesTo",
"(",
"v",
",",
"b",
".",
"buf",
"[",
"b",
".",
"writer... | // WriteUInt16 write uint16 value to buf using big order
// return write bytes count, error | [
"WriteUInt16",
"write",
"uint16",
"value",
"to",
"buf",
"using",
"big",
"order",
"return",
"write",
"bytes",
"count",
"error"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L461-L466 |
18,233 | fagongzi/goetty | buf.go | WriteUInt32 | func (b *ByteBuf) WriteUInt32(v uint32) (n int, err error) {
b.Expansion(4)
Uint32ToBytesTo(v, b.buf[b.writerIndex:b.writerIndex+4])
b.writerIndex += 4
return 4, nil
} | go | func (b *ByteBuf) WriteUInt32(v uint32) (n int, err error) {
b.Expansion(4)
Uint32ToBytesTo(v, b.buf[b.writerIndex:b.writerIndex+4])
b.writerIndex += 4
return 4, nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"WriteUInt32",
"(",
"v",
"uint32",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"b",
".",
"Expansion",
"(",
"4",
")",
"\n",
"Uint32ToBytesTo",
"(",
"v",
",",
"b",
".",
"buf",
"[",
"b",
".",
"writer... | // WriteUInt32 write uint32 value to buf using big order
// return write bytes count, error | [
"WriteUInt32",
"write",
"uint32",
"value",
"to",
"buf",
"using",
"big",
"order",
"return",
"write",
"bytes",
"count",
"error"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L470-L475 |
18,234 | fagongzi/goetty | buf.go | WriteUInt64 | func (b *ByteBuf) WriteUInt64(v uint64) (n int, err error) {
b.Expansion(8)
Uint64ToBytesTo(v, b.buf[b.writerIndex:b.writerIndex+8])
b.writerIndex += 8
return 8, nil
} | go | func (b *ByteBuf) WriteUInt64(v uint64) (n int, err error) {
b.Expansion(8)
Uint64ToBytesTo(v, b.buf[b.writerIndex:b.writerIndex+8])
b.writerIndex += 8
return 8, nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"WriteUInt64",
"(",
"v",
"uint64",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"b",
".",
"Expansion",
"(",
"8",
")",
"\n",
"Uint64ToBytesTo",
"(",
"v",
",",
"b",
".",
"buf",
"[",
"b",
".",
"writer... | // WriteUInt64 write uint64 value to buf using big order
// return write bytes count, error | [
"WriteUInt64",
"write",
"uint64",
"value",
"to",
"buf",
"using",
"big",
"order",
"return",
"write",
"bytes",
"count",
"error"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L479-L484 |
18,235 | fagongzi/goetty | buf.go | WriteInt64 | func (b *ByteBuf) WriteInt64(v int64) (n int, err error) {
b.Expansion(8)
Int64ToBytesTo(v, b.buf[b.writerIndex:b.writerIndex+8])
b.writerIndex += 8
return 8, nil
} | go | func (b *ByteBuf) WriteInt64(v int64) (n int, err error) {
b.Expansion(8)
Int64ToBytesTo(v, b.buf[b.writerIndex:b.writerIndex+8])
b.writerIndex += 8
return 8, nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"WriteInt64",
"(",
"v",
"int64",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"b",
".",
"Expansion",
"(",
"8",
")",
"\n",
"Int64ToBytesTo",
"(",
"v",
",",
"b",
".",
"buf",
"[",
"b",
".",
"writerInd... | // WriteInt64 write int64 value to buf using big order
// return write bytes count, error | [
"WriteInt64",
"write",
"int64",
"value",
"to",
"buf",
"using",
"big",
"order",
"return",
"write",
"bytes",
"count",
"error"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L488-L493 |
18,236 | fagongzi/goetty | buf.go | WriteByte | func (b *ByteBuf) WriteByte(v byte) error {
b.Expansion(1)
b.buf[b.writerIndex] = v
b.writerIndex++
return nil
} | go | func (b *ByteBuf) WriteByte(v byte) error {
b.Expansion(1)
b.buf[b.writerIndex] = v
b.writerIndex++
return nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"WriteByte",
"(",
"v",
"byte",
")",
"error",
"{",
"b",
".",
"Expansion",
"(",
"1",
")",
"\n",
"b",
".",
"buf",
"[",
"b",
".",
"writerIndex",
"]",
"=",
"v",
"\n",
"b",
".",
"writerIndex",
"++",
"\n",
"retur... | // WriteByte write a byte value to buf | [
"WriteByte",
"write",
"a",
"byte",
"value",
"to",
"buf"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L505-L510 |
18,237 | fagongzi/goetty | buf.go | WriteString | func (b *ByteBuf) WriteString(v string) error {
_, err := b.Write(StringToSlice(v))
return err
} | go | func (b *ByteBuf) WriteString(v string) error {
_, err := b.Write(StringToSlice(v))
return err
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"WriteString",
"(",
"v",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"b",
".",
"Write",
"(",
"StringToSlice",
"(",
"v",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // WriteString write a string value to buf | [
"WriteString",
"write",
"a",
"string",
"value",
"to",
"buf"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L513-L516 |
18,238 | fagongzi/goetty | buf.go | WriteByteBuf | func (b *ByteBuf) WriteByteBuf(from *ByteBuf) error {
size := from.Readable()
b.Expansion(size)
copy(b.buf[b.writerIndex:b.writerIndex+size], from.buf[from.readerIndex:from.writerIndex])
b.writerIndex += size
from.readerIndex = from.writerIndex
return nil
} | go | func (b *ByteBuf) WriteByteBuf(from *ByteBuf) error {
size := from.Readable()
b.Expansion(size)
copy(b.buf[b.writerIndex:b.writerIndex+size], from.buf[from.readerIndex:from.writerIndex])
b.writerIndex += size
from.readerIndex = from.writerIndex
return nil
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"WriteByteBuf",
"(",
"from",
"*",
"ByteBuf",
")",
"error",
"{",
"size",
":=",
"from",
".",
"Readable",
"(",
")",
"\n",
"b",
".",
"Expansion",
"(",
"size",
")",
"\n",
"copy",
"(",
"b",
".",
"buf",
"[",
"b",
... | // WriteByteBuf write all readable data to this buf | [
"WriteByteBuf",
"write",
"all",
"readable",
"data",
"to",
"this",
"buf"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L519-L526 |
18,239 | fagongzi/goetty | buf.go | Expansion | func (b *ByteBuf) Expansion(n int) {
if free := b.Writeable(); free < n {
newBuf := b.pool.Alloc(b.Capacity() + n)
offset := b.writerIndex - b.readerIndex
copy(newBuf, b.buf[b.readerIndex:b.writerIndex])
b.readerIndex = 0
b.writerIndex = offset
b.pool.Free(b.buf)
b.buf = newBuf
}
} | go | func (b *ByteBuf) Expansion(n int) {
if free := b.Writeable(); free < n {
newBuf := b.pool.Alloc(b.Capacity() + n)
offset := b.writerIndex - b.readerIndex
copy(newBuf, b.buf[b.readerIndex:b.writerIndex])
b.readerIndex = 0
b.writerIndex = offset
b.pool.Free(b.buf)
b.buf = newBuf
}
} | [
"func",
"(",
"b",
"*",
"ByteBuf",
")",
"Expansion",
"(",
"n",
"int",
")",
"{",
"if",
"free",
":=",
"b",
".",
"Writeable",
"(",
")",
";",
"free",
"<",
"n",
"{",
"newBuf",
":=",
"b",
".",
"pool",
".",
"Alloc",
"(",
"b",
".",
"Capacity",
"(",
")... | // Expansion expansion buf size | [
"Expansion",
"expansion",
"buf",
"size"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L529-L539 |
18,240 | fagongzi/goetty | protocol/redis/parser.go | ReadCommand | func ReadCommand(in *goetty.ByteBuf) (bool, Command, error) {
for {
// remember the begin read index,
// if we found has no enough data, we will resume this read index,
// and waiting for next.
backupReaderIndex := in.GetReaderIndex()
c, err := in.ReadByte()
if err != nil {
return false, nil, err
}
// 1. Read ( *<number of arguments> CR LF )
if c != CMDBegin {
return false, nil, fmt.Errorf("illegal cmd char %d", c)
}
// 2. Read number of arguments
count, argsCount, err := readStringInt(in)
if count == 0 && err == nil {
in.SetReaderIndex(backupReaderIndex)
return false, nil, nil
} else if err != nil {
return false, nil, err
}
data := make([][]byte, argsCount)
// 3. Read args
for i := 0; i < argsCount; i++ {
if 0 == in.Readable() {
in.SetReaderIndex(backupReaderIndex)
return false, nil, nil
}
// 3.1 Read ( $<number of bytes of argument 1> CR LF )
c, err := in.ReadByte()
if err != nil {
return false, nil, err
}
// 3.2 Read ( *<number of arguments> CR LF )
if c != ARGBegin {
return false, nil, fmt.Errorf("illegal arg char %d", c)
}
count, argBytesCount, err := readStringInt(in)
if count == 0 && err == nil {
in.SetReaderIndex(backupReaderIndex)
return false, nil, nil
} else if err != nil {
return false, nil, err
} else if count < 2 {
return false, nil, fmt.Errorf("illegal arg count: %d", count)
}
// 3.3 Read ( <argument data> CR LF )
if argBytesCount+2 > in.Readable() {
in.SetReaderIndex(backupReaderIndex)
return false, nil, nil
}
count, value, err := in.ReadBytes(argBytesCount + 2)
if count == 0 && err == nil {
in.SetReaderIndex(backupReaderIndex)
return false, nil, nil
} else if err != nil {
return false, nil, err
}
data[i] = value[:count-2]
}
return true, Command(data), nil
}
} | go | func ReadCommand(in *goetty.ByteBuf) (bool, Command, error) {
for {
// remember the begin read index,
// if we found has no enough data, we will resume this read index,
// and waiting for next.
backupReaderIndex := in.GetReaderIndex()
c, err := in.ReadByte()
if err != nil {
return false, nil, err
}
// 1. Read ( *<number of arguments> CR LF )
if c != CMDBegin {
return false, nil, fmt.Errorf("illegal cmd char %d", c)
}
// 2. Read number of arguments
count, argsCount, err := readStringInt(in)
if count == 0 && err == nil {
in.SetReaderIndex(backupReaderIndex)
return false, nil, nil
} else if err != nil {
return false, nil, err
}
data := make([][]byte, argsCount)
// 3. Read args
for i := 0; i < argsCount; i++ {
if 0 == in.Readable() {
in.SetReaderIndex(backupReaderIndex)
return false, nil, nil
}
// 3.1 Read ( $<number of bytes of argument 1> CR LF )
c, err := in.ReadByte()
if err != nil {
return false, nil, err
}
// 3.2 Read ( *<number of arguments> CR LF )
if c != ARGBegin {
return false, nil, fmt.Errorf("illegal arg char %d", c)
}
count, argBytesCount, err := readStringInt(in)
if count == 0 && err == nil {
in.SetReaderIndex(backupReaderIndex)
return false, nil, nil
} else if err != nil {
return false, nil, err
} else if count < 2 {
return false, nil, fmt.Errorf("illegal arg count: %d", count)
}
// 3.3 Read ( <argument data> CR LF )
if argBytesCount+2 > in.Readable() {
in.SetReaderIndex(backupReaderIndex)
return false, nil, nil
}
count, value, err := in.ReadBytes(argBytesCount + 2)
if count == 0 && err == nil {
in.SetReaderIndex(backupReaderIndex)
return false, nil, nil
} else if err != nil {
return false, nil, err
}
data[i] = value[:count-2]
}
return true, Command(data), nil
}
} | [
"func",
"ReadCommand",
"(",
"in",
"*",
"goetty",
".",
"ByteBuf",
")",
"(",
"bool",
",",
"Command",
",",
"error",
")",
"{",
"for",
"{",
"// remember the begin read index,\r",
"// if we found has no enough data, we will resume this read index,\r",
"// and waiting for next.\r"... | // ReadCommand returns redis command from buffer | [
"ReadCommand",
"returns",
"redis",
"command",
"from",
"buffer"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/protocol/redis/parser.go#L33-L107 |
18,241 | fagongzi/goetty | middleware_sync.go | NewSyncProtocolClientMiddleware | func NewSyncProtocolClientMiddleware(bizDecoder Decoder, bizEncoder Encoder, writer func(IOSession, interface{}) error, maxReadTimeouts int) Middleware {
return &syncClientMiddleware{
cached: newSimpleQueue(),
writer: writer,
bizDecoder: bizDecoder,
bizEncoder: bizEncoder,
maxReadTimeouts: maxReadTimeouts,
}
} | go | func NewSyncProtocolClientMiddleware(bizDecoder Decoder, bizEncoder Encoder, writer func(IOSession, interface{}) error, maxReadTimeouts int) Middleware {
return &syncClientMiddleware{
cached: newSimpleQueue(),
writer: writer,
bizDecoder: bizDecoder,
bizEncoder: bizEncoder,
maxReadTimeouts: maxReadTimeouts,
}
} | [
"func",
"NewSyncProtocolClientMiddleware",
"(",
"bizDecoder",
"Decoder",
",",
"bizEncoder",
"Encoder",
",",
"writer",
"func",
"(",
"IOSession",
",",
"interface",
"{",
"}",
")",
"error",
",",
"maxReadTimeouts",
"int",
")",
"Middleware",
"{",
"return",
"&",
"syncC... | // NewSyncProtocolClientMiddleware return a middleware to process sync protocol | [
"NewSyncProtocolClientMiddleware",
"return",
"a",
"middleware",
"to",
"process",
"sync",
"protocol"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/middleware_sync.go#L23-L31 |
18,242 | fagongzi/goetty | middleware_sync.go | NewSyncProtocolServerMiddleware | func NewSyncProtocolServerMiddleware(bizDecoder Decoder, bizEncoder Encoder, writer func(IOSession, interface{}) error) Middleware {
return &syncServerMiddleware{
bizDecoder: bizDecoder,
bizEncoder: bizEncoder,
writer: writer,
offsetQueueMap: make(map[interface{}]*OffsetQueue),
}
} | go | func NewSyncProtocolServerMiddleware(bizDecoder Decoder, bizEncoder Encoder, writer func(IOSession, interface{}) error) Middleware {
return &syncServerMiddleware{
bizDecoder: bizDecoder,
bizEncoder: bizEncoder,
writer: writer,
offsetQueueMap: make(map[interface{}]*OffsetQueue),
}
} | [
"func",
"NewSyncProtocolServerMiddleware",
"(",
"bizDecoder",
"Decoder",
",",
"bizEncoder",
"Encoder",
",",
"writer",
"func",
"(",
"IOSession",
",",
"interface",
"{",
"}",
")",
"error",
")",
"Middleware",
"{",
"return",
"&",
"syncServerMiddleware",
"{",
"bizDecode... | // NewSyncProtocolServerMiddleware return a middleware to process sync protocol | [
"NewSyncProtocolServerMiddleware",
"return",
"a",
"middleware",
"to",
"process",
"sync",
"protocol"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/middleware_sync.go#L180-L187 |
18,243 | fagongzi/goetty | timewheel.go | Stop | func (t *Timeout) Stop() bool {
if t.timeout == nil {
return false
}
t.timeout.mtx.Lock()
if t.timeout.generation != t.generation || t.timeout.state != timeoutActive {
t.timeout.mtx.Unlock()
return false
}
t.timeout.removeLocked()
t.timeout.wheel.putTimeoutLocked(t.timeout)
t.timeout.mtx.Unlock()
return true
} | go | func (t *Timeout) Stop() bool {
if t.timeout == nil {
return false
}
t.timeout.mtx.Lock()
if t.timeout.generation != t.generation || t.timeout.state != timeoutActive {
t.timeout.mtx.Unlock()
return false
}
t.timeout.removeLocked()
t.timeout.wheel.putTimeoutLocked(t.timeout)
t.timeout.mtx.Unlock()
return true
} | [
"func",
"(",
"t",
"*",
"Timeout",
")",
"Stop",
"(",
")",
"bool",
"{",
"if",
"t",
".",
"timeout",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"t",
".",
"timeout",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"if",
"t",
".",
"timeout",
".... | // Stop stops the scheduled timeout so that the callback will not be called. It returns true if it
// successfully canceled | [
"Stop",
"stops",
"the",
"scheduled",
"timeout",
"so",
"that",
"the",
"callback",
"will",
"not",
"be",
"called",
".",
"It",
"returns",
"true",
"if",
"it",
"successfully",
"canceled"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/timewheel.go#L54-L69 |
18,244 | fagongzi/goetty | timewheel.go | WithTickInterval | func WithTickInterval(interval time.Duration) Option {
return func(opts *opts) { opts.tickInterval = interval }
} | go | func WithTickInterval(interval time.Duration) Option {
return func(opts *opts) { opts.tickInterval = interval }
} | [
"func",
"WithTickInterval",
"(",
"interval",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"func",
"(",
"opts",
"*",
"opts",
")",
"{",
"opts",
".",
"tickInterval",
"=",
"interval",
"}",
"\n",
"}"
] | // WithTickInterval sets the frequency of ticks. | [
"WithTickInterval",
"sets",
"the",
"frequency",
"of",
"ticks",
"."
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/timewheel.go#L149-L151 |
18,245 | fagongzi/goetty | timewheel.go | WithBucketsExponent | func WithBucketsExponent(bucketExp uint) Option {
return func(opts *opts) {
opts.size = uint64(1 << bucketExp)
}
} | go | func WithBucketsExponent(bucketExp uint) Option {
return func(opts *opts) {
opts.size = uint64(1 << bucketExp)
}
} | [
"func",
"WithBucketsExponent",
"(",
"bucketExp",
"uint",
")",
"Option",
"{",
"return",
"func",
"(",
"opts",
"*",
"opts",
")",
"{",
"opts",
".",
"size",
"=",
"uint64",
"(",
"1",
"<<",
"bucketExp",
")",
"\n",
"}",
"\n",
"}"
] | // WithBucketsExponent sets the number of buckets in the hash table. | [
"WithBucketsExponent",
"sets",
"the",
"number",
"of",
"buckets",
"in",
"the",
"hash",
"table",
"."
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/timewheel.go#L154-L158 |
18,246 | fagongzi/goetty | timewheel.go | WithLocksExponent | func WithLocksExponent(lockExp uint) Option {
return func(opts *opts) {
opts.poolsize = uint64(1 << lockExp)
}
} | go | func WithLocksExponent(lockExp uint) Option {
return func(opts *opts) {
opts.poolsize = uint64(1 << lockExp)
}
} | [
"func",
"WithLocksExponent",
"(",
"lockExp",
"uint",
")",
"Option",
"{",
"return",
"func",
"(",
"opts",
"*",
"opts",
")",
"{",
"opts",
".",
"poolsize",
"=",
"uint64",
"(",
"1",
"<<",
"lockExp",
")",
"\n",
"}",
"\n",
"}"
] | // WithLocksExponent sets the number locks in the lockpool used to lock the time buckets. If the
// number is greater than the number of buckets, the number of buckets will be used instead. | [
"WithLocksExponent",
"sets",
"the",
"number",
"locks",
"in",
"the",
"lockpool",
"used",
"to",
"lock",
"the",
"time",
"buckets",
".",
"If",
"the",
"number",
"is",
"greater",
"than",
"the",
"number",
"of",
"buckets",
"the",
"number",
"of",
"buckets",
"will",
... | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/timewheel.go#L162-L166 |
18,247 | fagongzi/goetty | timewheel.go | NewTimeoutWheel | func NewTimeoutWheel(options ...Option) *TimeoutWheel {
opts := &opts{
tickInterval: defaultTickInterval,
size: defaultNumBuckets,
poolsize: defaultPoolSize,
}
for _, option := range options {
option(opts)
}
poolsize := opts.poolsize
if opts.size < opts.poolsize {
poolsize = opts.size
}
t := &TimeoutWheel{
mtxPool: make([]paddedMutex, poolsize),
freelists: make([]timeoutList, poolsize),
state: stopped,
poolMask: poolsize - 1,
buckets: make([]timeoutList, opts.size),
tickInterval: opts.tickInterval,
bucketMask: opts.size - 1,
ticks: 0,
}
t.Start()
return t
} | go | func NewTimeoutWheel(options ...Option) *TimeoutWheel {
opts := &opts{
tickInterval: defaultTickInterval,
size: defaultNumBuckets,
poolsize: defaultPoolSize,
}
for _, option := range options {
option(opts)
}
poolsize := opts.poolsize
if opts.size < opts.poolsize {
poolsize = opts.size
}
t := &TimeoutWheel{
mtxPool: make([]paddedMutex, poolsize),
freelists: make([]timeoutList, poolsize),
state: stopped,
poolMask: poolsize - 1,
buckets: make([]timeoutList, opts.size),
tickInterval: opts.tickInterval,
bucketMask: opts.size - 1,
ticks: 0,
}
t.Start()
return t
} | [
"func",
"NewTimeoutWheel",
"(",
"options",
"...",
"Option",
")",
"*",
"TimeoutWheel",
"{",
"opts",
":=",
"&",
"opts",
"{",
"tickInterval",
":",
"defaultTickInterval",
",",
"size",
":",
"defaultNumBuckets",
",",
"poolsize",
":",
"defaultPoolSize",
",",
"}",
"\n... | // NewTimeoutWheel creates and starts a new TimeoutWheel collection. | [
"NewTimeoutWheel",
"creates",
"and",
"starts",
"a",
"new",
"TimeoutWheel",
"collection",
"."
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/timewheel.go#L169-L197 |
18,248 | fagongzi/goetty | timewheel.go | Start | func (t *TimeoutWheel) Start() {
t.lockAllBuckets()
defer t.unlockAllBuckets()
for t.state != stopped {
switch t.state {
case stopping:
t.unlockAllBuckets()
<-t.done
t.lockAllBuckets()
case running:
panic("Tried to start a running TimeoutWheel")
}
}
t.state = running
t.done = make(chan struct{})
t.calloutCh = make(chan timeoutList)
go t.doTick()
go t.doExpired()
} | go | func (t *TimeoutWheel) Start() {
t.lockAllBuckets()
defer t.unlockAllBuckets()
for t.state != stopped {
switch t.state {
case stopping:
t.unlockAllBuckets()
<-t.done
t.lockAllBuckets()
case running:
panic("Tried to start a running TimeoutWheel")
}
}
t.state = running
t.done = make(chan struct{})
t.calloutCh = make(chan timeoutList)
go t.doTick()
go t.doExpired()
} | [
"func",
"(",
"t",
"*",
"TimeoutWheel",
")",
"Start",
"(",
")",
"{",
"t",
".",
"lockAllBuckets",
"(",
")",
"\n",
"defer",
"t",
".",
"unlockAllBuckets",
"(",
")",
"\n",
"for",
"t",
".",
"state",
"!=",
"stopped",
"{",
"switch",
"t",
".",
"state",
"{",... | // Start starts a stopped timeout wheel. Subsequent calls to Start panic. | [
"Start",
"starts",
"a",
"stopped",
"timeout",
"wheel",
".",
"Subsequent",
"calls",
"to",
"Start",
"panic",
"."
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/timewheel.go#L200-L221 |
18,249 | fagongzi/goetty | timewheel.go | Stop | func (t *TimeoutWheel) Stop() {
t.lockAllBuckets()
if t.state == running {
t.state = stopping
close(t.calloutCh)
for i := range t.buckets {
t.freeBucketLocked(t.buckets[i])
}
}
// unlock so the callouts can finish.
t.unlockAllBuckets()
<-t.done
} | go | func (t *TimeoutWheel) Stop() {
t.lockAllBuckets()
if t.state == running {
t.state = stopping
close(t.calloutCh)
for i := range t.buckets {
t.freeBucketLocked(t.buckets[i])
}
}
// unlock so the callouts can finish.
t.unlockAllBuckets()
<-t.done
} | [
"func",
"(",
"t",
"*",
"TimeoutWheel",
")",
"Stop",
"(",
")",
"{",
"t",
".",
"lockAllBuckets",
"(",
")",
"\n",
"if",
"t",
".",
"state",
"==",
"running",
"{",
"t",
".",
"state",
"=",
"stopping",
"\n",
"close",
"(",
"t",
".",
"calloutCh",
")",
"\n"... | // Stop stops tick processing, and deletes any remaining timeouts. | [
"Stop",
"stops",
"tick",
"processing",
"and",
"deletes",
"any",
"remaining",
"timeouts",
"."
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/timewheel.go#L224-L238 |
18,250 | fagongzi/goetty | timewheel.go | Schedule | func (t *TimeoutWheel) Schedule(
d time.Duration,
expireCb func(interface{}),
arg interface{},
) (Timeout, error) {
dTicks := (d + t.tickInterval - 1) / t.tickInterval
deadline := atomic.LoadUint64(&t.ticks) + uint64(dTicks)
timeout := t.getTimeoutLocked(deadline)
if t.state != running {
t.putTimeoutLocked(timeout)
timeout.mtx.Unlock()
return Timeout{}, ErrSystemStopped
}
bucket := &t.buckets[deadline&t.bucketMask]
timeout.expireCb = expireCb
timeout.expireArg = arg
timeout.deadline = deadline
timeout.state = timeoutActive
out := Timeout{timeout: timeout, generation: timeout.generation}
// execute the callback now, return a Timeout that is already Stopped (generation is bumped)
if bucket.lastTick >= deadline {
t.putTimeoutLocked(timeout)
timeout.mtx.Unlock()
expireCb(arg)
return out, nil
}
timeout.prependLocked(bucket)
timeout.mtx.Unlock()
return out, nil
} | go | func (t *TimeoutWheel) Schedule(
d time.Duration,
expireCb func(interface{}),
arg interface{},
) (Timeout, error) {
dTicks := (d + t.tickInterval - 1) / t.tickInterval
deadline := atomic.LoadUint64(&t.ticks) + uint64(dTicks)
timeout := t.getTimeoutLocked(deadline)
if t.state != running {
t.putTimeoutLocked(timeout)
timeout.mtx.Unlock()
return Timeout{}, ErrSystemStopped
}
bucket := &t.buckets[deadline&t.bucketMask]
timeout.expireCb = expireCb
timeout.expireArg = arg
timeout.deadline = deadline
timeout.state = timeoutActive
out := Timeout{timeout: timeout, generation: timeout.generation}
// execute the callback now, return a Timeout that is already Stopped (generation is bumped)
if bucket.lastTick >= deadline {
t.putTimeoutLocked(timeout)
timeout.mtx.Unlock()
expireCb(arg)
return out, nil
}
timeout.prependLocked(bucket)
timeout.mtx.Unlock()
return out, nil
} | [
"func",
"(",
"t",
"*",
"TimeoutWheel",
")",
"Schedule",
"(",
"d",
"time",
".",
"Duration",
",",
"expireCb",
"func",
"(",
"interface",
"{",
"}",
")",
",",
"arg",
"interface",
"{",
"}",
",",
")",
"(",
"Timeout",
",",
"error",
")",
"{",
"dTicks",
":="... | // Schedule adds a new function to be called after some duration of time has
// elapsed. The returned Timeout can be used to cancel calling the function. If the duration falls
// between two ticks, the latter tick is used. | [
"Schedule",
"adds",
"a",
"new",
"function",
"to",
"be",
"called",
"after",
"some",
"duration",
"of",
"time",
"has",
"elapsed",
".",
"The",
"returned",
"Timeout",
"can",
"be",
"used",
"to",
"cancel",
"calling",
"the",
"function",
".",
"If",
"the",
"duration... | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/timewheel.go#L243-L276 |
18,251 | fagongzi/goetty | timewheel.go | doTick | func (t *TimeoutWheel) doTick() {
var expiredList timeoutList
ticker := time.NewTicker(t.tickInterval)
for range ticker.C {
atomic.AddUint64(&t.ticks, 1)
mtx := t.lockBucket(t.ticks)
if t.state != running {
mtx.Unlock()
break
}
bucket := &t.buckets[t.ticks&t.bucketMask]
timeout := bucket.head
bucket.lastTick = t.ticks
// find all the expired timeouts in the bucket.
for timeout != nil {
next := timeout.next
if timeout.deadline <= t.ticks {
timeout.state = timeoutExpired
timeout.removeLocked()
timeout.prependLocked(&expiredList)
}
timeout = next
}
mtx.Unlock()
if expiredList.head == nil {
continue
}
select {
case t.calloutCh <- expiredList:
expiredList.head = nil
default:
}
}
ticker.Stop()
} | go | func (t *TimeoutWheel) doTick() {
var expiredList timeoutList
ticker := time.NewTicker(t.tickInterval)
for range ticker.C {
atomic.AddUint64(&t.ticks, 1)
mtx := t.lockBucket(t.ticks)
if t.state != running {
mtx.Unlock()
break
}
bucket := &t.buckets[t.ticks&t.bucketMask]
timeout := bucket.head
bucket.lastTick = t.ticks
// find all the expired timeouts in the bucket.
for timeout != nil {
next := timeout.next
if timeout.deadline <= t.ticks {
timeout.state = timeoutExpired
timeout.removeLocked()
timeout.prependLocked(&expiredList)
}
timeout = next
}
mtx.Unlock()
if expiredList.head == nil {
continue
}
select {
case t.calloutCh <- expiredList:
expiredList.head = nil
default:
}
}
ticker.Stop()
} | [
"func",
"(",
"t",
"*",
"TimeoutWheel",
")",
"doTick",
"(",
")",
"{",
"var",
"expiredList",
"timeoutList",
"\n",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"t",
".",
"tickInterval",
")",
"\n",
"for",
"range",
"ticker",
".",
"C",
"{",
"atomic",
".",
... | // doTick handles the ticker goroutine of the timer system | [
"doTick",
"handles",
"the",
"ticker",
"goroutine",
"of",
"the",
"timer",
"system"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/timewheel.go#L279-L320 |
18,252 | fagongzi/goetty | option.go | WithServerMiddleware | func WithServerMiddleware(middlewares ...Middleware) ServerOption {
return func(opts *serverOptions) {
opts.middlewares = append(opts.middlewares, middlewares...)
}
} | go | func WithServerMiddleware(middlewares ...Middleware) ServerOption {
return func(opts *serverOptions) {
opts.middlewares = append(opts.middlewares, middlewares...)
}
} | [
"func",
"WithServerMiddleware",
"(",
"middlewares",
"...",
"Middleware",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"serverOptions",
")",
"{",
"opts",
".",
"middlewares",
"=",
"append",
"(",
"opts",
".",
"middlewares",
",",
"middlewares",
".... | // WithServerMiddleware option of handle write timeout | [
"WithServerMiddleware",
"option",
"of",
"handle",
"write",
"timeout"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/option.go#L94-L98 |
18,253 | fagongzi/goetty | option.go | WithClientConnectTimeout | func WithClientConnectTimeout(timeout time.Duration) ClientOption {
return func(opts *clientOptions) {
opts.connectTimeout = timeout
}
} | go | func WithClientConnectTimeout(timeout time.Duration) ClientOption {
return func(opts *clientOptions) {
opts.connectTimeout = timeout
}
} | [
"func",
"WithClientConnectTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"ClientOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"clientOptions",
")",
"{",
"opts",
".",
"connectTimeout",
"=",
"timeout",
"\n",
"}",
"\n",
"}"
] | // WithClientConnectTimeout option of timeout to connect to server | [
"WithClientConnectTimeout",
"option",
"of",
"timeout",
"to",
"connect",
"to",
"server"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/option.go#L161-L165 |
18,254 | fagongzi/goetty | option.go | WithClientWriteTimeoutHandler | func WithClientWriteTimeoutHandler(timeout time.Duration, handler func(string, IOSession), timeWheel *TimeoutWheel) ClientOption {
return func(opts *clientOptions) {
opts.writeTimeout = timeout
opts.writeTimeoutHandler = handler
opts.timeWheel = timeWheel
}
} | go | func WithClientWriteTimeoutHandler(timeout time.Duration, handler func(string, IOSession), timeWheel *TimeoutWheel) ClientOption {
return func(opts *clientOptions) {
opts.writeTimeout = timeout
opts.writeTimeoutHandler = handler
opts.timeWheel = timeWheel
}
} | [
"func",
"WithClientWriteTimeoutHandler",
"(",
"timeout",
"time",
".",
"Duration",
",",
"handler",
"func",
"(",
"string",
",",
"IOSession",
")",
",",
"timeWheel",
"*",
"TimeoutWheel",
")",
"ClientOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"clientOptions",
... | // WithClientWriteTimeoutHandler option of handle write timeout | [
"WithClientWriteTimeoutHandler",
"option",
"of",
"handle",
"write",
"timeout"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/option.go#L168-L174 |
18,255 | fagongzi/goetty | option.go | WithClientMiddleware | func WithClientMiddleware(middlewares ...Middleware) ClientOption {
return func(opts *clientOptions) {
opts.middlewares = append(opts.middlewares, middlewares...)
}
} | go | func WithClientMiddleware(middlewares ...Middleware) ClientOption {
return func(opts *clientOptions) {
opts.middlewares = append(opts.middlewares, middlewares...)
}
} | [
"func",
"WithClientMiddleware",
"(",
"middlewares",
"...",
"Middleware",
")",
"ClientOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"clientOptions",
")",
"{",
"opts",
".",
"middlewares",
"=",
"append",
"(",
"opts",
".",
"middlewares",
",",
"middlewares",
".... | // WithClientMiddleware option of handle write timeout | [
"WithClientMiddleware",
"option",
"of",
"handle",
"write",
"timeout"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/option.go#L177-L181 |
18,256 | fagongzi/goetty | conv.go | BytesToUint64 | func BytesToUint64(b []byte) (uint64, error) {
if len(b) != 8 {
return 0, fmt.Errorf("invalid data, must 8 bytes, but %d", len(b))
}
return binary.BigEndian.Uint64(b), nil
} | go | func BytesToUint64(b []byte) (uint64, error) {
if len(b) != 8 {
return 0, fmt.Errorf("invalid data, must 8 bytes, but %d", len(b))
}
return binary.BigEndian.Uint64(b), nil
} | [
"func",
"BytesToUint64",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"if",
"len",
"(",
"b",
")",
"!=",
"8",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"b",
")",
")",
"\n",
"}... | // BytesToUint64 bytes -> uint64 | [
"BytesToUint64",
"bytes",
"-",
">",
"uint64"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/conv.go#L10-L16 |
18,257 | fagongzi/goetty | conv.go | Uint64ToBytes | func Uint64ToBytes(v uint64) []byte {
b := make([]byte, 8)
binary.BigEndian.PutUint64(b, v)
return b
} | go | func Uint64ToBytes(v uint64) []byte {
b := make([]byte, 8)
binary.BigEndian.PutUint64(b, v)
return b
} | [
"func",
"Uint64ToBytes",
"(",
"v",
"uint64",
")",
"[",
"]",
"byte",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"8",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint64",
"(",
"b",
",",
"v",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Uint64ToBytes uint64 -> bytes | [
"Uint64ToBytes",
"uint64",
"-",
">",
"bytes"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/conv.go#L19-L23 |
18,258 | fagongzi/goetty | middleware.go | PostWrite | func (sm *BaseMiddleware) PostWrite(msg interface{}, conn IOSession) (bool, error) {
return true, nil
} | go | func (sm *BaseMiddleware) PostWrite(msg interface{}, conn IOSession) (bool, error) {
return true, nil
} | [
"func",
"(",
"sm",
"*",
"BaseMiddleware",
")",
"PostWrite",
"(",
"msg",
"interface",
"{",
"}",
",",
"conn",
"IOSession",
")",
"(",
"bool",
",",
"error",
")",
"{",
"return",
"true",
",",
"nil",
"\n",
"}"
] | // PostWrite default reutrn value | [
"PostWrite",
"default",
"reutrn",
"value"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/middleware.go#L20-L22 |
18,259 | fagongzi/goetty | middleware.go | PreRead | func (sm *BaseMiddleware) PreRead(conn IOSession) (bool, interface{}, error) {
return true, nil, nil
} | go | func (sm *BaseMiddleware) PreRead(conn IOSession) (bool, interface{}, error) {
return true, nil, nil
} | [
"func",
"(",
"sm",
"*",
"BaseMiddleware",
")",
"PreRead",
"(",
"conn",
"IOSession",
")",
"(",
"bool",
",",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"return",
"true",
",",
"nil",
",",
"nil",
"\n",
"}"
] | // PreRead default reutrn value | [
"PreRead",
"default",
"reutrn",
"value"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/middleware.go#L30-L32 |
18,260 | fagongzi/goetty | middleware.go | PostRead | func (sm *BaseMiddleware) PostRead(msg interface{}, conn IOSession) (bool, interface{}, error) {
return false, true, nil
} | go | func (sm *BaseMiddleware) PostRead(msg interface{}, conn IOSession) (bool, interface{}, error) {
return false, true, nil
} | [
"func",
"(",
"sm",
"*",
"BaseMiddleware",
")",
"PostRead",
"(",
"msg",
"interface",
"{",
"}",
",",
"conn",
"IOSession",
")",
"(",
"bool",
",",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"return",
"false",
",",
"true",
",",
"nil",
"\n",
"}"
] | // PostRead default reutrn value | [
"PostRead",
"default",
"reutrn",
"value"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/middleware.go#L35-L37 |
18,261 | fagongzi/goetty | example/echo_client.go | NewEchoClient | func NewEchoClient(serverAddr string) (*EchoClient, error) {
c := &EchoClient{
serverAddr: serverAddr,
}
c.conn = goetty.NewConnector(serverAddr,
goetty.WithClientConnectTimeout(time.Second*3),
goetty.WithClientDecoder(&StringDecoder{}),
goetty.WithClientEncoder(&StringEncoder{}),
// if you want to send heartbeat to server, you can set conf as below, otherwise not set
goetty.WithClientWriteTimeoutHandler(time.Second*3, c.writeHeartbeat, goetty.NewTimeoutWheel(goetty.WithTickInterval(time.Second))))
_, err := c.conn.Connect()
return c, err
} | go | func NewEchoClient(serverAddr string) (*EchoClient, error) {
c := &EchoClient{
serverAddr: serverAddr,
}
c.conn = goetty.NewConnector(serverAddr,
goetty.WithClientConnectTimeout(time.Second*3),
goetty.WithClientDecoder(&StringDecoder{}),
goetty.WithClientEncoder(&StringEncoder{}),
// if you want to send heartbeat to server, you can set conf as below, otherwise not set
goetty.WithClientWriteTimeoutHandler(time.Second*3, c.writeHeartbeat, goetty.NewTimeoutWheel(goetty.WithTickInterval(time.Second))))
_, err := c.conn.Connect()
return c, err
} | [
"func",
"NewEchoClient",
"(",
"serverAddr",
"string",
")",
"(",
"*",
"EchoClient",
",",
"error",
")",
"{",
"c",
":=",
"&",
"EchoClient",
"{",
"serverAddr",
":",
"serverAddr",
",",
"}",
"\n",
"c",
".",
"conn",
"=",
"goetty",
".",
"NewConnector",
"(",
"s... | // NewEchoClient new client | [
"NewEchoClient",
"new",
"client"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/example/echo_client.go#L17-L31 |
18,262 | fagongzi/goetty | example/echo_client.go | SendMsg | func (c *EchoClient) SendMsg(msg string) error {
return c.conn.Write(msg)
} | go | func (c *EchoClient) SendMsg(msg string) error {
return c.conn.Write(msg)
} | [
"func",
"(",
"c",
"*",
"EchoClient",
")",
"SendMsg",
"(",
"msg",
"string",
")",
"error",
"{",
"return",
"c",
".",
"conn",
".",
"Write",
"(",
"msg",
")",
"\n",
"}"
] | // SendMsg send msg to server | [
"SendMsg",
"send",
"msg",
"to",
"server"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/example/echo_client.go#L38-L40 |
18,263 | fagongzi/goetty | example/echo_client.go | ReadLoop | func (c *EchoClient) ReadLoop() error {
// start loop to read msg from server
for {
msg, err := c.conn.Read() // if you want set a read deadline, you can use 'connector.ReadTimeout(timeout)'
if err != nil {
fmt.Printf("read msg from server<%s> failure", c.serverAddr)
return err
}
fmt.Printf("receive a msg<%s> from <%s>", msg, c.serverAddr)
}
} | go | func (c *EchoClient) ReadLoop() error {
// start loop to read msg from server
for {
msg, err := c.conn.Read() // if you want set a read deadline, you can use 'connector.ReadTimeout(timeout)'
if err != nil {
fmt.Printf("read msg from server<%s> failure", c.serverAddr)
return err
}
fmt.Printf("receive a msg<%s> from <%s>", msg, c.serverAddr)
}
} | [
"func",
"(",
"c",
"*",
"EchoClient",
")",
"ReadLoop",
"(",
")",
"error",
"{",
"// start loop to read msg from server\r",
"for",
"{",
"msg",
",",
"err",
":=",
"c",
".",
"conn",
".",
"Read",
"(",
")",
"// if you want set a read deadline, you can use 'connector.ReadTim... | // ReadLoop read loop | [
"ReadLoop",
"read",
"loop"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/example/echo_client.go#L43-L54 |
18,264 | fagongzi/goetty | connector.go | NewConnector | func NewConnector(svrAddr string, opts ...ClientOption) IOSession {
sopts := &clientOptions{}
for _, opt := range opts {
opt(sopts)
}
sopts.adjust()
return &connector{
addr: svrAddr,
in: NewByteBuf(sopts.readBufSize),
out: NewByteBuf(sopts.writeBufSize),
opts: sopts,
attrs: make(map[string]interface{}),
}
} | go | func NewConnector(svrAddr string, opts ...ClientOption) IOSession {
sopts := &clientOptions{}
for _, opt := range opts {
opt(sopts)
}
sopts.adjust()
return &connector{
addr: svrAddr,
in: NewByteBuf(sopts.readBufSize),
out: NewByteBuf(sopts.writeBufSize),
opts: sopts,
attrs: make(map[string]interface{}),
}
} | [
"func",
"NewConnector",
"(",
"svrAddr",
"string",
",",
"opts",
"...",
"ClientOption",
")",
"IOSession",
"{",
"sopts",
":=",
"&",
"clientOptions",
"{",
"}",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"opt",
"(",
"sopts",
")",
"\n",
"}",
... | // NewConnector create a new connector with opts | [
"NewConnector",
"create",
"a",
"new",
"connector",
"with",
"opts"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/connector.go#L36-L50 |
18,265 | fagongzi/goetty | connector.go | IsConnected | func (c *connector) IsConnected() bool {
return nil != c.conn && atomic.LoadInt32(&c.closed) == 0
} | go | func (c *connector) IsConnected() bool {
return nil != c.conn && atomic.LoadInt32(&c.closed) == 0
} | [
"func",
"(",
"c",
"*",
"connector",
")",
"IsConnected",
"(",
")",
"bool",
"{",
"return",
"nil",
"!=",
"c",
".",
"conn",
"&&",
"atomic",
".",
"LoadInt32",
"(",
"&",
"c",
".",
"closed",
")",
"==",
"0",
"\n",
"}"
] | // IsConnected is connected | [
"IsConnected",
"is",
"connected"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/connector.go#L128-L130 |
18,266 | fagongzi/goetty | connector.go | ReadTimeout | func (c *connector) ReadTimeout(timeout time.Duration) (interface{}, error) {
for {
if !c.IsConnected() {
return nil, ErrIllegalState
}
doRead, msg, err := c.doPreRead()
if err != nil {
return nil, err
}
if !doRead {
return msg, nil
}
var complete bool
for {
if c.in.Readable() > 0 {
complete, msg, err = c.opts.decoder.Decode(c.in)
if !complete && err == nil {
complete, msg, err = c.readFromConn(timeout)
}
} else {
complete, msg, err = c.readFromConn(timeout)
}
if nil != err {
c.in.Clear()
return nil, err
}
if complete {
break
}
}
if c.in.Readable() == 0 {
c.in.Clear()
}
returnRead, readMsg, err := c.doPostRead(msg)
if err != nil {
return nil, err
}
if returnRead {
return readMsg, err
}
}
} | go | func (c *connector) ReadTimeout(timeout time.Duration) (interface{}, error) {
for {
if !c.IsConnected() {
return nil, ErrIllegalState
}
doRead, msg, err := c.doPreRead()
if err != nil {
return nil, err
}
if !doRead {
return msg, nil
}
var complete bool
for {
if c.in.Readable() > 0 {
complete, msg, err = c.opts.decoder.Decode(c.in)
if !complete && err == nil {
complete, msg, err = c.readFromConn(timeout)
}
} else {
complete, msg, err = c.readFromConn(timeout)
}
if nil != err {
c.in.Clear()
return nil, err
}
if complete {
break
}
}
if c.in.Readable() == 0 {
c.in.Clear()
}
returnRead, readMsg, err := c.doPostRead(msg)
if err != nil {
return nil, err
}
if returnRead {
return readMsg, err
}
}
} | [
"func",
"(",
"c",
"*",
"connector",
")",
"ReadTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"for",
"{",
"if",
"!",
"c",
".",
"IsConnected",
"(",
")",
"{",
"return",
"nil",
",",
"ErrIlleg... | // ReadTimeout read data from server with a timeout duration | [
"ReadTimeout",
"read",
"data",
"from",
"server",
"with",
"a",
"timeout",
"duration"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/connector.go#L149-L199 |
18,267 | fagongzi/goetty | protocol/redis/req.go | InitRedisConn | func InitRedisConn(conn goetty.IOSession) {
conn.SetAttr(lenScratch, make([]byte, 32, 32))
conn.SetAttr(numScratch, make([]byte, 40, 40))
} | go | func InitRedisConn(conn goetty.IOSession) {
conn.SetAttr(lenScratch, make([]byte, 32, 32))
conn.SetAttr(numScratch, make([]byte, 40, 40))
} | [
"func",
"InitRedisConn",
"(",
"conn",
"goetty",
".",
"IOSession",
")",
"{",
"conn",
".",
"SetAttr",
"(",
"lenScratch",
",",
"make",
"(",
"[",
"]",
"byte",
",",
"32",
",",
"32",
")",
")",
"\n",
"conn",
".",
"SetAttr",
"(",
"numScratch",
",",
"make",
... | // InitRedisConn init redis conn | [
"InitRedisConn",
"init",
"redis",
"conn"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/protocol/redis/req.go#L15-L18 |
18,268 | fagongzi/goetty | protocol/redis/req.go | WriteCommand | func WriteCommand(conn goetty.IOSession, cmd string, args ...interface{}) error {
lenV := conn.GetAttr(lenScratch).([]byte)
numV := conn.GetAttr(lenScratch).([]byte)
return doWriteCommand(cmd, lenV, numV, conn.OutBuf(), args...)
} | go | func WriteCommand(conn goetty.IOSession, cmd string, args ...interface{}) error {
lenV := conn.GetAttr(lenScratch).([]byte)
numV := conn.GetAttr(lenScratch).([]byte)
return doWriteCommand(cmd, lenV, numV, conn.OutBuf(), args...)
} | [
"func",
"WriteCommand",
"(",
"conn",
"goetty",
".",
"IOSession",
",",
"cmd",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"lenV",
":=",
"conn",
".",
"GetAttr",
"(",
"lenScratch",
")",
".",
"(",
"[",
"]",
"byte",
")",
"\n",
... | // WriteCommand write redis command | [
"WriteCommand",
"write",
"redis",
"command"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/protocol/redis/req.go#L21-L26 |
18,269 | fagongzi/goetty | example/echo_server.go | NewEchoServer | func NewEchoServer(addr string) *EchoServer {
return &EchoServer{
addr: addr,
server: goetty.NewServer(addr,
goetty.WithServerDecoder(goetty.NewIntLengthFieldBasedDecoder(&StringDecoder{})),
goetty.WithServerEncoder(&StringEncoder{})),
}
} | go | func NewEchoServer(addr string) *EchoServer {
return &EchoServer{
addr: addr,
server: goetty.NewServer(addr,
goetty.WithServerDecoder(goetty.NewIntLengthFieldBasedDecoder(&StringDecoder{})),
goetty.WithServerEncoder(&StringEncoder{})),
}
} | [
"func",
"NewEchoServer",
"(",
"addr",
"string",
")",
"*",
"EchoServer",
"{",
"return",
"&",
"EchoServer",
"{",
"addr",
":",
"addr",
",",
"server",
":",
"goetty",
".",
"NewServer",
"(",
"addr",
",",
"goetty",
".",
"WithServerDecoder",
"(",
"goetty",
".",
... | // NewEchoServer create new server | [
"NewEchoServer",
"create",
"new",
"server"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/example/echo_server.go#L16-L23 |
18,270 | fagongzi/goetty | server.go | NewServer | func NewServer(addr string, opts ...ServerOption) *Server {
sopts := &serverOptions{}
for _, opt := range opts {
opt(sopts)
}
sopts.adjust()
s := &Server{
addr: addr,
sessionMaps: make(map[int]*sessionMap, sopts.sessionBucketSize),
opts: sopts,
stopOnce: &sync.Once{},
startCh: make(chan struct{}, 1),
}
for i := 0; i < sopts.sessionBucketSize; i++ {
s.sessionMaps[i] = &sessionMap{
sessions: make(map[interface{}]IOSession),
}
}
return s
} | go | func NewServer(addr string, opts ...ServerOption) *Server {
sopts := &serverOptions{}
for _, opt := range opts {
opt(sopts)
}
sopts.adjust()
s := &Server{
addr: addr,
sessionMaps: make(map[int]*sessionMap, sopts.sessionBucketSize),
opts: sopts,
stopOnce: &sync.Once{},
startCh: make(chan struct{}, 1),
}
for i := 0; i < sopts.sessionBucketSize; i++ {
s.sessionMaps[i] = &sessionMap{
sessions: make(map[interface{}]IOSession),
}
}
return s
} | [
"func",
"NewServer",
"(",
"addr",
"string",
",",
"opts",
"...",
"ServerOption",
")",
"*",
"Server",
"{",
"sopts",
":=",
"&",
"serverOptions",
"{",
"}",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"opt",
"(",
"sopts",
")",
"\n",
"}",
"... | // NewServer create server | [
"NewServer",
"create",
"server"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/server.go#L81-L104 |
18,271 | fagongzi/goetty | server.go | Stop | func (s *Server) Stop() {
s.stopOnce.Do(func() {
s.stopped = true
s.listener.Close()
close(s.startCh)
})
} | go | func (s *Server) Stop() {
s.stopOnce.Do(func() {
s.stopped = true
s.listener.Close()
close(s.startCh)
})
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Stop",
"(",
")",
"{",
"s",
".",
"stopOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"s",
".",
"stopped",
"=",
"true",
"\n",
"s",
".",
"listener",
".",
"Close",
"(",
")",
"\n",
"close",
"(",
"s",
".",
"s... | // Stop stop server | [
"Stop",
"stop",
"server"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/server.go#L112-L118 |
18,272 | fagongzi/goetty | server.go | Start | func (s *Server) Start(loopFn func(IOSession) error) error {
addr, err := net.ResolveTCPAddr("tcp", s.addr)
if err != nil {
return err
}
s.listener, err = net.ListenTCP("tcp", addr)
if err != nil {
return err
}
s.startCh <- struct{}{}
var tempDelay time.Duration
for {
conn, err := s.listener.AcceptTCP()
if s.stopped {
if nil != conn {
conn.Close()
}
return nil
}
if err != nil {
if ne, ok := err.(net.Error); ok && ne.Temporary() {
if tempDelay == 0 {
tempDelay = 5 * time.Millisecond
} else {
tempDelay *= 2
}
if max := 1 * time.Second; tempDelay > max {
tempDelay = max
}
time.Sleep(tempDelay)
continue
}
return err
}
tempDelay = 0
session := newClientIOSession(s.opts.generator.NewID(), conn, s)
s.addSession(session)
go func() {
defer func() {
if err := recover(); err != nil {
const size = 64 << 10
rBuf := make([]byte, size)
rBuf = rBuf[:runtime.Stack(rBuf, false)]
log.Printf("goetty: connection painc %+v, stack:\n%s",
err,
rBuf)
}
}()
loopFn(session)
session.Close()
s.deleteSession(session)
}()
}
} | go | func (s *Server) Start(loopFn func(IOSession) error) error {
addr, err := net.ResolveTCPAddr("tcp", s.addr)
if err != nil {
return err
}
s.listener, err = net.ListenTCP("tcp", addr)
if err != nil {
return err
}
s.startCh <- struct{}{}
var tempDelay time.Duration
for {
conn, err := s.listener.AcceptTCP()
if s.stopped {
if nil != conn {
conn.Close()
}
return nil
}
if err != nil {
if ne, ok := err.(net.Error); ok && ne.Temporary() {
if tempDelay == 0 {
tempDelay = 5 * time.Millisecond
} else {
tempDelay *= 2
}
if max := 1 * time.Second; tempDelay > max {
tempDelay = max
}
time.Sleep(tempDelay)
continue
}
return err
}
tempDelay = 0
session := newClientIOSession(s.opts.generator.NewID(), conn, s)
s.addSession(session)
go func() {
defer func() {
if err := recover(); err != nil {
const size = 64 << 10
rBuf := make([]byte, size)
rBuf = rBuf[:runtime.Stack(rBuf, false)]
log.Printf("goetty: connection painc %+v, stack:\n%s",
err,
rBuf)
}
}()
loopFn(session)
session.Close()
s.deleteSession(session)
}()
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Start",
"(",
"loopFn",
"func",
"(",
"IOSession",
")",
"error",
")",
"error",
"{",
"addr",
",",
"err",
":=",
"net",
".",
"ResolveTCPAddr",
"(",
"\"",
"\"",
",",
"s",
".",
"addr",
")",
"\n",
"if",
"err",
"!=",... | // Start start the server, this method will block until occur a error | [
"Start",
"start",
"the",
"server",
"this",
"method",
"will",
"block",
"until",
"occur",
"a",
"error"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/server.go#L121-L185 |
18,273 | fagongzi/goetty | server.go | GetSession | func (s *Server) GetSession(id interface{}) IOSession {
m := s.sessionMaps[getHash(id)%DefaultSessionBucketSize]
m.RLock()
session := m.sessions[id]
m.RUnlock()
return session
} | go | func (s *Server) GetSession(id interface{}) IOSession {
m := s.sessionMaps[getHash(id)%DefaultSessionBucketSize]
m.RLock()
session := m.sessions[id]
m.RUnlock()
return session
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"GetSession",
"(",
"id",
"interface",
"{",
"}",
")",
"IOSession",
"{",
"m",
":=",
"s",
".",
"sessionMaps",
"[",
"getHash",
"(",
"id",
")",
"%",
"DefaultSessionBucketSize",
"]",
"\n",
"m",
".",
"RLock",
"(",
")",
... | // GetSession get session by id | [
"GetSession",
"get",
"session",
"by",
"id"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/server.go#L210-L216 |
18,274 | fagongzi/goetty | session.go | ReadTimeout | func (s *clientIOSession) ReadTimeout(timeout time.Duration) (interface{}, error) {
for {
doRead, msg, err := s.doPreRead()
if err != nil {
return nil, err
}
if !doRead {
return msg, nil
}
var complete bool
for {
if s.in.Readable() > 0 {
complete, msg, err = s.svr.opts.decoder.Decode(s.in)
if !complete && err == nil {
complete, msg, err = s.readFromConn(timeout)
}
} else {
complete, msg, err = s.readFromConn(timeout)
}
if nil != err {
s.in.Clear()
return nil, err
}
if complete {
break
}
}
if s.in.Readable() == 0 {
s.in.Clear()
}
returnRead, readedMsg, err := s.doPostRead(msg)
if err != nil {
return nil, err
}
if returnRead {
return readedMsg, err
}
}
} | go | func (s *clientIOSession) ReadTimeout(timeout time.Duration) (interface{}, error) {
for {
doRead, msg, err := s.doPreRead()
if err != nil {
return nil, err
}
if !doRead {
return msg, nil
}
var complete bool
for {
if s.in.Readable() > 0 {
complete, msg, err = s.svr.opts.decoder.Decode(s.in)
if !complete && err == nil {
complete, msg, err = s.readFromConn(timeout)
}
} else {
complete, msg, err = s.readFromConn(timeout)
}
if nil != err {
s.in.Clear()
return nil, err
}
if complete {
break
}
}
if s.in.Readable() == 0 {
s.in.Clear()
}
returnRead, readedMsg, err := s.doPostRead(msg)
if err != nil {
return nil, err
}
if returnRead {
return readedMsg, err
}
}
} | [
"func",
"(",
"s",
"*",
"clientIOSession",
")",
"ReadTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"for",
"{",
"doRead",
",",
"msg",
",",
"err",
":=",
"s",
".",
"doPreRead",
"(",
")",
"\n... | // ReadTimeout read a msg with a timeout duration | [
"ReadTimeout",
"read",
"a",
"msg",
"with",
"a",
"timeout",
"duration"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/session.go#L81-L126 |
18,275 | fagongzi/goetty | protocol/redis/cmd.go | ToString | func (c Command) ToString() string {
buf := new(bytes.Buffer)
for _, arg := range c {
buf.Write(arg)
buf.WriteString(" ")
}
return strings.TrimSpace(buf.String())
} | go | func (c Command) ToString() string {
buf := new(bytes.Buffer)
for _, arg := range c {
buf.Write(arg)
buf.WriteString(" ")
}
return strings.TrimSpace(buf.String())
} | [
"func",
"(",
"c",
"Command",
")",
"ToString",
"(",
")",
"string",
"{",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"for",
"_",
",",
"arg",
":=",
"range",
"c",
"{",
"buf",
".",
"Write",
"(",
"arg",
")",
"\n",
"buf",
".",
"WriteSt... | // ToString returns a redis command as string | [
"ToString",
"returns",
"a",
"redis",
"command",
"as",
"string"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/protocol/redis/cmd.go#L29-L37 |
18,276 | fagongzi/goetty | uuid.go | newFromHash | func newFromHash(h hash.Hash, ns UUID, name string) UUID {
u := UUID{}
h.Write(ns[:])
h.Write([]byte(name))
copy(u[:], h.Sum(nil))
return u
} | go | func newFromHash(h hash.Hash, ns UUID, name string) UUID {
u := UUID{}
h.Write(ns[:])
h.Write([]byte(name))
copy(u[:], h.Sum(nil))
return u
} | [
"func",
"newFromHash",
"(",
"h",
"hash",
".",
"Hash",
",",
"ns",
"UUID",
",",
"name",
"string",
")",
"UUID",
"{",
"u",
":=",
"UUID",
"{",
"}",
"\n",
"h",
".",
"Write",
"(",
"ns",
"[",
":",
"]",
")",
"\n",
"h",
".",
"Write",
"(",
"[",
"]",
"... | // Returns UUID based on hashing of namespace UUID and name. | [
"Returns",
"UUID",
"based",
"on",
"hashing",
"of",
"namespace",
"UUID",
"and",
"name",
"."
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/uuid.go#L406-L413 |
18,277 | fagongzi/goetty | protocol/redis/reply.go | WriteError | func WriteError(err []byte, buf *goetty.ByteBuf) {
buf.WriteByte('-')
if err != nil {
buf.WriteByte(' ')
buf.Write(err)
}
buf.Write(Delims)
} | go | func WriteError(err []byte, buf *goetty.ByteBuf) {
buf.WriteByte('-')
if err != nil {
buf.WriteByte(' ')
buf.Write(err)
}
buf.Write(Delims)
} | [
"func",
"WriteError",
"(",
"err",
"[",
"]",
"byte",
",",
"buf",
"*",
"goetty",
".",
"ByteBuf",
")",
"{",
"buf",
".",
"WriteByte",
"(",
"'-'",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"buf",
".",
"WriteByte",
"(",
"' '",
")",
"\n",
"buf",
".",
... | // WriteError write error resp | [
"WriteError",
"write",
"error",
"resp"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/protocol/redis/reply.go#L11-L18 |
18,278 | fagongzi/goetty | protocol/redis/reply.go | WriteStatus | func WriteStatus(status []byte, buf *goetty.ByteBuf) {
buf.WriteByte('+')
buf.Write(status)
buf.Write(Delims)
} | go | func WriteStatus(status []byte, buf *goetty.ByteBuf) {
buf.WriteByte('+')
buf.Write(status)
buf.Write(Delims)
} | [
"func",
"WriteStatus",
"(",
"status",
"[",
"]",
"byte",
",",
"buf",
"*",
"goetty",
".",
"ByteBuf",
")",
"{",
"buf",
".",
"WriteByte",
"(",
"'+'",
")",
"\n",
"buf",
".",
"Write",
"(",
"status",
")",
"\n",
"buf",
".",
"Write",
"(",
"Delims",
")",
"... | // WriteStatus write status resp | [
"WriteStatus",
"write",
"status",
"resp"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/protocol/redis/reply.go#L21-L25 |
18,279 | fagongzi/goetty | protocol/redis/reply.go | WriteInteger | func WriteInteger(n int64, buf *goetty.ByteBuf) {
buf.WriteByte(':')
buf.Write(goetty.FormatInt64ToBytes(n))
buf.Write(Delims)
} | go | func WriteInteger(n int64, buf *goetty.ByteBuf) {
buf.WriteByte(':')
buf.Write(goetty.FormatInt64ToBytes(n))
buf.Write(Delims)
} | [
"func",
"WriteInteger",
"(",
"n",
"int64",
",",
"buf",
"*",
"goetty",
".",
"ByteBuf",
")",
"{",
"buf",
".",
"WriteByte",
"(",
"':'",
")",
"\n",
"buf",
".",
"Write",
"(",
"goetty",
".",
"FormatInt64ToBytes",
"(",
"n",
")",
")",
"\n",
"buf",
".",
"Wr... | // WriteInteger write integer resp | [
"WriteInteger",
"write",
"integer",
"resp"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/protocol/redis/reply.go#L28-L32 |
18,280 | fagongzi/goetty | protocol/redis/reply.go | WriteBulk | func WriteBulk(b []byte, buf *goetty.ByteBuf) {
buf.WriteByte('$')
if len(b) == 0 {
buf.Write(NullBulk)
} else {
buf.Write(goetty.StringToSlice(strconv.Itoa(len(b))))
buf.Write(Delims)
buf.Write(b)
}
buf.Write(Delims)
} | go | func WriteBulk(b []byte, buf *goetty.ByteBuf) {
buf.WriteByte('$')
if len(b) == 0 {
buf.Write(NullBulk)
} else {
buf.Write(goetty.StringToSlice(strconv.Itoa(len(b))))
buf.Write(Delims)
buf.Write(b)
}
buf.Write(Delims)
} | [
"func",
"WriteBulk",
"(",
"b",
"[",
"]",
"byte",
",",
"buf",
"*",
"goetty",
".",
"ByteBuf",
")",
"{",
"buf",
".",
"WriteByte",
"(",
"'$'",
")",
"\n",
"if",
"len",
"(",
"b",
")",
"==",
"0",
"{",
"buf",
".",
"Write",
"(",
"NullBulk",
")",
"\n",
... | // WriteBulk write bulk resp | [
"WriteBulk",
"write",
"bulk",
"resp"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/protocol/redis/reply.go#L35-L46 |
18,281 | fagongzi/goetty | protocol/redis/reply.go | WriteArray | func WriteArray(lst []interface{}, buf *goetty.ByteBuf) {
buf.WriteByte('*')
if len(lst) == 0 {
buf.Write(NullArray)
buf.Write(Delims)
} else {
buf.Write(goetty.StringToSlice(strconv.Itoa(len(lst))))
buf.Write(Delims)
for i := 0; i < len(lst); i++ {
switch v := lst[i].(type) {
case []interface{}:
WriteArray(v, buf)
case [][]byte:
WriteSliceArray(v, buf)
case []byte:
WriteBulk(v, buf)
case nil:
WriteBulk(nil, buf)
case int64:
WriteInteger(v, buf)
case string:
WriteStatus(goetty.StringToSlice(v), buf)
case error:
WriteError(goetty.StringToSlice(v.Error()), buf)
default:
panic(fmt.Sprintf("invalid array type %T %v", lst[i], v))
}
}
}
} | go | func WriteArray(lst []interface{}, buf *goetty.ByteBuf) {
buf.WriteByte('*')
if len(lst) == 0 {
buf.Write(NullArray)
buf.Write(Delims)
} else {
buf.Write(goetty.StringToSlice(strconv.Itoa(len(lst))))
buf.Write(Delims)
for i := 0; i < len(lst); i++ {
switch v := lst[i].(type) {
case []interface{}:
WriteArray(v, buf)
case [][]byte:
WriteSliceArray(v, buf)
case []byte:
WriteBulk(v, buf)
case nil:
WriteBulk(nil, buf)
case int64:
WriteInteger(v, buf)
case string:
WriteStatus(goetty.StringToSlice(v), buf)
case error:
WriteError(goetty.StringToSlice(v.Error()), buf)
default:
panic(fmt.Sprintf("invalid array type %T %v", lst[i], v))
}
}
}
} | [
"func",
"WriteArray",
"(",
"lst",
"[",
"]",
"interface",
"{",
"}",
",",
"buf",
"*",
"goetty",
".",
"ByteBuf",
")",
"{",
"buf",
".",
"WriteByte",
"(",
"'*'",
")",
"\n",
"if",
"len",
"(",
"lst",
")",
"==",
"0",
"{",
"buf",
".",
"Write",
"(",
"Nul... | // WriteArray write array resp | [
"WriteArray",
"write",
"array",
"resp"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/protocol/redis/reply.go#L49-L79 |
18,282 | fagongzi/goetty | protocol/redis/reply.go | WriteSliceArray | func WriteSliceArray(lst [][]byte, buf *goetty.ByteBuf) {
buf.WriteByte('*')
if len(lst) == 0 {
buf.Write(NullArray)
buf.Write(Delims)
} else {
buf.Write(goetty.StringToSlice(strconv.Itoa(len(lst))))
buf.Write(Delims)
for i := 0; i < len(lst); i++ {
WriteBulk(lst[i], buf)
}
}
} | go | func WriteSliceArray(lst [][]byte, buf *goetty.ByteBuf) {
buf.WriteByte('*')
if len(lst) == 0 {
buf.Write(NullArray)
buf.Write(Delims)
} else {
buf.Write(goetty.StringToSlice(strconv.Itoa(len(lst))))
buf.Write(Delims)
for i := 0; i < len(lst); i++ {
WriteBulk(lst[i], buf)
}
}
} | [
"func",
"WriteSliceArray",
"(",
"lst",
"[",
"]",
"[",
"]",
"byte",
",",
"buf",
"*",
"goetty",
".",
"ByteBuf",
")",
"{",
"buf",
".",
"WriteByte",
"(",
"'*'",
")",
"\n",
"if",
"len",
"(",
"lst",
")",
"==",
"0",
"{",
"buf",
".",
"Write",
"(",
"Nul... | // WriteSliceArray write slice array resp | [
"WriteSliceArray",
"write",
"slice",
"array",
"resp"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/protocol/redis/reply.go#L82-L95 |
18,283 | fagongzi/goetty | protocol/redis/reply.go | WriteFVPairArray | func WriteFVPairArray(fields, values [][]byte, buf *goetty.ByteBuf) {
buf.WriteByte('*')
if len(fields) == 0 || len(values) == 0 {
buf.Write(NullArray)
buf.Write(Delims)
} else {
buf.Write(goetty.StringToSlice(strconv.Itoa(len(fields) * 2)))
buf.Write(Delims)
for i := 0; i < len(values); i++ {
WriteBulk(fields[i], buf)
WriteBulk(values[i], buf)
}
}
} | go | func WriteFVPairArray(fields, values [][]byte, buf *goetty.ByteBuf) {
buf.WriteByte('*')
if len(fields) == 0 || len(values) == 0 {
buf.Write(NullArray)
buf.Write(Delims)
} else {
buf.Write(goetty.StringToSlice(strconv.Itoa(len(fields) * 2)))
buf.Write(Delims)
for i := 0; i < len(values); i++ {
WriteBulk(fields[i], buf)
WriteBulk(values[i], buf)
}
}
} | [
"func",
"WriteFVPairArray",
"(",
"fields",
",",
"values",
"[",
"]",
"[",
"]",
"byte",
",",
"buf",
"*",
"goetty",
".",
"ByteBuf",
")",
"{",
"buf",
".",
"WriteByte",
"(",
"'*'",
")",
"\n",
"if",
"len",
"(",
"fields",
")",
"==",
"0",
"||",
"len",
"(... | // WriteFVPairArray write field-value pair array resp | [
"WriteFVPairArray",
"write",
"field",
"-",
"value",
"pair",
"array",
"resp"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/protocol/redis/reply.go#L98-L112 |
18,284 | fagongzi/goetty | protocol/redis/reply.go | WriteScorePairArray | func WriteScorePairArray(members [][]byte, scores []float64, withScores bool, buf *goetty.ByteBuf) {
buf.WriteByte('*')
if len(members) == 0 || len(scores) == 0 {
buf.Write(NullArray)
buf.Write(Delims)
} else {
if withScores {
buf.Write(goetty.StringToSlice(strconv.Itoa(len(members) * 2)))
buf.Write(Delims)
} else {
buf.Write(goetty.StringToSlice(strconv.Itoa(len(members))))
buf.Write(Delims)
}
for i := 0; i < len(members); i++ {
WriteBulk(members[i], buf)
if withScores {
WriteBulk(goetty.FormatFloat64ToBytes(scores[i]), buf)
}
}
}
} | go | func WriteScorePairArray(members [][]byte, scores []float64, withScores bool, buf *goetty.ByteBuf) {
buf.WriteByte('*')
if len(members) == 0 || len(scores) == 0 {
buf.Write(NullArray)
buf.Write(Delims)
} else {
if withScores {
buf.Write(goetty.StringToSlice(strconv.Itoa(len(members) * 2)))
buf.Write(Delims)
} else {
buf.Write(goetty.StringToSlice(strconv.Itoa(len(members))))
buf.Write(Delims)
}
for i := 0; i < len(members); i++ {
WriteBulk(members[i], buf)
if withScores {
WriteBulk(goetty.FormatFloat64ToBytes(scores[i]), buf)
}
}
}
} | [
"func",
"WriteScorePairArray",
"(",
"members",
"[",
"]",
"[",
"]",
"byte",
",",
"scores",
"[",
"]",
"float64",
",",
"withScores",
"bool",
",",
"buf",
"*",
"goetty",
".",
"ByteBuf",
")",
"{",
"buf",
".",
"WriteByte",
"(",
"'*'",
")",
"\n",
"if",
"len"... | // WriteScorePairArray write score-member pair array resp | [
"WriteScorePairArray",
"write",
"score",
"-",
"member",
"pair",
"array",
"resp"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/protocol/redis/reply.go#L115-L138 |
18,285 | fagongzi/goetty | sync_queue.go | Add | func (q *OffsetQueue) Add(item interface{}) uint64 {
q.Lock()
q.end++
q.items = append(q.items, item)
max := q.getMaxOffset0()
q.Unlock()
return max
} | go | func (q *OffsetQueue) Add(item interface{}) uint64 {
q.Lock()
q.end++
q.items = append(q.items, item)
max := q.getMaxOffset0()
q.Unlock()
return max
} | [
"func",
"(",
"q",
"*",
"OffsetQueue",
")",
"Add",
"(",
"item",
"interface",
"{",
"}",
")",
"uint64",
"{",
"q",
".",
"Lock",
"(",
")",
"\n",
"q",
".",
"end",
"++",
"\n",
"q",
".",
"items",
"=",
"append",
"(",
"q",
".",
"items",
",",
"item",
")... | // Add add a item to the queue | [
"Add",
"add",
"a",
"item",
"to",
"the",
"queue"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/sync_queue.go#L34-L41 |
18,286 | fagongzi/goetty | sync_queue.go | Get | func (q *OffsetQueue) Get(offset uint64) ([]interface{}, uint64) {
oldOffset := offset
if offset > 0 {
offset = offset - 1
}
q.Lock()
max := q.getMaxOffset0()
if offset > max {
panic(fmt.Sprintf("bug: error offset %d, end is %d", offset, q.end))
} else if offset < q.start || (oldOffset == 0 && offset == q.start && q.start == 0) {
value := q.items[0:]
q.Unlock()
return value, max
}
var value []interface{}
for i := q.start; i < q.end; i++ {
if i <= offset {
q.items[i-q.start] = nil
} else {
value = append(value, q.items[i-q.start])
}
}
old := q.start
q.start = offset + 1
if q.start < q.end {
q.items = q.items[q.start-old:]
} else {
q.items = make([]interface{}, 0, 0)
}
q.Unlock()
return value, max
} | go | func (q *OffsetQueue) Get(offset uint64) ([]interface{}, uint64) {
oldOffset := offset
if offset > 0 {
offset = offset - 1
}
q.Lock()
max := q.getMaxOffset0()
if offset > max {
panic(fmt.Sprintf("bug: error offset %d, end is %d", offset, q.end))
} else if offset < q.start || (oldOffset == 0 && offset == q.start && q.start == 0) {
value := q.items[0:]
q.Unlock()
return value, max
}
var value []interface{}
for i := q.start; i < q.end; i++ {
if i <= offset {
q.items[i-q.start] = nil
} else {
value = append(value, q.items[i-q.start])
}
}
old := q.start
q.start = offset + 1
if q.start < q.end {
q.items = q.items[q.start-old:]
} else {
q.items = make([]interface{}, 0, 0)
}
q.Unlock()
return value, max
} | [
"func",
"(",
"q",
"*",
"OffsetQueue",
")",
"Get",
"(",
"offset",
"uint64",
")",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"uint64",
")",
"{",
"oldOffset",
":=",
"offset",
"\n",
"if",
"offset",
">",
"0",
"{",
"offset",
"=",
"offset",
"-",
"1",
"\... | // Get returns all the items after the offset, and remove all items before this offset | [
"Get",
"returns",
"all",
"the",
"items",
"after",
"the",
"offset",
"and",
"remove",
"all",
"items",
"before",
"this",
"offset"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/sync_queue.go#L44-L79 |
18,287 | fagongzi/goetty | sync_queue.go | GetMaxOffset | func (q *OffsetQueue) GetMaxOffset() uint64 {
q.Lock()
v := q.getMaxOffset0()
q.Unlock()
return v
} | go | func (q *OffsetQueue) GetMaxOffset() uint64 {
q.Lock()
v := q.getMaxOffset0()
q.Unlock()
return v
} | [
"func",
"(",
"q",
"*",
"OffsetQueue",
")",
"GetMaxOffset",
"(",
")",
"uint64",
"{",
"q",
".",
"Lock",
"(",
")",
"\n",
"v",
":=",
"q",
".",
"getMaxOffset0",
"(",
")",
"\n",
"q",
".",
"Unlock",
"(",
")",
"\n",
"return",
"v",
"\n",
"}"
] | // GetMaxOffset returns the max offset in the queue | [
"GetMaxOffset",
"returns",
"the",
"max",
"offset",
"in",
"the",
"queue"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/sync_queue.go#L82-L87 |
18,288 | fagongzi/goetty | codec_sync.go | Encode | func (codec *SyncCodec) Encode(data interface{}, out *ByteBuf) error {
if msg, ok := data.(*notifyRaw); ok {
out.WriteByte(cmdNotifyRaw)
out.WriteByteBuf(msg.buf)
releaseNotifyRaw(msg)
return nil
} else if msg, ok := data.(*notify); ok {
out.WriteByte(cmdNotify)
out.WriteUint64(msg.offset)
releaseNotify(msg)
return nil
} else if msg, ok := data.(*notifySync); ok {
out.WriteByte(cmdNotifySync)
out.WriteUint64(msg.offset)
releaseNotifySync(msg)
return nil
} else if msg, ok := data.(*notifySyncRsp); ok {
out.WriteByte(cmdNotifySyncRsp)
out.WriteUint64(msg.offset)
out.WriteByte(msg.count)
out.WriteByteBuf(msg.buf)
releaseNotifySyncRsp(msg)
return nil
} else if msg, ok := data.(*notifyHB); ok {
out.WriteByte(cmdNotifyHB)
out.WriteUint64(msg.offset)
return nil
}
return fmt.Errorf("not support msg: %v", data)
} | go | func (codec *SyncCodec) Encode(data interface{}, out *ByteBuf) error {
if msg, ok := data.(*notifyRaw); ok {
out.WriteByte(cmdNotifyRaw)
out.WriteByteBuf(msg.buf)
releaseNotifyRaw(msg)
return nil
} else if msg, ok := data.(*notify); ok {
out.WriteByte(cmdNotify)
out.WriteUint64(msg.offset)
releaseNotify(msg)
return nil
} else if msg, ok := data.(*notifySync); ok {
out.WriteByte(cmdNotifySync)
out.WriteUint64(msg.offset)
releaseNotifySync(msg)
return nil
} else if msg, ok := data.(*notifySyncRsp); ok {
out.WriteByte(cmdNotifySyncRsp)
out.WriteUint64(msg.offset)
out.WriteByte(msg.count)
out.WriteByteBuf(msg.buf)
releaseNotifySyncRsp(msg)
return nil
} else if msg, ok := data.(*notifyHB); ok {
out.WriteByte(cmdNotifyHB)
out.WriteUint64(msg.offset)
return nil
}
return fmt.Errorf("not support msg: %v", data)
} | [
"func",
"(",
"codec",
"*",
"SyncCodec",
")",
"Encode",
"(",
"data",
"interface",
"{",
"}",
",",
"out",
"*",
"ByteBuf",
")",
"error",
"{",
"if",
"msg",
",",
"ok",
":=",
"data",
".",
"(",
"*",
"notifyRaw",
")",
";",
"ok",
"{",
"out",
".",
"WriteByt... | // Encode encode sync protocol | [
"Encode",
"encode",
"sync",
"protocol"
] | 8db0d25ac2019c322508640bf56de7219332f94c | https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/codec_sync.go#L143-L173 |
18,289 | aaasen/kapok | stats/readability.go | Sentences | func Sentences(text string) []string {
sentences := sentenceRegex.Split(text, -1)
if sentences[len(sentences)-1] == "" {
return sentences[0 : len(sentences)-1]
}
return sentences
} | go | func Sentences(text string) []string {
sentences := sentenceRegex.Split(text, -1)
if sentences[len(sentences)-1] == "" {
return sentences[0 : len(sentences)-1]
}
return sentences
} | [
"func",
"Sentences",
"(",
"text",
"string",
")",
"[",
"]",
"string",
"{",
"sentences",
":=",
"sentenceRegex",
".",
"Split",
"(",
"text",
",",
"-",
"1",
")",
"\n\n",
"if",
"sentences",
"[",
"len",
"(",
"sentences",
")",
"-",
"1",
"]",
"==",
"\"",
"\... | // Sentences returns a slice of the sentences in a given string. | [
"Sentences",
"returns",
"a",
"slice",
"of",
"the",
"sentences",
"in",
"a",
"given",
"string",
"."
] | b3a454001825c4e26fe21fac61f214c1a6c284ed | https://github.com/aaasen/kapok/blob/b3a454001825c4e26fe21fac61f214c1a6c284ed/stats/readability.go#L21-L29 |
18,290 | aaasen/kapok | stats/readability.go | SyllableCount | func SyllableCount(word string) int {
if len(word) <= 3 {
return 1
}
word = endingRegex.ReplaceAllString(word, "")
word = staringYRegex.ReplaceAllString(word, "")
return len(vowelRegex.FindAllString(word, -1))
} | go | func SyllableCount(word string) int {
if len(word) <= 3 {
return 1
}
word = endingRegex.ReplaceAllString(word, "")
word = staringYRegex.ReplaceAllString(word, "")
return len(vowelRegex.FindAllString(word, -1))
} | [
"func",
"SyllableCount",
"(",
"word",
"string",
")",
"int",
"{",
"if",
"len",
"(",
"word",
")",
"<=",
"3",
"{",
"return",
"1",
"\n",
"}",
"\n\n",
"word",
"=",
"endingRegex",
".",
"ReplaceAllString",
"(",
"word",
",",
"\"",
"\"",
")",
"\n",
"word",
... | // SyllableCount returns the number of syllables in a given string.
// Dipthongs are not taken into account. | [
"SyllableCount",
"returns",
"the",
"number",
"of",
"syllables",
"in",
"a",
"given",
"string",
".",
"Dipthongs",
"are",
"not",
"taken",
"into",
"account",
"."
] | b3a454001825c4e26fe21fac61f214c1a6c284ed | https://github.com/aaasen/kapok/blob/b3a454001825c4e26fe21fac61f214c1a6c284ed/stats/readability.go#L33-L42 |
18,291 | aaasen/kapok | parse/page.go | NewPageFromXML | func NewPageFromXML(text []byte) (*Page, error) {
page := &Page{}
err := page.getTitle(text)
if err != nil {
return nil, err
}
page.getLinks(text)
return page, nil
} | go | func NewPageFromXML(text []byte) (*Page, error) {
page := &Page{}
err := page.getTitle(text)
if err != nil {
return nil, err
}
page.getLinks(text)
return page, nil
} | [
"func",
"NewPageFromXML",
"(",
"text",
"[",
"]",
"byte",
")",
"(",
"*",
"Page",
",",
"error",
")",
"{",
"page",
":=",
"&",
"Page",
"{",
"}",
"\n\n",
"err",
":=",
"page",
".",
"getTitle",
"(",
"text",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
... | // NewPageFromXML creates a Page object from XML. | [
"NewPageFromXML",
"creates",
"a",
"Page",
"object",
"from",
"XML",
"."
] | b3a454001825c4e26fe21fac61f214c1a6c284ed | https://github.com/aaasen/kapok/blob/b3a454001825c4e26fe21fac61f214c1a6c284ed/parse/page.go#L24-L36 |
18,292 | aaasen/kapok | parse/page.go | getTitle | func (page *Page) getTitle(text []byte) error {
startTag := []byte("<title>")
startIndex := bytes.Index(text, startTag)
endTag := []byte("</title>")
endIndex := bytes.Index(text, endTag)
if startIndex != -1 && endIndex != -1 {
title := text[startIndex+len(startTag) : endIndex]
if len(title) < 1 || !isTitle(title) {
return ErrTitleNotFound
}
page.Title = string(title)
} else {
return ErrTitleNotFound
}
return nil
} | go | func (page *Page) getTitle(text []byte) error {
startTag := []byte("<title>")
startIndex := bytes.Index(text, startTag)
endTag := []byte("</title>")
endIndex := bytes.Index(text, endTag)
if startIndex != -1 && endIndex != -1 {
title := text[startIndex+len(startTag) : endIndex]
if len(title) < 1 || !isTitle(title) {
return ErrTitleNotFound
}
page.Title = string(title)
} else {
return ErrTitleNotFound
}
return nil
} | [
"func",
"(",
"page",
"*",
"Page",
")",
"getTitle",
"(",
"text",
"[",
"]",
"byte",
")",
"error",
"{",
"startTag",
":=",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
"\n",
"startIndex",
":=",
"bytes",
".",
"Index",
"(",
"text",
",",
"startTag",
")",
"\n... | // getTitle parses the title from an XML representation of a Wikipedia page.
// In the event of an error or malformed XML, it will return ErrTitleNotFound. | [
"getTitle",
"parses",
"the",
"title",
"from",
"an",
"XML",
"representation",
"of",
"a",
"Wikipedia",
"page",
".",
"In",
"the",
"event",
"of",
"an",
"error",
"or",
"malformed",
"XML",
"it",
"will",
"return",
"ErrTitleNotFound",
"."
] | b3a454001825c4e26fe21fac61f214c1a6c284ed | https://github.com/aaasen/kapok/blob/b3a454001825c4e26fe21fac61f214c1a6c284ed/parse/page.go#L82-L102 |
18,293 | aaasen/kapok | parse/parse.go | Parse | func (parser *Parser) Parse(reader io.Reader, pages chan<- *Page) {
rawPages := make(chan []byte)
go parser.getRawPages(reader, rawPages)
go parser.getPages(rawPages, pages)
} | go | func (parser *Parser) Parse(reader io.Reader, pages chan<- *Page) {
rawPages := make(chan []byte)
go parser.getRawPages(reader, rawPages)
go parser.getPages(rawPages, pages)
} | [
"func",
"(",
"parser",
"*",
"Parser",
")",
"Parse",
"(",
"reader",
"io",
".",
"Reader",
",",
"pages",
"chan",
"<-",
"*",
"Page",
")",
"{",
"rawPages",
":=",
"make",
"(",
"chan",
"[",
"]",
"byte",
")",
"\n\n",
"go",
"parser",
".",
"getRawPages",
"("... | // Parse parses given reader as XML and dumps Page objects into the given channel.
// Parse will fill the Page's Title, Links, and Categories.
//
// When the reader is empty, Parse will close its output channel.
//
// Parse will throw away malformed input instead of exiting and reporting it. | [
"Parse",
"parses",
"given",
"reader",
"as",
"XML",
"and",
"dumps",
"Page",
"objects",
"into",
"the",
"given",
"channel",
".",
"Parse",
"will",
"fill",
"the",
"Page",
"s",
"Title",
"Links",
"and",
"Categories",
".",
"When",
"the",
"reader",
"is",
"empty",
... | b3a454001825c4e26fe21fac61f214c1a6c284ed | https://github.com/aaasen/kapok/blob/b3a454001825c4e26fe21fac61f214c1a6c284ed/parse/parse.go#L28-L33 |
18,294 | aaasen/kapok | parse/parse.go | getRawPages | func (parser *Parser) getRawPages(rawReader io.Reader, pages chan<- []byte) {
reader := bufio.NewReader(rawReader)
buffer := make([]byte, 0)
inPage := false
eof := false
for !eof {
text, err := reader.ReadBytes('>')
parser.BytesProcessed += int64(len(text))
if err != nil {
if err == io.EOF {
eof = true
} else {
log.Println(err.Error() + " skipping line")
}
}
startTag := []byte("<page>")
startIndex := bytes.Index(text, startTag)
endTag := []byte("</page>")
endIndex := bytes.Index(text, endTag)
if startIndex != -1 {
inPage = true
buffer = text[startIndex:]
} else if endIndex != -1 {
inPage = false
buffer = append(buffer, text[:endIndex+len(endTag)]...)
if bytes.Index(buffer, []byte("#REDIRECT")) == -1 {
pages <- buffer
}
buffer = make([]byte, 0)
} else if inPage {
buffer = append(buffer, text...)
}
}
close(pages)
} | go | func (parser *Parser) getRawPages(rawReader io.Reader, pages chan<- []byte) {
reader := bufio.NewReader(rawReader)
buffer := make([]byte, 0)
inPage := false
eof := false
for !eof {
text, err := reader.ReadBytes('>')
parser.BytesProcessed += int64(len(text))
if err != nil {
if err == io.EOF {
eof = true
} else {
log.Println(err.Error() + " skipping line")
}
}
startTag := []byte("<page>")
startIndex := bytes.Index(text, startTag)
endTag := []byte("</page>")
endIndex := bytes.Index(text, endTag)
if startIndex != -1 {
inPage = true
buffer = text[startIndex:]
} else if endIndex != -1 {
inPage = false
buffer = append(buffer, text[:endIndex+len(endTag)]...)
if bytes.Index(buffer, []byte("#REDIRECT")) == -1 {
pages <- buffer
}
buffer = make([]byte, 0)
} else if inPage {
buffer = append(buffer, text...)
}
}
close(pages)
} | [
"func",
"(",
"parser",
"*",
"Parser",
")",
"getRawPages",
"(",
"rawReader",
"io",
".",
"Reader",
",",
"pages",
"chan",
"<-",
"[",
"]",
"byte",
")",
"{",
"reader",
":=",
"bufio",
".",
"NewReader",
"(",
"rawReader",
")",
"\n\n",
"buffer",
":=",
"make",
... | // getRawPages creates full pages from a reader that can then be parsed with an XML parser. | [
"getRawPages",
"creates",
"full",
"pages",
"from",
"a",
"reader",
"that",
"can",
"then",
"be",
"parsed",
"with",
"an",
"XML",
"parser",
"."
] | b3a454001825c4e26fe21fac61f214c1a6c284ed | https://github.com/aaasen/kapok/blob/b3a454001825c4e26fe21fac61f214c1a6c284ed/parse/parse.go#L36-L80 |
18,295 | aaasen/kapok | parse/parse.go | getPages | func (parser *Parser) getPages(rawPages <-chan []byte, pages chan<- *Page) {
for {
select {
case rawPage, ok := <-rawPages:
if !ok {
close(pages)
return
}
page, err := NewPageFromXML(rawPage)
if err == nil {
pages <- page
}
}
}
} | go | func (parser *Parser) getPages(rawPages <-chan []byte, pages chan<- *Page) {
for {
select {
case rawPage, ok := <-rawPages:
if !ok {
close(pages)
return
}
page, err := NewPageFromXML(rawPage)
if err == nil {
pages <- page
}
}
}
} | [
"func",
"(",
"parser",
"*",
"Parser",
")",
"getPages",
"(",
"rawPages",
"<-",
"chan",
"[",
"]",
"byte",
",",
"pages",
"chan",
"<-",
"*",
"Page",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"rawPage",
",",
"ok",
":=",
"<-",
"rawPages",
":",
"if",
... | // GetPages parses a complete XML page into a page object. | [
"GetPages",
"parses",
"a",
"complete",
"XML",
"page",
"into",
"a",
"page",
"object",
"."
] | b3a454001825c4e26fe21fac61f214c1a6c284ed | https://github.com/aaasen/kapok/blob/b3a454001825c4e26fe21fac61f214c1a6c284ed/parse/parse.go#L83-L99 |
18,296 | VerbalExpressions/GoVerbalExpressions | helpers.go | Replace | func (v *VerbalExpression) Replace(src string, dst string) string {
return v.Regex().ReplaceAllString(src, dst)
} | go | func (v *VerbalExpression) Replace(src string, dst string) string {
return v.Regex().ReplaceAllString(src, dst)
} | [
"func",
"(",
"v",
"*",
"VerbalExpression",
")",
"Replace",
"(",
"src",
"string",
",",
"dst",
"string",
")",
"string",
"{",
"return",
"v",
".",
"Regex",
"(",
")",
".",
"ReplaceAllString",
"(",
"src",
",",
"dst",
")",
"\n",
"}"
] | // Replace alias to regexp.ReplaceAllString. It replace the found expression from
// string src by string dst | [
"Replace",
"alias",
"to",
"regexp",
".",
"ReplaceAllString",
".",
"It",
"replace",
"the",
"found",
"expression",
"from",
"string",
"src",
"by",
"string",
"dst"
] | 9cfb19cb04c9f48489be15cbacac3d3af9d7706a | https://github.com/VerbalExpressions/GoVerbalExpressions/blob/9cfb19cb04c9f48489be15cbacac3d3af9d7706a/helpers.go#L12-L14 |
18,297 | VerbalExpressions/GoVerbalExpressions | verbalexpressions.go | tostring | func tostring(i interface{}) string {
var r string
switch x := i.(type) {
case string:
r = x
case uint64:
r = strconv.FormatUint(x, 10)
case int64:
r = strconv.FormatInt(x, 10)
case uint:
r = strconv.FormatUint(uint64(x), 10)
case int:
r = strconv.FormatInt(int64(x), 10)
default:
log.Panicf("Could not convert %v %t", x, x)
}
return r
} | go | func tostring(i interface{}) string {
var r string
switch x := i.(type) {
case string:
r = x
case uint64:
r = strconv.FormatUint(x, 10)
case int64:
r = strconv.FormatInt(x, 10)
case uint:
r = strconv.FormatUint(uint64(x), 10)
case int:
r = strconv.FormatInt(int64(x), 10)
default:
log.Panicf("Could not convert %v %t", x, x)
}
return r
} | [
"func",
"tostring",
"(",
"i",
"interface",
"{",
"}",
")",
"string",
"{",
"var",
"r",
"string",
"\n",
"switch",
"x",
":=",
"i",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"r",
"=",
"x",
"\n",
"case",
"uint64",
":",
"r",
"=",
"strconv",
"... | // utility function to return only strings | [
"utility",
"function",
"to",
"return",
"only",
"strings"
] | 9cfb19cb04c9f48489be15cbacac3d3af9d7706a | https://github.com/VerbalExpressions/GoVerbalExpressions/blob/9cfb19cb04c9f48489be15cbacac3d3af9d7706a/verbalexpressions.go#L41-L58 |
18,298 | VerbalExpressions/GoVerbalExpressions | verbalexpressions.go | addmodifier | func (v *VerbalExpression) addmodifier(f Flag) *VerbalExpression {
v.compiled = false //reinit previous regexp compilation
v.flags |= f
return v
} | go | func (v *VerbalExpression) addmodifier(f Flag) *VerbalExpression {
v.compiled = false //reinit previous regexp compilation
v.flags |= f
return v
} | [
"func",
"(",
"v",
"*",
"VerbalExpression",
")",
"addmodifier",
"(",
"f",
"Flag",
")",
"*",
"VerbalExpression",
"{",
"v",
".",
"compiled",
"=",
"false",
"//reinit previous regexp compilation",
"\n",
"v",
".",
"flags",
"|=",
"f",
"\n",
"return",
"v",
"\n",
"... | // append a modifier | [
"append",
"a",
"modifier"
] | 9cfb19cb04c9f48489be15cbacac3d3af9d7706a | https://github.com/VerbalExpressions/GoVerbalExpressions/blob/9cfb19cb04c9f48489be15cbacac3d3af9d7706a/verbalexpressions.go#L73-L77 |
18,299 | VerbalExpressions/GoVerbalExpressions | verbalexpressions.go | removemodifier | func (v *VerbalExpression) removemodifier(f Flag) *VerbalExpression {
v.compiled = false //reinit previous regexp compilation
v.flags &= ^f
return v
} | go | func (v *VerbalExpression) removemodifier(f Flag) *VerbalExpression {
v.compiled = false //reinit previous regexp compilation
v.flags &= ^f
return v
} | [
"func",
"(",
"v",
"*",
"VerbalExpression",
")",
"removemodifier",
"(",
"f",
"Flag",
")",
"*",
"VerbalExpression",
"{",
"v",
".",
"compiled",
"=",
"false",
"//reinit previous regexp compilation",
"\n",
"v",
".",
"flags",
"&=",
"^",
"f",
"\n",
"return",
"v",
... | // remove a modifier | [
"remove",
"a",
"modifier"
] | 9cfb19cb04c9f48489be15cbacac3d3af9d7706a | https://github.com/VerbalExpressions/GoVerbalExpressions/blob/9cfb19cb04c9f48489be15cbacac3d3af9d7706a/verbalexpressions.go#L80-L84 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.