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
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
15,700
proullon/ramsql
engine/predicate.go
Eval
func (p *Predicate) Eval(row virtualRow) (bool, error) { if p.True { return true, nil } // Find left attribute left := p.LeftValue.table + "." + p.LeftValue.lexeme val, ok := row[left] if !ok { return false, fmt.Errorf("Attribute [%s] not found in row", left) } p.LeftValue.v = val.v return p.Operator(p.LeftValue, p.RightValue), nil }
go
func (p *Predicate) Eval(row virtualRow) (bool, error) { if p.True { return true, nil } // Find left attribute left := p.LeftValue.table + "." + p.LeftValue.lexeme val, ok := row[left] if !ok { return false, fmt.Errorf("Attribute [%s] not found in row", left) } p.LeftValue.v = val.v return p.Operator(p.LeftValue, p.RightValue), nil }
[ "func", "(", "p", "*", "Predicate", ")", "Eval", "(", "row", "virtualRow", ")", "(", "bool", ",", "error", ")", "{", "if", "p", ".", "True", "{", "return", "true", ",", "nil", "\n", "}", "\n\n", "// Find left attribute", "left", ":=", "p", ".", "LeftValue", ".", "table", "+", "\"", "\"", "+", "p", ".", "LeftValue", ".", "lexeme", "\n", "val", ",", "ok", ":=", "row", "[", "left", "]", "\n", "if", "!", "ok", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "left", ")", "\n", "}", "\n", "p", ".", "LeftValue", ".", "v", "=", "val", ".", "v", "\n\n", "return", "p", ".", "Operator", "(", "p", ".", "LeftValue", ",", "p", ".", "RightValue", ")", ",", "nil", "\n", "}" ]
// Eval fetches operand from virtual row and run operator
[ "Eval", "fetches", "operand", "from", "virtual", "row", "and", "run", "operator" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/predicate.go#L102-L117
15,701
proullon/ramsql
engine/attribute.go
NewAttribute
func NewAttribute(name string, typeName string, autoIncrement bool) Attribute { a := Attribute{ name: name, typeName: typeName, autoIncrement: autoIncrement, } return a }
go
func NewAttribute(name string, typeName string, autoIncrement bool) Attribute { a := Attribute{ name: name, typeName: typeName, autoIncrement: autoIncrement, } return a }
[ "func", "NewAttribute", "(", "name", "string", ",", "typeName", "string", ",", "autoIncrement", "bool", ")", "Attribute", "{", "a", ":=", "Attribute", "{", "name", ":", "name", ",", "typeName", ":", "typeName", ",", "autoIncrement", ":", "autoIncrement", ",", "}", "\n\n", "return", "a", "\n", "}" ]
// NewAttribute initialize a new Attribute struct
[ "NewAttribute", "initialize", "a", "new", "Attribute", "struct" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/attribute.go#L82-L90
15,702
proullon/ramsql
driver/conn.go
Close
func (c *Conn) Close() error { log.Debug("Conn.Close") c.conn.Close() if c.parent != nil { c.parent.closingConn() } return nil }
go
func (c *Conn) Close() error { log.Debug("Conn.Close") c.conn.Close() if c.parent != nil { c.parent.closingConn() } return nil }
[ "func", "(", "c", "*", "Conn", ")", "Close", "(", ")", "error", "{", "log", ".", "Debug", "(", "\"", "\"", ")", "\n", "c", ".", "conn", ".", "Close", "(", ")", "\n\n", "if", "c", ".", "parent", "!=", "nil", "{", "c", ".", "parent", ".", "closingConn", "(", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Close invalidates and potentially stops any current // prepared statements and transactions, marking this // connection as no longer in use. // // Because the sql package maintains a free pool of // connections and only calls Close when there's a surplus of // idle connections, it shouldn't be necessary for drivers to // do their own connection caching.
[ "Close", "invalidates", "and", "potentially", "stops", "any", "current", "prepared", "statements", "and", "transactions", "marking", "this", "connection", "as", "no", "longer", "in", "use", ".", "Because", "the", "sql", "package", "maintains", "a", "free", "pool", "of", "connections", "and", "only", "calls", "Close", "when", "there", "s", "a", "surplus", "of", "idle", "connections", "it", "shouldn", "t", "be", "necessary", "for", "drivers", "to", "do", "their", "own", "connection", "caching", "." ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/driver/conn.go#L46-L55
15,703
proullon/ramsql
driver/conn.go
Begin
func (c *Conn) Begin() (driver.Tx, error) { tx := Tx{ conn: c, } return &tx, nil }
go
func (c *Conn) Begin() (driver.Tx, error) { tx := Tx{ conn: c, } return &tx, nil }
[ "func", "(", "c", "*", "Conn", ")", "Begin", "(", ")", "(", "driver", ".", "Tx", ",", "error", ")", "{", "tx", ":=", "Tx", "{", "conn", ":", "c", ",", "}", "\n\n", "return", "&", "tx", ",", "nil", "\n", "}" ]
// Begin starts and returns a new transaction.
[ "Begin", "starts", "and", "returns", "a", "new", "transaction", "." ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/driver/conn.go#L58-L65
15,704
proullon/ramsql
cli/cli.go
Run
func Run(db *sql.DB) { // Readline reader := bufio.NewReader(os.Stdin) for { fmt.Printf("ramsql> ") buffer, err := reader.ReadBytes(';') if err != nil { if err == io.EOF { fmt.Printf("exit\n") return } fmt.Printf("Reading error\n") return } buffer = buffer[:len(buffer)-1] if len(buffer) == 0 { continue } stmt := string(buffer) stmt = strings.Replace(stmt, "\n", "", -1) // Do things here if strings.HasPrefix(stmt, "SELECT") { query(db, stmt) } else if strings.HasPrefix(stmt, "SHOW") { query(db, stmt) } else if strings.HasPrefix(stmt, "DESCRIBE") { query(db, stmt) } else { exec(db, stmt) } } }
go
func Run(db *sql.DB) { // Readline reader := bufio.NewReader(os.Stdin) for { fmt.Printf("ramsql> ") buffer, err := reader.ReadBytes(';') if err != nil { if err == io.EOF { fmt.Printf("exit\n") return } fmt.Printf("Reading error\n") return } buffer = buffer[:len(buffer)-1] if len(buffer) == 0 { continue } stmt := string(buffer) stmt = strings.Replace(stmt, "\n", "", -1) // Do things here if strings.HasPrefix(stmt, "SELECT") { query(db, stmt) } else if strings.HasPrefix(stmt, "SHOW") { query(db, stmt) } else if strings.HasPrefix(stmt, "DESCRIBE") { query(db, stmt) } else { exec(db, stmt) } } }
[ "func", "Run", "(", "db", "*", "sql", ".", "DB", ")", "{", "// Readline", "reader", ":=", "bufio", ".", "NewReader", "(", "os", ".", "Stdin", ")", "\n\n", "for", "{", "fmt", ".", "Printf", "(", "\"", "\"", ")", "\n", "buffer", ",", "err", ":=", "reader", ".", "ReadBytes", "(", "';'", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "EOF", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ")", "\n", "return", "\n", "}", "\n\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ")", "\n", "return", "\n", "}", "\n\n", "buffer", "=", "buffer", "[", ":", "len", "(", "buffer", ")", "-", "1", "]", "\n\n", "if", "len", "(", "buffer", ")", "==", "0", "{", "continue", "\n", "}", "\n\n", "stmt", ":=", "string", "(", "buffer", ")", "\n", "stmt", "=", "strings", ".", "Replace", "(", "stmt", ",", "\"", "\\n", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n\n", "// Do things here", "if", "strings", ".", "HasPrefix", "(", "stmt", ",", "\"", "\"", ")", "{", "query", "(", "db", ",", "stmt", ")", "\n", "}", "else", "if", "strings", ".", "HasPrefix", "(", "stmt", ",", "\"", "\"", ")", "{", "query", "(", "db", ",", "stmt", ")", "\n", "}", "else", "if", "strings", ".", "HasPrefix", "(", "stmt", ",", "\"", "\"", ")", "{", "query", "(", "db", ",", "stmt", ")", "\n", "}", "else", "{", "exec", "(", "db", ",", "stmt", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Run start a command line interface reading on stdin and execute queries // on given sql.DB
[ "Run", "start", "a", "command", "line", "interface", "reading", "on", "stdin", "and", "execute", "queries", "on", "given", "sql", ".", "DB" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/cli/cli.go#L100-L137
15,705
proullon/ramsql
engine/protocol/channel.go
Close
func (cdc *ChannelDriverConn) Close() { if cdc.conn == nil { return } close(cdc.conn) cdc.conn = nil }
go
func (cdc *ChannelDriverConn) Close() { if cdc.conn == nil { return } close(cdc.conn) cdc.conn = nil }
[ "func", "(", "cdc", "*", "ChannelDriverConn", ")", "Close", "(", ")", "{", "if", "cdc", ".", "conn", "==", "nil", "{", "return", "\n", "}", "\n", "close", "(", "cdc", ".", "conn", ")", "\n", "cdc", ".", "conn", "=", "nil", "\n", "}" ]
// Close method closes the connection to RamSQL server
[ "Close", "method", "closes", "the", "connection", "to", "RamSQL", "server" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/protocol/channel.go#L35-L41
15,706
proullon/ramsql
engine/protocol/channel.go
New
func (cde *ChannelDriverEndpoint) New(uri string) (DriverConn, error) { if cde.newConnChannel == nil { return nil, fmt.Errorf("connection closed") } channel := make(chan message) cdc := &ChannelDriverConn{conn: channel} cde.newConnChannel <- channel return cdc, nil }
go
func (cde *ChannelDriverEndpoint) New(uri string) (DriverConn, error) { if cde.newConnChannel == nil { return nil, fmt.Errorf("connection closed") } channel := make(chan message) cdc := &ChannelDriverConn{conn: channel} cde.newConnChannel <- channel return cdc, nil }
[ "func", "(", "cde", "*", "ChannelDriverEndpoint", ")", "New", "(", "uri", "string", ")", "(", "DriverConn", ",", "error", ")", "{", "if", "cde", ".", "newConnChannel", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "channel", ":=", "make", "(", "chan", "message", ")", "\n", "cdc", ":=", "&", "ChannelDriverConn", "{", "conn", ":", "channel", "}", "\n", "cde", ".", "newConnChannel", "<-", "channel", "\n", "return", "cdc", ",", "nil", "\n", "}" ]
// New method creates a new DriverConn from DriverEndpoint
[ "New", "method", "creates", "a", "new", "DriverConn", "from", "DriverEndpoint" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/protocol/channel.go#L44-L54
15,707
proullon/ramsql
engine/protocol/channel.go
Accept
func (cee *ChannelEngineEndpoint) Accept() (EngineConn, error) { newConn, ok := <-cee.newConnChannel if !ok { return nil, io.EOF } return NewChannelEngineConn(newConn), nil }
go
func (cee *ChannelEngineEndpoint) Accept() (EngineConn, error) { newConn, ok := <-cee.newConnChannel if !ok { return nil, io.EOF } return NewChannelEngineConn(newConn), nil }
[ "func", "(", "cee", "*", "ChannelEngineEndpoint", ")", "Accept", "(", ")", "(", "EngineConn", ",", "error", ")", "{", "newConn", ",", "ok", ":=", "<-", "cee", ".", "newConnChannel", "\n", "if", "!", "ok", "{", "return", "nil", ",", "io", ".", "EOF", "\n", "}", "\n\n", "return", "NewChannelEngineConn", "(", "newConn", ")", ",", "nil", "\n", "}" ]
// Accept read from new channels channel and return an EngineConn
[ "Accept", "read", "from", "new", "channels", "channel", "and", "return", "an", "EngineConn" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/protocol/channel.go#L80-L87
15,708
proullon/ramsql
engine/protocol/channel.go
ReadStatement
func (cec *ChannelEngineConn) ReadStatement() (string, error) { message, ok := <-cec.conn if !ok { cec.conn = nil return "", io.EOF } return message.Value[0], nil }
go
func (cec *ChannelEngineConn) ReadStatement() (string, error) { message, ok := <-cec.conn if !ok { cec.conn = nil return "", io.EOF } return message.Value[0], nil }
[ "func", "(", "cec", "*", "ChannelEngineConn", ")", "ReadStatement", "(", ")", "(", "string", ",", "error", ")", "{", "message", ",", "ok", ":=", "<-", "cec", ".", "conn", "\n", "if", "!", "ok", "{", "cec", ".", "conn", "=", "nil", "\n", "return", "\"", "\"", ",", "io", ".", "EOF", "\n", "}", "\n\n", "return", "message", ".", "Value", "[", "0", "]", ",", "nil", "\n", "}" ]
// ReadStatement get SQL statements from client
[ "ReadStatement", "get", "SQL", "statements", "from", "client" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/protocol/channel.go#L108-L116
15,709
proullon/ramsql
engine/protocol/channel.go
WriteResult
func (cec *ChannelEngineConn) WriteResult(lastInsertedID int64, rowsAffected int64) error { m := message{ Type: resultMessage, Value: []string{fmt.Sprintf("%d %d", lastInsertedID, rowsAffected)}, } cec.conn <- m return nil }
go
func (cec *ChannelEngineConn) WriteResult(lastInsertedID int64, rowsAffected int64) error { m := message{ Type: resultMessage, Value: []string{fmt.Sprintf("%d %d", lastInsertedID, rowsAffected)}, } cec.conn <- m return nil }
[ "func", "(", "cec", "*", "ChannelEngineConn", ")", "WriteResult", "(", "lastInsertedID", "int64", ",", "rowsAffected", "int64", ")", "error", "{", "m", ":=", "message", "{", "Type", ":", "resultMessage", ",", "Value", ":", "[", "]", "string", "{", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "lastInsertedID", ",", "rowsAffected", ")", "}", ",", "}", "\n\n", "cec", ".", "conn", "<-", "m", "\n", "return", "nil", "\n", "}" ]
// WriteResult is used to answer to statements other than SELECT
[ "WriteResult", "is", "used", "to", "answer", "to", "statements", "other", "than", "SELECT" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/protocol/channel.go#L119-L127
15,710
proullon/ramsql
engine/protocol/channel.go
WriteError
func (cec *ChannelEngineConn) WriteError(err error) error { m := message{ Type: errMessage, Value: []string{err.Error()}, } cec.conn <- m return nil }
go
func (cec *ChannelEngineConn) WriteError(err error) error { m := message{ Type: errMessage, Value: []string{err.Error()}, } cec.conn <- m return nil }
[ "func", "(", "cec", "*", "ChannelEngineConn", ")", "WriteError", "(", "err", "error", ")", "error", "{", "m", ":=", "message", "{", "Type", ":", "errMessage", ",", "Value", ":", "[", "]", "string", "{", "err", ".", "Error", "(", ")", "}", ",", "}", "\n\n", "cec", ".", "conn", "<-", "m", "\n", "return", "nil", "\n\n", "}" ]
// WriteError when error occurs
[ "WriteError", "when", "error", "occurs" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/protocol/channel.go#L130-L139
15,711
proullon/ramsql
engine/protocol/channel.go
WriteRowHeader
func (cec *ChannelEngineConn) WriteRowHeader(header []string) error { m := message{ Type: rowHeaderMessage, Value: header, } cec.conn <- m return nil }
go
func (cec *ChannelEngineConn) WriteRowHeader(header []string) error { m := message{ Type: rowHeaderMessage, Value: header, } cec.conn <- m return nil }
[ "func", "(", "cec", "*", "ChannelEngineConn", ")", "WriteRowHeader", "(", "header", "[", "]", "string", ")", "error", "{", "m", ":=", "message", "{", "Type", ":", "rowHeaderMessage", ",", "Value", ":", "header", ",", "}", "\n\n", "cec", ".", "conn", "<-", "m", "\n", "return", "nil", "\n\n", "}" ]
// WriteRowHeader indicates that rows are coming next
[ "WriteRowHeader", "indicates", "that", "rows", "are", "coming", "next" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/protocol/channel.go#L142-L151
15,712
proullon/ramsql
engine/protocol/channel.go
WriteRow
func (cec *ChannelEngineConn) WriteRow(row []string) error { m := message{ Type: rowValueMessage, Value: row, } cec.conn <- m return nil }
go
func (cec *ChannelEngineConn) WriteRow(row []string) error { m := message{ Type: rowValueMessage, Value: row, } cec.conn <- m return nil }
[ "func", "(", "cec", "*", "ChannelEngineConn", ")", "WriteRow", "(", "row", "[", "]", "string", ")", "error", "{", "m", ":=", "message", "{", "Type", ":", "rowValueMessage", ",", "Value", ":", "row", ",", "}", "\n\n", "cec", ".", "conn", "<-", "m", "\n", "return", "nil", "\n", "}" ]
// WriteRow must be called after WriteRowHeader and before WriteRowEnd
[ "WriteRow", "must", "be", "called", "after", "WriteRowHeader", "and", "before", "WriteRowEnd" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/protocol/channel.go#L154-L162
15,713
proullon/ramsql
engine/protocol/channel.go
WriteRowEnd
func (cec *ChannelEngineConn) WriteRowEnd() error { m := message{ Type: rowEndMessage, } cec.conn <- m return nil }
go
func (cec *ChannelEngineConn) WriteRowEnd() error { m := message{ Type: rowEndMessage, } cec.conn <- m return nil }
[ "func", "(", "cec", "*", "ChannelEngineConn", ")", "WriteRowEnd", "(", ")", "error", "{", "m", ":=", "message", "{", "Type", ":", "rowEndMessage", ",", "}", "\n\n", "cec", ".", "conn", "<-", "m", "\n", "return", "nil", "\n", "}" ]
// WriteRowEnd indicates that query is done
[ "WriteRowEnd", "indicates", "that", "query", "is", "done" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/protocol/channel.go#L165-L172
15,714
proullon/ramsql
engine/protocol/channel.go
WriteQuery
func (cdc *ChannelDriverConn) WriteQuery(query string) error { if cdc.conn == nil { return fmt.Errorf("connection closed") } m := message{ Type: queryMessage, Value: []string{query}, } cdc.conn <- m return nil }
go
func (cdc *ChannelDriverConn) WriteQuery(query string) error { if cdc.conn == nil { return fmt.Errorf("connection closed") } m := message{ Type: queryMessage, Value: []string{query}, } cdc.conn <- m return nil }
[ "func", "(", "cdc", "*", "ChannelDriverConn", ")", "WriteQuery", "(", "query", "string", ")", "error", "{", "if", "cdc", ".", "conn", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "m", ":=", "message", "{", "Type", ":", "queryMessage", ",", "Value", ":", "[", "]", "string", "{", "query", "}", ",", "}", "\n\n", "cdc", ".", "conn", "<-", "m", "\n", "return", "nil", "\n", "}" ]
// WriteQuery allows client to query the RamSQL server
[ "WriteQuery", "allows", "client", "to", "query", "the", "RamSQL", "server" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/protocol/channel.go#L175-L187
15,715
proullon/ramsql
engine/protocol/channel.go
WriteExec
func (cdc *ChannelDriverConn) WriteExec(statement string) error { if cdc.conn == nil { return fmt.Errorf("connection closed") } m := message{ Type: execMessage, Value: []string{statement}, } cdc.conn <- m return nil }
go
func (cdc *ChannelDriverConn) WriteExec(statement string) error { if cdc.conn == nil { return fmt.Errorf("connection closed") } m := message{ Type: execMessage, Value: []string{statement}, } cdc.conn <- m return nil }
[ "func", "(", "cdc", "*", "ChannelDriverConn", ")", "WriteExec", "(", "statement", "string", ")", "error", "{", "if", "cdc", ".", "conn", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "m", ":=", "message", "{", "Type", ":", "execMessage", ",", "Value", ":", "[", "]", "string", "{", "statement", "}", ",", "}", "\n\n", "cdc", ".", "conn", "<-", "m", "\n", "return", "nil", "\n", "}" ]
// WriteExec allows client to manipulate the RamSQL server
[ "WriteExec", "allows", "client", "to", "manipulate", "the", "RamSQL", "server" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/protocol/channel.go#L190-L202
15,716
proullon/ramsql
engine/protocol/channel.go
ReadResult
func (cdc *ChannelDriverConn) ReadResult() (lastInsertedID int64, rowsAffected int64, err error) { if cdc.conn == nil { return 0, 0, fmt.Errorf("connection closed") } m := <-cdc.conn if m.Type != resultMessage { if m.Type == errMessage { return 0, 0, errors.New(m.Value[0]) } return 0, 0, fmt.Errorf("Protocal error: ReadResult received %v", m) } _, err = fmt.Sscanf(m.Value[0], "%d %d", &lastInsertedID, &rowsAffected) return lastInsertedID, rowsAffected, err }
go
func (cdc *ChannelDriverConn) ReadResult() (lastInsertedID int64, rowsAffected int64, err error) { if cdc.conn == nil { return 0, 0, fmt.Errorf("connection closed") } m := <-cdc.conn if m.Type != resultMessage { if m.Type == errMessage { return 0, 0, errors.New(m.Value[0]) } return 0, 0, fmt.Errorf("Protocal error: ReadResult received %v", m) } _, err = fmt.Sscanf(m.Value[0], "%d %d", &lastInsertedID, &rowsAffected) return lastInsertedID, rowsAffected, err }
[ "func", "(", "cdc", "*", "ChannelDriverConn", ")", "ReadResult", "(", ")", "(", "lastInsertedID", "int64", ",", "rowsAffected", "int64", ",", "err", "error", ")", "{", "if", "cdc", ".", "conn", "==", "nil", "{", "return", "0", ",", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "m", ":=", "<-", "cdc", ".", "conn", "\n", "if", "m", ".", "Type", "!=", "resultMessage", "{", "if", "m", ".", "Type", "==", "errMessage", "{", "return", "0", ",", "0", ",", "errors", ".", "New", "(", "m", ".", "Value", "[", "0", "]", ")", "\n", "}", "\n", "return", "0", ",", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "m", ")", "\n", "}", "\n\n", "_", ",", "err", "=", "fmt", ".", "Sscanf", "(", "m", ".", "Value", "[", "0", "]", ",", "\"", "\"", ",", "&", "lastInsertedID", ",", "&", "rowsAffected", ")", "\n", "return", "lastInsertedID", ",", "rowsAffected", ",", "err", "\n", "}" ]
// ReadResult when Exec has been used
[ "ReadResult", "when", "Exec", "has", "been", "used" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/protocol/channel.go#L205-L220
15,717
proullon/ramsql
engine/protocol/channel.go
ReadRows
func (cdc *ChannelDriverConn) ReadRows() (chan []string, error) { if cdc.conn == nil { return nil, fmt.Errorf("connection closed") } m := <-cdc.conn if m.Type == errMessage { return nil, errors.New(m.Value[0]) } if m.Type != rowHeaderMessage { return nil, errors.New("not a rows header") } return UnlimitedRowsChannel(cdc.conn, m), nil }
go
func (cdc *ChannelDriverConn) ReadRows() (chan []string, error) { if cdc.conn == nil { return nil, fmt.Errorf("connection closed") } m := <-cdc.conn if m.Type == errMessage { return nil, errors.New(m.Value[0]) } if m.Type != rowHeaderMessage { return nil, errors.New("not a rows header") } return UnlimitedRowsChannel(cdc.conn, m), nil }
[ "func", "(", "cdc", "*", "ChannelDriverConn", ")", "ReadRows", "(", ")", "(", "chan", "[", "]", "string", ",", "error", ")", "{", "if", "cdc", ".", "conn", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "m", ":=", "<-", "cdc", ".", "conn", "\n", "if", "m", ".", "Type", "==", "errMessage", "{", "return", "nil", ",", "errors", ".", "New", "(", "m", ".", "Value", "[", "0", "]", ")", "\n", "}", "\n\n", "if", "m", ".", "Type", "!=", "rowHeaderMessage", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "UnlimitedRowsChannel", "(", "cdc", ".", "conn", ",", "m", ")", ",", "nil", "\n", "}" ]
// ReadRows when Query has been used
[ "ReadRows", "when", "Query", "has", "been", "used" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/protocol/channel.go#L223-L238
15,718
proullon/ramsql
engine/relation.go
Insert
func (r *Relation) Insert(t *Tuple) error { // Maybe do somthing like lock read/write here // Maybe index r.rows = append(r.rows, t) return nil }
go
func (r *Relation) Insert(t *Tuple) error { // Maybe do somthing like lock read/write here // Maybe index r.rows = append(r.rows, t) return nil }
[ "func", "(", "r", "*", "Relation", ")", "Insert", "(", "t", "*", "Tuple", ")", "error", "{", "// Maybe do somthing like lock read/write here", "// Maybe index", "r", ".", "rows", "=", "append", "(", "r", ".", "rows", ",", "t", ")", "\n", "return", "nil", "\n", "}" ]
// Insert a tuple in relation
[ "Insert", "a", "tuple", "in", "relation" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/relation.go#L25-L30
15,719
proullon/ramsql
driver/stmt.go
Exec
func (s *Stmt) Exec(args []driver.Value) (r driver.Result, err error) { defer func() { if r := recover(); r != nil { err = fmt.Errorf("fatalf error: %s", r) return } }() defer s.conn.mutex.Unlock() if s.query == "" { return nil, fmt.Errorf("empty statement") } var finalQuery string // replace $* by arguments in query string finalQuery = replaceArguments(s.query, args) log.Info("Exec <%s>\n", finalQuery) // Send query to server err = s.conn.conn.WriteExec(finalQuery) if err != nil { log.Warning("Exec: Cannot send query to server: %s", err) return nil, fmt.Errorf("Cannot send query to server: %s", err) } // Get answer from server lastInsertedID, rowsAffected, err := s.conn.conn.ReadResult() if err != nil { return nil, err } // Create a driver.Result return newResult(lastInsertedID, rowsAffected), nil }
go
func (s *Stmt) Exec(args []driver.Value) (r driver.Result, err error) { defer func() { if r := recover(); r != nil { err = fmt.Errorf("fatalf error: %s", r) return } }() defer s.conn.mutex.Unlock() if s.query == "" { return nil, fmt.Errorf("empty statement") } var finalQuery string // replace $* by arguments in query string finalQuery = replaceArguments(s.query, args) log.Info("Exec <%s>\n", finalQuery) // Send query to server err = s.conn.conn.WriteExec(finalQuery) if err != nil { log.Warning("Exec: Cannot send query to server: %s", err) return nil, fmt.Errorf("Cannot send query to server: %s", err) } // Get answer from server lastInsertedID, rowsAffected, err := s.conn.conn.ReadResult() if err != nil { return nil, err } // Create a driver.Result return newResult(lastInsertedID, rowsAffected), nil }
[ "func", "(", "s", "*", "Stmt", ")", "Exec", "(", "args", "[", "]", "driver", ".", "Value", ")", "(", "r", "driver", ".", "Result", ",", "err", "error", ")", "{", "defer", "func", "(", ")", "{", "if", "r", ":=", "recover", "(", ")", ";", "r", "!=", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "r", ")", "\n", "return", "\n", "}", "\n", "}", "(", ")", "\n", "defer", "s", ".", "conn", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "query", "==", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "var", "finalQuery", "string", "\n\n", "// replace $* by arguments in query string", "finalQuery", "=", "replaceArguments", "(", "s", ".", "query", ",", "args", ")", "\n", "log", ".", "Info", "(", "\"", "\\n", "\"", ",", "finalQuery", ")", "\n\n", "// Send query to server", "err", "=", "s", ".", "conn", ".", "conn", ".", "WriteExec", "(", "finalQuery", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Warning", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Get answer from server", "lastInsertedID", ",", "rowsAffected", ",", "err", ":=", "s", ".", "conn", ".", "conn", ".", "ReadResult", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Create a driver.Result", "return", "newResult", "(", "lastInsertedID", ",", "rowsAffected", ")", ",", "nil", "\n", "}" ]
// Exec executes a query that doesn't return rows, such // as an INSERT or UPDATE.
[ "Exec", "executes", "a", "query", "that", "doesn", "t", "return", "rows", "such", "as", "an", "INSERT", "or", "UPDATE", "." ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/driver/stmt.go#L75-L109
15,720
proullon/ramsql
driver/stmt.go
Query
func (s *Stmt) Query(args []driver.Value) (r driver.Rows, err error) { defer func() { if r := recover(); r != nil { err = fmt.Errorf("fatalf error: %s", r) return } }() defer s.conn.mutex.Unlock() if s.query == "" { return nil, fmt.Errorf("empty statement") } finalQuery := replaceArguments(s.query, args) log.Info("Query < %s >\n", finalQuery) err = s.conn.conn.WriteQuery(finalQuery) if err != nil { return nil, err } rowsChannel, err := s.conn.conn.ReadRows() if err != nil { return nil, err } r = newRows(rowsChannel) return r, nil }
go
func (s *Stmt) Query(args []driver.Value) (r driver.Rows, err error) { defer func() { if r := recover(); r != nil { err = fmt.Errorf("fatalf error: %s", r) return } }() defer s.conn.mutex.Unlock() if s.query == "" { return nil, fmt.Errorf("empty statement") } finalQuery := replaceArguments(s.query, args) log.Info("Query < %s >\n", finalQuery) err = s.conn.conn.WriteQuery(finalQuery) if err != nil { return nil, err } rowsChannel, err := s.conn.conn.ReadRows() if err != nil { return nil, err } r = newRows(rowsChannel) return r, nil }
[ "func", "(", "s", "*", "Stmt", ")", "Query", "(", "args", "[", "]", "driver", ".", "Value", ")", "(", "r", "driver", ".", "Rows", ",", "err", "error", ")", "{", "defer", "func", "(", ")", "{", "if", "r", ":=", "recover", "(", ")", ";", "r", "!=", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "r", ")", "\n", "return", "\n", "}", "\n", "}", "(", ")", "\n", "defer", "s", ".", "conn", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "query", "==", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "finalQuery", ":=", "replaceArguments", "(", "s", ".", "query", ",", "args", ")", "\n", "log", ".", "Info", "(", "\"", "\\n", "\"", ",", "finalQuery", ")", "\n", "err", "=", "s", ".", "conn", ".", "conn", ".", "WriteQuery", "(", "finalQuery", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "rowsChannel", ",", "err", ":=", "s", ".", "conn", ".", "conn", ".", "ReadRows", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "r", "=", "newRows", "(", "rowsChannel", ")", "\n", "return", "r", ",", "nil", "\n", "}" ]
// Query executes a query that may return rows, such as a // SELECT.
[ "Query", "executes", "a", "query", "that", "may", "return", "rows", "such", "as", "a", "SELECT", "." ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/driver/stmt.go#L113-L140
15,721
proullon/ramsql
engine/protocol/buffer.go
UnlimitedRowsChannel
func UnlimitedRowsChannel(bufferThis chan message, firstMessage message) chan []string { driverChannel := make(chan []string) rowList := list.New() rowList.PushBack(firstMessage.Value) go func() { for { // If nothing comes in and nothing is going out... if rowList.Len() == 0 && bufferThis == nil { close(driverChannel) return } // Create a copy of driverChannel because if there is nothing to send // We can disable the case in select with a nil channel and get a chance // to fetch new data on bufferThis channel driverChannelNullable := driverChannel var nextRow []string if rowList.Len() != 0 { nextRow = rowList.Front().Value.([]string) } else { driverChannelNullable = nil } select { // In case a new row is sent to driver case driverChannelNullable <- nextRow: if nextRow != nil { rowList.Remove(rowList.Front()) } // In case we receive a new value to buffer from engine channel case newRow, ok := <-bufferThis: if !ok || newRow.Type == rowEndMessage { // Stop listening to bufferThis channel bufferThis = nil // If there is nothing more to listen and there is nothing in buffer, exit // close driverChannel so *Rows knows there is nothing more to read if rowList.Len() == 0 { if driverChannel != nil { close(driverChannel) } return } if driverChannel == nil { log.Critical("Unlimited: But there is nobody to read it, exiting") return } } else if newRow.Type == errMessage { log.Critical("Runtime error: %s", newRow.Value[0]) if driverChannel != nil { close(driverChannel) } return } else { // Everything is ok, buffering new value rowList.PushBack(newRow.Value) } case exit := <-driverChannel: // this means driverChannel is closed // set driverChannel to nil so we don't try to close it again driverChannel = nil _ = exit } } }() return driverChannel }
go
func UnlimitedRowsChannel(bufferThis chan message, firstMessage message) chan []string { driverChannel := make(chan []string) rowList := list.New() rowList.PushBack(firstMessage.Value) go func() { for { // If nothing comes in and nothing is going out... if rowList.Len() == 0 && bufferThis == nil { close(driverChannel) return } // Create a copy of driverChannel because if there is nothing to send // We can disable the case in select with a nil channel and get a chance // to fetch new data on bufferThis channel driverChannelNullable := driverChannel var nextRow []string if rowList.Len() != 0 { nextRow = rowList.Front().Value.([]string) } else { driverChannelNullable = nil } select { // In case a new row is sent to driver case driverChannelNullable <- nextRow: if nextRow != nil { rowList.Remove(rowList.Front()) } // In case we receive a new value to buffer from engine channel case newRow, ok := <-bufferThis: if !ok || newRow.Type == rowEndMessage { // Stop listening to bufferThis channel bufferThis = nil // If there is nothing more to listen and there is nothing in buffer, exit // close driverChannel so *Rows knows there is nothing more to read if rowList.Len() == 0 { if driverChannel != nil { close(driverChannel) } return } if driverChannel == nil { log.Critical("Unlimited: But there is nobody to read it, exiting") return } } else if newRow.Type == errMessage { log.Critical("Runtime error: %s", newRow.Value[0]) if driverChannel != nil { close(driverChannel) } return } else { // Everything is ok, buffering new value rowList.PushBack(newRow.Value) } case exit := <-driverChannel: // this means driverChannel is closed // set driverChannel to nil so we don't try to close it again driverChannel = nil _ = exit } } }() return driverChannel }
[ "func", "UnlimitedRowsChannel", "(", "bufferThis", "chan", "message", ",", "firstMessage", "message", ")", "chan", "[", "]", "string", "{", "driverChannel", ":=", "make", "(", "chan", "[", "]", "string", ")", "\n", "rowList", ":=", "list", ".", "New", "(", ")", "\n\n", "rowList", ".", "PushBack", "(", "firstMessage", ".", "Value", ")", "\n\n", "go", "func", "(", ")", "{", "for", "{", "// If nothing comes in and nothing is going out...", "if", "rowList", ".", "Len", "(", ")", "==", "0", "&&", "bufferThis", "==", "nil", "{", "close", "(", "driverChannel", ")", "\n", "return", "\n", "}", "\n\n", "// Create a copy of driverChannel because if there is nothing to send", "// We can disable the case in select with a nil channel and get a chance", "// to fetch new data on bufferThis channel", "driverChannelNullable", ":=", "driverChannel", "\n", "var", "nextRow", "[", "]", "string", "\n", "if", "rowList", ".", "Len", "(", ")", "!=", "0", "{", "nextRow", "=", "rowList", ".", "Front", "(", ")", ".", "Value", ".", "(", "[", "]", "string", ")", "\n", "}", "else", "{", "driverChannelNullable", "=", "nil", "\n", "}", "\n\n", "select", "{", "// In case a new row is sent to driver", "case", "driverChannelNullable", "<-", "nextRow", ":", "if", "nextRow", "!=", "nil", "{", "rowList", ".", "Remove", "(", "rowList", ".", "Front", "(", ")", ")", "\n", "}", "\n", "// In case we receive a new value to buffer from engine channel", "case", "newRow", ",", "ok", ":=", "<-", "bufferThis", ":", "if", "!", "ok", "||", "newRow", ".", "Type", "==", "rowEndMessage", "{", "// Stop listening to bufferThis channel", "bufferThis", "=", "nil", "\n", "// If there is nothing more to listen and there is nothing in buffer, exit", "// close driverChannel so *Rows knows there is nothing more to read", "if", "rowList", ".", "Len", "(", ")", "==", "0", "{", "if", "driverChannel", "!=", "nil", "{", "close", "(", "driverChannel", ")", "\n", "}", "\n", "return", "\n", "}", "\n\n", "if", "driverChannel", "==", "nil", "{", "log", ".", "Critical", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n", "}", "else", "if", "newRow", ".", "Type", "==", "errMessage", "{", "log", ".", "Critical", "(", "\"", "\"", ",", "newRow", ".", "Value", "[", "0", "]", ")", "\n", "if", "driverChannel", "!=", "nil", "{", "close", "(", "driverChannel", ")", "\n", "}", "\n", "return", "\n", "}", "else", "{", "// Everything is ok, buffering new value", "rowList", ".", "PushBack", "(", "newRow", ".", "Value", ")", "\n", "}", "\n", "case", "exit", ":=", "<-", "driverChannel", ":", "// this means driverChannel is closed", "// set driverChannel to nil so we don't try to close it again", "driverChannel", "=", "nil", "\n", "_", "=", "exit", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n\n", "return", "driverChannel", "\n", "}" ]
// UnlimitedRowsChannel buffers incomming message from bufferThis channel and forward them to // returned channel. // ONLY CREATED CHANNEL IS CLOSED HERE.
[ "UnlimitedRowsChannel", "buffers", "incomming", "message", "from", "bufferThis", "channel", "and", "forward", "them", "to", "returned", "channel", ".", "ONLY", "CREATED", "CHANNEL", "IS", "CLOSED", "HERE", "." ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/protocol/buffer.go#L12-L81
15,722
proullon/ramsql
engine/operator.go
NewOperator
func NewOperator(token int, lexeme string) (Operator, error) { switch token { case parser.EqualityToken: return equalityOperator, nil case parser.LeftDipleToken: return lessThanOperator, nil case parser.RightDipleToken: return greaterThanOperator, nil case parser.LessOrEqualToken: return lessOrEqualOperator, nil case parser.GreaterOrEqualToken: return greaterOrEqualOperator, nil } return nil, fmt.Errorf("Operator '%s' does not exist", lexeme) }
go
func NewOperator(token int, lexeme string) (Operator, error) { switch token { case parser.EqualityToken: return equalityOperator, nil case parser.LeftDipleToken: return lessThanOperator, nil case parser.RightDipleToken: return greaterThanOperator, nil case parser.LessOrEqualToken: return lessOrEqualOperator, nil case parser.GreaterOrEqualToken: return greaterOrEqualOperator, nil } return nil, fmt.Errorf("Operator '%s' does not exist", lexeme) }
[ "func", "NewOperator", "(", "token", "int", ",", "lexeme", "string", ")", "(", "Operator", ",", "error", ")", "{", "switch", "token", "{", "case", "parser", ".", "EqualityToken", ":", "return", "equalityOperator", ",", "nil", "\n", "case", "parser", ".", "LeftDipleToken", ":", "return", "lessThanOperator", ",", "nil", "\n", "case", "parser", ".", "RightDipleToken", ":", "return", "greaterThanOperator", ",", "nil", "\n", "case", "parser", ".", "LessOrEqualToken", ":", "return", "lessOrEqualOperator", ",", "nil", "\n", "case", "parser", ".", "GreaterOrEqualToken", ":", "return", "greaterOrEqualOperator", ",", "nil", "\n", "}", "\n\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "lexeme", ")", "\n", "}" ]
// NewOperator initializes the operator matching the Token number
[ "NewOperator", "initializes", "the", "operator", "matching", "the", "Token", "number" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/operator.go#L15-L30
15,723
proullon/ramsql
engine/operator.go
equalityOperator
func equalityOperator(leftValue Value, rightValue Value) bool { if fmt.Sprintf("%v", leftValue.v) == rightValue.lexeme { return true } return false }
go
func equalityOperator(leftValue Value, rightValue Value) bool { if fmt.Sprintf("%v", leftValue.v) == rightValue.lexeme { return true } return false }
[ "func", "equalityOperator", "(", "leftValue", "Value", ",", "rightValue", "Value", ")", "bool", "{", "if", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "leftValue", ".", "v", ")", "==", "rightValue", ".", "lexeme", "{", "return", "true", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// EqualityOperator checks if given value are equal
[ "EqualityOperator", "checks", "if", "given", "value", "are", "equal" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/operator.go#L164-L171
15,724
proullon/ramsql
engine/table.go
AddAttribute
func (t *Table) AddAttribute(attr Attribute) error { t.attributes = append(t.attributes, attr) return nil }
go
func (t *Table) AddAttribute(attr Attribute) error { t.attributes = append(t.attributes, attr) return nil }
[ "func", "(", "t", "*", "Table", ")", "AddAttribute", "(", "attr", "Attribute", ")", "error", "{", "t", ".", "attributes", "=", "append", "(", "t", ".", "attributes", ",", "attr", ")", "\n", "return", "nil", "\n", "}" ]
// AddAttribute is used by CREATE TABLE and ALTER TABLE // Want to check that name isn't already taken
[ "AddAttribute", "is", "used", "by", "CREATE", "TABLE", "and", "ALTER", "TABLE", "Want", "to", "check", "that", "name", "isn", "t", "already", "taken" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/table.go#L28-L31
15,725
proullon/ramsql
engine/table.go
String
func (t Table) String() string { stringy := t.name + " (" for i, a := range t.attributes { if i != 0 { stringy += " | " } stringy += a.name + " " + a.typeName } stringy += ")" return stringy }
go
func (t Table) String() string { stringy := t.name + " (" for i, a := range t.attributes { if i != 0 { stringy += " | " } stringy += a.name + " " + a.typeName } stringy += ")" return stringy }
[ "func", "(", "t", "Table", ")", "String", "(", ")", "string", "{", "stringy", ":=", "t", ".", "name", "+", "\"", "\"", "\n", "for", "i", ",", "a", ":=", "range", "t", ".", "attributes", "{", "if", "i", "!=", "0", "{", "stringy", "+=", "\"", "\"", "\n", "}", "\n", "stringy", "+=", "a", ".", "name", "+", "\"", "\"", "+", "a", ".", "typeName", "\n", "}", "\n", "stringy", "+=", "\"", "\"", "\n", "return", "stringy", "\n", "}" ]
// String returns a printable string with table name and attributes
[ "String", "returns", "a", "printable", "string", "with", "table", "name", "and", "attributes" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/table.go#L34-L44
15,726
proullon/ramsql
engine/log/log.go
Debug
func Debug(format string, values ...interface{}) { if lvl() <= DebugLevel { logger.Logf("[DEBUG] "+format, values...) } }
go
func Debug(format string, values ...interface{}) { if lvl() <= DebugLevel { logger.Logf("[DEBUG] "+format, values...) } }
[ "func", "Debug", "(", "format", "string", ",", "values", "...", "interface", "{", "}", ")", "{", "if", "lvl", "(", ")", "<=", "DebugLevel", "{", "logger", ".", "Logf", "(", "\"", "\"", "+", "format", ",", "values", "...", ")", "\n", "}", "\n", "}" ]
// Debug prints debug log
[ "Debug", "prints", "debug", "log" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/log/log.go#L52-L56
15,727
proullon/ramsql
engine/log/log.go
Info
func Info(format string, values ...interface{}) { if lvl() <= InfoLevel { logger.Logf("[INFO] "+format, values...) } }
go
func Info(format string, values ...interface{}) { if lvl() <= InfoLevel { logger.Logf("[INFO] "+format, values...) } }
[ "func", "Info", "(", "format", "string", ",", "values", "...", "interface", "{", "}", ")", "{", "if", "lvl", "(", ")", "<=", "InfoLevel", "{", "logger", ".", "Logf", "(", "\"", "\"", "+", "format", ",", "values", "...", ")", "\n", "}", "\n", "}" ]
// Info prints information log
[ "Info", "prints", "information", "log" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/log/log.go#L59-L63
15,728
proullon/ramsql
engine/log/log.go
Notice
func Notice(format string, values ...interface{}) { if lvl() <= NoticeLevel { logger.Logf("[NOTICE] "+format, values...) } }
go
func Notice(format string, values ...interface{}) { if lvl() <= NoticeLevel { logger.Logf("[NOTICE] "+format, values...) } }
[ "func", "Notice", "(", "format", "string", ",", "values", "...", "interface", "{", "}", ")", "{", "if", "lvl", "(", ")", "<=", "NoticeLevel", "{", "logger", ".", "Logf", "(", "\"", "\"", "+", "format", ",", "values", "...", ")", "\n", "}", "\n", "}" ]
// Notice prints information that should be seen
[ "Notice", "prints", "information", "that", "should", "be", "seen" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/log/log.go#L66-L70
15,729
proullon/ramsql
engine/log/log.go
Warning
func Warning(format string, values ...interface{}) { if lvl() <= WarningLevel { logger.Logf("[WARNING] "+format, values...) } }
go
func Warning(format string, values ...interface{}) { if lvl() <= WarningLevel { logger.Logf("[WARNING] "+format, values...) } }
[ "func", "Warning", "(", "format", "string", ",", "values", "...", "interface", "{", "}", ")", "{", "if", "lvl", "(", ")", "<=", "WarningLevel", "{", "logger", ".", "Logf", "(", "\"", "\"", "+", "format", ",", "values", "...", ")", "\n", "}", "\n", "}" ]
// Warning prints warnings for user
[ "Warning", "prints", "warnings", "for", "user" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/log/log.go#L73-L77
15,730
proullon/ramsql
engine/log/log.go
Critical
func Critical(format string, values ...interface{}) { mu.Lock() logger.Logf("[CRITICAL] "+format, values...) mu.Unlock() }
go
func Critical(format string, values ...interface{}) { mu.Lock() logger.Logf("[CRITICAL] "+format, values...) mu.Unlock() }
[ "func", "Critical", "(", "format", "string", ",", "values", "...", "interface", "{", "}", ")", "{", "mu", ".", "Lock", "(", ")", "\n", "logger", ".", "Logf", "(", "\"", "\"", "+", "format", ",", "values", "...", ")", "\n", "mu", ".", "Unlock", "(", ")", "\n", "}" ]
// Critical prints error informations
[ "Critical", "prints", "error", "informations" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/log/log.go#L80-L84
15,731
proullon/ramsql
engine/log/log.go
Logf
func (l BaseLogger) Logf(fmt string, values ...interface{}) { log.Printf(fmt, values...) }
go
func (l BaseLogger) Logf(fmt string, values ...interface{}) { log.Printf(fmt, values...) }
[ "func", "(", "l", "BaseLogger", ")", "Logf", "(", "fmt", "string", ",", "values", "...", "interface", "{", "}", ")", "{", "log", ".", "Printf", "(", "fmt", ",", "values", "...", ")", "\n", "}" ]
// Logf logs on stdout
[ "Logf", "logs", "on", "stdout" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/log/log.go#L91-L93
15,732
proullon/ramsql
engine/log/log.go
Logf
func (l TestLogger) Logf(fmt string, values ...interface{}) { l.t.Logf(fmt, values...) }
go
func (l TestLogger) Logf(fmt string, values ...interface{}) { l.t.Logf(fmt, values...) }
[ "func", "(", "l", "TestLogger", ")", "Logf", "(", "fmt", "string", ",", "values", "...", "interface", "{", "}", ")", "{", "l", ".", "t", ".", "Logf", "(", "fmt", ",", "values", "...", ")", "\n", "}" ]
// Logf logs in testing log buffer
[ "Logf", "logs", "in", "testing", "log", "buffer" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/log/log.go#L101-L103
15,733
proullon/ramsql
engine/parser/interface.go
ParseInstruction
func ParseInstruction(instruction string) ([]Instruction, error) { l := lexer{} tokens, err := l.lex([]byte(instruction)) if err != nil { return nil, err } p := parser{} instructions, err := p.parse(tokens) if err != nil { return nil, err } if len(instructions) == 0 { return nil, errors.New("Error in syntax near " + instruction) } return instructions, nil }
go
func ParseInstruction(instruction string) ([]Instruction, error) { l := lexer{} tokens, err := l.lex([]byte(instruction)) if err != nil { return nil, err } p := parser{} instructions, err := p.parse(tokens) if err != nil { return nil, err } if len(instructions) == 0 { return nil, errors.New("Error in syntax near " + instruction) } return instructions, nil }
[ "func", "ParseInstruction", "(", "instruction", "string", ")", "(", "[", "]", "Instruction", ",", "error", ")", "{", "l", ":=", "lexer", "{", "}", "\n", "tokens", ",", "err", ":=", "l", ".", "lex", "(", "[", "]", "byte", "(", "instruction", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "p", ":=", "parser", "{", "}", "\n", "instructions", ",", "err", ":=", "p", ".", "parse", "(", "tokens", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "len", "(", "instructions", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", "+", "instruction", ")", "\n", "}", "\n\n", "return", "instructions", ",", "nil", "\n", "}" ]
// ParseInstruction calls lexer and parser, then return Decl tree for each instruction
[ "ParseInstruction", "calls", "lexer", "and", "parser", "then", "return", "Decl", "tree", "for", "each", "instruction" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/parser/interface.go#L8-L27
15,734
proullon/ramsql
engine/parser/date.go
ParseDate
func ParseDate(data string) (*time.Time, error) { t, err := time.Parse(DateLongFormat, data) if err == nil { return &t, nil } t, err = time.Parse(time.RFC3339, data) if err == nil { return &t, nil } t, err = time.Parse(DateShortFormat, data) if err == nil { return &t, nil } t, err = time.Parse(DateNumberFormat, data) if err == nil { return &t, nil } return nil, fmt.Errorf("not a date") }
go
func ParseDate(data string) (*time.Time, error) { t, err := time.Parse(DateLongFormat, data) if err == nil { return &t, nil } t, err = time.Parse(time.RFC3339, data) if err == nil { return &t, nil } t, err = time.Parse(DateShortFormat, data) if err == nil { return &t, nil } t, err = time.Parse(DateNumberFormat, data) if err == nil { return &t, nil } return nil, fmt.Errorf("not a date") }
[ "func", "ParseDate", "(", "data", "string", ")", "(", "*", "time", ".", "Time", ",", "error", ")", "{", "t", ",", "err", ":=", "time", ".", "Parse", "(", "DateLongFormat", ",", "data", ")", "\n", "if", "err", "==", "nil", "{", "return", "&", "t", ",", "nil", "\n", "}", "\n\n", "t", ",", "err", "=", "time", ".", "Parse", "(", "time", ".", "RFC3339", ",", "data", ")", "\n", "if", "err", "==", "nil", "{", "return", "&", "t", ",", "nil", "\n", "}", "\n\n", "t", ",", "err", "=", "time", ".", "Parse", "(", "DateShortFormat", ",", "data", ")", "\n", "if", "err", "==", "nil", "{", "return", "&", "t", ",", "nil", "\n", "}", "\n\n", "t", ",", "err", "=", "time", ".", "Parse", "(", "DateNumberFormat", ",", "data", ")", "\n", "if", "err", "==", "nil", "{", "return", "&", "t", ",", "nil", "\n", "}", "\n\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}" ]
// ParseDate intends to parse all SQL date format
[ "ParseDate", "intends", "to", "parse", "all", "SQL", "date", "format" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/parser/date.go#L17-L39
15,735
proullon/ramsql
driver/driver.go
Open
func (rs *Driver) Open(dsn string) (conn driver.Conn, err error) { rs.Lock() connConf, err := parseConnectionURI(dsn) if err != nil { rs.Unlock() return nil, err } dsnServer, exist := rs.servers[dsn] if !exist { driverEndpoint, engineEndpoint, err := endpoints(connConf) if err != nil { rs.Unlock() return nil, err } server, err := engine.New(engineEndpoint) if err != nil { rs.Unlock() return nil, err } driverConn, err := driverEndpoint.New(dsn) if err != nil { rs.Unlock() return nil, err } s := &Server{ endpoint: driverEndpoint, server: server, } rs.servers[dsn] = s rs.Unlock() return newConn(driverConn, s), nil } rs.Unlock() driverConn, err := dsnServer.endpoint.New(dsn) return newConn(driverConn, dsnServer), err }
go
func (rs *Driver) Open(dsn string) (conn driver.Conn, err error) { rs.Lock() connConf, err := parseConnectionURI(dsn) if err != nil { rs.Unlock() return nil, err } dsnServer, exist := rs.servers[dsn] if !exist { driverEndpoint, engineEndpoint, err := endpoints(connConf) if err != nil { rs.Unlock() return nil, err } server, err := engine.New(engineEndpoint) if err != nil { rs.Unlock() return nil, err } driverConn, err := driverEndpoint.New(dsn) if err != nil { rs.Unlock() return nil, err } s := &Server{ endpoint: driverEndpoint, server: server, } rs.servers[dsn] = s rs.Unlock() return newConn(driverConn, s), nil } rs.Unlock() driverConn, err := dsnServer.endpoint.New(dsn) return newConn(driverConn, dsnServer), err }
[ "func", "(", "rs", "*", "Driver", ")", "Open", "(", "dsn", "string", ")", "(", "conn", "driver", ".", "Conn", ",", "err", "error", ")", "{", "rs", ".", "Lock", "(", ")", "\n\n", "connConf", ",", "err", ":=", "parseConnectionURI", "(", "dsn", ")", "\n", "if", "err", "!=", "nil", "{", "rs", ".", "Unlock", "(", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "dsnServer", ",", "exist", ":=", "rs", ".", "servers", "[", "dsn", "]", "\n", "if", "!", "exist", "{", "driverEndpoint", ",", "engineEndpoint", ",", "err", ":=", "endpoints", "(", "connConf", ")", "\n", "if", "err", "!=", "nil", "{", "rs", ".", "Unlock", "(", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "server", ",", "err", ":=", "engine", ".", "New", "(", "engineEndpoint", ")", "\n", "if", "err", "!=", "nil", "{", "rs", ".", "Unlock", "(", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "driverConn", ",", "err", ":=", "driverEndpoint", ".", "New", "(", "dsn", ")", "\n", "if", "err", "!=", "nil", "{", "rs", ".", "Unlock", "(", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "s", ":=", "&", "Server", "{", "endpoint", ":", "driverEndpoint", ",", "server", ":", "server", ",", "}", "\n", "rs", ".", "servers", "[", "dsn", "]", "=", "s", "\n\n", "rs", ".", "Unlock", "(", ")", "\n", "return", "newConn", "(", "driverConn", ",", "s", ")", ",", "nil", "\n", "}", "\n\n", "rs", ".", "Unlock", "(", ")", "\n", "driverConn", ",", "err", ":=", "dsnServer", ".", "endpoint", ".", "New", "(", "dsn", ")", "\n", "return", "newConn", "(", "driverConn", ",", "dsnServer", ")", ",", "err", "\n", "}" ]
// Open return an active connection so RamSQL server // If there is no connection in pool, start a new server. // After first instantiation of the server,
[ "Open", "return", "an", "active", "connection", "so", "RamSQL", "server", "If", "there", "is", "no", "connection", "in", "pool", "start", "a", "new", "server", ".", "After", "first", "instantiation", "of", "the", "server" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/driver/driver.go#L62-L104
15,736
proullon/ramsql
driver/rows.go
Close
func (r *Rows) Close() error { r.Lock() defer r.Unlock() if r.rowsChannel == nil { return nil } _, ok := <-r.rowsChannel if !ok { return nil } // Tels UnlimitedRowsChannel to close itself //r.rowsChannel <- []string{} r.rowsChannel = nil return nil }
go
func (r *Rows) Close() error { r.Lock() defer r.Unlock() if r.rowsChannel == nil { return nil } _, ok := <-r.rowsChannel if !ok { return nil } // Tels UnlimitedRowsChannel to close itself //r.rowsChannel <- []string{} r.rowsChannel = nil return nil }
[ "func", "(", "r", "*", "Rows", ")", "Close", "(", ")", "error", "{", "r", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "Unlock", "(", ")", "\n\n", "if", "r", ".", "rowsChannel", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "_", ",", "ok", ":=", "<-", "r", ".", "rowsChannel", "\n", "if", "!", "ok", "{", "return", "nil", "\n", "}", "\n\n", "// Tels UnlimitedRowsChannel to close itself", "//r.rowsChannel <- []string{}", "r", ".", "rowsChannel", "=", "nil", "\n", "return", "nil", "\n", "}" ]
// Close closes the rows iterator.
[ "Close", "closes", "the", "rows", "iterator", "." ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/driver/rows.go#L43-L60
15,737
proullon/ramsql
engine/protocol/public.go
NewChannelEndpoints
func NewChannelEndpoints() (DriverEndpoint, EngineEndpoint) { channel := make(chan chan message) return NewChannelDriverEndpoint(channel), NewChannelEngineEndpoint(channel) }
go
func NewChannelEndpoints() (DriverEndpoint, EngineEndpoint) { channel := make(chan chan message) return NewChannelDriverEndpoint(channel), NewChannelEngineEndpoint(channel) }
[ "func", "NewChannelEndpoints", "(", ")", "(", "DriverEndpoint", ",", "EngineEndpoint", ")", "{", "channel", ":=", "make", "(", "chan", "chan", "message", ")", "\n\n", "return", "NewChannelDriverEndpoint", "(", "channel", ")", ",", "NewChannelEngineEndpoint", "(", "channel", ")", "\n", "}" ]
// NewChannelEndpoints instanciates a Driver and // Engine channel endpoints
[ "NewChannelEndpoints", "instanciates", "a", "Driver", "and", "Engine", "channel", "endpoints" ]
817cee58a24456db9e01091be07f562703408ca3
https://github.com/proullon/ramsql/blob/817cee58a24456db9e01091be07f562703408ca3/engine/protocol/public.go#L39-L43
15,738
gortc/sdp
sdp.go
Equal
func (l Line) Equal(b Line) bool { if l.Type != b.Type { return false } return bytes.Equal(l.Value, b.Value) }
go
func (l Line) Equal(b Line) bool { if l.Type != b.Type { return false } return bytes.Equal(l.Value, b.Value) }
[ "func", "(", "l", "Line", ")", "Equal", "(", "b", "Line", ")", "bool", "{", "if", "l", ".", "Type", "!=", "b", ".", "Type", "{", "return", "false", "\n", "}", "\n", "return", "bytes", ".", "Equal", "(", "l", ".", "Value", ",", "b", ".", "Value", ")", "\n", "}" ]
// Equal returns true if l == b.
[ "Equal", "returns", "true", "if", "l", "==", "b", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/sdp.go#L48-L53
15,739
gortc/sdp
sdp.go
Decode
func (l *Line) Decode(b []byte) error { delimiter := bytes.IndexRune(b, lineDelimiter) if delimiter == -1 { reason := `delimiter "=" not found` err := newDecodeError("line", reason) return errors.Wrap(err, "failed to decode") } if len(b) <= (delimiter + 1) { reason := fmt.Sprintf( "len(b) %d < (%d + 1), no value found after delimiter", len(b), delimiter, ) err := newDecodeError("line", reason) return errors.Wrap(err, "failed to decode") } r, _ := utf8.DecodeRune(b[:delimiter]) l.Type = Type(r) l.Value = append(l.Value, b[delimiter+1:]...) return nil }
go
func (l *Line) Decode(b []byte) error { delimiter := bytes.IndexRune(b, lineDelimiter) if delimiter == -1 { reason := `delimiter "=" not found` err := newDecodeError("line", reason) return errors.Wrap(err, "failed to decode") } if len(b) <= (delimiter + 1) { reason := fmt.Sprintf( "len(b) %d < (%d + 1), no value found after delimiter", len(b), delimiter, ) err := newDecodeError("line", reason) return errors.Wrap(err, "failed to decode") } r, _ := utf8.DecodeRune(b[:delimiter]) l.Type = Type(r) l.Value = append(l.Value, b[delimiter+1:]...) return nil }
[ "func", "(", "l", "*", "Line", ")", "Decode", "(", "b", "[", "]", "byte", ")", "error", "{", "delimiter", ":=", "bytes", ".", "IndexRune", "(", "b", ",", "lineDelimiter", ")", "\n", "if", "delimiter", "==", "-", "1", "{", "reason", ":=", "`delimiter \"=\" not found`", "\n", "err", ":=", "newDecodeError", "(", "\"", "\"", ",", "reason", ")", "\n", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "b", ")", "<=", "(", "delimiter", "+", "1", ")", "{", "reason", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "len", "(", "b", ")", ",", "delimiter", ",", ")", "\n", "err", ":=", "newDecodeError", "(", "\"", "\"", ",", "reason", ")", "\n", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "r", ",", "_", ":=", "utf8", ".", "DecodeRune", "(", "b", "[", ":", "delimiter", "]", ")", "\n", "l", ".", "Type", "=", "Type", "(", "r", ")", "\n", "l", ".", "Value", "=", "append", "(", "l", ".", "Value", ",", "b", "[", "delimiter", "+", "1", ":", "]", "...", ")", "\n", "return", "nil", "\n", "}" ]
// Decode parses b into l and returns error if any. // // Decode does not reuse b, so it is safe to corrupt it.
[ "Decode", "parses", "b", "into", "l", "and", "returns", "error", "if", "any", ".", "Decode", "does", "not", "reuse", "b", "so", "it", "is", "safe", "to", "corrupt", "it", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/sdp.go#L58-L77
15,740
gortc/sdp
sdp.go
AppendTo
func (l Line) AppendTo(b []byte) []byte { b = l.Type.appendTo(b) b = appendRune(b, lineDelimiter) return append(b, l.Value...) }
go
func (l Line) AppendTo(b []byte) []byte { b = l.Type.appendTo(b) b = appendRune(b, lineDelimiter) return append(b, l.Value...) }
[ "func", "(", "l", "Line", ")", "AppendTo", "(", "b", "[", "]", "byte", ")", "[", "]", "byte", "{", "b", "=", "l", ".", "Type", ".", "appendTo", "(", "b", ")", "\n", "b", "=", "appendRune", "(", "b", ",", "lineDelimiter", ")", "\n", "return", "append", "(", "b", ",", "l", ".", "Value", "...", ")", "\n", "}" ]
// AppendTo appends Line encoded value to b.
[ "AppendTo", "appends", "Line", "encoded", "value", "to", "b", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/sdp.go#L100-L104
15,741
gortc/sdp
sdp.go
AppendTo
func (s Session) AppendTo(b []byte) []byte { for _, l := range s { b = l.AppendTo(b) b = appendCLRF(b) } return b }
go
func (s Session) AppendTo(b []byte) []byte { for _, l := range s { b = l.AppendTo(b) b = appendCLRF(b) } return b }
[ "func", "(", "s", "Session", ")", "AppendTo", "(", "b", "[", "]", "byte", ")", "[", "]", "byte", "{", "for", "_", ",", "l", ":=", "range", "s", "{", "b", "=", "l", ".", "AppendTo", "(", "b", ")", "\n", "b", "=", "appendCLRF", "(", "b", ")", "\n", "}", "\n", "return", "b", "\n", "}" ]
// AppendTo appends all session lines to b and returns b.
[ "AppendTo", "appends", "all", "session", "lines", "to", "b", "and", "returns", "b", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/sdp.go#L167-L173
15,742
gortc/sdp
sdp.go
Equal
func (s Session) Equal(b Session) bool { if len(s) != len(b) { return false } for i := range s { if !s[i].Equal(b[i]) { return false } } return true }
go
func (s Session) Equal(b Session) bool { if len(s) != len(b) { return false } for i := range s { if !s[i].Equal(b[i]) { return false } } return true }
[ "func", "(", "s", "Session", ")", "Equal", "(", "b", "Session", ")", "bool", "{", "if", "len", "(", "s", ")", "!=", "len", "(", "b", ")", "{", "return", "false", "\n", "}", "\n", "for", "i", ":=", "range", "s", "{", "if", "!", "s", "[", "i", "]", ".", "Equal", "(", "b", "[", "i", "]", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Equal returns true if b == s.
[ "Equal", "returns", "true", "if", "b", "==", "s", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/sdp.go#L176-L186
15,743
gortc/sdp
message.go
Value
func (a Attributes) Value(attribute string) string { for _, v := range a { if v.Key == attribute { return v.Value } } return blank }
go
func (a Attributes) Value(attribute string) string { for _, v := range a { if v.Key == attribute { return v.Value } } return blank }
[ "func", "(", "a", "Attributes", ")", "Value", "(", "attribute", "string", ")", "string", "{", "for", "_", ",", "v", ":=", "range", "a", "{", "if", "v", ".", "Key", "==", "attribute", "{", "return", "v", ".", "Value", "\n", "}", "\n", "}", "\n", "return", "blank", "\n", "}" ]
// Value returns value of first attribute.
[ "Value", "returns", "value", "of", "first", "attribute", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/message.go#L18-L25
15,744
gortc/sdp
message.go
Values
func (a Attributes) Values(attribute string) []string { var values []string for _, v := range a { if v.Key == attribute { values = append(values, v.Value) } } return values }
go
func (a Attributes) Values(attribute string) []string { var values []string for _, v := range a { if v.Key == attribute { values = append(values, v.Value) } } return values }
[ "func", "(", "a", "Attributes", ")", "Values", "(", "attribute", "string", ")", "[", "]", "string", "{", "var", "values", "[", "]", "string", "\n", "for", "_", ",", "v", ":=", "range", "a", "{", "if", "v", ".", "Key", "==", "attribute", "{", "values", "=", "append", "(", "values", ",", "v", ".", "Value", ")", "\n", "}", "\n", "}", "\n", "return", "values", "\n", "}" ]
// Values returns list of values associated to attribute.
[ "Values", "returns", "list", "of", "values", "associated", "to", "attribute", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/message.go#L28-L36
15,745
gortc/sdp
message.go
Start
func (m *Message) Start() time.Time { if len(m.Timing) == 0 { return time.Time{} } return m.Timing[0].Start }
go
func (m *Message) Start() time.Time { if len(m.Timing) == 0 { return time.Time{} } return m.Timing[0].Start }
[ "func", "(", "m", "*", "Message", ")", "Start", "(", ")", "time", ".", "Time", "{", "if", "len", "(", "m", ".", "Timing", ")", "==", "0", "{", "return", "time", ".", "Time", "{", "}", "\n", "}", "\n", "return", "m", ".", "Timing", "[", "0", "]", ".", "Start", "\n", "}" ]
// Start returns start of session.
[ "Start", "returns", "start", "of", "session", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/message.go#L77-L82
15,746
gortc/sdp
message.go
End
func (m *Message) End() time.Time { if len(m.Timing) == 0 { return time.Time{} } return m.Timing[0].End }
go
func (m *Message) End() time.Time { if len(m.Timing) == 0 { return time.Time{} } return m.Timing[0].End }
[ "func", "(", "m", "*", "Message", ")", "End", "(", ")", "time", ".", "Time", "{", "if", "len", "(", "m", ".", "Timing", ")", "==", "0", "{", "return", "time", ".", "Time", "{", "}", "\n", "}", "\n", "return", "m", ".", "Timing", "[", "0", "]", ".", "End", "\n", "}" ]
// End returns end of session.
[ "End", "returns", "end", "of", "session", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/message.go#L85-L90
15,747
gortc/sdp
message.go
PayloadFormat
func (m *Media) PayloadFormat(payloadType string) string { for _, v := range m.Attributes.Values("rtpmap") { if strings.HasPrefix(v, payloadType) { return strings.TrimSpace( strings.TrimPrefix(v, payloadType), ) } } return "" }
go
func (m *Media) PayloadFormat(payloadType string) string { for _, v := range m.Attributes.Values("rtpmap") { if strings.HasPrefix(v, payloadType) { return strings.TrimSpace( strings.TrimPrefix(v, payloadType), ) } } return "" }
[ "func", "(", "m", "*", "Media", ")", "PayloadFormat", "(", "payloadType", "string", ")", "string", "{", "for", "_", ",", "v", ":=", "range", "m", ".", "Attributes", ".", "Values", "(", "\"", "\"", ")", "{", "if", "strings", ".", "HasPrefix", "(", "v", ",", "payloadType", ")", "{", "return", "strings", ".", "TrimSpace", "(", "strings", ".", "TrimPrefix", "(", "v", ",", "payloadType", ")", ",", ")", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// PayloadFormat returns payload format from a=rtpmap. // See RFC 4566 Section 6.
[ "PayloadFormat", "returns", "payload", "format", "from", "a", "=", "rtpmap", ".", "See", "RFC", "4566", "Section", "6", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/message.go#L152-L161
15,748
gortc/sdp
fields.go
appendUint
func appendUint(dst []byte, n int) []byte { if n < 0 { panic("BUG: n should be positive") } var b [20]byte buf := b[:] i := len(buf) var q int for n >= 10 { i-- q = n / 10 buf[i] = '0' + byte(n-q*10) n = q } i-- buf[i] = '0' + byte(n) dst = append(dst, buf[i:]...) return dst }
go
func appendUint(dst []byte, n int) []byte { if n < 0 { panic("BUG: n should be positive") } var b [20]byte buf := b[:] i := len(buf) var q int for n >= 10 { i-- q = n / 10 buf[i] = '0' + byte(n-q*10) n = q } i-- buf[i] = '0' + byte(n) dst = append(dst, buf[i:]...) return dst }
[ "func", "appendUint", "(", "dst", "[", "]", "byte", ",", "n", "int", ")", "[", "]", "byte", "{", "if", "n", "<", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "var", "b", "[", "20", "]", "byte", "\n", "buf", ":=", "b", "[", ":", "]", "\n", "i", ":=", "len", "(", "buf", ")", "\n", "var", "q", "int", "\n", "for", "n", ">=", "10", "{", "i", "--", "\n", "q", "=", "n", "/", "10", "\n", "buf", "[", "i", "]", "=", "'0'", "+", "byte", "(", "n", "-", "q", "*", "10", ")", "\n", "n", "=", "q", "\n", "}", "\n", "i", "--", "\n", "buf", "[", "i", "]", "=", "'0'", "+", "byte", "(", "n", ")", "\n", "dst", "=", "append", "(", "dst", ",", "buf", "[", "i", ":", "]", "...", ")", "\n", "return", "dst", "\n", "}" ]
// AppendUint appends n to dst and returns the extended dst.
[ "AppendUint", "appends", "n", "to", "dst", "and", "returns", "the", "extended", "dst", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L27-L45
15,749
gortc/sdp
fields.go
AddRaw
func (s Session) AddRaw(k rune, v string) Session { return s.appendString(Type(k), v) }
go
func (s Session) AddRaw(k rune, v string) Session { return s.appendString(Type(k), v) }
[ "func", "(", "s", "Session", ")", "AddRaw", "(", "k", "rune", ",", "v", "string", ")", "Session", "{", "return", "s", ".", "appendString", "(", "Type", "(", "k", ")", ",", "v", ")", "\n", "}" ]
// AddRaw appends k=v to Session.
[ "AddRaw", "appends", "k", "=", "v", "to", "Session", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L85-L87
15,750
gortc/sdp
fields.go
AddLine
func (s Session) AddLine(t Type, v string) Session { return s.appendString(t, v) }
go
func (s Session) AddLine(t Type, v string) Session { return s.appendString(t, v) }
[ "func", "(", "s", "Session", ")", "AddLine", "(", "t", "Type", ",", "v", "string", ")", "Session", "{", "return", "s", ".", "appendString", "(", "t", ",", "v", ")", "\n", "}" ]
// AddLine appends t=v to Session.
[ "AddLine", "appends", "t", "=", "v", "to", "Session", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L90-L92
15,751
gortc/sdp
fields.go
AddVersion
func (s Session) AddVersion(version int) Session { v := make([]byte, 0, 64) v = appendInt(v, version) return s.append(TypeProtocolVersion, v) }
go
func (s Session) AddVersion(version int) Session { v := make([]byte, 0, 64) v = appendInt(v, version) return s.append(TypeProtocolVersion, v) }
[ "func", "(", "s", "Session", ")", "AddVersion", "(", "version", "int", ")", "Session", "{", "v", ":=", "make", "(", "[", "]", "byte", ",", "0", ",", "64", ")", "\n", "v", "=", "appendInt", "(", "v", ",", "version", ")", "\n", "return", "s", ".", "append", "(", "TypeProtocolVersion", ",", "v", ")", "\n", "}" ]
// AddVersion appends Version field to Session.
[ "AddVersion", "appends", "Version", "field", "to", "Session", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L95-L99
15,752
gortc/sdp
fields.go
AddPhone
func (s Session) AddPhone(phone string) Session { return s.appendString(TypePhone, phone) }
go
func (s Session) AddPhone(phone string) Session { return s.appendString(TypePhone, phone) }
[ "func", "(", "s", "Session", ")", "AddPhone", "(", "phone", "string", ")", "Session", "{", "return", "s", ".", "appendString", "(", "TypePhone", ",", "phone", ")", "\n", "}" ]
// AddPhone appends Phone Address field to Session.
[ "AddPhone", "appends", "Phone", "Address", "field", "to", "Session", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L102-L104
15,753
gortc/sdp
fields.go
AddEmail
func (s Session) AddEmail(email string) Session { return s.appendString(TypeEmail, email) }
go
func (s Session) AddEmail(email string) Session { return s.appendString(TypeEmail, email) }
[ "func", "(", "s", "Session", ")", "AddEmail", "(", "email", "string", ")", "Session", "{", "return", "s", ".", "appendString", "(", "TypeEmail", ",", "email", ")", "\n", "}" ]
// AddEmail appends Email Address field to Session.
[ "AddEmail", "appends", "Email", "Address", "field", "to", "Session", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L107-L109
15,754
gortc/sdp
fields.go
AddConnectionData
func (s Session) AddConnectionData(data ConnectionData) Session { v := make([]byte, 0, 512) v = append(v, data.getNetworkType()...) v = appendSpace(v) v = append(v, data.getAddressType()...) v = appendSpace(v) v = data.appendAddress(v) return s.append(TypeConnectionData, v) }
go
func (s Session) AddConnectionData(data ConnectionData) Session { v := make([]byte, 0, 512) v = append(v, data.getNetworkType()...) v = appendSpace(v) v = append(v, data.getAddressType()...) v = appendSpace(v) v = data.appendAddress(v) return s.append(TypeConnectionData, v) }
[ "func", "(", "s", "Session", ")", "AddConnectionData", "(", "data", "ConnectionData", ")", "Session", "{", "v", ":=", "make", "(", "[", "]", "byte", ",", "0", ",", "512", ")", "\n", "v", "=", "append", "(", "v", ",", "data", ".", "getNetworkType", "(", ")", "...", ")", "\n", "v", "=", "appendSpace", "(", "v", ")", "\n", "v", "=", "append", "(", "v", ",", "data", ".", "getAddressType", "(", ")", "...", ")", "\n", "v", "=", "appendSpace", "(", "v", ")", "\n", "v", "=", "data", ".", "appendAddress", "(", "v", ")", "\n", "return", "s", ".", "append", "(", "TypeConnectionData", ",", "v", ")", "\n", "}" ]
// AddConnectionData appends Connection Data field to Session // using ConnectionData struct with sensible defaults.
[ "AddConnectionData", "appends", "Connection", "Data", "field", "to", "Session", "using", "ConnectionData", "struct", "with", "sensible", "defaults", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L113-L121
15,755
gortc/sdp
fields.go
AddConnectionDataIP
func (s Session) AddConnectionDataIP(ip net.IP) Session { return s.AddConnectionData(ConnectionData{ IP: ip, }) }
go
func (s Session) AddConnectionDataIP(ip net.IP) Session { return s.AddConnectionData(ConnectionData{ IP: ip, }) }
[ "func", "(", "s", "Session", ")", "AddConnectionDataIP", "(", "ip", "net", ".", "IP", ")", "Session", "{", "return", "s", ".", "AddConnectionData", "(", "ConnectionData", "{", "IP", ":", "ip", ",", "}", ")", "\n", "}" ]
// AddConnectionDataIP appends Connection Data field using only ip address.
[ "AddConnectionDataIP", "appends", "Connection", "Data", "field", "using", "only", "ip", "address", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L124-L128
15,756
gortc/sdp
fields.go
AddSessionName
func (s Session) AddSessionName(name string) Session { return s.appendString(TypeSessionName, name) }
go
func (s Session) AddSessionName(name string) Session { return s.appendString(TypeSessionName, name) }
[ "func", "(", "s", "Session", ")", "AddSessionName", "(", "name", "string", ")", "Session", "{", "return", "s", ".", "appendString", "(", "TypeSessionName", ",", "name", ")", "\n", "}" ]
// AddSessionName appends Session Name field to Session.
[ "AddSessionName", "appends", "Session", "Name", "field", "to", "Session", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L131-L133
15,757
gortc/sdp
fields.go
AddSessionInfo
func (s Session) AddSessionInfo(info string) Session { return s.appendString(TypeSessionInformation, info) }
go
func (s Session) AddSessionInfo(info string) Session { return s.appendString(TypeSessionInformation, info) }
[ "func", "(", "s", "Session", ")", "AddSessionInfo", "(", "info", "string", ")", "Session", "{", "return", "s", ".", "appendString", "(", "TypeSessionInformation", ",", "info", ")", "\n", "}" ]
// AddSessionInfo appends Session Information field to Session.
[ "AddSessionInfo", "appends", "Session", "Information", "field", "to", "Session", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L136-L138
15,758
gortc/sdp
fields.go
AddURI
func (s Session) AddURI(uri string) Session { return s.appendString(TypeURI, uri) }
go
func (s Session) AddURI(uri string) Session { return s.appendString(TypeURI, uri) }
[ "func", "(", "s", "Session", ")", "AddURI", "(", "uri", "string", ")", "Session", "{", "return", "s", ".", "appendString", "(", "TypeURI", ",", "uri", ")", "\n", "}" ]
// AddURI appends Uniform Resource Identifier field to Session.
[ "AddURI", "appends", "Uniform", "Resource", "Identifier", "field", "to", "Session", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L141-L143
15,759
gortc/sdp
fields.go
Equal
func (c ConnectionData) Equal(b ConnectionData) bool { if c.NetworkType != b.NetworkType { return false } if c.AddressType != b.AddressType { return false } if !c.IP.Equal(b.IP) { return false } if c.TTL != b.TTL { return false } if c.Addresses != b.Addresses { return false } return true }
go
func (c ConnectionData) Equal(b ConnectionData) bool { if c.NetworkType != b.NetworkType { return false } if c.AddressType != b.AddressType { return false } if !c.IP.Equal(b.IP) { return false } if c.TTL != b.TTL { return false } if c.Addresses != b.Addresses { return false } return true }
[ "func", "(", "c", "ConnectionData", ")", "Equal", "(", "b", "ConnectionData", ")", "bool", "{", "if", "c", ".", "NetworkType", "!=", "b", ".", "NetworkType", "{", "return", "false", "\n", "}", "\n", "if", "c", ".", "AddressType", "!=", "b", ".", "AddressType", "{", "return", "false", "\n", "}", "\n", "if", "!", "c", ".", "IP", ".", "Equal", "(", "b", ".", "IP", ")", "{", "return", "false", "\n", "}", "\n", "if", "c", ".", "TTL", "!=", "b", ".", "TTL", "{", "return", "false", "\n", "}", "\n", "if", "c", ".", "Addresses", "!=", "b", ".", "Addresses", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Equal returns c == b.
[ "Equal", "returns", "c", "==", "b", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L162-L179
15,760
gortc/sdp
fields.go
Equal
func (o *Origin) Equal(b Origin) bool { if o.Username != b.Username { return false } if o.SessionID != b.SessionID { return false } if o.SessionVersion != b.SessionVersion { return false } if o.NetworkType != b.NetworkType { return false } if o.AddressType != b.AddressType { return false } if o.Address != b.Address { return false } return true }
go
func (o *Origin) Equal(b Origin) bool { if o.Username != b.Username { return false } if o.SessionID != b.SessionID { return false } if o.SessionVersion != b.SessionVersion { return false } if o.NetworkType != b.NetworkType { return false } if o.AddressType != b.AddressType { return false } if o.Address != b.Address { return false } return true }
[ "func", "(", "o", "*", "Origin", ")", "Equal", "(", "b", "Origin", ")", "bool", "{", "if", "o", ".", "Username", "!=", "b", ".", "Username", "{", "return", "false", "\n", "}", "\n", "if", "o", ".", "SessionID", "!=", "b", ".", "SessionID", "{", "return", "false", "\n", "}", "\n", "if", "o", ".", "SessionVersion", "!=", "b", ".", "SessionVersion", "{", "return", "false", "\n", "}", "\n", "if", "o", ".", "NetworkType", "!=", "b", ".", "NetworkType", "{", "return", "false", "\n", "}", "\n", "if", "o", ".", "AddressType", "!=", "b", ".", "AddressType", "{", "return", "false", "\n", "}", "\n", "if", "o", ".", "Address", "!=", "b", ".", "Address", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Equal returns b == o.
[ "Equal", "returns", "b", "==", "o", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L283-L303
15,761
gortc/sdp
fields.go
AddOrigin
func (s Session) AddOrigin(o Origin) Session { v := make([]byte, 0, 2048) v = appendSpace(append(v, o.Username...)) v = appendSpace(appendInt(v, o.SessionID)) v = appendSpace(appendInt(v, o.SessionVersion)) v = appendSpace(append(v, o.getNetworkType()...)) v = appendSpace(append(v, o.getAddressType()...)) v = append(v, o.Address...) return s.append(TypeOrigin, v) }
go
func (s Session) AddOrigin(o Origin) Session { v := make([]byte, 0, 2048) v = appendSpace(append(v, o.Username...)) v = appendSpace(appendInt(v, o.SessionID)) v = appendSpace(appendInt(v, o.SessionVersion)) v = appendSpace(append(v, o.getNetworkType()...)) v = appendSpace(append(v, o.getAddressType()...)) v = append(v, o.Address...) return s.append(TypeOrigin, v) }
[ "func", "(", "s", "Session", ")", "AddOrigin", "(", "o", "Origin", ")", "Session", "{", "v", ":=", "make", "(", "[", "]", "byte", ",", "0", ",", "2048", ")", "\n", "v", "=", "appendSpace", "(", "append", "(", "v", ",", "o", ".", "Username", "...", ")", ")", "\n", "v", "=", "appendSpace", "(", "appendInt", "(", "v", ",", "o", ".", "SessionID", ")", ")", "\n", "v", "=", "appendSpace", "(", "appendInt", "(", "v", ",", "o", ".", "SessionVersion", ")", ")", "\n", "v", "=", "appendSpace", "(", "append", "(", "v", ",", "o", ".", "getNetworkType", "(", ")", "...", ")", ")", "\n", "v", "=", "appendSpace", "(", "append", "(", "v", ",", "o", ".", "getAddressType", "(", ")", "...", ")", ")", "\n", "v", "=", "append", "(", "v", ",", "o", ".", "Address", "...", ")", "\n", "return", "s", ".", "append", "(", "TypeOrigin", ",", "v", ")", "\n", "}" ]
// AddOrigin appends Origin field to Session.
[ "AddOrigin", "appends", "Origin", "field", "to", "Session", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L306-L315
15,762
gortc/sdp
fields.go
TimeToNTP
func TimeToNTP(t time.Time) uint64 { if t.IsZero() { return 0 } return uint64(t.Unix()) + ntpDelta }
go
func TimeToNTP(t time.Time) uint64 { if t.IsZero() { return 0 } return uint64(t.Unix()) + ntpDelta }
[ "func", "TimeToNTP", "(", "t", "time", ".", "Time", ")", "uint64", "{", "if", "t", ".", "IsZero", "(", ")", "{", "return", "0", "\n", "}", "\n", "return", "uint64", "(", "t", ".", "Unix", "(", ")", ")", "+", "ntpDelta", "\n", "}" ]
// TimeToNTP converts time.Time to NTP timestamp with special case for Zero // time, that is interpreted as 0 timestamp.
[ "TimeToNTP", "converts", "time", ".", "Time", "to", "NTP", "timestamp", "with", "special", "case", "for", "Zero", "time", "that", "is", "interpreted", "as", "0", "timestamp", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L324-L329
15,763
gortc/sdp
fields.go
NTPToTime
func NTPToTime(v uint64) time.Time { if v == 0 { return time.Time{} } return time.Unix(int64(v-ntpDelta), 0) }
go
func NTPToTime(v uint64) time.Time { if v == 0 { return time.Time{} } return time.Unix(int64(v-ntpDelta), 0) }
[ "func", "NTPToTime", "(", "v", "uint64", ")", "time", ".", "Time", "{", "if", "v", "==", "0", "{", "return", "time", ".", "Time", "{", "}", "\n", "}", "\n", "return", "time", ".", "Unix", "(", "int64", "(", "v", "-", "ntpDelta", ")", ",", "0", ")", "\n", "}" ]
// NTPToTime converts NTP timestamp to time.Time with special case for Zero // time, that is interpreted as 0 timestamp.
[ "NTPToTime", "converts", "NTP", "timestamp", "to", "time", ".", "Time", "with", "special", "case", "for", "Zero", "time", "that", "is", "interpreted", "as", "0", "timestamp", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L333-L338
15,764
gortc/sdp
fields.go
AddTiming
func (s Session) AddTiming(start, end time.Time) Session { v := make([]byte, 0, 256) v = appendUint64(v, TimeToNTP(start)) v = appendSpace(v) v = appendUint64(v, TimeToNTP(end)) return s.append(TypeTiming, v) }
go
func (s Session) AddTiming(start, end time.Time) Session { v := make([]byte, 0, 256) v = appendUint64(v, TimeToNTP(start)) v = appendSpace(v) v = appendUint64(v, TimeToNTP(end)) return s.append(TypeTiming, v) }
[ "func", "(", "s", "Session", ")", "AddTiming", "(", "start", ",", "end", "time", ".", "Time", ")", "Session", "{", "v", ":=", "make", "(", "[", "]", "byte", ",", "0", ",", "256", ")", "\n", "v", "=", "appendUint64", "(", "v", ",", "TimeToNTP", "(", "start", ")", ")", "\n", "v", "=", "appendSpace", "(", "v", ")", "\n", "v", "=", "appendUint64", "(", "v", ",", "TimeToNTP", "(", "end", ")", ")", "\n", "return", "s", ".", "append", "(", "TypeTiming", ",", "v", ")", "\n", "}" ]
// AddTiming appends Timing field to Session. Both start and end can be zero.
[ "AddTiming", "appends", "Timing", "field", "to", "Session", ".", "Both", "start", "and", "end", "can", "be", "zero", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L345-L351
15,765
gortc/sdp
fields.go
AddTimingNTP
func (s Session) AddTimingNTP(start, end uint64) Session { return s.AddTiming(NTPToTime(start), NTPToTime(end)) }
go
func (s Session) AddTimingNTP(start, end uint64) Session { return s.AddTiming(NTPToTime(start), NTPToTime(end)) }
[ "func", "(", "s", "Session", ")", "AddTimingNTP", "(", "start", ",", "end", "uint64", ")", "Session", "{", "return", "s", ".", "AddTiming", "(", "NTPToTime", "(", "start", ")", ",", "NTPToTime", "(", "end", ")", ")", "\n", "}" ]
// AddTimingNTP appends Timing field to Session with NTP timestamps as input. // It is just wrapper for AddTiming and NTPToTime.
[ "AddTimingNTP", "appends", "Timing", "field", "to", "Session", "with", "NTP", "timestamps", "as", "input", ".", "It", "is", "just", "wrapper", "for", "AddTiming", "and", "NTPToTime", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L355-L357
15,766
gortc/sdp
fields.go
AddBandwidth
func (s Session) AddBandwidth(t BandwidthType, bandwidth int) Session { v := make([]byte, 0, 128) v = append(v, string(t)...) v = appendRune(v, ':') v = appendInt(v, bandwidth) return s.append(TypeBandwidth, v) }
go
func (s Session) AddBandwidth(t BandwidthType, bandwidth int) Session { v := make([]byte, 0, 128) v = append(v, string(t)...) v = appendRune(v, ':') v = appendInt(v, bandwidth) return s.append(TypeBandwidth, v) }
[ "func", "(", "s", "Session", ")", "AddBandwidth", "(", "t", "BandwidthType", ",", "bandwidth", "int", ")", "Session", "{", "v", ":=", "make", "(", "[", "]", "byte", ",", "0", ",", "128", ")", "\n", "v", "=", "append", "(", "v", ",", "string", "(", "t", ")", "...", ")", "\n", "v", "=", "appendRune", "(", "v", ",", "':'", ")", "\n", "v", "=", "appendInt", "(", "v", ",", "bandwidth", ")", "\n", "return", "s", ".", "append", "(", "TypeBandwidth", ",", "v", ")", "\n", "}" ]
// AddBandwidth appends Bandwidth field to Session.
[ "AddBandwidth", "appends", "Bandwidth", "field", "to", "Session", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L390-L396
15,767
gortc/sdp
fields.go
AddRepeatTimes
func (s Session) AddRepeatTimes(interval, duration time.Duration, offsets ...time.Duration) Session { return s.addRepeatTimes(false, interval, duration, offsets...) }
go
func (s Session) AddRepeatTimes(interval, duration time.Duration, offsets ...time.Duration) Session { return s.addRepeatTimes(false, interval, duration, offsets...) }
[ "func", "(", "s", "Session", ")", "AddRepeatTimes", "(", "interval", ",", "duration", "time", ".", "Duration", ",", "offsets", "...", "time", ".", "Duration", ")", "Session", "{", "return", "s", ".", "addRepeatTimes", "(", "false", ",", "interval", ",", "duration", ",", "offsets", "...", ")", "\n", "}" ]
// AddRepeatTimes appends Repeat Times field to Session.
[ "AddRepeatTimes", "appends", "Repeat", "Times", "field", "to", "Session", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L451-L454
15,768
gortc/sdp
fields.go
AddRepeatTimesCompact
func (s Session) AddRepeatTimesCompact(interval, duration time.Duration, offsets ...time.Duration) Session { return s.addRepeatTimes(true, interval, duration, offsets...) }
go
func (s Session) AddRepeatTimesCompact(interval, duration time.Duration, offsets ...time.Duration) Session { return s.addRepeatTimes(true, interval, duration, offsets...) }
[ "func", "(", "s", "Session", ")", "AddRepeatTimesCompact", "(", "interval", ",", "duration", "time", ".", "Duration", ",", "offsets", "...", "time", ".", "Duration", ")", "Session", "{", "return", "s", ".", "addRepeatTimes", "(", "true", ",", "interval", ",", "duration", ",", "offsets", "...", ")", "\n", "}" ]
// AddRepeatTimesCompact appends Repeat Times field to Session using "compact" // syntax.
[ "AddRepeatTimesCompact", "appends", "Repeat", "Times", "field", "to", "Session", "using", "compact", "syntax", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L458-L461
15,769
gortc/sdp
fields.go
Equal
func (m MediaDescription) Equal(b MediaDescription) bool { if m.Type != b.Type { return false } if m.Port != b.Port { return false } if m.PortsNumber != b.PortsNumber { return false } if m.Protocol != b.Protocol { return false } if len(m.Formats) != len(b.Formats) { return false } for i := range m.Formats { if m.Formats[i] != b.Formats[i] { return false } } return true }
go
func (m MediaDescription) Equal(b MediaDescription) bool { if m.Type != b.Type { return false } if m.Port != b.Port { return false } if m.PortsNumber != b.PortsNumber { return false } if m.Protocol != b.Protocol { return false } if len(m.Formats) != len(b.Formats) { return false } for i := range m.Formats { if m.Formats[i] != b.Formats[i] { return false } } return true }
[ "func", "(", "m", "MediaDescription", ")", "Equal", "(", "b", "MediaDescription", ")", "bool", "{", "if", "m", ".", "Type", "!=", "b", ".", "Type", "{", "return", "false", "\n", "}", "\n", "if", "m", ".", "Port", "!=", "b", ".", "Port", "{", "return", "false", "\n", "}", "\n", "if", "m", ".", "PortsNumber", "!=", "b", ".", "PortsNumber", "{", "return", "false", "\n", "}", "\n", "if", "m", ".", "Protocol", "!=", "b", ".", "Protocol", "{", "return", "false", "\n", "}", "\n", "if", "len", "(", "m", ".", "Formats", ")", "!=", "len", "(", "b", ".", "Formats", ")", "{", "return", "false", "\n", "}", "\n", "for", "i", ":=", "range", "m", ".", "Formats", "{", "if", "m", ".", "Formats", "[", "i", "]", "!=", "b", ".", "Formats", "[", "i", "]", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Equal returns true if b equals to m.
[ "Equal", "returns", "true", "if", "b", "equals", "to", "m", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L473-L495
15,770
gortc/sdp
fields.go
AddMediaDescription
func (s Session) AddMediaDescription(m MediaDescription) Session { v := make([]byte, 0, 512) v = appendSpace(append(v, m.Type...)) v = appendInt(v, m.Port) if m.PortsNumber != 0 { v = appendRune(v, '/') v = appendInt(v, m.PortsNumber) } v = appendSpace(v) v = appendSpace(append(v, m.Protocol...)) for i := range m.Formats { v = append(v, m.Formats[i]...) if i != len(m.Formats)-1 { v = appendRune(v, fieldsDelimiter) } } return s.append(TypeMediaDescription, v) }
go
func (s Session) AddMediaDescription(m MediaDescription) Session { v := make([]byte, 0, 512) v = appendSpace(append(v, m.Type...)) v = appendInt(v, m.Port) if m.PortsNumber != 0 { v = appendRune(v, '/') v = appendInt(v, m.PortsNumber) } v = appendSpace(v) v = appendSpace(append(v, m.Protocol...)) for i := range m.Formats { v = append(v, m.Formats[i]...) if i != len(m.Formats)-1 { v = appendRune(v, fieldsDelimiter) } } return s.append(TypeMediaDescription, v) }
[ "func", "(", "s", "Session", ")", "AddMediaDescription", "(", "m", "MediaDescription", ")", "Session", "{", "v", ":=", "make", "(", "[", "]", "byte", ",", "0", ",", "512", ")", "\n", "v", "=", "appendSpace", "(", "append", "(", "v", ",", "m", ".", "Type", "...", ")", ")", "\n", "v", "=", "appendInt", "(", "v", ",", "m", ".", "Port", ")", "\n", "if", "m", ".", "PortsNumber", "!=", "0", "{", "v", "=", "appendRune", "(", "v", ",", "'/'", ")", "\n", "v", "=", "appendInt", "(", "v", ",", "m", ".", "PortsNumber", ")", "\n", "}", "\n", "v", "=", "appendSpace", "(", "v", ")", "\n", "v", "=", "appendSpace", "(", "append", "(", "v", ",", "m", ".", "Protocol", "...", ")", ")", "\n", "for", "i", ":=", "range", "m", ".", "Formats", "{", "v", "=", "append", "(", "v", ",", "m", ".", "Formats", "[", "i", "]", "...", ")", "\n", "if", "i", "!=", "len", "(", "m", ".", "Formats", ")", "-", "1", "{", "v", "=", "appendRune", "(", "v", ",", "fieldsDelimiter", ")", "\n", "}", "\n", "}", "\n", "return", "s", ".", "append", "(", "TypeMediaDescription", ",", "v", ")", "\n", "}" ]
// AddMediaDescription appends Media Description field to Session.
[ "AddMediaDescription", "appends", "Media", "Description", "field", "to", "Session", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L498-L515
15,771
gortc/sdp
fields.go
AddEncryption
func (s Session) AddEncryption(e Encryption) Session { return s.AddEncryptionKey(e.Method, e.Key) }
go
func (s Session) AddEncryption(e Encryption) Session { return s.AddEncryptionKey(e.Method, e.Key) }
[ "func", "(", "s", "Session", ")", "AddEncryption", "(", "e", "Encryption", ")", "Session", "{", "return", "s", ".", "AddEncryptionKey", "(", "e", ".", "Method", ",", "e", ".", "Key", ")", "\n", "}" ]
// AddEncryption appends Encryption and is shorthand for AddEncryptionKey.
[ "AddEncryption", "appends", "Encryption", "and", "is", "shorthand", "for", "AddEncryptionKey", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L518-L520
15,772
gortc/sdp
fields.go
AddTimeZones
func (s Session) AddTimeZones(zones ...TimeZone) Session { v := make([]byte, 0, 512) for i, zone := range zones { v = zone.append(v) if i != len(zones)-1 { v = appendSpace(v) } } return s.append(TypeTimeZones, v) }
go
func (s Session) AddTimeZones(zones ...TimeZone) Session { v := make([]byte, 0, 512) for i, zone := range zones { v = zone.append(v) if i != len(zones)-1 { v = appendSpace(v) } } return s.append(TypeTimeZones, v) }
[ "func", "(", "s", "Session", ")", "AddTimeZones", "(", "zones", "...", "TimeZone", ")", "Session", "{", "v", ":=", "make", "(", "[", "]", "byte", ",", "0", ",", "512", ")", "\n", "for", "i", ",", "zone", ":=", "range", "zones", "{", "v", "=", "zone", ".", "append", "(", "v", ")", "\n", "if", "i", "!=", "len", "(", "zones", ")", "-", "1", "{", "v", "=", "appendSpace", "(", "v", ")", "\n", "}", "\n", "}", "\n", "return", "s", ".", "append", "(", "TypeTimeZones", ",", "v", ")", "\n", "}" ]
// AddTimeZones append TimeZones field to Session.
[ "AddTimeZones", "append", "TimeZones", "field", "to", "Session", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/fields.go#L558-L567
15,773
gortc/sdp
decoder.go
isKnown
func isKnown(t Type) bool { switch t { case TypeProtocolVersion, TypeOrigin, TypeSessionName, TypeSessionInformation, TypeURI, TypeEmail, TypePhone, TypeConnectionData, TypeBandwidth, TypeTiming, TypeRepeatTimes, TypeTimeZones, TypeEncryptionKey, TypeAttribute, TypeMediaDescription: return true default: return false } }
go
func isKnown(t Type) bool { switch t { case TypeProtocolVersion, TypeOrigin, TypeSessionName, TypeSessionInformation, TypeURI, TypeEmail, TypePhone, TypeConnectionData, TypeBandwidth, TypeTiming, TypeRepeatTimes, TypeTimeZones, TypeEncryptionKey, TypeAttribute, TypeMediaDescription: return true default: return false } }
[ "func", "isKnown", "(", "t", "Type", ")", "bool", "{", "switch", "t", "{", "case", "TypeProtocolVersion", ",", "TypeOrigin", ",", "TypeSessionName", ",", "TypeSessionInformation", ",", "TypeURI", ",", "TypeEmail", ",", "TypePhone", ",", "TypeConnectionData", ",", "TypeBandwidth", ",", "TypeTiming", ",", "TypeRepeatTimes", ",", "TypeTimeZones", ",", "TypeEncryptionKey", ",", "TypeAttribute", ",", "TypeMediaDescription", ":", "return", "true", "\n", "default", ":", "return", "false", "\n", "}", "\n", "}" ]
// isKnown returns true if t is defined in RFC 4566.
[ "isKnown", "returns", "true", "if", "t", "is", "defined", "in", "RFC", "4566", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/decoder.go#L111-L125
15,774
gortc/sdp
decoder.go
isExpected
func isExpected(t Type, s section, pos int) error { o := getOrdering(s) if len(o) > pos { for _, expected := range o[pos:] { if expected == t { return nil } if isOptional(expected) { continue } } } // Checking possible section transitions. switch s { case sectionSession: if pos < orderingAfterTime && isExpected(t, sectionTime, 0) == nil { return nil } if isExpected(t, sectionMedia, 0) == nil { return nil } case sectionTime: if isExpected(t, sectionSession, orderingAfterTime) == nil { return nil } case sectionMedia: if pos != 0 && isExpected(t, sectionMedia, 0) == nil { return nil } } if !isKnown(t) { return errUnknownType } // Attribute is known, but out of order. msg := fmt.Sprintf("no matches in ordering array at %s[%d] for %s", s, pos, t, ) err := newSectionDecodeError(s, msg) return errors.Wrapf(err, "field %s is unexpected", t) }
go
func isExpected(t Type, s section, pos int) error { o := getOrdering(s) if len(o) > pos { for _, expected := range o[pos:] { if expected == t { return nil } if isOptional(expected) { continue } } } // Checking possible section transitions. switch s { case sectionSession: if pos < orderingAfterTime && isExpected(t, sectionTime, 0) == nil { return nil } if isExpected(t, sectionMedia, 0) == nil { return nil } case sectionTime: if isExpected(t, sectionSession, orderingAfterTime) == nil { return nil } case sectionMedia: if pos != 0 && isExpected(t, sectionMedia, 0) == nil { return nil } } if !isKnown(t) { return errUnknownType } // Attribute is known, but out of order. msg := fmt.Sprintf("no matches in ordering array at %s[%d] for %s", s, pos, t, ) err := newSectionDecodeError(s, msg) return errors.Wrapf(err, "field %s is unexpected", t) }
[ "func", "isExpected", "(", "t", "Type", ",", "s", "section", ",", "pos", "int", ")", "error", "{", "o", ":=", "getOrdering", "(", "s", ")", "\n", "if", "len", "(", "o", ")", ">", "pos", "{", "for", "_", ",", "expected", ":=", "range", "o", "[", "pos", ":", "]", "{", "if", "expected", "==", "t", "{", "return", "nil", "\n", "}", "\n", "if", "isOptional", "(", "expected", ")", "{", "continue", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Checking possible section transitions.", "switch", "s", "{", "case", "sectionSession", ":", "if", "pos", "<", "orderingAfterTime", "&&", "isExpected", "(", "t", ",", "sectionTime", ",", "0", ")", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "isExpected", "(", "t", ",", "sectionMedia", ",", "0", ")", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "case", "sectionTime", ":", "if", "isExpected", "(", "t", ",", "sectionSession", ",", "orderingAfterTime", ")", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "case", "sectionMedia", ":", "if", "pos", "!=", "0", "&&", "isExpected", "(", "t", ",", "sectionMedia", ",", "0", ")", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "}", "\n", "if", "!", "isKnown", "(", "t", ")", "{", "return", "errUnknownType", "\n", "}", "\n", "// Attribute is known, but out of order.", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ",", "pos", ",", "t", ",", ")", "\n", "err", ":=", "newSectionDecodeError", "(", "s", ",", "msg", ")", "\n", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "t", ")", "\n", "}" ]
// isExpected determines if t is expected on pos in s section and returns nil, // if it is expected and DecodeError if not.
[ "isExpected", "determines", "if", "t", "is", "expected", "on", "pos", "in", "s", "section", "and", "returns", "nil", "if", "it", "is", "expected", "and", "DecodeError", "if", "not", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/decoder.go#L129-L169
15,775
gortc/sdp
encoder.go
Append
func (m *Message) Append(s Session) Session { s = s.AddVersion(m.Version) s = s.AddOrigin(m.Origin) s = s.AddSessionName(m.Name) if len(m.Info) > 0 { s = s.AddSessionInfo(m.Info) } if len(m.URI) > 0 { s = s.AddURI(m.URI) } if len(m.Email) > 0 { s = s.AddEmail(m.Email) } if len(m.Phone) > 0 { s = s.AddPhone(m.Phone) } if !m.Connection.Blank() { s = s.AddConnectionData(m.Connection) } for t, v := range m.Bandwidths { s = s.AddBandwidth(t, v) } // One or more time descriptions ("t=" and "r=" lines) for _, t := range m.Timing { s = s.AddTiming(t.Start, t.End) if len(t.Offsets) > 0 { s = s.AddRepeatTimesCompact(t.Repeat, t.Active, t.Offsets...) } } if len(m.TZAdjustments) > 0 { s = s.AddTimeZones(m.TZAdjustments...) } if !m.Encryption.Blank() { s = s.AddEncryption(m.Encryption) } s = s.appendAttributes(m.Attributes) for i := range m.Medias { s = s.AddMediaDescription(m.Medias[i].Description) if len(m.Medias[i].Title) > 0 { s = s.AddSessionInfo(m.Medias[i].Title) } if !m.Medias[i].Connection.Blank() { s = s.AddConnectionData(m.Medias[i].Connection) } for t, v := range m.Medias[i].Bandwidths { s = s.AddBandwidth(t, v) } if !m.Medias[i].Encryption.Blank() { s = s.AddEncryption(m.Medias[i].Encryption) } s = s.appendAttributes(m.Medias[i].Attributes) } return s }
go
func (m *Message) Append(s Session) Session { s = s.AddVersion(m.Version) s = s.AddOrigin(m.Origin) s = s.AddSessionName(m.Name) if len(m.Info) > 0 { s = s.AddSessionInfo(m.Info) } if len(m.URI) > 0 { s = s.AddURI(m.URI) } if len(m.Email) > 0 { s = s.AddEmail(m.Email) } if len(m.Phone) > 0 { s = s.AddPhone(m.Phone) } if !m.Connection.Blank() { s = s.AddConnectionData(m.Connection) } for t, v := range m.Bandwidths { s = s.AddBandwidth(t, v) } // One or more time descriptions ("t=" and "r=" lines) for _, t := range m.Timing { s = s.AddTiming(t.Start, t.End) if len(t.Offsets) > 0 { s = s.AddRepeatTimesCompact(t.Repeat, t.Active, t.Offsets...) } } if len(m.TZAdjustments) > 0 { s = s.AddTimeZones(m.TZAdjustments...) } if !m.Encryption.Blank() { s = s.AddEncryption(m.Encryption) } s = s.appendAttributes(m.Attributes) for i := range m.Medias { s = s.AddMediaDescription(m.Medias[i].Description) if len(m.Medias[i].Title) > 0 { s = s.AddSessionInfo(m.Medias[i].Title) } if !m.Medias[i].Connection.Blank() { s = s.AddConnectionData(m.Medias[i].Connection) } for t, v := range m.Medias[i].Bandwidths { s = s.AddBandwidth(t, v) } if !m.Medias[i].Encryption.Blank() { s = s.AddEncryption(m.Medias[i].Encryption) } s = s.appendAttributes(m.Medias[i].Attributes) } return s }
[ "func", "(", "m", "*", "Message", ")", "Append", "(", "s", "Session", ")", "Session", "{", "s", "=", "s", ".", "AddVersion", "(", "m", ".", "Version", ")", "\n", "s", "=", "s", ".", "AddOrigin", "(", "m", ".", "Origin", ")", "\n", "s", "=", "s", ".", "AddSessionName", "(", "m", ".", "Name", ")", "\n", "if", "len", "(", "m", ".", "Info", ")", ">", "0", "{", "s", "=", "s", ".", "AddSessionInfo", "(", "m", ".", "Info", ")", "\n", "}", "\n", "if", "len", "(", "m", ".", "URI", ")", ">", "0", "{", "s", "=", "s", ".", "AddURI", "(", "m", ".", "URI", ")", "\n", "}", "\n", "if", "len", "(", "m", ".", "Email", ")", ">", "0", "{", "s", "=", "s", ".", "AddEmail", "(", "m", ".", "Email", ")", "\n", "}", "\n", "if", "len", "(", "m", ".", "Phone", ")", ">", "0", "{", "s", "=", "s", ".", "AddPhone", "(", "m", ".", "Phone", ")", "\n", "}", "\n", "if", "!", "m", ".", "Connection", ".", "Blank", "(", ")", "{", "s", "=", "s", ".", "AddConnectionData", "(", "m", ".", "Connection", ")", "\n", "}", "\n", "for", "t", ",", "v", ":=", "range", "m", ".", "Bandwidths", "{", "s", "=", "s", ".", "AddBandwidth", "(", "t", ",", "v", ")", "\n", "}", "\n", "// One or more time descriptions (\"t=\" and \"r=\" lines)", "for", "_", ",", "t", ":=", "range", "m", ".", "Timing", "{", "s", "=", "s", ".", "AddTiming", "(", "t", ".", "Start", ",", "t", ".", "End", ")", "\n", "if", "len", "(", "t", ".", "Offsets", ")", ">", "0", "{", "s", "=", "s", ".", "AddRepeatTimesCompact", "(", "t", ".", "Repeat", ",", "t", ".", "Active", ",", "t", ".", "Offsets", "...", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "m", ".", "TZAdjustments", ")", ">", "0", "{", "s", "=", "s", ".", "AddTimeZones", "(", "m", ".", "TZAdjustments", "...", ")", "\n", "}", "\n", "if", "!", "m", ".", "Encryption", ".", "Blank", "(", ")", "{", "s", "=", "s", ".", "AddEncryption", "(", "m", ".", "Encryption", ")", "\n", "}", "\n", "s", "=", "s", ".", "appendAttributes", "(", "m", ".", "Attributes", ")", "\n\n", "for", "i", ":=", "range", "m", ".", "Medias", "{", "s", "=", "s", ".", "AddMediaDescription", "(", "m", ".", "Medias", "[", "i", "]", ".", "Description", ")", "\n", "if", "len", "(", "m", ".", "Medias", "[", "i", "]", ".", "Title", ")", ">", "0", "{", "s", "=", "s", ".", "AddSessionInfo", "(", "m", ".", "Medias", "[", "i", "]", ".", "Title", ")", "\n", "}", "\n", "if", "!", "m", ".", "Medias", "[", "i", "]", ".", "Connection", ".", "Blank", "(", ")", "{", "s", "=", "s", ".", "AddConnectionData", "(", "m", ".", "Medias", "[", "i", "]", ".", "Connection", ")", "\n", "}", "\n", "for", "t", ",", "v", ":=", "range", "m", ".", "Medias", "[", "i", "]", ".", "Bandwidths", "{", "s", "=", "s", ".", "AddBandwidth", "(", "t", ",", "v", ")", "\n", "}", "\n", "if", "!", "m", ".", "Medias", "[", "i", "]", ".", "Encryption", ".", "Blank", "(", ")", "{", "s", "=", "s", ".", "AddEncryption", "(", "m", ".", "Medias", "[", "i", "]", ".", "Encryption", ")", "\n", "}", "\n", "s", "=", "s", ".", "appendAttributes", "(", "m", ".", "Medias", "[", "i", "]", ".", "Attributes", ")", "\n", "}", "\n", "return", "s", "\n", "}" ]
// Append encodes message to Session and returns result. // // See RFC 4566 Section 5.
[ "Append", "encodes", "message", "to", "Session", "and", "returns", "result", ".", "See", "RFC", "4566", "Section", "5", "." ]
d420057ced39eaa53ebd2e5465bce76045e848a5
https://github.com/gortc/sdp/blob/d420057ced39eaa53ebd2e5465bce76045e848a5/encoder.go#L17-L71
15,776
mna/pigeon
builder/builder.go
Optimize
func Optimize(optimize bool) Option { return func(b *builder) Option { prev := b.optimize b.optimize = optimize return Optimize(prev) } }
go
func Optimize(optimize bool) Option { return func(b *builder) Option { prev := b.optimize b.optimize = optimize return Optimize(prev) } }
[ "func", "Optimize", "(", "optimize", "bool", ")", "Option", "{", "return", "func", "(", "b", "*", "builder", ")", "Option", "{", "prev", ":=", "b", ".", "optimize", "\n", "b", ".", "optimize", "=", "optimize", "\n", "return", "Optimize", "(", "prev", ")", "\n", "}", "\n", "}" ]
// Optimize returns an option that specifies the optimize option // If optimize is true, the Debug and Memoize code is completely // removed from the resulting parser
[ "Optimize", "returns", "an", "option", "that", "specifies", "the", "optimize", "option", "If", "optimize", "is", "true", "the", "Debug", "and", "Memoize", "code", "is", "completely", "removed", "from", "the", "resulting", "parser" ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/builder/builder.go#L73-L79
15,777
mna/pigeon
builder/builder.go
BuildParser
func BuildParser(w io.Writer, g *ast.Grammar, opts ...Option) error { b := &builder{w: w, recvName: "c"} b.setOptions(opts) return b.buildParser(g) }
go
func BuildParser(w io.Writer, g *ast.Grammar, opts ...Option) error { b := &builder{w: w, recvName: "c"} b.setOptions(opts) return b.buildParser(g) }
[ "func", "BuildParser", "(", "w", "io", ".", "Writer", ",", "g", "*", "ast", ".", "Grammar", ",", "opts", "...", "Option", ")", "error", "{", "b", ":=", "&", "builder", "{", "w", ":", "w", ",", "recvName", ":", "\"", "\"", "}", "\n", "b", ".", "setOptions", "(", "opts", ")", "\n", "return", "b", ".", "buildParser", "(", "g", ")", "\n", "}" ]
// BuildParser builds the PEG parser using the provider grammar. The code is // written to the specified w.
[ "BuildParser", "builds", "the", "PEG", "parser", "using", "the", "provider", "grammar", ".", "The", "code", "is", "written", "to", "the", "specified", "w", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/builder/builder.go#L106-L110
15,778
mna/pigeon
builder/builder.go
BasicLatinLookup
func BasicLatinLookup(chars, ranges []rune, unicodeClasses []string, ignoreCase bool) (basicLatinChars [128]bool) { for _, rn := range chars { if rn < 128 { basicLatinChars[rn] = true if ignoreCase { if unicode.IsLower(rn) { basicLatinChars[unicode.ToUpper(rn)] = true } else { basicLatinChars[unicode.ToLower(rn)] = true } } } } for i := 0; i < len(ranges); i += 2 { if ranges[i] < 128 { for j := ranges[i]; j < 128 && j <= ranges[i+1]; j++ { basicLatinChars[j] = true if ignoreCase { if unicode.IsLower(j) { basicLatinChars[unicode.ToUpper(j)] = true } else { basicLatinChars[unicode.ToLower(j)] = true } } } } } for _, cl := range unicodeClasses { rt := rangeTable(cl) for r := rune(0); r < 128; r++ { if unicode.Is(rt, r) { basicLatinChars[r] = true } } } return }
go
func BasicLatinLookup(chars, ranges []rune, unicodeClasses []string, ignoreCase bool) (basicLatinChars [128]bool) { for _, rn := range chars { if rn < 128 { basicLatinChars[rn] = true if ignoreCase { if unicode.IsLower(rn) { basicLatinChars[unicode.ToUpper(rn)] = true } else { basicLatinChars[unicode.ToLower(rn)] = true } } } } for i := 0; i < len(ranges); i += 2 { if ranges[i] < 128 { for j := ranges[i]; j < 128 && j <= ranges[i+1]; j++ { basicLatinChars[j] = true if ignoreCase { if unicode.IsLower(j) { basicLatinChars[unicode.ToUpper(j)] = true } else { basicLatinChars[unicode.ToLower(j)] = true } } } } } for _, cl := range unicodeClasses { rt := rangeTable(cl) for r := rune(0); r < 128; r++ { if unicode.Is(rt, r) { basicLatinChars[r] = true } } } return }
[ "func", "BasicLatinLookup", "(", "chars", ",", "ranges", "[", "]", "rune", ",", "unicodeClasses", "[", "]", "string", ",", "ignoreCase", "bool", ")", "(", "basicLatinChars", "[", "128", "]", "bool", ")", "{", "for", "_", ",", "rn", ":=", "range", "chars", "{", "if", "rn", "<", "128", "{", "basicLatinChars", "[", "rn", "]", "=", "true", "\n", "if", "ignoreCase", "{", "if", "unicode", ".", "IsLower", "(", "rn", ")", "{", "basicLatinChars", "[", "unicode", ".", "ToUpper", "(", "rn", ")", "]", "=", "true", "\n", "}", "else", "{", "basicLatinChars", "[", "unicode", ".", "ToLower", "(", "rn", ")", "]", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "ranges", ")", ";", "i", "+=", "2", "{", "if", "ranges", "[", "i", "]", "<", "128", "{", "for", "j", ":=", "ranges", "[", "i", "]", ";", "j", "<", "128", "&&", "j", "<=", "ranges", "[", "i", "+", "1", "]", ";", "j", "++", "{", "basicLatinChars", "[", "j", "]", "=", "true", "\n", "if", "ignoreCase", "{", "if", "unicode", ".", "IsLower", "(", "j", ")", "{", "basicLatinChars", "[", "unicode", ".", "ToUpper", "(", "j", ")", "]", "=", "true", "\n", "}", "else", "{", "basicLatinChars", "[", "unicode", ".", "ToLower", "(", "j", ")", "]", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "for", "_", ",", "cl", ":=", "range", "unicodeClasses", "{", "rt", ":=", "rangeTable", "(", "cl", ")", "\n", "for", "r", ":=", "rune", "(", "0", ")", ";", "r", "<", "128", ";", "r", "++", "{", "if", "unicode", ".", "Is", "(", "rt", ",", "r", ")", "{", "basicLatinChars", "[", "r", "]", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// BasicLatinLookup calculates the decision results for the first 256 characters of the UTF-8 character // set for a given set of chars, ranges and unicodeClasses to speedup the CharClassMatcher.
[ "BasicLatinLookup", "calculates", "the", "decision", "results", "for", "the", "first", "256", "characters", "of", "the", "UTF", "-", "8", "character", "set", "for", "a", "given", "set", "of", "chars", "ranges", "and", "unicodeClasses", "to", "speedup", "the", "CharClassMatcher", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/builder/builder.go#L339-L375
15,779
mna/pigeon
main.go
argError
func argError(exitCode int, msg string, args ...interface{}) { fmt.Fprintf(os.Stderr, msg, args...) fmt.Fprintln(os.Stderr) usage() exit(exitCode) }
go
func argError(exitCode int, msg string, args ...interface{}) { fmt.Fprintf(os.Stderr, msg, args...) fmt.Fprintln(os.Stderr) usage() exit(exitCode) }
[ "func", "argError", "(", "exitCode", "int", ",", "msg", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "msg", ",", "args", "...", ")", "\n", "fmt", ".", "Fprintln", "(", "os", ".", "Stderr", ")", "\n", "usage", "(", ")", "\n", "exit", "(", "exitCode", ")", "\n", "}" ]
// argError prints an error message to stderr, prints the command usage // and exits with the specified exit code.
[ "argError", "prints", "an", "error", "message", "to", "stderr", "prints", "the", "command", "usage", "and", "exits", "with", "the", "specified", "exit", "code", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/main.go#L221-L226
15,780
mna/pigeon
main.go
input
func input(filename string) (nm string, rc io.ReadCloser) { nm = "stdin" inf := os.Stdin if filename != "" { f, err := os.Open(filename) if err != nil { fmt.Fprintln(os.Stderr, err) exit(2) } inf = f nm = filename } r := bufio.NewReader(inf) return nm, makeReadCloser(r, inf) }
go
func input(filename string) (nm string, rc io.ReadCloser) { nm = "stdin" inf := os.Stdin if filename != "" { f, err := os.Open(filename) if err != nil { fmt.Fprintln(os.Stderr, err) exit(2) } inf = f nm = filename } r := bufio.NewReader(inf) return nm, makeReadCloser(r, inf) }
[ "func", "input", "(", "filename", "string", ")", "(", "nm", "string", ",", "rc", "io", ".", "ReadCloser", ")", "{", "nm", "=", "\"", "\"", "\n", "inf", ":=", "os", ".", "Stdin", "\n", "if", "filename", "!=", "\"", "\"", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Fprintln", "(", "os", ".", "Stderr", ",", "err", ")", "\n", "exit", "(", "2", ")", "\n", "}", "\n", "inf", "=", "f", "\n", "nm", "=", "filename", "\n", "}", "\n", "r", ":=", "bufio", ".", "NewReader", "(", "inf", ")", "\n", "return", "nm", ",", "makeReadCloser", "(", "r", ",", "inf", ")", "\n", "}" ]
// input gets the name and reader to get input text from.
[ "input", "gets", "the", "name", "and", "reader", "to", "get", "input", "text", "from", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/main.go#L229-L243
15,781
mna/pigeon
main.go
output
func output(filename string) io.WriteCloser { out := os.Stdout if filename != "" { f, err := os.Create(filename) if err != nil { fmt.Fprintln(os.Stderr, err) exit(4) } out = f } return out }
go
func output(filename string) io.WriteCloser { out := os.Stdout if filename != "" { f, err := os.Create(filename) if err != nil { fmt.Fprintln(os.Stderr, err) exit(4) } out = f } return out }
[ "func", "output", "(", "filename", "string", ")", "io", ".", "WriteCloser", "{", "out", ":=", "os", ".", "Stdout", "\n", "if", "filename", "!=", "\"", "\"", "{", "f", ",", "err", ":=", "os", ".", "Create", "(", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Fprintln", "(", "os", ".", "Stderr", ",", "err", ")", "\n", "exit", "(", "4", ")", "\n", "}", "\n", "out", "=", "f", "\n", "}", "\n", "return", "out", "\n", "}" ]
// output gets the writer to write the generated parser to.
[ "output", "gets", "the", "writer", "to", "write", "the", "generated", "parser", "to", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/main.go#L246-L257
15,782
mna/pigeon
main.go
makeReadCloser
func makeReadCloser(r io.Reader, c io.Closer) io.ReadCloser { rc := struct { io.Reader io.Closer }{r, c} return io.ReadCloser(rc) }
go
func makeReadCloser(r io.Reader, c io.Closer) io.ReadCloser { rc := struct { io.Reader io.Closer }{r, c} return io.ReadCloser(rc) }
[ "func", "makeReadCloser", "(", "r", "io", ".", "Reader", ",", "c", "io", ".", "Closer", ")", "io", ".", "ReadCloser", "{", "rc", ":=", "struct", "{", "io", ".", "Reader", "\n", "io", ".", "Closer", "\n", "}", "{", "r", ",", "c", "}", "\n", "return", "io", ".", "ReadCloser", "(", "rc", ")", "\n", "}" ]
// create a ReadCloser that reads from r and closes c.
[ "create", "a", "ReadCloser", "that", "reads", "from", "r", "and", "closes", "c", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/main.go#L260-L266
15,783
mna/pigeon
main.go
astPos
func (c *current) astPos() ast.Pos { return ast.Pos{Line: c.pos.line, Col: c.pos.col, Off: c.pos.offset} }
go
func (c *current) astPos() ast.Pos { return ast.Pos{Line: c.pos.line, Col: c.pos.col, Off: c.pos.offset} }
[ "func", "(", "c", "*", "current", ")", "astPos", "(", ")", "ast", ".", "Pos", "{", "return", "ast", ".", "Pos", "{", "Line", ":", "c", ".", "pos", ".", "line", ",", "Col", ":", "c", ".", "pos", ".", "col", ",", "Off", ":", "c", ".", "pos", ".", "offset", "}", "\n", "}" ]
// astPos is a helper method for the PEG grammar parser. It returns the // position of the current match as an ast.Pos.
[ "astPos", "is", "a", "helper", "method", "for", "the", "PEG", "grammar", "parser", ".", "It", "returns", "the", "position", "of", "the", "current", "match", "as", "an", "ast", ".", "Pos", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/main.go#L270-L272
15,784
mna/pigeon
ast/ast.go
String
func (p Pos) String() string { if p.Filename != "" { return fmt.Sprintf("%s:%d:%d (%d)", p.Filename, p.Line, p.Col, p.Off) } return fmt.Sprintf("%d:%d (%d)", p.Line, p.Col, p.Off) }
go
func (p Pos) String() string { if p.Filename != "" { return fmt.Sprintf("%s:%d:%d (%d)", p.Filename, p.Line, p.Col, p.Off) } return fmt.Sprintf("%d:%d (%d)", p.Line, p.Col, p.Off) }
[ "func", "(", "p", "Pos", ")", "String", "(", ")", "string", "{", "if", "p", ".", "Filename", "!=", "\"", "\"", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "p", ".", "Filename", ",", "p", ".", "Line", ",", "p", ".", "Col", ",", "p", ".", "Off", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "p", ".", "Line", ",", "p", ".", "Col", ",", "p", ".", "Off", ")", "\n", "}" ]
// String returns the textual representation of a position.
[ "String", "returns", "the", "textual", "representation", "of", "a", "position", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/ast/ast.go#L24-L29
15,785
mna/pigeon
ast/ast.go
NewRule
func NewRule(p Pos, name *Identifier) *Rule { return &Rule{p: p, Name: name} }
go
func NewRule(p Pos, name *Identifier) *Rule { return &Rule{p: p, Name: name} }
[ "func", "NewRule", "(", "p", "Pos", ",", "name", "*", "Identifier", ")", "*", "Rule", "{", "return", "&", "Rule", "{", "p", ":", "p", ",", "Name", ":", "name", "}", "\n", "}" ]
// NewRule creates a rule with at the specified position and with the // specified name as identifier.
[ "NewRule", "creates", "a", "rule", "with", "at", "the", "specified", "position", "and", "with", "the", "specified", "name", "as", "identifier", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/ast/ast.go#L70-L72
15,786
mna/pigeon
ast/ast.go
NewLitMatcher
func NewLitMatcher(p Pos, v string) *LitMatcher { return &LitMatcher{posValue: posValue{p: p, Val: v}} }
go
func NewLitMatcher(p Pos, v string) *LitMatcher { return &LitMatcher{posValue: posValue{p: p, Val: v}} }
[ "func", "NewLitMatcher", "(", "p", "Pos", ",", "v", "string", ")", "*", "LitMatcher", "{", "return", "&", "LitMatcher", "{", "posValue", ":", "posValue", "{", "p", ":", "p", ",", "Val", ":", "v", "}", "}", "\n", "}" ]
// NewLitMatcher creates a new literal matcher at the specified position and // with the specified value.
[ "NewLitMatcher", "creates", "a", "new", "literal", "matcher", "at", "the", "specified", "position", "and", "with", "the", "specified", "value", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/ast/ast.go#L436-L438
15,787
mna/pigeon
ast/ast.go
NewCharClassMatcher
func NewCharClassMatcher(p Pos, raw string) *CharClassMatcher { c := &CharClassMatcher{posValue: posValue{p: p, Val: raw}} c.parse() return c }
go
func NewCharClassMatcher(p Pos, raw string) *CharClassMatcher { c := &CharClassMatcher{posValue: posValue{p: p, Val: raw}} c.parse() return c }
[ "func", "NewCharClassMatcher", "(", "p", "Pos", ",", "raw", "string", ")", "*", "CharClassMatcher", "{", "c", ":=", "&", "CharClassMatcher", "{", "posValue", ":", "posValue", "{", "p", ":", "p", ",", "Val", ":", "raw", "}", "}", "\n", "c", ".", "parse", "(", ")", "\n", "return", "c", "\n", "}" ]
// NewCharClassMatcher creates a new character class matcher at the specified // position and with the specified raw value. It parses the raw value into // the list of characters, ranges and Unicode classes.
[ "NewCharClassMatcher", "creates", "a", "new", "character", "class", "matcher", "at", "the", "specified", "position", "and", "with", "the", "specified", "raw", "value", ".", "It", "parses", "the", "raw", "value", "into", "the", "list", "of", "characters", "ranges", "and", "Unicode", "classes", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/ast/ast.go#L463-L467
15,788
mna/pigeon
ast/ast.go
NewAnyMatcher
func NewAnyMatcher(p Pos, v string) *AnyMatcher { return &AnyMatcher{posValue{p, v}} }
go
func NewAnyMatcher(p Pos, v string) *AnyMatcher { return &AnyMatcher{posValue{p, v}} }
[ "func", "NewAnyMatcher", "(", "p", "Pos", ",", "v", "string", ")", "*", "AnyMatcher", "{", "return", "&", "AnyMatcher", "{", "posValue", "{", "p", ",", "v", "}", "}", "\n", "}" ]
// NewAnyMatcher creates a new any matcher at the specified position. The // value is provided for completeness' sake, but it is always the dot.
[ "NewAnyMatcher", "creates", "a", "new", "any", "matcher", "at", "the", "specified", "position", ".", "The", "value", "is", "provided", "for", "completeness", "sake", "but", "it", "is", "always", "the", "dot", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/ast/ast.go#L590-L592
15,789
mna/pigeon
ast/ast.go
NewCodeBlock
func NewCodeBlock(p Pos, code string) *CodeBlock { return &CodeBlock{posValue{p, code}} }
go
func NewCodeBlock(p Pos, code string) *CodeBlock { return &CodeBlock{posValue{p, code}} }
[ "func", "NewCodeBlock", "(", "p", "Pos", ",", "code", "string", ")", "*", "CodeBlock", "{", "return", "&", "CodeBlock", "{", "posValue", "{", "p", ",", "code", "}", "}", "\n", "}" ]
// NewCodeBlock creates a new code block at the specified position and with // the specified value. The value includes the outer braces.
[ "NewCodeBlock", "creates", "a", "new", "code", "block", "at", "the", "specified", "position", "and", "with", "the", "specified", "value", ".", "The", "value", "includes", "the", "outer", "braces", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/ast/ast.go#L609-L611
15,790
mna/pigeon
ast/ast.go
NewIdentifier
func NewIdentifier(p Pos, name string) *Identifier { return &Identifier{posValue{p: p, Val: name}} }
go
func NewIdentifier(p Pos, name string) *Identifier { return &Identifier{posValue{p: p, Val: name}} }
[ "func", "NewIdentifier", "(", "p", "Pos", ",", "name", "string", ")", "*", "Identifier", "{", "return", "&", "Identifier", "{", "posValue", "{", "p", ":", "p", ",", "Val", ":", "name", "}", "}", "\n", "}" ]
// NewIdentifier creates a new identifier at the specified position and // with the specified name.
[ "NewIdentifier", "creates", "a", "new", "identifier", "at", "the", "specified", "position", "and", "with", "the", "specified", "name", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/ast/ast.go#L628-L630
15,791
mna/pigeon
ast/ast.go
NewStringLit
func NewStringLit(p Pos, val string) *StringLit { return &StringLit{posValue{p: p, Val: val}} }
go
func NewStringLit(p Pos, val string) *StringLit { return &StringLit{posValue{p: p, Val: val}} }
[ "func", "NewStringLit", "(", "p", "Pos", ",", "val", "string", ")", "*", "StringLit", "{", "return", "&", "StringLit", "{", "posValue", "{", "p", ":", "p", ",", "Val", ":", "val", "}", "}", "\n", "}" ]
// NewStringLit creates a new string literal at the specified position and // with the specified value.
[ "NewStringLit", "creates", "a", "new", "string", "literal", "at", "the", "specified", "position", "and", "with", "the", "specified", "value", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/ast/ast.go#L647-L649
15,792
mna/pigeon
bootstrap/scan.go
Init
func (s *Scanner) Init(filename string, r io.Reader, errh func(ast.Pos, error)) { s.r = runeReader(r) s.errh = errh s.eof = false s.cpos = ast.Pos{ Filename: filename, Line: 1, } s.cur, s.cw = -1, 0 s.tok.Reset() }
go
func (s *Scanner) Init(filename string, r io.Reader, errh func(ast.Pos, error)) { s.r = runeReader(r) s.errh = errh s.eof = false s.cpos = ast.Pos{ Filename: filename, Line: 1, } s.cur, s.cw = -1, 0 s.tok.Reset() }
[ "func", "(", "s", "*", "Scanner", ")", "Init", "(", "filename", "string", ",", "r", "io", ".", "Reader", ",", "errh", "func", "(", "ast", ".", "Pos", ",", "error", ")", ")", "{", "s", ".", "r", "=", "runeReader", "(", "r", ")", "\n", "s", ".", "errh", "=", "errh", "\n\n", "s", ".", "eof", "=", "false", "\n", "s", ".", "cpos", "=", "ast", ".", "Pos", "{", "Filename", ":", "filename", ",", "Line", ":", "1", ",", "}", "\n\n", "s", ".", "cur", ",", "s", ".", "cw", "=", "-", "1", ",", "0", "\n", "s", ".", "tok", ".", "Reset", "(", ")", "\n", "}" ]
// Init initializes the scanner to read and tokenize text from r.
[ "Init", "initializes", "the", "scanner", "to", "read", "and", "tokenize", "text", "from", "r", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/bootstrap/scan.go#L28-L40
15,793
mna/pigeon
bootstrap/scan.go
read
func (s *Scanner) read() { if s.eof { return } r, w, err := s.r.ReadRune() if err != nil { s.fatalError(err) return } s.cur = r s.cpos.Off += s.cw s.cw = w // newline is '\n' as in Go if r == '\n' { s.cpos.Line++ s.cpos.Col = 0 } else { s.cpos.Col++ } }
go
func (s *Scanner) read() { if s.eof { return } r, w, err := s.r.ReadRune() if err != nil { s.fatalError(err) return } s.cur = r s.cpos.Off += s.cw s.cw = w // newline is '\n' as in Go if r == '\n' { s.cpos.Line++ s.cpos.Col = 0 } else { s.cpos.Col++ } }
[ "func", "(", "s", "*", "Scanner", ")", "read", "(", ")", "{", "if", "s", ".", "eof", "{", "return", "\n", "}", "\n\n", "r", ",", "w", ",", "err", ":=", "s", ".", "r", ".", "ReadRune", "(", ")", "\n", "if", "err", "!=", "nil", "{", "s", ".", "fatalError", "(", "err", ")", "\n", "return", "\n", "}", "\n\n", "s", ".", "cur", "=", "r", "\n", "s", ".", "cpos", ".", "Off", "+=", "s", ".", "cw", "\n", "s", ".", "cw", "=", "w", "\n\n", "// newline is '\\n' as in Go", "if", "r", "==", "'\\n'", "{", "s", ".", "cpos", ".", "Line", "++", "\n", "s", ".", "cpos", ".", "Col", "=", "0", "\n", "}", "else", "{", "s", ".", "cpos", ".", "Col", "++", "\n", "}", "\n", "}" ]
// read advances the Scanner to the next rune.
[ "read", "advances", "the", "Scanner", "to", "the", "next", "rune", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/bootstrap/scan.go#L465-L487
15,794
mna/pigeon
bootstrap/scan.go
skipWhitespace
func (s *Scanner) skipWhitespace() { for s.cur == ' ' || s.cur == '\t' || s.cur == '\r' { s.read() } }
go
func (s *Scanner) skipWhitespace() { for s.cur == ' ' || s.cur == '\t' || s.cur == '\r' { s.read() } }
[ "func", "(", "s", "*", "Scanner", ")", "skipWhitespace", "(", ")", "{", "for", "s", ".", "cur", "==", "' '", "||", "s", ".", "cur", "==", "'\\t'", "||", "s", ".", "cur", "==", "'\\r'", "{", "s", ".", "read", "(", ")", "\n", "}", "\n", "}" ]
// whitespace is the same as Go, except that it doesn't skip newlines, // those are returned as tokens.
[ "whitespace", "is", "the", "same", "as", "Go", "except", "that", "it", "doesn", "t", "skip", "newlines", "those", "are", "returned", "as", "tokens", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/bootstrap/scan.go#L491-L495
15,795
mna/pigeon
bootstrap/scan.go
isLetter
func isLetter(r rune) bool { return 'a' <= r && r <= 'z' || 'A' <= r && r <= 'Z' || r == '_' || r >= 0x80 && unicode.IsLetter(r) }
go
func isLetter(r rune) bool { return 'a' <= r && r <= 'z' || 'A' <= r && r <= 'Z' || r == '_' || r >= 0x80 && unicode.IsLetter(r) }
[ "func", "isLetter", "(", "r", "rune", ")", "bool", "{", "return", "'a'", "<=", "r", "&&", "r", "<=", "'z'", "||", "'A'", "<=", "r", "&&", "r", "<=", "'Z'", "||", "r", "==", "'_'", "||", "r", ">=", "0x80", "&&", "unicode", ".", "IsLetter", "(", "r", ")", "\n", "}" ]
// isLetter has the same definition as Go.
[ "isLetter", "has", "the", "same", "definition", "as", "Go", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/bootstrap/scan.go#L503-L506
15,796
mna/pigeon
bootstrap/scan.go
isDigit
func isDigit(r rune) bool { return '0' <= r && r <= '9' || r >= 0x80 && unicode.IsDigit(r) }
go
func isDigit(r rune) bool { return '0' <= r && r <= '9' || r >= 0x80 && unicode.IsDigit(r) }
[ "func", "isDigit", "(", "r", "rune", ")", "bool", "{", "return", "'0'", "<=", "r", "&&", "r", "<=", "'9'", "||", "r", ">=", "0x80", "&&", "unicode", ".", "IsDigit", "(", "r", ")", "\n", "}" ]
// isDigit has the same definition as Go.
[ "isDigit", "has", "the", "same", "definition", "as", "Go", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/bootstrap/scan.go#L509-L511
15,797
mna/pigeon
bootstrap/scan.go
error
func (s *Scanner) error(p ast.Pos, err error) { if s.errh != nil { s.errh(p, err) return } fmt.Fprintf(os.Stderr, "%s: %v\n", p, err) }
go
func (s *Scanner) error(p ast.Pos, err error) { if s.errh != nil { s.errh(p, err) return } fmt.Fprintf(os.Stderr, "%s: %v\n", p, err) }
[ "func", "(", "s", "*", "Scanner", ")", "error", "(", "p", "ast", ".", "Pos", ",", "err", "error", ")", "{", "if", "s", ".", "errh", "!=", "nil", "{", "s", ".", "errh", "(", "p", ",", "err", ")", "\n", "return", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\\n", "\"", ",", "p", ",", "err", ")", "\n", "}" ]
// notify the handler of an error.
[ "notify", "the", "handler", "of", "an", "error", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/bootstrap/scan.go#L526-L532
15,798
mna/pigeon
bootstrap/scan.go
errorf
func (s *Scanner) errorf(f string, args ...interface{}) { s.errorpf(s.cpos, f, args...) }
go
func (s *Scanner) errorf(f string, args ...interface{}) { s.errorpf(s.cpos, f, args...) }
[ "func", "(", "s", "*", "Scanner", ")", "errorf", "(", "f", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "s", ".", "errorpf", "(", "s", ".", "cpos", ",", "f", ",", "args", "...", ")", "\n", "}" ]
// helper to generate and notify of an error.
[ "helper", "to", "generate", "and", "notify", "of", "an", "error", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/bootstrap/scan.go#L535-L537
15,799
mna/pigeon
bootstrap/scan.go
errorpf
func (s *Scanner) errorpf(p ast.Pos, f string, args ...interface{}) { s.error(p, fmt.Errorf(f, args...)) }
go
func (s *Scanner) errorpf(p ast.Pos, f string, args ...interface{}) { s.error(p, fmt.Errorf(f, args...)) }
[ "func", "(", "s", "*", "Scanner", ")", "errorpf", "(", "p", "ast", ".", "Pos", ",", "f", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "s", ".", "error", "(", "p", ",", "fmt", ".", "Errorf", "(", "f", ",", "args", "...", ")", ")", "\n", "}" ]
// helper to generate and notify of an error at a specific position.
[ "helper", "to", "generate", "and", "notify", "of", "an", "error", "at", "a", "specific", "position", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/bootstrap/scan.go#L540-L542