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
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
10,100 | honeycombio/honeytail | tail/tail.go | getStartLocation | func getStartLocation(stateFile string, logfile string) *tail.SeekInfo {
beginning := &tail.SeekInfo{}
end := &tail.SeekInfo{0, 2}
fh, err := os.Open(stateFile)
if err != nil {
logrus.WithFields(logrus.Fields{
"starting at": "end", "error": err,
}).Debug("getStartLocation failed to open the statefile")
return end
}
defer fh.Close()
// read the contents of the state file (JSON)
content := make([]byte, 1024)
bytesRead, err := fh.Read(content)
if err != nil {
logrus.WithFields(logrus.Fields{
"starting at": "end", "error": err,
}).Debug("getStartLocation failed to read the statefile contents")
return end
}
content = content[:bytesRead]
// decode the contents of the statefile
state := State{}
if err := json.Unmarshal(content, &state); err != nil {
logrus.WithFields(logrus.Fields{
"starting at": "end", "error": err,
}).Debug("getStartLocation failed to json decode the statefile")
return end
}
// get the details of the existing log file
logStat := unix.Stat_t{}
if err := unix.Stat(logfile, &logStat); err != nil {
logrus.WithFields(logrus.Fields{
"starting at": "end", "error": err,
}).Debug("getStartLocation failed to get unix.stat() on the logfile")
return end
}
// compare inode numbers of the last-seen and existing log files
if state.INode != uint64(logStat.Ino) {
logrus.WithFields(logrus.Fields{
"starting at": "beginning", "error": err,
}).Debug("getStartLocation found a different inode number for the logfile")
// file's been rotated
return beginning
}
logrus.WithFields(logrus.Fields{
"starting at": state.Offset,
}).Debug("getStartLocation seeking to offset in logfile")
// we're good; start reading from the remembered state
return &tail.SeekInfo{
Offset: state.Offset,
Whence: 0,
}
} | go | func getStartLocation(stateFile string, logfile string) *tail.SeekInfo {
beginning := &tail.SeekInfo{}
end := &tail.SeekInfo{0, 2}
fh, err := os.Open(stateFile)
if err != nil {
logrus.WithFields(logrus.Fields{
"starting at": "end", "error": err,
}).Debug("getStartLocation failed to open the statefile")
return end
}
defer fh.Close()
// read the contents of the state file (JSON)
content := make([]byte, 1024)
bytesRead, err := fh.Read(content)
if err != nil {
logrus.WithFields(logrus.Fields{
"starting at": "end", "error": err,
}).Debug("getStartLocation failed to read the statefile contents")
return end
}
content = content[:bytesRead]
// decode the contents of the statefile
state := State{}
if err := json.Unmarshal(content, &state); err != nil {
logrus.WithFields(logrus.Fields{
"starting at": "end", "error": err,
}).Debug("getStartLocation failed to json decode the statefile")
return end
}
// get the details of the existing log file
logStat := unix.Stat_t{}
if err := unix.Stat(logfile, &logStat); err != nil {
logrus.WithFields(logrus.Fields{
"starting at": "end", "error": err,
}).Debug("getStartLocation failed to get unix.stat() on the logfile")
return end
}
// compare inode numbers of the last-seen and existing log files
if state.INode != uint64(logStat.Ino) {
logrus.WithFields(logrus.Fields{
"starting at": "beginning", "error": err,
}).Debug("getStartLocation found a different inode number for the logfile")
// file's been rotated
return beginning
}
logrus.WithFields(logrus.Fields{
"starting at": state.Offset,
}).Debug("getStartLocation seeking to offset in logfile")
// we're good; start reading from the remembered state
return &tail.SeekInfo{
Offset: state.Offset,
Whence: 0,
}
} | [
"func",
"getStartLocation",
"(",
"stateFile",
"string",
",",
"logfile",
"string",
")",
"*",
"tail",
".",
"SeekInfo",
"{",
"beginning",
":=",
"&",
"tail",
".",
"SeekInfo",
"{",
"}",
"\n",
"end",
":=",
"&",
"tail",
".",
"SeekInfo",
"{",
"0",
",",
"2",
"}",
"\n",
"fh",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"stateFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"err",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"end",
"\n",
"}",
"\n",
"defer",
"fh",
".",
"Close",
"(",
")",
"\n",
"// read the contents of the state file (JSON)",
"content",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"1024",
")",
"\n",
"bytesRead",
",",
"err",
":=",
"fh",
".",
"Read",
"(",
"content",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"err",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"end",
"\n",
"}",
"\n",
"content",
"=",
"content",
"[",
":",
"bytesRead",
"]",
"\n",
"// decode the contents of the statefile",
"state",
":=",
"State",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"content",
",",
"&",
"state",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"err",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"end",
"\n",
"}",
"\n",
"// get the details of the existing log file",
"logStat",
":=",
"unix",
".",
"Stat_t",
"{",
"}",
"\n",
"if",
"err",
":=",
"unix",
".",
"Stat",
"(",
"logfile",
",",
"&",
"logStat",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"err",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"end",
"\n",
"}",
"\n",
"// compare inode numbers of the last-seen and existing log files",
"if",
"state",
".",
"INode",
"!=",
"uint64",
"(",
"logStat",
".",
"Ino",
")",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"err",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"// file's been rotated",
"return",
"beginning",
"\n",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"state",
".",
"Offset",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"// we're good; start reading from the remembered state",
"return",
"&",
"tail",
".",
"SeekInfo",
"{",
"Offset",
":",
"state",
".",
"Offset",
",",
"Whence",
":",
"0",
",",
"}",
"\n",
"}"
] | // getStartLocation reads the state file and creates an appropriate start
// location. See details at the top of this file on how the loc is chosen. | [
"getStartLocation",
"reads",
"the",
"state",
"file",
"and",
"creates",
"an",
"appropriate",
"start",
"location",
".",
"See",
"details",
"at",
"the",
"top",
"of",
"this",
"file",
"on",
"how",
"the",
"loc",
"is",
"chosen",
"."
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/tail/tail.go#L289-L342 |
10,101 | honeycombio/honeytail | tail/tail.go | updateStateFile | func updateStateFile(state *State, t *tail.Tail, file string, stateFh *os.File) {
logStat := unix.Stat_t{}
unix.Stat(file, &logStat)
currentPos, err := t.Tell()
if err != nil {
return
}
state.INode = uint64(logStat.Ino)
state.Offset = currentPos
out, err := json.Marshal(state)
if err != nil {
return
}
stateFh.Truncate(0)
out = append(out, '\n')
stateFh.WriteAt(out, 0)
stateFh.Sync()
} | go | func updateStateFile(state *State, t *tail.Tail, file string, stateFh *os.File) {
logStat := unix.Stat_t{}
unix.Stat(file, &logStat)
currentPos, err := t.Tell()
if err != nil {
return
}
state.INode = uint64(logStat.Ino)
state.Offset = currentPos
out, err := json.Marshal(state)
if err != nil {
return
}
stateFh.Truncate(0)
out = append(out, '\n')
stateFh.WriteAt(out, 0)
stateFh.Sync()
} | [
"func",
"updateStateFile",
"(",
"state",
"*",
"State",
",",
"t",
"*",
"tail",
".",
"Tail",
",",
"file",
"string",
",",
"stateFh",
"*",
"os",
".",
"File",
")",
"{",
"logStat",
":=",
"unix",
".",
"Stat_t",
"{",
"}",
"\n",
"unix",
".",
"Stat",
"(",
"file",
",",
"&",
"logStat",
")",
"\n",
"currentPos",
",",
"err",
":=",
"t",
".",
"Tell",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"state",
".",
"INode",
"=",
"uint64",
"(",
"logStat",
".",
"Ino",
")",
"\n",
"state",
".",
"Offset",
"=",
"currentPos",
"\n",
"out",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"state",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"stateFh",
".",
"Truncate",
"(",
"0",
")",
"\n",
"out",
"=",
"append",
"(",
"out",
",",
"'\\n'",
")",
"\n",
"stateFh",
".",
"WriteAt",
"(",
"out",
",",
"0",
")",
"\n",
"stateFh",
".",
"Sync",
"(",
")",
"\n",
"}"
] | // updateStateFile updates the state file once per second with the current
// values for the logfile's inode number and offset | [
"updateStateFile",
"updates",
"the",
"state",
"file",
"once",
"per",
"second",
"with",
"the",
"current",
"values",
"for",
"the",
"logfile",
"s",
"inode",
"number",
"and",
"offset"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/tail/tail.go#L424-L441 |
10,102 | honeycombio/honeytail | parsers/regex/regex.go | ParseLineRegexes | func ParseLineRegexes(regexStrs []string) ([]*regexp.Regexp, error) {
regexes := make([]*regexp.Regexp, 0)
for _, regexStr := range regexStrs {
regex, err := ParseLineRegex(regexStr)
if err != nil {
return regexes, err
}
regexes = append(regexes, regex)
}
return regexes, nil
} | go | func ParseLineRegexes(regexStrs []string) ([]*regexp.Regexp, error) {
regexes := make([]*regexp.Regexp, 0)
for _, regexStr := range regexStrs {
regex, err := ParseLineRegex(regexStr)
if err != nil {
return regexes, err
}
regexes = append(regexes, regex)
}
return regexes, nil
} | [
"func",
"ParseLineRegexes",
"(",
"regexStrs",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"regexp",
".",
"Regexp",
",",
"error",
")",
"{",
"regexes",
":=",
"make",
"(",
"[",
"]",
"*",
"regexp",
".",
"Regexp",
",",
"0",
")",
"\n",
"for",
"_",
",",
"regexStr",
":=",
"range",
"regexStrs",
"{",
"regex",
",",
"err",
":=",
"ParseLineRegex",
"(",
"regexStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"regexes",
",",
"err",
"\n",
"}",
"\n",
"regexes",
"=",
"append",
"(",
"regexes",
",",
"regex",
")",
"\n",
"}",
"\n",
"return",
"regexes",
",",
"nil",
"\n",
"}"
] | // Compile multiple log line regexes | [
"Compile",
"multiple",
"log",
"line",
"regexes"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/parsers/regex/regex.go#L51-L61 |
10,103 | honeycombio/honeytail | parsers/regex/regex.go | ParseLineRegex | func ParseLineRegex(regexStr string) (*regexp.Regexp, error) {
// Regex can't be blank
if regexStr == "" {
logrus.Debug("LineRegex is blank; required field")
return nil, errors.New("Must provide a regex for parsing log lines; use `--regex.line_regex` flag.")
}
// Compile regex
lineRegex, err := regexp.Compile(regexStr)
if err != nil {
logrus.WithFields(logrus.Fields{
"lineRegex": regexStr,
}).Error("Could not compile line regex")
return nil, err
}
// Require at least one named group
var numNamedGroups int
for _, groupName := range lineRegex.SubexpNames() {
if groupName != "" {
numNamedGroups++
}
}
if numNamedGroups == 0 {
logrus.WithFields(logrus.Fields{
"LineRegex": regexStr,
}).Error("No named capture groups")
return nil, errors.New(fmt.Sprintf("No named capture groups found in regex: '%s'. Must provide at least one named group with line regex. Example: `(?P<name>re)`", regexStr))
}
return lineRegex, nil
} | go | func ParseLineRegex(regexStr string) (*regexp.Regexp, error) {
// Regex can't be blank
if regexStr == "" {
logrus.Debug("LineRegex is blank; required field")
return nil, errors.New("Must provide a regex for parsing log lines; use `--regex.line_regex` flag.")
}
// Compile regex
lineRegex, err := regexp.Compile(regexStr)
if err != nil {
logrus.WithFields(logrus.Fields{
"lineRegex": regexStr,
}).Error("Could not compile line regex")
return nil, err
}
// Require at least one named group
var numNamedGroups int
for _, groupName := range lineRegex.SubexpNames() {
if groupName != "" {
numNamedGroups++
}
}
if numNamedGroups == 0 {
logrus.WithFields(logrus.Fields{
"LineRegex": regexStr,
}).Error("No named capture groups")
return nil, errors.New(fmt.Sprintf("No named capture groups found in regex: '%s'. Must provide at least one named group with line regex. Example: `(?P<name>re)`", regexStr))
}
return lineRegex, nil
} | [
"func",
"ParseLineRegex",
"(",
"regexStr",
"string",
")",
"(",
"*",
"regexp",
".",
"Regexp",
",",
"error",
")",
"{",
"// Regex can't be blank",
"if",
"regexStr",
"==",
"\"",
"\"",
"{",
"logrus",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Compile regex",
"lineRegex",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"regexStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"regexStr",
",",
"}",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Require at least one named group",
"var",
"numNamedGroups",
"int",
"\n",
"for",
"_",
",",
"groupName",
":=",
"range",
"lineRegex",
".",
"SubexpNames",
"(",
")",
"{",
"if",
"groupName",
"!=",
"\"",
"\"",
"{",
"numNamedGroups",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"numNamedGroups",
"==",
"0",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"regexStr",
",",
"}",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"regexStr",
")",
")",
"\n",
"}",
"\n\n",
"return",
"lineRegex",
",",
"nil",
"\n",
"}"
] | // Compile a regex & validate expectations for log line parsing | [
"Compile",
"a",
"regex",
"&",
"validate",
"expectations",
"for",
"log",
"line",
"parsing"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/parsers/regex/regex.go#L64-L95 |
10,104 | honeycombio/honeytail | response_stats.go | newResponseStats | func newResponseStats() *responseStats {
r := &responseStats{}
r.totalStatusCodes = make(map[int]int)
r.lock = &sync.Mutex{}
r.reset()
return r
} | go | func newResponseStats() *responseStats {
r := &responseStats{}
r.totalStatusCodes = make(map[int]int)
r.lock = &sync.Mutex{}
r.reset()
return r
} | [
"func",
"newResponseStats",
"(",
")",
"*",
"responseStats",
"{",
"r",
":=",
"&",
"responseStats",
"{",
"}",
"\n",
"r",
".",
"totalStatusCodes",
"=",
"make",
"(",
"map",
"[",
"int",
"]",
"int",
")",
"\n",
"r",
".",
"lock",
"=",
"&",
"sync",
".",
"Mutex",
"{",
"}",
"\n",
"r",
".",
"reset",
"(",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // newResponseStats initializes the struct's complex data types | [
"newResponseStats",
"initializes",
"the",
"struct",
"s",
"complex",
"data",
"types"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/response_stats.go#L36-L42 |
10,105 | honeycombio/honeytail | response_stats.go | update | func (r *responseStats) update(rsp libhoney.Response) {
r.lock.Lock()
defer r.lock.Unlock()
r.count += 1
r.statusCodes[rsp.StatusCode] += 1
r.bodies[strings.TrimSpace(string(rsp.Body))] += 1
if rsp.Err != nil {
r.errors[rsp.Err.Error()] += 1
}
if r.minDuration == 0 {
r.minDuration = rsp.Duration
}
if rsp.Duration < r.minDuration {
r.minDuration = rsp.Duration
} else if rsp.Duration > r.maxDuration {
r.maxDuration = rsp.Duration
}
r.sumDuration += rsp.Duration
ev := rsp.Metadata.(event.Event)
r.event = &ev
} | go | func (r *responseStats) update(rsp libhoney.Response) {
r.lock.Lock()
defer r.lock.Unlock()
r.count += 1
r.statusCodes[rsp.StatusCode] += 1
r.bodies[strings.TrimSpace(string(rsp.Body))] += 1
if rsp.Err != nil {
r.errors[rsp.Err.Error()] += 1
}
if r.minDuration == 0 {
r.minDuration = rsp.Duration
}
if rsp.Duration < r.minDuration {
r.minDuration = rsp.Duration
} else if rsp.Duration > r.maxDuration {
r.maxDuration = rsp.Duration
}
r.sumDuration += rsp.Duration
ev := rsp.Metadata.(event.Event)
r.event = &ev
} | [
"func",
"(",
"r",
"*",
"responseStats",
")",
"update",
"(",
"rsp",
"libhoney",
".",
"Response",
")",
"{",
"r",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"count",
"+=",
"1",
"\n",
"r",
".",
"statusCodes",
"[",
"rsp",
".",
"StatusCode",
"]",
"+=",
"1",
"\n",
"r",
".",
"bodies",
"[",
"strings",
".",
"TrimSpace",
"(",
"string",
"(",
"rsp",
".",
"Body",
")",
")",
"]",
"+=",
"1",
"\n",
"if",
"rsp",
".",
"Err",
"!=",
"nil",
"{",
"r",
".",
"errors",
"[",
"rsp",
".",
"Err",
".",
"Error",
"(",
")",
"]",
"+=",
"1",
"\n",
"}",
"\n",
"if",
"r",
".",
"minDuration",
"==",
"0",
"{",
"r",
".",
"minDuration",
"=",
"rsp",
".",
"Duration",
"\n",
"}",
"\n",
"if",
"rsp",
".",
"Duration",
"<",
"r",
".",
"minDuration",
"{",
"r",
".",
"minDuration",
"=",
"rsp",
".",
"Duration",
"\n",
"}",
"else",
"if",
"rsp",
".",
"Duration",
">",
"r",
".",
"maxDuration",
"{",
"r",
".",
"maxDuration",
"=",
"rsp",
".",
"Duration",
"\n",
"}",
"\n",
"r",
".",
"sumDuration",
"+=",
"rsp",
".",
"Duration",
"\n",
"ev",
":=",
"rsp",
".",
"Metadata",
".",
"(",
"event",
".",
"Event",
")",
"\n",
"r",
".",
"event",
"=",
"&",
"ev",
"\n",
"}"
] | // update adds a response into the stats container | [
"update",
"adds",
"a",
"response",
"into",
"the",
"stats",
"container"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/response_stats.go#L45-L65 |
10,106 | honeycombio/honeytail | response_stats.go | logAndReset | func (r *responseStats) logAndReset() {
r.lock.Lock()
defer r.lock.Unlock()
r.log()
r.reset()
} | go | func (r *responseStats) logAndReset() {
r.lock.Lock()
defer r.lock.Unlock()
r.log()
r.reset()
} | [
"func",
"(",
"r",
"*",
"responseStats",
")",
"logAndReset",
"(",
")",
"{",
"r",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"log",
"(",
")",
"\n",
"r",
".",
"reset",
"(",
")",
"\n",
"}"
] | // log the current stats and reset them all to zero.
// thread safe. | [
"log",
"the",
"current",
"stats",
"and",
"reset",
"them",
"all",
"to",
"zero",
".",
"thread",
"safe",
"."
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/response_stats.go#L69-L74 |
10,107 | honeycombio/honeytail | response_stats.go | log | func (r *responseStats) log() {
var avg time.Duration
if r.count != 0 {
avg = r.sumDuration / time.Duration(r.count)
} else {
avg = 0
}
logrus.WithFields(logrus.Fields{
"count": r.count,
"lifetime_count": r.totalCount + r.count,
"slowest": r.maxDuration,
"fastest": r.minDuration,
"avg_duration": avg,
"count_per_status": r.statusCodes,
"response_bodies": r.bodies,
"errors": r.errors,
}).Info("Summary of sent events")
if r.event != nil {
fields := make(map[string]interface{})
fields["event"] = r.event.Data
fields["event_timestamp"] = r.event.Timestamp
logrus.WithFields(fields).Info("Last parsed event")
}
} | go | func (r *responseStats) log() {
var avg time.Duration
if r.count != 0 {
avg = r.sumDuration / time.Duration(r.count)
} else {
avg = 0
}
logrus.WithFields(logrus.Fields{
"count": r.count,
"lifetime_count": r.totalCount + r.count,
"slowest": r.maxDuration,
"fastest": r.minDuration,
"avg_duration": avg,
"count_per_status": r.statusCodes,
"response_bodies": r.bodies,
"errors": r.errors,
}).Info("Summary of sent events")
if r.event != nil {
fields := make(map[string]interface{})
fields["event"] = r.event.Data
fields["event_timestamp"] = r.event.Timestamp
logrus.WithFields(fields).Info("Last parsed event")
}
} | [
"func",
"(",
"r",
"*",
"responseStats",
")",
"log",
"(",
")",
"{",
"var",
"avg",
"time",
".",
"Duration",
"\n",
"if",
"r",
".",
"count",
"!=",
"0",
"{",
"avg",
"=",
"r",
".",
"sumDuration",
"/",
"time",
".",
"Duration",
"(",
"r",
".",
"count",
")",
"\n",
"}",
"else",
"{",
"avg",
"=",
"0",
"\n",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"r",
".",
"count",
",",
"\"",
"\"",
":",
"r",
".",
"totalCount",
"+",
"r",
".",
"count",
",",
"\"",
"\"",
":",
"r",
".",
"maxDuration",
",",
"\"",
"\"",
":",
"r",
".",
"minDuration",
",",
"\"",
"\"",
":",
"avg",
",",
"\"",
"\"",
":",
"r",
".",
"statusCodes",
",",
"\"",
"\"",
":",
"r",
".",
"bodies",
",",
"\"",
"\"",
":",
"r",
".",
"errors",
",",
"}",
")",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"if",
"r",
".",
"event",
"!=",
"nil",
"{",
"fields",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"fields",
"[",
"\"",
"\"",
"]",
"=",
"r",
".",
"event",
".",
"Data",
"\n",
"fields",
"[",
"\"",
"\"",
"]",
"=",
"r",
".",
"event",
".",
"Timestamp",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // log the current statistics to logrus.
// NOT thread safe. | [
"log",
"the",
"current",
"statistics",
"to",
"logrus",
".",
"NOT",
"thread",
"safe",
"."
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/response_stats.go#L78-L101 |
10,108 | honeycombio/honeytail | response_stats.go | logFinal | func (r *responseStats) logFinal() {
r.lock.Lock()
defer r.lock.Unlock()
r.totalCount += r.count
for code, count := range r.statusCodes {
r.totalStatusCodes[code] += count
}
logrus.WithFields(logrus.Fields{
"total attempted sends": r.totalCount,
"number sent by response status code": r.totalStatusCodes,
}).Info("Total number of events sent")
} | go | func (r *responseStats) logFinal() {
r.lock.Lock()
defer r.lock.Unlock()
r.totalCount += r.count
for code, count := range r.statusCodes {
r.totalStatusCodes[code] += count
}
logrus.WithFields(logrus.Fields{
"total attempted sends": r.totalCount,
"number sent by response status code": r.totalStatusCodes,
}).Info("Total number of events sent")
} | [
"func",
"(",
"r",
"*",
"responseStats",
")",
"logFinal",
"(",
")",
"{",
"r",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"totalCount",
"+=",
"r",
".",
"count",
"\n",
"for",
"code",
",",
"count",
":=",
"range",
"r",
".",
"statusCodes",
"{",
"r",
".",
"totalStatusCodes",
"[",
"code",
"]",
"+=",
"count",
"\n",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"r",
".",
"totalCount",
",",
"\"",
"\"",
":",
"r",
".",
"totalStatusCodes",
",",
"}",
")",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // log the total count on its own | [
"log",
"the",
"total",
"count",
"on",
"its",
"own"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/response_stats.go#L104-L115 |
10,109 | honeycombio/honeytail | response_stats.go | reset | func (r *responseStats) reset() {
r.totalCount += r.count
for code, count := range r.statusCodes {
r.totalStatusCodes[code] += count
}
r.count = 0
r.statusCodes = make(map[int]int)
r.bodies = make(map[string]int)
r.errors = make(map[string]int)
r.maxDuration = 0
r.sumDuration = 0
r.minDuration = 0
} | go | func (r *responseStats) reset() {
r.totalCount += r.count
for code, count := range r.statusCodes {
r.totalStatusCodes[code] += count
}
r.count = 0
r.statusCodes = make(map[int]int)
r.bodies = make(map[string]int)
r.errors = make(map[string]int)
r.maxDuration = 0
r.sumDuration = 0
r.minDuration = 0
} | [
"func",
"(",
"r",
"*",
"responseStats",
")",
"reset",
"(",
")",
"{",
"r",
".",
"totalCount",
"+=",
"r",
".",
"count",
"\n",
"for",
"code",
",",
"count",
":=",
"range",
"r",
".",
"statusCodes",
"{",
"r",
".",
"totalStatusCodes",
"[",
"code",
"]",
"+=",
"count",
"\n",
"}",
"\n",
"r",
".",
"count",
"=",
"0",
"\n",
"r",
".",
"statusCodes",
"=",
"make",
"(",
"map",
"[",
"int",
"]",
"int",
")",
"\n",
"r",
".",
"bodies",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
"\n",
"r",
".",
"errors",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
"\n",
"r",
".",
"maxDuration",
"=",
"0",
"\n",
"r",
".",
"sumDuration",
"=",
"0",
"\n",
"r",
".",
"minDuration",
"=",
"0",
"\n",
"}"
] | // reset the counters to zero.
// NOT thread safe | [
"reset",
"the",
"counters",
"to",
"zero",
".",
"NOT",
"thread",
"safe"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/response_stats.go#L119-L131 |
10,110 | honeycombio/honeytail | main.go | setVersionUserAgent | func setVersionUserAgent(backfill bool, parserName string) {
if BuildID == "" {
version = "dev"
} else {
version = BuildID
}
if backfill {
parserName += " backfill"
}
libhoney.UserAgentAddition = fmt.Sprintf("honeytail/%s (%s)", version, parserName)
} | go | func setVersionUserAgent(backfill bool, parserName string) {
if BuildID == "" {
version = "dev"
} else {
version = BuildID
}
if backfill {
parserName += " backfill"
}
libhoney.UserAgentAddition = fmt.Sprintf("honeytail/%s (%s)", version, parserName)
} | [
"func",
"setVersionUserAgent",
"(",
"backfill",
"bool",
",",
"parserName",
"string",
")",
"{",
"if",
"BuildID",
"==",
"\"",
"\"",
"{",
"version",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"version",
"=",
"BuildID",
"\n",
"}",
"\n",
"if",
"backfill",
"{",
"parserName",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"libhoney",
".",
"UserAgentAddition",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"version",
",",
"parserName",
")",
"\n",
"}"
] | // setVersion sets the internal version ID and updates libhoney's user-agent | [
"setVersion",
"sets",
"the",
"internal",
"version",
"ID",
"and",
"updates",
"libhoney",
"s",
"user",
"-",
"agent"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/main.go#L199-L209 |
10,111 | honeycombio/honeytail | main.go | handleOtherModes | func handleOtherModes(fp *flag.Parser, modes OtherModes) {
if modes.Version {
fmt.Println("Honeytail version", version)
os.Exit(0)
}
if modes.Help {
fp.WriteHelp(os.Stdout)
fmt.Println("")
os.Exit(0)
}
if modes.WriteManPage {
fp.WriteManPage(os.Stdout)
os.Exit(0)
}
if modes.WriteDefaultConfig {
ip := flag.NewIniParser(fp)
ip.Write(os.Stdout, flag.IniIncludeDefaults|flag.IniCommentDefaults|flag.IniIncludeComments)
os.Exit(0)
}
if modes.WriteCurrentConfig {
ip := flag.NewIniParser(fp)
ip.Write(os.Stdout, flag.IniIncludeComments)
os.Exit(0)
}
if modes.ListParsers {
fmt.Println("Available parsers:", strings.Join(validParsers, ", "))
os.Exit(0)
}
} | go | func handleOtherModes(fp *flag.Parser, modes OtherModes) {
if modes.Version {
fmt.Println("Honeytail version", version)
os.Exit(0)
}
if modes.Help {
fp.WriteHelp(os.Stdout)
fmt.Println("")
os.Exit(0)
}
if modes.WriteManPage {
fp.WriteManPage(os.Stdout)
os.Exit(0)
}
if modes.WriteDefaultConfig {
ip := flag.NewIniParser(fp)
ip.Write(os.Stdout, flag.IniIncludeDefaults|flag.IniCommentDefaults|flag.IniIncludeComments)
os.Exit(0)
}
if modes.WriteCurrentConfig {
ip := flag.NewIniParser(fp)
ip.Write(os.Stdout, flag.IniIncludeComments)
os.Exit(0)
}
if modes.ListParsers {
fmt.Println("Available parsers:", strings.Join(validParsers, ", "))
os.Exit(0)
}
} | [
"func",
"handleOtherModes",
"(",
"fp",
"*",
"flag",
".",
"Parser",
",",
"modes",
"OtherModes",
")",
"{",
"if",
"modes",
".",
"Version",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"version",
")",
"\n",
"os",
".",
"Exit",
"(",
"0",
")",
"\n",
"}",
"\n",
"if",
"modes",
".",
"Help",
"{",
"fp",
".",
"WriteHelp",
"(",
"os",
".",
"Stdout",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"os",
".",
"Exit",
"(",
"0",
")",
"\n",
"}",
"\n",
"if",
"modes",
".",
"WriteManPage",
"{",
"fp",
".",
"WriteManPage",
"(",
"os",
".",
"Stdout",
")",
"\n",
"os",
".",
"Exit",
"(",
"0",
")",
"\n",
"}",
"\n",
"if",
"modes",
".",
"WriteDefaultConfig",
"{",
"ip",
":=",
"flag",
".",
"NewIniParser",
"(",
"fp",
")",
"\n",
"ip",
".",
"Write",
"(",
"os",
".",
"Stdout",
",",
"flag",
".",
"IniIncludeDefaults",
"|",
"flag",
".",
"IniCommentDefaults",
"|",
"flag",
".",
"IniIncludeComments",
")",
"\n",
"os",
".",
"Exit",
"(",
"0",
")",
"\n",
"}",
"\n",
"if",
"modes",
".",
"WriteCurrentConfig",
"{",
"ip",
":=",
"flag",
".",
"NewIniParser",
"(",
"fp",
")",
"\n",
"ip",
".",
"Write",
"(",
"os",
".",
"Stdout",
",",
"flag",
".",
"IniIncludeComments",
")",
"\n",
"os",
".",
"Exit",
"(",
"0",
")",
"\n",
"}",
"\n\n",
"if",
"modes",
".",
"ListParsers",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"validParsers",
",",
"\"",
"\"",
")",
")",
"\n",
"os",
".",
"Exit",
"(",
"0",
")",
"\n",
"}",
"\n",
"}"
] | // handleOtherModes takse care of all flags that say we should just do something
// and exit rather than actually parsing logs | [
"handleOtherModes",
"takse",
"care",
"of",
"all",
"flags",
"that",
"say",
"we",
"should",
"just",
"do",
"something",
"and",
"exit",
"rather",
"than",
"actually",
"parsing",
"logs"
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/main.go#L213-L242 |
10,112 | honeycombio/honeytail | parsers/arangodb/arangodb.go | ParseLine | func (m *ArangoLineParser) ParseLine(line string) (_ map[string]interface{}, err error) {
// Do the actual work here, we look for log lines in the log topic "requests",
// there are two types, one is a DEBUG line (could be switched off) containing
// the request body, the other is the INFO line marking the end of the
// request.
var v = make(map[string]interface{})
err = errors.New("Line is not a request log line.")
var abort bool
var s string
v[timestampFieldName], abort = firstWord(&line)
if abort {
return
}
s, abort = firstWord(&line)
if abort {
return
}
v[pidFieldName] = removeBrackets(s)
v[logLevelFieldName], abort = firstWord(&line)
if abort {
return
}
s, abort = firstWord(&line)
if abort {
return
}
v[logTopicFieldName] = s
if s != "{requests}" {
return
}
var fields = strings.Split(line, ",")
if v[logLevelFieldName] == "DEBUG" {
if len(fields) != 6 {
return
}
v[idFieldName] = removeQuotes(fields[1])
v[sourceIPFieldName] = removeQuotes(fields[2])
v[methodFieldName] = removeQuotes(fields[3])
v[protocolFieldName] = removeQuotes(fields[4])
v[fullURLFieldName] = removeQuotes(fields[5])
} else {
if len(fields) != 10 {
return
}
v[idFieldName] = removeQuotes(fields[1])
v[sourceIPFieldName] = removeQuotes(fields[2])
v[methodFieldName] = removeQuotes(fields[3])
v[protocolFieldName] = removeQuotes(fields[4])
v[resCodeFieldName], _ = strconv.ParseInt(fields[5], 10, 32)
v[reqBodyLenFieldName], _ = strconv.ParseInt(fields[6], 10, 64)
v[resBodyLenFieldName], _ = strconv.ParseInt(fields[7], 10, 64)
v[fullURLFieldName] = removeQuotes(fields[8])
v[totalTimeFieldName], _ = strconv.ParseFloat(fields[9], 64)
}
return v, nil
} | go | func (m *ArangoLineParser) ParseLine(line string) (_ map[string]interface{}, err error) {
// Do the actual work here, we look for log lines in the log topic "requests",
// there are two types, one is a DEBUG line (could be switched off) containing
// the request body, the other is the INFO line marking the end of the
// request.
var v = make(map[string]interface{})
err = errors.New("Line is not a request log line.")
var abort bool
var s string
v[timestampFieldName], abort = firstWord(&line)
if abort {
return
}
s, abort = firstWord(&line)
if abort {
return
}
v[pidFieldName] = removeBrackets(s)
v[logLevelFieldName], abort = firstWord(&line)
if abort {
return
}
s, abort = firstWord(&line)
if abort {
return
}
v[logTopicFieldName] = s
if s != "{requests}" {
return
}
var fields = strings.Split(line, ",")
if v[logLevelFieldName] == "DEBUG" {
if len(fields) != 6 {
return
}
v[idFieldName] = removeQuotes(fields[1])
v[sourceIPFieldName] = removeQuotes(fields[2])
v[methodFieldName] = removeQuotes(fields[3])
v[protocolFieldName] = removeQuotes(fields[4])
v[fullURLFieldName] = removeQuotes(fields[5])
} else {
if len(fields) != 10 {
return
}
v[idFieldName] = removeQuotes(fields[1])
v[sourceIPFieldName] = removeQuotes(fields[2])
v[methodFieldName] = removeQuotes(fields[3])
v[protocolFieldName] = removeQuotes(fields[4])
v[resCodeFieldName], _ = strconv.ParseInt(fields[5], 10, 32)
v[reqBodyLenFieldName], _ = strconv.ParseInt(fields[6], 10, 64)
v[resBodyLenFieldName], _ = strconv.ParseInt(fields[7], 10, 64)
v[fullURLFieldName] = removeQuotes(fields[8])
v[totalTimeFieldName], _ = strconv.ParseFloat(fields[9], 64)
}
return v, nil
} | [
"func",
"(",
"m",
"*",
"ArangoLineParser",
")",
"ParseLine",
"(",
"line",
"string",
")",
"(",
"_",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"// Do the actual work here, we look for log lines in the log topic \"requests\",",
"// there are two types, one is a DEBUG line (could be switched off) containing",
"// the request body, the other is the INFO line marking the end of the",
"// request.",
"var",
"v",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"var",
"abort",
"bool",
"\n",
"var",
"s",
"string",
"\n\n",
"v",
"[",
"timestampFieldName",
"]",
",",
"abort",
"=",
"firstWord",
"(",
"&",
"line",
")",
"\n",
"if",
"abort",
"{",
"return",
"\n",
"}",
"\n\n",
"s",
",",
"abort",
"=",
"firstWord",
"(",
"&",
"line",
")",
"\n",
"if",
"abort",
"{",
"return",
"\n",
"}",
"\n",
"v",
"[",
"pidFieldName",
"]",
"=",
"removeBrackets",
"(",
"s",
")",
"\n\n",
"v",
"[",
"logLevelFieldName",
"]",
",",
"abort",
"=",
"firstWord",
"(",
"&",
"line",
")",
"\n",
"if",
"abort",
"{",
"return",
"\n",
"}",
"\n\n",
"s",
",",
"abort",
"=",
"firstWord",
"(",
"&",
"line",
")",
"\n",
"if",
"abort",
"{",
"return",
"\n",
"}",
"\n",
"v",
"[",
"logTopicFieldName",
"]",
"=",
"s",
"\n\n",
"if",
"s",
"!=",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n\n",
"var",
"fields",
"=",
"strings",
".",
"Split",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"if",
"v",
"[",
"logLevelFieldName",
"]",
"==",
"\"",
"\"",
"{",
"if",
"len",
"(",
"fields",
")",
"!=",
"6",
"{",
"return",
"\n",
"}",
"\n",
"v",
"[",
"idFieldName",
"]",
"=",
"removeQuotes",
"(",
"fields",
"[",
"1",
"]",
")",
"\n",
"v",
"[",
"sourceIPFieldName",
"]",
"=",
"removeQuotes",
"(",
"fields",
"[",
"2",
"]",
")",
"\n",
"v",
"[",
"methodFieldName",
"]",
"=",
"removeQuotes",
"(",
"fields",
"[",
"3",
"]",
")",
"\n",
"v",
"[",
"protocolFieldName",
"]",
"=",
"removeQuotes",
"(",
"fields",
"[",
"4",
"]",
")",
"\n",
"v",
"[",
"fullURLFieldName",
"]",
"=",
"removeQuotes",
"(",
"fields",
"[",
"5",
"]",
")",
"\n",
"}",
"else",
"{",
"if",
"len",
"(",
"fields",
")",
"!=",
"10",
"{",
"return",
"\n",
"}",
"\n",
"v",
"[",
"idFieldName",
"]",
"=",
"removeQuotes",
"(",
"fields",
"[",
"1",
"]",
")",
"\n",
"v",
"[",
"sourceIPFieldName",
"]",
"=",
"removeQuotes",
"(",
"fields",
"[",
"2",
"]",
")",
"\n",
"v",
"[",
"methodFieldName",
"]",
"=",
"removeQuotes",
"(",
"fields",
"[",
"3",
"]",
")",
"\n",
"v",
"[",
"protocolFieldName",
"]",
"=",
"removeQuotes",
"(",
"fields",
"[",
"4",
"]",
")",
"\n",
"v",
"[",
"resCodeFieldName",
"]",
",",
"_",
"=",
"strconv",
".",
"ParseInt",
"(",
"fields",
"[",
"5",
"]",
",",
"10",
",",
"32",
")",
"\n",
"v",
"[",
"reqBodyLenFieldName",
"]",
",",
"_",
"=",
"strconv",
".",
"ParseInt",
"(",
"fields",
"[",
"6",
"]",
",",
"10",
",",
"64",
")",
"\n",
"v",
"[",
"resBodyLenFieldName",
"]",
",",
"_",
"=",
"strconv",
".",
"ParseInt",
"(",
"fields",
"[",
"7",
"]",
",",
"10",
",",
"64",
")",
"\n",
"v",
"[",
"fullURLFieldName",
"]",
"=",
"removeQuotes",
"(",
"fields",
"[",
"8",
"]",
")",
"\n",
"v",
"[",
"totalTimeFieldName",
"]",
",",
"_",
"=",
"strconv",
".",
"ParseFloat",
"(",
"fields",
"[",
"9",
"]",
",",
"64",
")",
"\n",
"}",
"\n",
"return",
"v",
",",
"nil",
"\n",
"}"
] | // ParseLine method for an ArangoLineParser implementing LineParser. | [
"ParseLine",
"method",
"for",
"an",
"ArangoLineParser",
"implementing",
"LineParser",
"."
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/parsers/arangodb/arangodb.go#L99-L160 |
10,113 | honeycombio/honeytail | parsers/arangodb/arangodb.go | ProcessLines | func (p *Parser) ProcessLines(lines <-chan string, send chan<- event.Event, prefixRegex *parsers.ExtRegexp) {
wg := sync.WaitGroup{}
for i := 0; i < numParsers; i++ {
wg.Add(1)
go func() {
for line := range lines {
line = strings.TrimSpace(line)
// take care of any headers on the line
var prefixFields map[string]string
if prefixRegex != nil {
var prefix string
prefix, prefixFields = prefixRegex.FindStringSubmatchMap(line)
line = strings.TrimPrefix(line, prefix)
}
values, err := p.lineParser.ParseLine(line)
// we get a bunch of errors from the parser on ArangoDB logs, skip em
if err == nil {
timestamp, err := p.parseTimestamp(values)
if err != nil {
logSkipped(line, "couldn't parse logline timestamp, skipping")
continue
}
// merge the prefix fields and the parsed line contents
for k, v := range prefixFields {
values[k] = v
}
logrus.WithFields(logrus.Fields{
"line": line,
"values": values,
}).Debug("Successfully parsed line")
// we'll be putting the timestamp in the Event
// itself, no need to also have it in the Data
delete(values, timestampFieldName)
send <- event.Event{
Timestamp: timestamp,
Data: values,
}
} else {
logSkipped(line, "logline didn't parse, skipping.")
}
}
wg.Done()
}()
}
wg.Wait()
logrus.Debug("lines channel is closed, ending arangodb processor")
} | go | func (p *Parser) ProcessLines(lines <-chan string, send chan<- event.Event, prefixRegex *parsers.ExtRegexp) {
wg := sync.WaitGroup{}
for i := 0; i < numParsers; i++ {
wg.Add(1)
go func() {
for line := range lines {
line = strings.TrimSpace(line)
// take care of any headers on the line
var prefixFields map[string]string
if prefixRegex != nil {
var prefix string
prefix, prefixFields = prefixRegex.FindStringSubmatchMap(line)
line = strings.TrimPrefix(line, prefix)
}
values, err := p.lineParser.ParseLine(line)
// we get a bunch of errors from the parser on ArangoDB logs, skip em
if err == nil {
timestamp, err := p.parseTimestamp(values)
if err != nil {
logSkipped(line, "couldn't parse logline timestamp, skipping")
continue
}
// merge the prefix fields and the parsed line contents
for k, v := range prefixFields {
values[k] = v
}
logrus.WithFields(logrus.Fields{
"line": line,
"values": values,
}).Debug("Successfully parsed line")
// we'll be putting the timestamp in the Event
// itself, no need to also have it in the Data
delete(values, timestampFieldName)
send <- event.Event{
Timestamp: timestamp,
Data: values,
}
} else {
logSkipped(line, "logline didn't parse, skipping.")
}
}
wg.Done()
}()
}
wg.Wait()
logrus.Debug("lines channel is closed, ending arangodb processor")
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"ProcessLines",
"(",
"lines",
"<-",
"chan",
"string",
",",
"send",
"chan",
"<-",
"event",
".",
"Event",
",",
"prefixRegex",
"*",
"parsers",
".",
"ExtRegexp",
")",
"{",
"wg",
":=",
"sync",
".",
"WaitGroup",
"{",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"numParsers",
";",
"i",
"++",
"{",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"for",
"line",
":=",
"range",
"lines",
"{",
"line",
"=",
"strings",
".",
"TrimSpace",
"(",
"line",
")",
"\n",
"// take care of any headers on the line",
"var",
"prefixFields",
"map",
"[",
"string",
"]",
"string",
"\n",
"if",
"prefixRegex",
"!=",
"nil",
"{",
"var",
"prefix",
"string",
"\n",
"prefix",
",",
"prefixFields",
"=",
"prefixRegex",
".",
"FindStringSubmatchMap",
"(",
"line",
")",
"\n",
"line",
"=",
"strings",
".",
"TrimPrefix",
"(",
"line",
",",
"prefix",
")",
"\n",
"}",
"\n\n",
"values",
",",
"err",
":=",
"p",
".",
"lineParser",
".",
"ParseLine",
"(",
"line",
")",
"\n",
"// we get a bunch of errors from the parser on ArangoDB logs, skip em",
"if",
"err",
"==",
"nil",
"{",
"timestamp",
",",
"err",
":=",
"p",
".",
"parseTimestamp",
"(",
"values",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logSkipped",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"// merge the prefix fields and the parsed line contents",
"for",
"k",
",",
"v",
":=",
"range",
"prefixFields",
"{",
"values",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"line",
",",
"\"",
"\"",
":",
"values",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"// we'll be putting the timestamp in the Event",
"// itself, no need to also have it in the Data",
"delete",
"(",
"values",
",",
"timestampFieldName",
")",
"\n\n",
"send",
"<-",
"event",
".",
"Event",
"{",
"Timestamp",
":",
"timestamp",
",",
"Data",
":",
"values",
",",
"}",
"\n",
"}",
"else",
"{",
"logSkipped",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"wg",
".",
"Done",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"logrus",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // ProcessLines method for Parser. | [
"ProcessLines",
"method",
"for",
"Parser",
"."
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/parsers/arangodb/arangodb.go#L170-L221 |
10,114 | honeycombio/honeytail | sample/deterministic_sampler.go | bytesToUint32be | func bytesToUint32be(b []byte) uint32 {
return uint32(b[3]) | (uint32(b[2]) << 8) | (uint32(b[1]) << 16) | (uint32(b[0]) << 24)
} | go | func bytesToUint32be(b []byte) uint32 {
return uint32(b[3]) | (uint32(b[2]) << 8) | (uint32(b[1]) << 16) | (uint32(b[0]) << 24)
} | [
"func",
"bytesToUint32be",
"(",
"b",
"[",
"]",
"byte",
")",
"uint32",
"{",
"return",
"uint32",
"(",
"b",
"[",
"3",
"]",
")",
"|",
"(",
"uint32",
"(",
"b",
"[",
"2",
"]",
")",
"<<",
"8",
")",
"|",
"(",
"uint32",
"(",
"b",
"[",
"1",
"]",
")",
"<<",
"16",
")",
"|",
"(",
"uint32",
"(",
"b",
"[",
"0",
"]",
")",
"<<",
"24",
")",
"\n",
"}"
] | // bytesToUint32 takes a slice of 4 bytes representing a big endian 32 bit
// unsigned value and returns the equivalent uint32. | [
"bytesToUint32",
"takes",
"a",
"slice",
"of",
"4",
"bytes",
"representing",
"a",
"big",
"endian",
"32",
"bit",
"unsigned",
"value",
"and",
"returns",
"the",
"equivalent",
"uint32",
"."
] | a4d169e4b0f5204538da680d276e09be979ee26c | https://github.com/honeycombio/honeytail/blob/a4d169e4b0f5204538da680d276e09be979ee26c/sample/deterministic_sampler.go#L43-L45 |
10,115 | currantlabs/ble | uuid.go | Parse | func Parse(s string) (UUID, error) {
s = strings.Replace(s, "-", "", -1)
b, err := hex.DecodeString(s)
if err != nil {
return nil, err
}
if err := lenErr(len(b)); err != nil {
return nil, err
}
return UUID(Reverse(b)), nil
} | go | func Parse(s string) (UUID, error) {
s = strings.Replace(s, "-", "", -1)
b, err := hex.DecodeString(s)
if err != nil {
return nil, err
}
if err := lenErr(len(b)); err != nil {
return nil, err
}
return UUID(Reverse(b)), nil
} | [
"func",
"Parse",
"(",
"s",
"string",
")",
"(",
"UUID",
",",
"error",
")",
"{",
"s",
"=",
"strings",
".",
"Replace",
"(",
"s",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"b",
",",
"err",
":=",
"hex",
".",
"DecodeString",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"lenErr",
"(",
"len",
"(",
"b",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"UUID",
"(",
"Reverse",
"(",
"b",
")",
")",
",",
"nil",
"\n",
"}"
] | // Parse parses a standard-format UUID string, such
// as "1800" or "34DA3AD1-7110-41A1-B1EF-4430F509CDE7". | [
"Parse",
"parses",
"a",
"standard",
"-",
"format",
"UUID",
"string",
"such",
"as",
"1800",
"or",
"34DA3AD1",
"-",
"7110",
"-",
"41A1",
"-",
"B1EF",
"-",
"4430F509CDE7",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/uuid.go#L23-L33 |
10,116 | currantlabs/ble | uuid.go | MustParse | func MustParse(s string) UUID {
u, err := Parse(s)
if err != nil {
panic(err)
}
return u
} | go | func MustParse(s string) UUID {
u, err := Parse(s)
if err != nil {
panic(err)
}
return u
} | [
"func",
"MustParse",
"(",
"s",
"string",
")",
"UUID",
"{",
"u",
",",
"err",
":=",
"Parse",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"u",
"\n",
"}"
] | // MustParse parses a standard-format UUID string,
// like Parse, but panics in case of error. | [
"MustParse",
"parses",
"a",
"standard",
"-",
"format",
"UUID",
"string",
"like",
"Parse",
"but",
"panics",
"in",
"case",
"of",
"error",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/uuid.go#L37-L43 |
10,117 | currantlabs/ble | uuid.go | Contains | func Contains(s []UUID, u UUID) bool {
if s == nil {
return true
}
for _, a := range s {
if a.Equal(u) {
return true
}
}
return false
} | go | func Contains(s []UUID, u UUID) bool {
if s == nil {
return true
}
for _, a := range s {
if a.Equal(u) {
return true
}
}
return false
} | [
"func",
"Contains",
"(",
"s",
"[",
"]",
"UUID",
",",
"u",
"UUID",
")",
"bool",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"a",
":=",
"range",
"s",
"{",
"if",
"a",
".",
"Equal",
"(",
"u",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // Contains returns a boolean reporting whether u is in the slice s. | [
"Contains",
"returns",
"a",
"boolean",
"reporting",
"whether",
"u",
"is",
"in",
"the",
"slice",
"s",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/uuid.go#L71-L83 |
10,118 | currantlabs/ble | uuid.go | Reverse | func Reverse(u []byte) []byte {
// Special-case 16 bit UUIDS for speed.
l := len(u)
if l == 2 {
return []byte{u[1], u[0]}
}
b := make([]byte, l)
for i := 0; i < l/2+1; i++ {
b[i], b[l-i-1] = u[l-i-1], u[i]
}
return b
} | go | func Reverse(u []byte) []byte {
// Special-case 16 bit UUIDS for speed.
l := len(u)
if l == 2 {
return []byte{u[1], u[0]}
}
b := make([]byte, l)
for i := 0; i < l/2+1; i++ {
b[i], b[l-i-1] = u[l-i-1], u[i]
}
return b
} | [
"func",
"Reverse",
"(",
"u",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"// Special-case 16 bit UUIDS for speed.",
"l",
":=",
"len",
"(",
"u",
")",
"\n",
"if",
"l",
"==",
"2",
"{",
"return",
"[",
"]",
"byte",
"{",
"u",
"[",
"1",
"]",
",",
"u",
"[",
"0",
"]",
"}",
"\n",
"}",
"\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"l",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"l",
"/",
"2",
"+",
"1",
";",
"i",
"++",
"{",
"b",
"[",
"i",
"]",
",",
"b",
"[",
"l",
"-",
"i",
"-",
"1",
"]",
"=",
"u",
"[",
"l",
"-",
"i",
"-",
"1",
"]",
",",
"u",
"[",
"i",
"]",
"\n",
"}",
"\n",
"return",
"b",
"\n",
"}"
] | // Reverse returns a reversed copy of u. | [
"Reverse",
"returns",
"a",
"reversed",
"copy",
"of",
"u",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/uuid.go#L86-L97 |
10,119 | currantlabs/ble | linux/hci/buffer.go | Get | func (c *Client) Get() *bytes.Buffer {
b := <-c.p.ch
b.Reset()
c.sent <- b
return b
} | go | func (c *Client) Get() *bytes.Buffer {
b := <-c.p.ch
b.Reset()
c.sent <- b
return b
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Get",
"(",
")",
"*",
"bytes",
".",
"Buffer",
"{",
"b",
":=",
"<-",
"c",
".",
"p",
".",
"ch",
"\n",
"b",
".",
"Reset",
"(",
")",
"\n",
"c",
".",
"sent",
"<-",
"b",
"\n",
"return",
"b",
"\n",
"}"
] | // Get returns a buffer from the shared buffer pool. | [
"Get",
"returns",
"a",
"buffer",
"from",
"the",
"shared",
"buffer",
"pool",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/buffer.go#L48-L53 |
10,120 | currantlabs/ble | linux/hci/buffer.go | Put | func (c *Client) Put() {
select {
case b := <-c.sent:
c.p.ch <- b
default:
}
} | go | func (c *Client) Put() {
select {
case b := <-c.sent:
c.p.ch <- b
default:
}
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Put",
"(",
")",
"{",
"select",
"{",
"case",
"b",
":=",
"<-",
"c",
".",
"sent",
":",
"c",
".",
"p",
".",
"ch",
"<-",
"b",
"\n",
"default",
":",
"}",
"\n",
"}"
] | // Put puts the oldest sent buffer back to the shared pool. | [
"Put",
"puts",
"the",
"oldest",
"sent",
"buffer",
"back",
"to",
"the",
"shared",
"pool",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/buffer.go#L56-L62 |
10,121 | currantlabs/ble | linux/hci/buffer.go | PutAll | func (c *Client) PutAll() {
for {
select {
case b := <-c.sent:
c.p.ch <- b
default:
return
}
}
} | go | func (c *Client) PutAll() {
for {
select {
case b := <-c.sent:
c.p.ch <- b
default:
return
}
}
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"PutAll",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"b",
":=",
"<-",
"c",
".",
"sent",
":",
"c",
".",
"p",
".",
"ch",
"<-",
"b",
"\n",
"default",
":",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // PutAll puts all the sent buffers back to the shared pool. | [
"PutAll",
"puts",
"all",
"the",
"sent",
"buffers",
"back",
"to",
"the",
"shared",
"pool",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/buffer.go#L65-L74 |
10,122 | currantlabs/ble | linux/device.go | NewDevice | func NewDevice() (*Device, error) {
dev, err := hci.NewHCI()
if err != nil {
return nil, errors.Wrap(err, "can't create hci")
}
if err = dev.Init(); err != nil {
return nil, errors.Wrap(err, "can't init hci")
}
s, err := gatt.NewServer()
if err != nil {
return nil, errors.Wrap(err, "can't create server")
}
mtu := ble.DefaultMTU
mtu = ble.MaxMTU // TODO: get this from user using Option.
if mtu > ble.MaxMTU {
return nil, errors.Wrapf(err, "maximum ATT_MTU is %d", ble.MaxMTU)
}
go func() {
for {
l2c, err := dev.Accept()
if err != nil {
log.Printf("can't accept: %s", err)
return
}
// Initialize the per-connection cccd values.
l2c.SetContext(context.WithValue(l2c.Context(), "ccc", make(map[uint16]uint16)))
l2c.SetRxMTU(mtu)
s.Lock()
as, err := att.NewServer(s.DB(), l2c)
s.Unlock()
if err != nil {
log.Printf("can't create ATT server: %s", err)
continue
}
go as.Loop()
}
}()
return &Device{HCI: dev, Server: s}, nil
} | go | func NewDevice() (*Device, error) {
dev, err := hci.NewHCI()
if err != nil {
return nil, errors.Wrap(err, "can't create hci")
}
if err = dev.Init(); err != nil {
return nil, errors.Wrap(err, "can't init hci")
}
s, err := gatt.NewServer()
if err != nil {
return nil, errors.Wrap(err, "can't create server")
}
mtu := ble.DefaultMTU
mtu = ble.MaxMTU // TODO: get this from user using Option.
if mtu > ble.MaxMTU {
return nil, errors.Wrapf(err, "maximum ATT_MTU is %d", ble.MaxMTU)
}
go func() {
for {
l2c, err := dev.Accept()
if err != nil {
log.Printf("can't accept: %s", err)
return
}
// Initialize the per-connection cccd values.
l2c.SetContext(context.WithValue(l2c.Context(), "ccc", make(map[uint16]uint16)))
l2c.SetRxMTU(mtu)
s.Lock()
as, err := att.NewServer(s.DB(), l2c)
s.Unlock()
if err != nil {
log.Printf("can't create ATT server: %s", err)
continue
}
go as.Loop()
}
}()
return &Device{HCI: dev, Server: s}, nil
} | [
"func",
"NewDevice",
"(",
")",
"(",
"*",
"Device",
",",
"error",
")",
"{",
"dev",
",",
"err",
":=",
"hci",
".",
"NewHCI",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
"=",
"dev",
".",
"Init",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"s",
",",
"err",
":=",
"gatt",
".",
"NewServer",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"mtu",
":=",
"ble",
".",
"DefaultMTU",
"\n",
"mtu",
"=",
"ble",
".",
"MaxMTU",
"// TODO: get this from user using Option.",
"\n",
"if",
"mtu",
">",
"ble",
".",
"MaxMTU",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"ble",
".",
"MaxMTU",
")",
"\n",
"}",
"\n\n",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"l2c",
",",
"err",
":=",
"dev",
".",
"Accept",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Initialize the per-connection cccd values.",
"l2c",
".",
"SetContext",
"(",
"context",
".",
"WithValue",
"(",
"l2c",
".",
"Context",
"(",
")",
",",
"\"",
"\"",
",",
"make",
"(",
"map",
"[",
"uint16",
"]",
"uint16",
")",
")",
")",
"\n",
"l2c",
".",
"SetRxMTU",
"(",
"mtu",
")",
"\n\n",
"s",
".",
"Lock",
"(",
")",
"\n",
"as",
",",
"err",
":=",
"att",
".",
"NewServer",
"(",
"s",
".",
"DB",
"(",
")",
",",
"l2c",
")",
"\n",
"s",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"continue",
"\n\n",
"}",
"\n",
"go",
"as",
".",
"Loop",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"return",
"&",
"Device",
"{",
"HCI",
":",
"dev",
",",
"Server",
":",
"s",
"}",
",",
"nil",
"\n",
"}"
] | // NewDevice returns the default HCI device. | [
"NewDevice",
"returns",
"the",
"default",
"HCI",
"device",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/device.go#L16-L60 |
10,123 | currantlabs/ble | linux/device.go | AdvertiseNameAndServices | func (d *Device) AdvertiseNameAndServices(ctx context.Context, name string, uuids ...ble.UUID) error {
if err := d.HCI.AdvertiseNameAndServices(name, uuids...); err != nil {
return err
}
<-ctx.Done()
d.HCI.StopAdvertising()
return ctx.Err()
} | go | func (d *Device) AdvertiseNameAndServices(ctx context.Context, name string, uuids ...ble.UUID) error {
if err := d.HCI.AdvertiseNameAndServices(name, uuids...); err != nil {
return err
}
<-ctx.Done()
d.HCI.StopAdvertising()
return ctx.Err()
} | [
"func",
"(",
"d",
"*",
"Device",
")",
"AdvertiseNameAndServices",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"uuids",
"...",
"ble",
".",
"UUID",
")",
"error",
"{",
"if",
"err",
":=",
"d",
".",
"HCI",
".",
"AdvertiseNameAndServices",
"(",
"name",
",",
"uuids",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"<-",
"ctx",
".",
"Done",
"(",
")",
"\n",
"d",
".",
"HCI",
".",
"StopAdvertising",
"(",
")",
"\n",
"return",
"ctx",
".",
"Err",
"(",
")",
"\n",
"}"
] | // AdvertiseNameAndServices advertises device name, and specified service UUIDs.
// It tres to fit the UUIDs in the advertising packet as much as possible.
// If name doesn't fit in the advertising packet, it will be put in scan response. | [
"AdvertiseNameAndServices",
"advertises",
"device",
"name",
"and",
"specified",
"service",
"UUIDs",
".",
"It",
"tres",
"to",
"fit",
"the",
"UUIDs",
"in",
"the",
"advertising",
"packet",
"as",
"much",
"as",
"possible",
".",
"If",
"name",
"doesn",
"t",
"fit",
"in",
"the",
"advertising",
"packet",
"it",
"will",
"be",
"put",
"in",
"scan",
"response",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/device.go#L92-L99 |
10,124 | currantlabs/ble | linux/hci/hci.go | NewHCI | func NewHCI(opts ...Option) (*HCI, error) {
h := &HCI{
id: -1,
chCmdPkt: make(chan *pkt),
chCmdBufs: make(chan []byte, 8),
sent: make(map[int]*pkt),
evth: map[int]handlerFn{},
subh: map[int]handlerFn{},
muConns: &sync.Mutex{},
conns: make(map[uint16]*Conn),
chMasterConn: make(chan *Conn),
chSlaveConn: make(chan *Conn),
done: make(chan bool),
}
h.params.init()
if err := h.Option(opts...); err != nil {
return nil, errors.Wrap(err, "can't set options")
}
return h, nil
} | go | func NewHCI(opts ...Option) (*HCI, error) {
h := &HCI{
id: -1,
chCmdPkt: make(chan *pkt),
chCmdBufs: make(chan []byte, 8),
sent: make(map[int]*pkt),
evth: map[int]handlerFn{},
subh: map[int]handlerFn{},
muConns: &sync.Mutex{},
conns: make(map[uint16]*Conn),
chMasterConn: make(chan *Conn),
chSlaveConn: make(chan *Conn),
done: make(chan bool),
}
h.params.init()
if err := h.Option(opts...); err != nil {
return nil, errors.Wrap(err, "can't set options")
}
return h, nil
} | [
"func",
"NewHCI",
"(",
"opts",
"...",
"Option",
")",
"(",
"*",
"HCI",
",",
"error",
")",
"{",
"h",
":=",
"&",
"HCI",
"{",
"id",
":",
"-",
"1",
",",
"chCmdPkt",
":",
"make",
"(",
"chan",
"*",
"pkt",
")",
",",
"chCmdBufs",
":",
"make",
"(",
"chan",
"[",
"]",
"byte",
",",
"8",
")",
",",
"sent",
":",
"make",
"(",
"map",
"[",
"int",
"]",
"*",
"pkt",
")",
",",
"evth",
":",
"map",
"[",
"int",
"]",
"handlerFn",
"{",
"}",
",",
"subh",
":",
"map",
"[",
"int",
"]",
"handlerFn",
"{",
"}",
",",
"muConns",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
",",
"conns",
":",
"make",
"(",
"map",
"[",
"uint16",
"]",
"*",
"Conn",
")",
",",
"chMasterConn",
":",
"make",
"(",
"chan",
"*",
"Conn",
")",
",",
"chSlaveConn",
":",
"make",
"(",
"chan",
"*",
"Conn",
")",
",",
"done",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"}",
"\n",
"h",
".",
"params",
".",
"init",
"(",
")",
"\n",
"if",
"err",
":=",
"h",
".",
"Option",
"(",
"opts",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"h",
",",
"nil",
"\n",
"}"
] | // NewHCI returns a hci device. | [
"NewHCI",
"returns",
"a",
"hci",
"device",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/hci.go#L37-L61 |
10,125 | currantlabs/ble | linux/hci/socket/socket.go | NewSocket | func NewSocket(id int) (*Socket, error) {
var err error
// Create RAW HCI Socket.
fd, err := unix.Socket(unix.AF_BLUETOOTH, unix.SOCK_RAW, unix.BTPROTO_HCI)
if err != nil {
return nil, errors.Wrap(err, "can't create socket")
}
if id != -1 {
return open(fd, id)
}
req := devListRequest{devNum: hciMaxDevices}
if err = ioctl(uintptr(fd), hciGetDeviceList, uintptr(unsafe.Pointer(&req))); err != nil {
return nil, errors.Wrap(err, "can't get device list")
}
var msg string
for id := 0; id < int(req.devNum); id++ {
s, err := open(fd, id)
if err == nil {
return s, nil
}
msg = msg + fmt.Sprintf("(hci%d: %s)", id, err)
}
return nil, errors.Errorf("no devices available: %s", msg)
} | go | func NewSocket(id int) (*Socket, error) {
var err error
// Create RAW HCI Socket.
fd, err := unix.Socket(unix.AF_BLUETOOTH, unix.SOCK_RAW, unix.BTPROTO_HCI)
if err != nil {
return nil, errors.Wrap(err, "can't create socket")
}
if id != -1 {
return open(fd, id)
}
req := devListRequest{devNum: hciMaxDevices}
if err = ioctl(uintptr(fd), hciGetDeviceList, uintptr(unsafe.Pointer(&req))); err != nil {
return nil, errors.Wrap(err, "can't get device list")
}
var msg string
for id := 0; id < int(req.devNum); id++ {
s, err := open(fd, id)
if err == nil {
return s, nil
}
msg = msg + fmt.Sprintf("(hci%d: %s)", id, err)
}
return nil, errors.Errorf("no devices available: %s", msg)
} | [
"func",
"NewSocket",
"(",
"id",
"int",
")",
"(",
"*",
"Socket",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"// Create RAW HCI Socket.",
"fd",
",",
"err",
":=",
"unix",
".",
"Socket",
"(",
"unix",
".",
"AF_BLUETOOTH",
",",
"unix",
".",
"SOCK_RAW",
",",
"unix",
".",
"BTPROTO_HCI",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"id",
"!=",
"-",
"1",
"{",
"return",
"open",
"(",
"fd",
",",
"id",
")",
"\n",
"}",
"\n\n",
"req",
":=",
"devListRequest",
"{",
"devNum",
":",
"hciMaxDevices",
"}",
"\n",
"if",
"err",
"=",
"ioctl",
"(",
"uintptr",
"(",
"fd",
")",
",",
"hciGetDeviceList",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"req",
")",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"msg",
"string",
"\n",
"for",
"id",
":=",
"0",
";",
"id",
"<",
"int",
"(",
"req",
".",
"devNum",
")",
";",
"id",
"++",
"{",
"s",
",",
"err",
":=",
"open",
"(",
"fd",
",",
"id",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"s",
",",
"nil",
"\n",
"}",
"\n",
"msg",
"=",
"msg",
"+",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"id",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"msg",
")",
"\n",
"}"
] | // NewSocket returns a HCI User Channel of specified device id.
// If id is -1, the first available HCI device is returned. | [
"NewSocket",
"returns",
"a",
"HCI",
"User",
"Channel",
"of",
"specified",
"device",
"id",
".",
"If",
"id",
"is",
"-",
"1",
"the",
"first",
"available",
"HCI",
"device",
"is",
"returned",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/socket/socket.go#L62-L87 |
10,126 | currantlabs/ble | linux/adv/packet.go | NewPacket | func NewPacket(fields ...Field) (*Packet, error) {
p := &Packet{b: make([]byte, 0, MaxEIRPacketLength)}
for _, f := range fields {
if err := f(p); err != nil {
return nil, err
}
}
return p, nil
} | go | func NewPacket(fields ...Field) (*Packet, error) {
p := &Packet{b: make([]byte, 0, MaxEIRPacketLength)}
for _, f := range fields {
if err := f(p); err != nil {
return nil, err
}
}
return p, nil
} | [
"func",
"NewPacket",
"(",
"fields",
"...",
"Field",
")",
"(",
"*",
"Packet",
",",
"error",
")",
"{",
"p",
":=",
"&",
"Packet",
"{",
"b",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"MaxEIRPacketLength",
")",
"}",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"fields",
"{",
"if",
"err",
":=",
"f",
"(",
"p",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"p",
",",
"nil",
"\n",
"}"
] | // NewPacket returns a new advertising Packet. | [
"NewPacket",
"returns",
"a",
"new",
"advertising",
"Packet",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L26-L34 |
10,127 | currantlabs/ble | linux/adv/packet.go | NewRawPacket | func NewRawPacket(bytes ...[]byte) *Packet {
p := &Packet{b: make([]byte, 0, MaxEIRPacketLength)}
for _, b := range bytes {
p.b = append(p.b, b...)
}
return p
} | go | func NewRawPacket(bytes ...[]byte) *Packet {
p := &Packet{b: make([]byte, 0, MaxEIRPacketLength)}
for _, b := range bytes {
p.b = append(p.b, b...)
}
return p
} | [
"func",
"NewRawPacket",
"(",
"bytes",
"...",
"[",
"]",
"byte",
")",
"*",
"Packet",
"{",
"p",
":=",
"&",
"Packet",
"{",
"b",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"MaxEIRPacketLength",
")",
"}",
"\n",
"for",
"_",
",",
"b",
":=",
"range",
"bytes",
"{",
"p",
".",
"b",
"=",
"append",
"(",
"p",
".",
"b",
",",
"b",
"...",
")",
"\n",
"}",
"\n",
"return",
"p",
"\n",
"}"
] | // NewRawPacket returns a new advertising Packet. | [
"NewRawPacket",
"returns",
"a",
"new",
"advertising",
"Packet",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L37-L43 |
10,128 | currantlabs/ble | linux/adv/packet.go | append | func (p *Packet) append(typ byte, b []byte) error {
if p.Len()+1+1+len(b) > MaxEIRPacketLength {
return ErrNotFit
}
p.b = append(p.b, byte(len(b)+1))
p.b = append(p.b, typ)
p.b = append(p.b, b...)
return nil
} | go | func (p *Packet) append(typ byte, b []byte) error {
if p.Len()+1+1+len(b) > MaxEIRPacketLength {
return ErrNotFit
}
p.b = append(p.b, byte(len(b)+1))
p.b = append(p.b, typ)
p.b = append(p.b, b...)
return nil
} | [
"func",
"(",
"p",
"*",
"Packet",
")",
"append",
"(",
"typ",
"byte",
",",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"p",
".",
"Len",
"(",
")",
"+",
"1",
"+",
"1",
"+",
"len",
"(",
"b",
")",
">",
"MaxEIRPacketLength",
"{",
"return",
"ErrNotFit",
"\n",
"}",
"\n",
"p",
".",
"b",
"=",
"append",
"(",
"p",
".",
"b",
",",
"byte",
"(",
"len",
"(",
"b",
")",
"+",
"1",
")",
")",
"\n",
"p",
".",
"b",
"=",
"append",
"(",
"p",
".",
"b",
",",
"typ",
")",
"\n",
"p",
".",
"b",
"=",
"append",
"(",
"p",
".",
"b",
",",
"b",
"...",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // appends appends a field to the packet. It returns ErrNotFit if the field
// doesn't fit into the packet, and leaves the packet intact. | [
"appends",
"appends",
"a",
"field",
"to",
"the",
"packet",
".",
"It",
"returns",
"ErrNotFit",
"if",
"the",
"field",
"doesn",
"t",
"fit",
"into",
"the",
"packet",
"and",
"leaves",
"the",
"packet",
"intact",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L56-L64 |
10,129 | currantlabs/ble | linux/adv/packet.go | Raw | func Raw(b []byte) Field {
return func(p *Packet) error {
if p.Len()+len(b) > MaxEIRPacketLength {
return ErrNotFit
}
p.b = append(p.b, b...)
return nil
}
} | go | func Raw(b []byte) Field {
return func(p *Packet) error {
if p.Len()+len(b) > MaxEIRPacketLength {
return ErrNotFit
}
p.b = append(p.b, b...)
return nil
}
} | [
"func",
"Raw",
"(",
"b",
"[",
"]",
"byte",
")",
"Field",
"{",
"return",
"func",
"(",
"p",
"*",
"Packet",
")",
"error",
"{",
"if",
"p",
".",
"Len",
"(",
")",
"+",
"len",
"(",
"b",
")",
">",
"MaxEIRPacketLength",
"{",
"return",
"ErrNotFit",
"\n",
"}",
"\n",
"p",
".",
"b",
"=",
"append",
"(",
"p",
".",
"b",
",",
"b",
"...",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // Raw appends the bytes to the current packet.
// This is helpful for creating new packet from existing packets. | [
"Raw",
"appends",
"the",
"bytes",
"to",
"the",
"current",
"packet",
".",
"This",
"is",
"helpful",
"for",
"creating",
"new",
"packet",
"from",
"existing",
"packets",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L68-L76 |
10,130 | currantlabs/ble | linux/adv/packet.go | IBeaconData | func IBeaconData(md []byte) Field {
return func(p *Packet) error {
return ManufacturerData(0x004C, md)(p)
}
} | go | func IBeaconData(md []byte) Field {
return func(p *Packet) error {
return ManufacturerData(0x004C, md)(p)
}
} | [
"func",
"IBeaconData",
"(",
"md",
"[",
"]",
"byte",
")",
"Field",
"{",
"return",
"func",
"(",
"p",
"*",
"Packet",
")",
"error",
"{",
"return",
"ManufacturerData",
"(",
"0x004C",
",",
"md",
")",
"(",
"p",
")",
"\n",
"}",
"\n",
"}"
] | // IBeaconData returns an iBeacon advertising packet with specified parameters. | [
"IBeaconData",
"returns",
"an",
"iBeacon",
"advertising",
"packet",
"with",
"specified",
"parameters",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L79-L83 |
10,131 | currantlabs/ble | linux/adv/packet.go | IBeacon | func IBeacon(u ble.UUID, major, minor uint16, pwr int8) Field {
return func(p *Packet) error {
if u.Len() != 16 {
return ErrInvalid
}
md := make([]byte, 23)
md[0] = 0x02 // Data type: iBeacon
md[1] = 0x15 // Data length: 21 bytes
copy(md[2:], ble.Reverse(u)) // Big endian
binary.BigEndian.PutUint16(md[18:], major) // Big endian
binary.BigEndian.PutUint16(md[20:], minor) // Big endian
md[22] = uint8(pwr) // Measured Tx Power
return ManufacturerData(0x004C, md)(p)
}
} | go | func IBeacon(u ble.UUID, major, minor uint16, pwr int8) Field {
return func(p *Packet) error {
if u.Len() != 16 {
return ErrInvalid
}
md := make([]byte, 23)
md[0] = 0x02 // Data type: iBeacon
md[1] = 0x15 // Data length: 21 bytes
copy(md[2:], ble.Reverse(u)) // Big endian
binary.BigEndian.PutUint16(md[18:], major) // Big endian
binary.BigEndian.PutUint16(md[20:], minor) // Big endian
md[22] = uint8(pwr) // Measured Tx Power
return ManufacturerData(0x004C, md)(p)
}
} | [
"func",
"IBeacon",
"(",
"u",
"ble",
".",
"UUID",
",",
"major",
",",
"minor",
"uint16",
",",
"pwr",
"int8",
")",
"Field",
"{",
"return",
"func",
"(",
"p",
"*",
"Packet",
")",
"error",
"{",
"if",
"u",
".",
"Len",
"(",
")",
"!=",
"16",
"{",
"return",
"ErrInvalid",
"\n",
"}",
"\n",
"md",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"23",
")",
"\n",
"md",
"[",
"0",
"]",
"=",
"0x02",
"// Data type: iBeacon",
"\n",
"md",
"[",
"1",
"]",
"=",
"0x15",
"// Data length: 21 bytes",
"\n",
"copy",
"(",
"md",
"[",
"2",
":",
"]",
",",
"ble",
".",
"Reverse",
"(",
"u",
")",
")",
"// Big endian",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"md",
"[",
"18",
":",
"]",
",",
"major",
")",
"// Big endian",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"md",
"[",
"20",
":",
"]",
",",
"minor",
")",
"// Big endian",
"\n",
"md",
"[",
"22",
"]",
"=",
"uint8",
"(",
"pwr",
")",
"// Measured Tx Power",
"\n",
"return",
"ManufacturerData",
"(",
"0x004C",
",",
"md",
")",
"(",
"p",
")",
"\n",
"}",
"\n",
"}"
] | // IBeacon returns an iBeacon advertising packet with specified parameters. | [
"IBeacon",
"returns",
"an",
"iBeacon",
"advertising",
"packet",
"with",
"specified",
"parameters",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L86-L100 |
10,132 | currantlabs/ble | linux/adv/packet.go | Flags | func Flags(f byte) Field {
return func(p *Packet) error {
return p.append(flags, []byte{f})
}
} | go | func Flags(f byte) Field {
return func(p *Packet) error {
return p.append(flags, []byte{f})
}
} | [
"func",
"Flags",
"(",
"f",
"byte",
")",
"Field",
"{",
"return",
"func",
"(",
"p",
"*",
"Packet",
")",
"error",
"{",
"return",
"p",
".",
"append",
"(",
"flags",
",",
"[",
"]",
"byte",
"{",
"f",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // Flags is a flags. | [
"Flags",
"is",
"a",
"flags",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L103-L107 |
10,133 | currantlabs/ble | linux/adv/packet.go | ShortName | func ShortName(n string) Field {
return func(p *Packet) error {
return p.append(shortName, []byte(n))
}
} | go | func ShortName(n string) Field {
return func(p *Packet) error {
return p.append(shortName, []byte(n))
}
} | [
"func",
"ShortName",
"(",
"n",
"string",
")",
"Field",
"{",
"return",
"func",
"(",
"p",
"*",
"Packet",
")",
"error",
"{",
"return",
"p",
".",
"append",
"(",
"shortName",
",",
"[",
"]",
"byte",
"(",
"n",
")",
")",
"\n",
"}",
"\n",
"}"
] | // ShortName is a short local name. | [
"ShortName",
"is",
"a",
"short",
"local",
"name",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L110-L114 |
10,134 | currantlabs/ble | linux/adv/packet.go | CompleteName | func CompleteName(n string) Field {
return func(p *Packet) error {
return p.append(completeName, []byte(n))
}
} | go | func CompleteName(n string) Field {
return func(p *Packet) error {
return p.append(completeName, []byte(n))
}
} | [
"func",
"CompleteName",
"(",
"n",
"string",
")",
"Field",
"{",
"return",
"func",
"(",
"p",
"*",
"Packet",
")",
"error",
"{",
"return",
"p",
".",
"append",
"(",
"completeName",
",",
"[",
"]",
"byte",
"(",
"n",
")",
")",
"\n",
"}",
"\n",
"}"
] | // CompleteName is a compelete local name. | [
"CompleteName",
"is",
"a",
"compelete",
"local",
"name",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L117-L121 |
10,135 | currantlabs/ble | linux/adv/packet.go | ManufacturerData | func ManufacturerData(id uint16, b []byte) Field {
return func(p *Packet) error {
d := append([]byte{uint8(id), uint8(id >> 8)}, b...)
return p.append(manufacturerData, d)
}
} | go | func ManufacturerData(id uint16, b []byte) Field {
return func(p *Packet) error {
d := append([]byte{uint8(id), uint8(id >> 8)}, b...)
return p.append(manufacturerData, d)
}
} | [
"func",
"ManufacturerData",
"(",
"id",
"uint16",
",",
"b",
"[",
"]",
"byte",
")",
"Field",
"{",
"return",
"func",
"(",
"p",
"*",
"Packet",
")",
"error",
"{",
"d",
":=",
"append",
"(",
"[",
"]",
"byte",
"{",
"uint8",
"(",
"id",
")",
",",
"uint8",
"(",
"id",
">>",
"8",
")",
"}",
",",
"b",
"...",
")",
"\n",
"return",
"p",
".",
"append",
"(",
"manufacturerData",
",",
"d",
")",
"\n",
"}",
"\n",
"}"
] | // ManufacturerData is manufacturer specific data. | [
"ManufacturerData",
"is",
"manufacturer",
"specific",
"data",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L124-L129 |
10,136 | currantlabs/ble | linux/adv/packet.go | AllUUID | func AllUUID(u ble.UUID) Field {
return func(p *Packet) error {
if u.Len() == 2 {
return p.append(allUUID16, u)
}
if u.Len() == 4 {
return p.append(allUUID32, u)
}
return p.append(allUUID128, u)
}
} | go | func AllUUID(u ble.UUID) Field {
return func(p *Packet) error {
if u.Len() == 2 {
return p.append(allUUID16, u)
}
if u.Len() == 4 {
return p.append(allUUID32, u)
}
return p.append(allUUID128, u)
}
} | [
"func",
"AllUUID",
"(",
"u",
"ble",
".",
"UUID",
")",
"Field",
"{",
"return",
"func",
"(",
"p",
"*",
"Packet",
")",
"error",
"{",
"if",
"u",
".",
"Len",
"(",
")",
"==",
"2",
"{",
"return",
"p",
".",
"append",
"(",
"allUUID16",
",",
"u",
")",
"\n",
"}",
"\n",
"if",
"u",
".",
"Len",
"(",
")",
"==",
"4",
"{",
"return",
"p",
".",
"append",
"(",
"allUUID32",
",",
"u",
")",
"\n",
"}",
"\n",
"return",
"p",
".",
"append",
"(",
"allUUID128",
",",
"u",
")",
"\n",
"}",
"\n",
"}"
] | // AllUUID is one of the complete service UUID list. | [
"AllUUID",
"is",
"one",
"of",
"the",
"complete",
"service",
"UUID",
"list",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L132-L142 |
10,137 | currantlabs/ble | linux/adv/packet.go | SomeUUID | func SomeUUID(u ble.UUID) Field {
return func(p *Packet) error {
if u.Len() == 2 {
return p.append(someUUID16, u)
}
if u.Len() == 4 {
return p.append(someUUID32, u)
}
return p.append(someUUID128, u)
}
} | go | func SomeUUID(u ble.UUID) Field {
return func(p *Packet) error {
if u.Len() == 2 {
return p.append(someUUID16, u)
}
if u.Len() == 4 {
return p.append(someUUID32, u)
}
return p.append(someUUID128, u)
}
} | [
"func",
"SomeUUID",
"(",
"u",
"ble",
".",
"UUID",
")",
"Field",
"{",
"return",
"func",
"(",
"p",
"*",
"Packet",
")",
"error",
"{",
"if",
"u",
".",
"Len",
"(",
")",
"==",
"2",
"{",
"return",
"p",
".",
"append",
"(",
"someUUID16",
",",
"u",
")",
"\n",
"}",
"\n",
"if",
"u",
".",
"Len",
"(",
")",
"==",
"4",
"{",
"return",
"p",
".",
"append",
"(",
"someUUID32",
",",
"u",
")",
"\n",
"}",
"\n",
"return",
"p",
".",
"append",
"(",
"someUUID128",
",",
"u",
")",
"\n",
"}",
"\n",
"}"
] | // SomeUUID is one of the incomplete service UUID list. | [
"SomeUUID",
"is",
"one",
"of",
"the",
"incomplete",
"service",
"UUID",
"list",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L145-L155 |
10,138 | currantlabs/ble | linux/adv/packet.go | ServiceData16 | func ServiceData16(id uint16, b []byte) Field {
return func(p *Packet) error {
uuid := ble.UUID16(id)
if err := p.append(allUUID16, uuid); err != nil {
return err
}
return p.append(serviceData16, append(uuid, b...))
}
} | go | func ServiceData16(id uint16, b []byte) Field {
return func(p *Packet) error {
uuid := ble.UUID16(id)
if err := p.append(allUUID16, uuid); err != nil {
return err
}
return p.append(serviceData16, append(uuid, b...))
}
} | [
"func",
"ServiceData16",
"(",
"id",
"uint16",
",",
"b",
"[",
"]",
"byte",
")",
"Field",
"{",
"return",
"func",
"(",
"p",
"*",
"Packet",
")",
"error",
"{",
"uuid",
":=",
"ble",
".",
"UUID16",
"(",
"id",
")",
"\n",
"if",
"err",
":=",
"p",
".",
"append",
"(",
"allUUID16",
",",
"uuid",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"p",
".",
"append",
"(",
"serviceData16",
",",
"append",
"(",
"uuid",
",",
"b",
"...",
")",
")",
"\n",
"}",
"\n",
"}"
] | // ServiceData16 is service data for a 16bit service uuid | [
"ServiceData16",
"is",
"service",
"data",
"for",
"a",
"16bit",
"service",
"uuid"
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L158-L166 |
10,139 | currantlabs/ble | linux/adv/packet.go | Flags | func (p *Packet) Flags() (flags byte, present bool) {
b := p.Field(flags)
if len(b) < 2 {
return 0, false
}
return b[2], true
} | go | func (p *Packet) Flags() (flags byte, present bool) {
b := p.Field(flags)
if len(b) < 2 {
return 0, false
}
return b[2], true
} | [
"func",
"(",
"p",
"*",
"Packet",
")",
"Flags",
"(",
")",
"(",
"flags",
"byte",
",",
"present",
"bool",
")",
"{",
"b",
":=",
"p",
".",
"Field",
"(",
"flags",
")",
"\n",
"if",
"len",
"(",
"b",
")",
"<",
"2",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"return",
"b",
"[",
"2",
"]",
",",
"true",
"\n",
"}"
] | // Flags returns the flags of the packet. | [
"Flags",
"returns",
"the",
"flags",
"of",
"the",
"packet",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L189-L195 |
10,140 | currantlabs/ble | linux/adv/packet.go | LocalName | func (p *Packet) LocalName() string {
if b := p.Field(shortName); b != nil {
return string(b)
}
return string(p.Field(completeName))
} | go | func (p *Packet) LocalName() string {
if b := p.Field(shortName); b != nil {
return string(b)
}
return string(p.Field(completeName))
} | [
"func",
"(",
"p",
"*",
"Packet",
")",
"LocalName",
"(",
")",
"string",
"{",
"if",
"b",
":=",
"p",
".",
"Field",
"(",
"shortName",
")",
";",
"b",
"!=",
"nil",
"{",
"return",
"string",
"(",
"b",
")",
"\n",
"}",
"\n",
"return",
"string",
"(",
"p",
".",
"Field",
"(",
"completeName",
")",
")",
"\n",
"}"
] | // LocalName returns the ShortName or CompleteName if it presents. | [
"LocalName",
"returns",
"the",
"ShortName",
"or",
"CompleteName",
"if",
"it",
"presents",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L198-L203 |
10,141 | currantlabs/ble | linux/adv/packet.go | TxPower | func (p *Packet) TxPower() (power int, present bool) {
b := p.Field(txPower)
if len(b) < 3 {
return 0, false
}
return int(int8(b[2])), true
} | go | func (p *Packet) TxPower() (power int, present bool) {
b := p.Field(txPower)
if len(b) < 3 {
return 0, false
}
return int(int8(b[2])), true
} | [
"func",
"(",
"p",
"*",
"Packet",
")",
"TxPower",
"(",
")",
"(",
"power",
"int",
",",
"present",
"bool",
")",
"{",
"b",
":=",
"p",
".",
"Field",
"(",
"txPower",
")",
"\n",
"if",
"len",
"(",
"b",
")",
"<",
"3",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"return",
"int",
"(",
"int8",
"(",
"b",
"[",
"2",
"]",
")",
")",
",",
"true",
"\n",
"}"
] | // TxPower returns the TxPower, if it presents. | [
"TxPower",
"returns",
"the",
"TxPower",
"if",
"it",
"presents",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L206-L212 |
10,142 | currantlabs/ble | linux/adv/packet.go | UUIDs | func (p *Packet) UUIDs() []ble.UUID {
var u []ble.UUID
if b := p.Field(someUUID16); b != nil {
u = uuidList(u, b, 2)
}
if b := p.Field(allUUID16); b != nil {
u = uuidList(u, b, 2)
}
if b := p.Field(someUUID32); b != nil {
u = uuidList(u, b, 4)
}
if b := p.Field(allUUID32); b != nil {
u = uuidList(u, b, 4)
}
if b := p.Field(someUUID128); b != nil {
u = uuidList(u, b, 16)
}
if b := p.Field(allUUID128); b != nil {
u = uuidList(u, b, 16)
}
return u
} | go | func (p *Packet) UUIDs() []ble.UUID {
var u []ble.UUID
if b := p.Field(someUUID16); b != nil {
u = uuidList(u, b, 2)
}
if b := p.Field(allUUID16); b != nil {
u = uuidList(u, b, 2)
}
if b := p.Field(someUUID32); b != nil {
u = uuidList(u, b, 4)
}
if b := p.Field(allUUID32); b != nil {
u = uuidList(u, b, 4)
}
if b := p.Field(someUUID128); b != nil {
u = uuidList(u, b, 16)
}
if b := p.Field(allUUID128); b != nil {
u = uuidList(u, b, 16)
}
return u
} | [
"func",
"(",
"p",
"*",
"Packet",
")",
"UUIDs",
"(",
")",
"[",
"]",
"ble",
".",
"UUID",
"{",
"var",
"u",
"[",
"]",
"ble",
".",
"UUID",
"\n",
"if",
"b",
":=",
"p",
".",
"Field",
"(",
"someUUID16",
")",
";",
"b",
"!=",
"nil",
"{",
"u",
"=",
"uuidList",
"(",
"u",
",",
"b",
",",
"2",
")",
"\n",
"}",
"\n",
"if",
"b",
":=",
"p",
".",
"Field",
"(",
"allUUID16",
")",
";",
"b",
"!=",
"nil",
"{",
"u",
"=",
"uuidList",
"(",
"u",
",",
"b",
",",
"2",
")",
"\n",
"}",
"\n",
"if",
"b",
":=",
"p",
".",
"Field",
"(",
"someUUID32",
")",
";",
"b",
"!=",
"nil",
"{",
"u",
"=",
"uuidList",
"(",
"u",
",",
"b",
",",
"4",
")",
"\n",
"}",
"\n",
"if",
"b",
":=",
"p",
".",
"Field",
"(",
"allUUID32",
")",
";",
"b",
"!=",
"nil",
"{",
"u",
"=",
"uuidList",
"(",
"u",
",",
"b",
",",
"4",
")",
"\n",
"}",
"\n",
"if",
"b",
":=",
"p",
".",
"Field",
"(",
"someUUID128",
")",
";",
"b",
"!=",
"nil",
"{",
"u",
"=",
"uuidList",
"(",
"u",
",",
"b",
",",
"16",
")",
"\n",
"}",
"\n",
"if",
"b",
":=",
"p",
".",
"Field",
"(",
"allUUID128",
")",
";",
"b",
"!=",
"nil",
"{",
"u",
"=",
"uuidList",
"(",
"u",
",",
"b",
",",
"16",
")",
"\n",
"}",
"\n",
"return",
"u",
"\n",
"}"
] | // UUIDs returns a list of service UUIDs. | [
"UUIDs",
"returns",
"a",
"list",
"of",
"service",
"UUIDs",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L215-L236 |
10,143 | currantlabs/ble | linux/adv/packet.go | uuidList | func uuidList(u []ble.UUID, d []byte, w int) []ble.UUID {
for len(d) > 0 {
u = append(u, ble.UUID(d[:w]))
d = d[w:]
}
return u
} | go | func uuidList(u []ble.UUID, d []byte, w int) []ble.UUID {
for len(d) > 0 {
u = append(u, ble.UUID(d[:w]))
d = d[w:]
}
return u
} | [
"func",
"uuidList",
"(",
"u",
"[",
"]",
"ble",
".",
"UUID",
",",
"d",
"[",
"]",
"byte",
",",
"w",
"int",
")",
"[",
"]",
"ble",
".",
"UUID",
"{",
"for",
"len",
"(",
"d",
")",
">",
"0",
"{",
"u",
"=",
"append",
"(",
"u",
",",
"ble",
".",
"UUID",
"(",
"d",
"[",
":",
"w",
"]",
")",
")",
"\n",
"d",
"=",
"d",
"[",
"w",
":",
"]",
"\n",
"}",
"\n",
"return",
"u",
"\n",
"}"
] | // Utility function for creating a list of uuids. | [
"Utility",
"function",
"for",
"creating",
"a",
"list",
"of",
"uuids",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/adv/packet.go#L274-L280 |
10,144 | currantlabs/ble | profile.go | NewCharacteristic | func (s *Service) NewCharacteristic(u UUID) *Characteristic {
return s.AddCharacteristic(&Characteristic{UUID: u})
} | go | func (s *Service) NewCharacteristic(u UUID) *Characteristic {
return s.AddCharacteristic(&Characteristic{UUID: u})
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"NewCharacteristic",
"(",
"u",
"UUID",
")",
"*",
"Characteristic",
"{",
"return",
"s",
".",
"AddCharacteristic",
"(",
"&",
"Characteristic",
"{",
"UUID",
":",
"u",
"}",
")",
"\n",
"}"
] | // NewCharacteristic adds a characteristic to a service.
// NewCharacteristic panics if the service already contains another characteristic with the same UUID. | [
"NewCharacteristic",
"adds",
"a",
"characteristic",
"to",
"a",
"service",
".",
"NewCharacteristic",
"panics",
"if",
"the",
"service",
"already",
"contains",
"another",
"characteristic",
"with",
"the",
"same",
"UUID",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/profile.go#L93-L95 |
10,145 | currantlabs/ble | profile.go | NewDescriptor | func (c *Characteristic) NewDescriptor(u UUID) *Descriptor {
return c.AddDescriptor(&Descriptor{UUID: u})
} | go | func (c *Characteristic) NewDescriptor(u UUID) *Descriptor {
return c.AddDescriptor(&Descriptor{UUID: u})
} | [
"func",
"(",
"c",
"*",
"Characteristic",
")",
"NewDescriptor",
"(",
"u",
"UUID",
")",
"*",
"Descriptor",
"{",
"return",
"c",
".",
"AddDescriptor",
"(",
"&",
"Descriptor",
"{",
"UUID",
":",
"u",
"}",
")",
"\n",
"}"
] | // NewDescriptor adds a descriptor to a characteristic.
// NewDescriptor panics if the characteristic already contains another descriptor with the same UUID. | [
"NewDescriptor",
"adds",
"a",
"descriptor",
"to",
"a",
"characteristic",
".",
"NewDescriptor",
"panics",
"if",
"the",
"characteristic",
"already",
"contains",
"another",
"descriptor",
"with",
"the",
"same",
"UUID",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/profile.go#L131-L133 |
10,146 | currantlabs/ble | profile.go | HandleIndicate | func (c *Characteristic) HandleIndicate(h NotifyHandler) {
c.Property |= CharIndicate
c.IndicateHandler = h
} | go | func (c *Characteristic) HandleIndicate(h NotifyHandler) {
c.Property |= CharIndicate
c.IndicateHandler = h
} | [
"func",
"(",
"c",
"*",
"Characteristic",
")",
"HandleIndicate",
"(",
"h",
"NotifyHandler",
")",
"{",
"c",
".",
"Property",
"|=",
"CharIndicate",
"\n",
"c",
".",
"IndicateHandler",
"=",
"h",
"\n",
"}"
] | // HandleIndicate makes the characteristic support indicate requests, and routes notification requests to h.
// HandleIndicate must be called before the containing service is added to a server. | [
"HandleIndicate",
"makes",
"the",
"characteristic",
"support",
"indicate",
"requests",
"and",
"routes",
"notification",
"requests",
"to",
"h",
".",
"HandleIndicate",
"must",
"be",
"called",
"before",
"the",
"containing",
"service",
"is",
"added",
"to",
"a",
"server",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/profile.go#L175-L178 |
10,147 | currantlabs/ble | linux/att/server.go | notify | func (s *Server) notify(h uint16, data []byte) (int, error) {
// Acquire and reuse notifyBuffer. Release it after usage.
nBuf := <-s.chNotBuf
defer func() { s.chNotBuf <- nBuf }()
rsp := HandleValueNotification(nBuf)
rsp.SetAttributeOpcode()
rsp.SetAttributeHandle(h)
buf := bytes.NewBuffer(rsp.AttributeValue())
buf.Reset()
if len(data) > buf.Cap() {
data = data[:buf.Cap()]
}
buf.Write(data)
return s.conn.Write(rsp[:3+buf.Len()])
} | go | func (s *Server) notify(h uint16, data []byte) (int, error) {
// Acquire and reuse notifyBuffer. Release it after usage.
nBuf := <-s.chNotBuf
defer func() { s.chNotBuf <- nBuf }()
rsp := HandleValueNotification(nBuf)
rsp.SetAttributeOpcode()
rsp.SetAttributeHandle(h)
buf := bytes.NewBuffer(rsp.AttributeValue())
buf.Reset()
if len(data) > buf.Cap() {
data = data[:buf.Cap()]
}
buf.Write(data)
return s.conn.Write(rsp[:3+buf.Len()])
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"notify",
"(",
"h",
"uint16",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"// Acquire and reuse notifyBuffer. Release it after usage.",
"nBuf",
":=",
"<-",
"s",
".",
"chNotBuf",
"\n",
"defer",
"func",
"(",
")",
"{",
"s",
".",
"chNotBuf",
"<-",
"nBuf",
"}",
"(",
")",
"\n\n",
"rsp",
":=",
"HandleValueNotification",
"(",
"nBuf",
")",
"\n",
"rsp",
".",
"SetAttributeOpcode",
"(",
")",
"\n",
"rsp",
".",
"SetAttributeHandle",
"(",
"h",
")",
"\n",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"rsp",
".",
"AttributeValue",
"(",
")",
")",
"\n",
"buf",
".",
"Reset",
"(",
")",
"\n",
"if",
"len",
"(",
"data",
")",
">",
"buf",
".",
"Cap",
"(",
")",
"{",
"data",
"=",
"data",
"[",
":",
"buf",
".",
"Cap",
"(",
")",
"]",
"\n",
"}",
"\n",
"buf",
".",
"Write",
"(",
"data",
")",
"\n",
"return",
"s",
".",
"conn",
".",
"Write",
"(",
"rsp",
"[",
":",
"3",
"+",
"buf",
".",
"Len",
"(",
")",
"]",
")",
"\n",
"}"
] | // notify sends notification to remote central. | [
"notify",
"sends",
"notification",
"to",
"remote",
"central",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/att/server.go#L70-L85 |
10,148 | currantlabs/ble | linux/att/server.go | indicate | func (s *Server) indicate(h uint16, data []byte) (int, error) {
// Acquire and reuse indicateBuffer. Release it after usage.
iBuf := <-s.chIndBuf
defer func() { s.chIndBuf <- iBuf }()
rsp := HandleValueIndication(iBuf)
rsp.SetAttributeOpcode()
rsp.SetAttributeHandle(h)
buf := bytes.NewBuffer(rsp.AttributeValue())
buf.Reset()
if len(data) > buf.Cap() {
data = data[:buf.Cap()]
}
buf.Write(data)
n, err := s.conn.Write(rsp[:3+buf.Len()])
if err != nil {
return n, err
}
select {
case _, ok := <-s.chConfirm:
if !ok {
return 0, io.ErrClosedPipe
}
return n, nil
case <-time.After(time.Second * 30):
return 0, ErrSeqProtoTimeout
}
} | go | func (s *Server) indicate(h uint16, data []byte) (int, error) {
// Acquire and reuse indicateBuffer. Release it after usage.
iBuf := <-s.chIndBuf
defer func() { s.chIndBuf <- iBuf }()
rsp := HandleValueIndication(iBuf)
rsp.SetAttributeOpcode()
rsp.SetAttributeHandle(h)
buf := bytes.NewBuffer(rsp.AttributeValue())
buf.Reset()
if len(data) > buf.Cap() {
data = data[:buf.Cap()]
}
buf.Write(data)
n, err := s.conn.Write(rsp[:3+buf.Len()])
if err != nil {
return n, err
}
select {
case _, ok := <-s.chConfirm:
if !ok {
return 0, io.ErrClosedPipe
}
return n, nil
case <-time.After(time.Second * 30):
return 0, ErrSeqProtoTimeout
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"indicate",
"(",
"h",
"uint16",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"// Acquire and reuse indicateBuffer. Release it after usage.",
"iBuf",
":=",
"<-",
"s",
".",
"chIndBuf",
"\n",
"defer",
"func",
"(",
")",
"{",
"s",
".",
"chIndBuf",
"<-",
"iBuf",
"}",
"(",
")",
"\n\n",
"rsp",
":=",
"HandleValueIndication",
"(",
"iBuf",
")",
"\n",
"rsp",
".",
"SetAttributeOpcode",
"(",
")",
"\n",
"rsp",
".",
"SetAttributeHandle",
"(",
"h",
")",
"\n",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"rsp",
".",
"AttributeValue",
"(",
")",
")",
"\n",
"buf",
".",
"Reset",
"(",
")",
"\n",
"if",
"len",
"(",
"data",
")",
">",
"buf",
".",
"Cap",
"(",
")",
"{",
"data",
"=",
"data",
"[",
":",
"buf",
".",
"Cap",
"(",
")",
"]",
"\n",
"}",
"\n",
"buf",
".",
"Write",
"(",
"data",
")",
"\n",
"n",
",",
"err",
":=",
"s",
".",
"conn",
".",
"Write",
"(",
"rsp",
"[",
":",
"3",
"+",
"buf",
".",
"Len",
"(",
")",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"n",
",",
"err",
"\n",
"}",
"\n",
"select",
"{",
"case",
"_",
",",
"ok",
":=",
"<-",
"s",
".",
"chConfirm",
":",
"if",
"!",
"ok",
"{",
"return",
"0",
",",
"io",
".",
"ErrClosedPipe",
"\n",
"}",
"\n",
"return",
"n",
",",
"nil",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"time",
".",
"Second",
"*",
"30",
")",
":",
"return",
"0",
",",
"ErrSeqProtoTimeout",
"\n",
"}",
"\n",
"}"
] | // indicate sends indication to remote central. | [
"indicate",
"sends",
"indication",
"to",
"remote",
"central",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/att/server.go#L88-L115 |
10,149 | currantlabs/ble | linux/att/server.go | Loop | func (s *Server) Loop() {
type sbuf struct {
buf []byte
len int
}
pool := make(chan *sbuf, 2)
pool <- &sbuf{buf: make([]byte, s.rxMTU)}
pool <- &sbuf{buf: make([]byte, s.rxMTU)}
seq := make(chan *sbuf)
go func() {
b := <-pool
for {
n, err := s.conn.Read(b.buf)
if n == 0 || err != nil {
close(seq)
close(s.chConfirm)
_ = s.conn.Close()
return
}
if b.buf[0] == HandleValueConfirmationCode {
select {
case s.chConfirm <- true:
default:
logger.Error("server", "recieved a spurious confirmation", nil)
}
continue
}
b.len = n
seq <- b // Send the current request for handling
b = <-pool // Swap the buffer for next incoming request.
}
}()
for req := range seq {
if rsp := s.handleRequest(req.buf[:req.len]); rsp != nil {
if len(rsp) != 0 {
s.conn.Write(rsp)
}
}
pool <- req
}
for h, ccc := range s.conn.cccs {
if ccc != 0 {
logger.Info("cleanup", "ccc", fmt.Sprintf("0x%02X", ccc))
}
if ccc&cccIndicate != 0 {
s.conn.in[h].Close()
}
if ccc&cccNotify != 0 {
s.conn.nn[h].Close()
}
}
} | go | func (s *Server) Loop() {
type sbuf struct {
buf []byte
len int
}
pool := make(chan *sbuf, 2)
pool <- &sbuf{buf: make([]byte, s.rxMTU)}
pool <- &sbuf{buf: make([]byte, s.rxMTU)}
seq := make(chan *sbuf)
go func() {
b := <-pool
for {
n, err := s.conn.Read(b.buf)
if n == 0 || err != nil {
close(seq)
close(s.chConfirm)
_ = s.conn.Close()
return
}
if b.buf[0] == HandleValueConfirmationCode {
select {
case s.chConfirm <- true:
default:
logger.Error("server", "recieved a spurious confirmation", nil)
}
continue
}
b.len = n
seq <- b // Send the current request for handling
b = <-pool // Swap the buffer for next incoming request.
}
}()
for req := range seq {
if rsp := s.handleRequest(req.buf[:req.len]); rsp != nil {
if len(rsp) != 0 {
s.conn.Write(rsp)
}
}
pool <- req
}
for h, ccc := range s.conn.cccs {
if ccc != 0 {
logger.Info("cleanup", "ccc", fmt.Sprintf("0x%02X", ccc))
}
if ccc&cccIndicate != 0 {
s.conn.in[h].Close()
}
if ccc&cccNotify != 0 {
s.conn.nn[h].Close()
}
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Loop",
"(",
")",
"{",
"type",
"sbuf",
"struct",
"{",
"buf",
"[",
"]",
"byte",
"\n",
"len",
"int",
"\n",
"}",
"\n",
"pool",
":=",
"make",
"(",
"chan",
"*",
"sbuf",
",",
"2",
")",
"\n",
"pool",
"<-",
"&",
"sbuf",
"{",
"buf",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"s",
".",
"rxMTU",
")",
"}",
"\n",
"pool",
"<-",
"&",
"sbuf",
"{",
"buf",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"s",
".",
"rxMTU",
")",
"}",
"\n\n",
"seq",
":=",
"make",
"(",
"chan",
"*",
"sbuf",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"b",
":=",
"<-",
"pool",
"\n",
"for",
"{",
"n",
",",
"err",
":=",
"s",
".",
"conn",
".",
"Read",
"(",
"b",
".",
"buf",
")",
"\n",
"if",
"n",
"==",
"0",
"||",
"err",
"!=",
"nil",
"{",
"close",
"(",
"seq",
")",
"\n",
"close",
"(",
"s",
".",
"chConfirm",
")",
"\n",
"_",
"=",
"s",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"b",
".",
"buf",
"[",
"0",
"]",
"==",
"HandleValueConfirmationCode",
"{",
"select",
"{",
"case",
"s",
".",
"chConfirm",
"<-",
"true",
":",
"default",
":",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
")",
"\n",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"b",
".",
"len",
"=",
"n",
"\n",
"seq",
"<-",
"b",
"// Send the current request for handling",
"\n",
"b",
"=",
"<-",
"pool",
"// Swap the buffer for next incoming request.",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"for",
"req",
":=",
"range",
"seq",
"{",
"if",
"rsp",
":=",
"s",
".",
"handleRequest",
"(",
"req",
".",
"buf",
"[",
":",
"req",
".",
"len",
"]",
")",
";",
"rsp",
"!=",
"nil",
"{",
"if",
"len",
"(",
"rsp",
")",
"!=",
"0",
"{",
"s",
".",
"conn",
".",
"Write",
"(",
"rsp",
")",
"\n",
"}",
"\n",
"}",
"\n",
"pool",
"<-",
"req",
"\n",
"}",
"\n",
"for",
"h",
",",
"ccc",
":=",
"range",
"s",
".",
"conn",
".",
"cccs",
"{",
"if",
"ccc",
"!=",
"0",
"{",
"logger",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ccc",
")",
")",
"\n",
"}",
"\n",
"if",
"ccc",
"&",
"cccIndicate",
"!=",
"0",
"{",
"s",
".",
"conn",
".",
"in",
"[",
"h",
"]",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"if",
"ccc",
"&",
"cccNotify",
"!=",
"0",
"{",
"s",
".",
"conn",
".",
"nn",
"[",
"h",
"]",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Loop accepts incoming ATT request, and respond response. | [
"Loop",
"accepts",
"incoming",
"ATT",
"request",
"and",
"respond",
"response",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/att/server.go#L118-L170 |
10,150 | currantlabs/ble | linux/hci/option.go | OptDeviceID | func OptDeviceID(id int) Option {
return func(h *HCI) error {
h.id = id
return nil
}
} | go | func OptDeviceID(id int) Option {
return func(h *HCI) error {
h.id = id
return nil
}
} | [
"func",
"OptDeviceID",
"(",
"id",
"int",
")",
"Option",
"{",
"return",
"func",
"(",
"h",
"*",
"HCI",
")",
"error",
"{",
"h",
".",
"id",
"=",
"id",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // OptDeviceID sets HCI device ID. | [
"OptDeviceID",
"sets",
"HCI",
"device",
"ID",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/option.go#L13-L18 |
10,151 | currantlabs/ble | linux/hci/option.go | OptDialerTimeout | func OptDialerTimeout(d time.Duration) Option {
return func(h *HCI) error {
h.dialerTmo = d
return nil
}
} | go | func OptDialerTimeout(d time.Duration) Option {
return func(h *HCI) error {
h.dialerTmo = d
return nil
}
} | [
"func",
"OptDialerTimeout",
"(",
"d",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"func",
"(",
"h",
"*",
"HCI",
")",
"error",
"{",
"h",
".",
"dialerTmo",
"=",
"d",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // OptDialerTimeout sets dialing timeout for Dialer. | [
"OptDialerTimeout",
"sets",
"dialing",
"timeout",
"for",
"Dialer",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/option.go#L21-L26 |
10,152 | currantlabs/ble | linux/hci/option.go | OptListenerTimeout | func OptListenerTimeout(d time.Duration) Option {
return func(h *HCI) error {
h.listenerTmo = d
return nil
}
} | go | func OptListenerTimeout(d time.Duration) Option {
return func(h *HCI) error {
h.listenerTmo = d
return nil
}
} | [
"func",
"OptListenerTimeout",
"(",
"d",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"func",
"(",
"h",
"*",
"HCI",
")",
"error",
"{",
"h",
".",
"listenerTmo",
"=",
"d",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // OptListenerTimeout sets dialing timeout for Listener. | [
"OptListenerTimeout",
"sets",
"dialing",
"timeout",
"for",
"Listener",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/option.go#L29-L34 |
10,153 | currantlabs/ble | linux/hci/option.go | OptConnParams | func OptConnParams(param cmd.LECreateConnection) Option {
return func(h *HCI) error {
h.params.connParams = param
return nil
}
} | go | func OptConnParams(param cmd.LECreateConnection) Option {
return func(h *HCI) error {
h.params.connParams = param
return nil
}
} | [
"func",
"OptConnParams",
"(",
"param",
"cmd",
".",
"LECreateConnection",
")",
"Option",
"{",
"return",
"func",
"(",
"h",
"*",
"HCI",
")",
"error",
"{",
"h",
".",
"params",
".",
"connParams",
"=",
"param",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // OptConnParams overrides default connection parameters. | [
"OptConnParams",
"overrides",
"default",
"connection",
"parameters",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/option.go#L37-L42 |
10,154 | currantlabs/ble | linux/att/db.go | at | func (r *DB) at(h uint16) (a *attr, ok bool) {
i := r.idx(int(h))
if i < 0 {
return nil, false
}
return r.attrs[i], true
} | go | func (r *DB) at(h uint16) (a *attr, ok bool) {
i := r.idx(int(h))
if i < 0 {
return nil, false
}
return r.attrs[i], true
} | [
"func",
"(",
"r",
"*",
"DB",
")",
"at",
"(",
"h",
"uint16",
")",
"(",
"a",
"*",
"attr",
",",
"ok",
"bool",
")",
"{",
"i",
":=",
"r",
".",
"idx",
"(",
"int",
"(",
"h",
")",
")",
"\n",
"if",
"i",
"<",
"0",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"return",
"r",
".",
"attrs",
"[",
"i",
"]",
",",
"true",
"\n",
"}"
] | // at returns attr a. | [
"at",
"returns",
"attr",
"a",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/att/db.go#L35-L41 |
10,155 | currantlabs/ble | linux/gatt/client.go | NewClient | func NewClient(conn ble.Conn) (*Client, error) {
p := &Client{
subs: make(map[uint16]*sub),
conn: conn,
}
p.ac = att.NewClient(conn, p)
go p.ac.Loop()
return p, nil
} | go | func NewClient(conn ble.Conn) (*Client, error) {
p := &Client{
subs: make(map[uint16]*sub),
conn: conn,
}
p.ac = att.NewClient(conn, p)
go p.ac.Loop()
return p, nil
} | [
"func",
"NewClient",
"(",
"conn",
"ble",
".",
"Conn",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"p",
":=",
"&",
"Client",
"{",
"subs",
":",
"make",
"(",
"map",
"[",
"uint16",
"]",
"*",
"sub",
")",
",",
"conn",
":",
"conn",
",",
"}",
"\n",
"p",
".",
"ac",
"=",
"att",
".",
"NewClient",
"(",
"conn",
",",
"p",
")",
"\n",
"go",
"p",
".",
"ac",
".",
"Loop",
"(",
")",
"\n",
"return",
"p",
",",
"nil",
"\n",
"}"
] | // NewClient returns a GATT Client. | [
"NewClient",
"returns",
"a",
"GATT",
"Client",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/gatt/client.go#L19-L27 |
10,156 | currantlabs/ble | linux/gatt/client.go | Address | func (p *Client) Address() ble.Addr {
p.RLock()
defer p.RUnlock()
return p.conn.RemoteAddr()
} | go | func (p *Client) Address() ble.Addr {
p.RLock()
defer p.RUnlock()
return p.conn.RemoteAddr()
} | [
"func",
"(",
"p",
"*",
"Client",
")",
"Address",
"(",
")",
"ble",
".",
"Addr",
"{",
"p",
".",
"RLock",
"(",
")",
"\n",
"defer",
"p",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"p",
".",
"conn",
".",
"RemoteAddr",
"(",
")",
"\n",
"}"
] | // Address returns the address of the client. | [
"Address",
"returns",
"the",
"address",
"of",
"the",
"client",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/gatt/client.go#L42-L46 |
10,157 | currantlabs/ble | linux/gatt/client.go | Name | func (p *Client) Name() string {
p.RLock()
defer p.RUnlock()
return p.name
} | go | func (p *Client) Name() string {
p.RLock()
defer p.RUnlock()
return p.name
} | [
"func",
"(",
"p",
"*",
"Client",
")",
"Name",
"(",
")",
"string",
"{",
"p",
".",
"RLock",
"(",
")",
"\n",
"defer",
"p",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"p",
".",
"name",
"\n",
"}"
] | // Name returns the name of the client. | [
"Name",
"returns",
"the",
"name",
"of",
"the",
"client",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/gatt/client.go#L49-L53 |
10,158 | currantlabs/ble | linux/gatt/client.go | Profile | func (p *Client) Profile() *ble.Profile {
p.RLock()
defer p.RUnlock()
return p.profile
} | go | func (p *Client) Profile() *ble.Profile {
p.RLock()
defer p.RUnlock()
return p.profile
} | [
"func",
"(",
"p",
"*",
"Client",
")",
"Profile",
"(",
")",
"*",
"ble",
".",
"Profile",
"{",
"p",
".",
"RLock",
"(",
")",
"\n",
"defer",
"p",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"p",
".",
"profile",
"\n",
"}"
] | // Profile returns the discovered profile. | [
"Profile",
"returns",
"the",
"discovered",
"profile",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/gatt/client.go#L56-L60 |
10,159 | currantlabs/ble | linux/gatt/client.go | DiscoverProfile | func (p *Client) DiscoverProfile(force bool) (*ble.Profile, error) {
if p.profile != nil && !force {
return p.profile, nil
}
ss, err := p.DiscoverServices(nil)
if err != nil {
return nil, fmt.Errorf("can't discover services: %s\n", err)
}
for _, s := range ss {
cs, err := p.DiscoverCharacteristics(nil, s)
if err != nil {
return nil, fmt.Errorf("can't discover characteristics: %s\n", err)
}
for _, c := range cs {
_, err := p.DiscoverDescriptors(nil, c)
if err != nil {
return nil, fmt.Errorf("can't discover descriptors: %s\n", err)
}
}
}
p.profile = &ble.Profile{Services: ss}
return p.profile, nil
} | go | func (p *Client) DiscoverProfile(force bool) (*ble.Profile, error) {
if p.profile != nil && !force {
return p.profile, nil
}
ss, err := p.DiscoverServices(nil)
if err != nil {
return nil, fmt.Errorf("can't discover services: %s\n", err)
}
for _, s := range ss {
cs, err := p.DiscoverCharacteristics(nil, s)
if err != nil {
return nil, fmt.Errorf("can't discover characteristics: %s\n", err)
}
for _, c := range cs {
_, err := p.DiscoverDescriptors(nil, c)
if err != nil {
return nil, fmt.Errorf("can't discover descriptors: %s\n", err)
}
}
}
p.profile = &ble.Profile{Services: ss}
return p.profile, nil
} | [
"func",
"(",
"p",
"*",
"Client",
")",
"DiscoverProfile",
"(",
"force",
"bool",
")",
"(",
"*",
"ble",
".",
"Profile",
",",
"error",
")",
"{",
"if",
"p",
".",
"profile",
"!=",
"nil",
"&&",
"!",
"force",
"{",
"return",
"p",
".",
"profile",
",",
"nil",
"\n",
"}",
"\n",
"ss",
",",
"err",
":=",
"p",
".",
"DiscoverServices",
"(",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"ss",
"{",
"cs",
",",
"err",
":=",
"p",
".",
"DiscoverCharacteristics",
"(",
"nil",
",",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"cs",
"{",
"_",
",",
"err",
":=",
"p",
".",
"DiscoverDescriptors",
"(",
"nil",
",",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"p",
".",
"profile",
"=",
"&",
"ble",
".",
"Profile",
"{",
"Services",
":",
"ss",
"}",
"\n",
"return",
"p",
".",
"profile",
",",
"nil",
"\n",
"}"
] | // DiscoverProfile discovers the whole hierachy of a server. | [
"DiscoverProfile",
"discovers",
"the",
"whole",
"hierachy",
"of",
"a",
"server",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/gatt/client.go#L63-L85 |
10,160 | currantlabs/ble | linux/gatt/client.go | Disconnected | func (p *Client) Disconnected() <-chan struct{} {
p.Lock()
defer p.Unlock()
return p.conn.Disconnected()
} | go | func (p *Client) Disconnected() <-chan struct{} {
p.Lock()
defer p.Unlock()
return p.conn.Disconnected()
} | [
"func",
"(",
"p",
"*",
"Client",
")",
"Disconnected",
"(",
")",
"<-",
"chan",
"struct",
"{",
"}",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n",
"return",
"p",
".",
"conn",
".",
"Disconnected",
"(",
")",
"\n",
"}"
] | // Disconnected returns a receiving channel, which is closed when the client disconnects. | [
"Disconnected",
"returns",
"a",
"receiving",
"channel",
"which",
"is",
"closed",
"when",
"the",
"client",
"disconnects",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/gatt/client.go#L354-L358 |
10,161 | currantlabs/ble | linux/att/client.go | NewClient | func NewClient(l2c ble.Conn, h NotificationHandler) *Client {
c := &Client{
l2c: l2c,
rspc: make(chan []byte),
chTxBuf: make(chan []byte, 1),
rxBuf: make([]byte, ble.MaxMTU),
chErr: make(chan error, 1),
handler: h,
}
c.chTxBuf <- make([]byte, l2c.TxMTU(), l2c.TxMTU())
return c
} | go | func NewClient(l2c ble.Conn, h NotificationHandler) *Client {
c := &Client{
l2c: l2c,
rspc: make(chan []byte),
chTxBuf: make(chan []byte, 1),
rxBuf: make([]byte, ble.MaxMTU),
chErr: make(chan error, 1),
handler: h,
}
c.chTxBuf <- make([]byte, l2c.TxMTU(), l2c.TxMTU())
return c
} | [
"func",
"NewClient",
"(",
"l2c",
"ble",
".",
"Conn",
",",
"h",
"NotificationHandler",
")",
"*",
"Client",
"{",
"c",
":=",
"&",
"Client",
"{",
"l2c",
":",
"l2c",
",",
"rspc",
":",
"make",
"(",
"chan",
"[",
"]",
"byte",
")",
",",
"chTxBuf",
":",
"make",
"(",
"chan",
"[",
"]",
"byte",
",",
"1",
")",
",",
"rxBuf",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"ble",
".",
"MaxMTU",
")",
",",
"chErr",
":",
"make",
"(",
"chan",
"error",
",",
"1",
")",
",",
"handler",
":",
"h",
",",
"}",
"\n",
"c",
".",
"chTxBuf",
"<-",
"make",
"(",
"[",
"]",
"byte",
",",
"l2c",
".",
"TxMTU",
"(",
")",
",",
"l2c",
".",
"TxMTU",
"(",
")",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // NewClient returns an Attribute Protocol Client. | [
"NewClient",
"returns",
"an",
"Attribute",
"Protocol",
"Client",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/att/client.go#L29-L40 |
10,162 | currantlabs/ble | linux/hci/conn.go | Read | func (c *Conn) Read(sdu []byte) (n int, err error) {
p, ok := <-c.chInPDU
if !ok {
return 0, errors.Wrap(io.ErrClosedPipe, "input channel closed")
}
if len(p) == 0 {
return 0, errors.Wrap(io.ErrUnexpectedEOF, "recieved empty packet")
}
// Assume it's a B-Frame.
slen := p.dlen()
data := p.payload()
if c.leFrame {
// LE-Frame.
slen = leFrameHdr(p).slen()
data = leFrameHdr(p).payload()
}
if cap(sdu) < slen {
return 0, errors.Wrapf(io.ErrShortBuffer, "payload recieved exceeds sdu buffer")
}
buf := bytes.NewBuffer(sdu)
buf.Reset()
buf.Write(data)
for buf.Len() < slen {
p := <-c.chInPDU
buf.Write(pdu(p).payload())
}
return slen, nil
} | go | func (c *Conn) Read(sdu []byte) (n int, err error) {
p, ok := <-c.chInPDU
if !ok {
return 0, errors.Wrap(io.ErrClosedPipe, "input channel closed")
}
if len(p) == 0 {
return 0, errors.Wrap(io.ErrUnexpectedEOF, "recieved empty packet")
}
// Assume it's a B-Frame.
slen := p.dlen()
data := p.payload()
if c.leFrame {
// LE-Frame.
slen = leFrameHdr(p).slen()
data = leFrameHdr(p).payload()
}
if cap(sdu) < slen {
return 0, errors.Wrapf(io.ErrShortBuffer, "payload recieved exceeds sdu buffer")
}
buf := bytes.NewBuffer(sdu)
buf.Reset()
buf.Write(data)
for buf.Len() < slen {
p := <-c.chInPDU
buf.Write(pdu(p).payload())
}
return slen, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Read",
"(",
"sdu",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"p",
",",
"ok",
":=",
"<-",
"c",
".",
"chInPDU",
"\n",
"if",
"!",
"ok",
"{",
"return",
"0",
",",
"errors",
".",
"Wrap",
"(",
"io",
".",
"ErrClosedPipe",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"p",
")",
"==",
"0",
"{",
"return",
"0",
",",
"errors",
".",
"Wrap",
"(",
"io",
".",
"ErrUnexpectedEOF",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Assume it's a B-Frame.",
"slen",
":=",
"p",
".",
"dlen",
"(",
")",
"\n",
"data",
":=",
"p",
".",
"payload",
"(",
")",
"\n",
"if",
"c",
".",
"leFrame",
"{",
"// LE-Frame.",
"slen",
"=",
"leFrameHdr",
"(",
"p",
")",
".",
"slen",
"(",
")",
"\n",
"data",
"=",
"leFrameHdr",
"(",
"p",
")",
".",
"payload",
"(",
")",
"\n",
"}",
"\n",
"if",
"cap",
"(",
"sdu",
")",
"<",
"slen",
"{",
"return",
"0",
",",
"errors",
".",
"Wrapf",
"(",
"io",
".",
"ErrShortBuffer",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"sdu",
")",
"\n",
"buf",
".",
"Reset",
"(",
")",
"\n",
"buf",
".",
"Write",
"(",
"data",
")",
"\n",
"for",
"buf",
".",
"Len",
"(",
")",
"<",
"slen",
"{",
"p",
":=",
"<-",
"c",
".",
"chInPDU",
"\n",
"buf",
".",
"Write",
"(",
"pdu",
"(",
"p",
")",
".",
"payload",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"slen",
",",
"nil",
"\n",
"}"
] | // Read copies re-assembled L2CAP PDUs into sdu. | [
"Read",
"copies",
"re",
"-",
"assembled",
"L2CAP",
"PDUs",
"into",
"sdu",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/conn.go#L119-L147 |
10,163 | currantlabs/ble | linux/hci/conn.go | Close | func (c *Conn) Close() error {
select {
case <-c.chDone:
// Return if it's already closed.
return nil
default:
c.hci.Send(&cmd.Disconnect{
ConnectionHandle: c.param.ConnectionHandle(),
Reason: 0x13,
}, nil)
return nil
}
} | go | func (c *Conn) Close() error {
select {
case <-c.chDone:
// Return if it's already closed.
return nil
default:
c.hci.Send(&cmd.Disconnect{
ConnectionHandle: c.param.ConnectionHandle(),
Reason: 0x13,
}, nil)
return nil
}
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Close",
"(",
")",
"error",
"{",
"select",
"{",
"case",
"<-",
"c",
".",
"chDone",
":",
"// Return if it's already closed.",
"return",
"nil",
"\n",
"default",
":",
"c",
".",
"hci",
".",
"Send",
"(",
"&",
"cmd",
".",
"Disconnect",
"{",
"ConnectionHandle",
":",
"c",
".",
"param",
".",
"ConnectionHandle",
"(",
")",
",",
"Reason",
":",
"0x13",
",",
"}",
",",
"nil",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // Close disconnects the connection by sending hci disconnect command to the device. | [
"Close",
"disconnects",
"the",
"connection",
"by",
"sending",
"hci",
"disconnect",
"command",
"to",
"the",
"device",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/conn.go#L281-L293 |
10,164 | currantlabs/ble | linux/hci/conn.go | RemoteAddr | func (c *Conn) RemoteAddr() ble.Addr {
a := c.param.PeerAddress()
return net.HardwareAddr([]byte{a[5], a[4], a[3], a[2], a[1], a[0]})
} | go | func (c *Conn) RemoteAddr() ble.Addr {
a := c.param.PeerAddress()
return net.HardwareAddr([]byte{a[5], a[4], a[3], a[2], a[1], a[0]})
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"RemoteAddr",
"(",
")",
"ble",
".",
"Addr",
"{",
"a",
":=",
"c",
".",
"param",
".",
"PeerAddress",
"(",
")",
"\n",
"return",
"net",
".",
"HardwareAddr",
"(",
"[",
"]",
"byte",
"{",
"a",
"[",
"5",
"]",
",",
"a",
"[",
"4",
"]",
",",
"a",
"[",
"3",
"]",
",",
"a",
"[",
"2",
"]",
",",
"a",
"[",
"1",
"]",
",",
"a",
"[",
"0",
"]",
"}",
")",
"\n",
"}"
] | // RemoteAddr returns remote device's MAC address. | [
"RemoteAddr",
"returns",
"remote",
"device",
"s",
"MAC",
"address",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/conn.go#L299-L302 |
10,165 | currantlabs/ble | handler.go | NewRequest | func NewRequest(conn Conn, data []byte, offset int) Request {
return &request{conn: conn, data: data, offset: offset}
} | go | func NewRequest(conn Conn, data []byte, offset int) Request {
return &request{conn: conn, data: data, offset: offset}
} | [
"func",
"NewRequest",
"(",
"conn",
"Conn",
",",
"data",
"[",
"]",
"byte",
",",
"offset",
"int",
")",
"Request",
"{",
"return",
"&",
"request",
"{",
"conn",
":",
"conn",
",",
"data",
":",
"data",
",",
"offset",
":",
"offset",
"}",
"\n",
"}"
] | // NewRequest returns a default implementation of Request. | [
"NewRequest",
"returns",
"a",
"default",
"implementation",
"of",
"Request",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/handler.go#L57-L59 |
10,166 | currantlabs/ble | handler.go | Len | func (r *responseWriter) Len() int {
if r.buf == nil {
return 0
}
return r.buf.Len()
} | go | func (r *responseWriter) Len() int {
if r.buf == nil {
return 0
}
return r.buf.Len()
} | [
"func",
"(",
"r",
"*",
"responseWriter",
")",
"Len",
"(",
")",
"int",
"{",
"if",
"r",
".",
"buf",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"r",
".",
"buf",
".",
"Len",
"(",
")",
"\n",
"}"
] | // Len returns length of the buffer.
// Len returns 0 if it is a dummy write response for WriteCommand. | [
"Len",
"returns",
"length",
"of",
"the",
"buffer",
".",
"Len",
"returns",
"0",
"if",
"it",
"is",
"a",
"dummy",
"write",
"response",
"for",
"WriteCommand",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/handler.go#L113-L118 |
10,167 | currantlabs/ble | handler.go | Cap | func (r *responseWriter) Cap() int {
if r.buf == nil {
return 0
}
return r.buf.Cap()
} | go | func (r *responseWriter) Cap() int {
if r.buf == nil {
return 0
}
return r.buf.Cap()
} | [
"func",
"(",
"r",
"*",
"responseWriter",
")",
"Cap",
"(",
")",
"int",
"{",
"if",
"r",
".",
"buf",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"r",
".",
"buf",
".",
"Cap",
"(",
")",
"\n",
"}"
] | // Cap returns capacity of the buffer.
// Cap returns 0 if it is a dummy write response for WriteCommand. | [
"Cap",
"returns",
"capacity",
"of",
"the",
"buffer",
".",
"Cap",
"returns",
"0",
"if",
"it",
"is",
"a",
"dummy",
"write",
"response",
"for",
"WriteCommand",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/handler.go#L122-L127 |
10,168 | currantlabs/ble | handler.go | Write | func (r *responseWriter) Write(b []byte) (int, error) {
if r.buf == nil {
return 0, ErrReqNotSupp
}
if len(b) > r.buf.Cap()-r.buf.Len() {
return 0, io.ErrShortWrite
}
return r.buf.Write(b)
} | go | func (r *responseWriter) Write(b []byte) (int, error) {
if r.buf == nil {
return 0, ErrReqNotSupp
}
if len(b) > r.buf.Cap()-r.buf.Len() {
return 0, io.ErrShortWrite
}
return r.buf.Write(b)
} | [
"func",
"(",
"r",
"*",
"responseWriter",
")",
"Write",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"r",
".",
"buf",
"==",
"nil",
"{",
"return",
"0",
",",
"ErrReqNotSupp",
"\n",
"}",
"\n",
"if",
"len",
"(",
"b",
")",
">",
"r",
".",
"buf",
".",
"Cap",
"(",
")",
"-",
"r",
".",
"buf",
".",
"Len",
"(",
")",
"{",
"return",
"0",
",",
"io",
".",
"ErrShortWrite",
"\n",
"}",
"\n\n",
"return",
"r",
".",
"buf",
".",
"Write",
"(",
"b",
")",
"\n",
"}"
] | // Write writes data to return as the characteristic value.
// Cap returns 0 with error set to ErrReqNotSupp if it is a dummy write response for WriteCommand. | [
"Write",
"writes",
"data",
"to",
"return",
"as",
"the",
"characteristic",
"value",
".",
"Cap",
"returns",
"0",
"with",
"error",
"set",
"to",
"ErrReqNotSupp",
"if",
"it",
"is",
"a",
"dummy",
"write",
"response",
"for",
"WriteCommand",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/handler.go#L131-L140 |
10,169 | currantlabs/ble | gatt.go | AdvertiseNameAndServices | func AdvertiseNameAndServices(ctx context.Context, name string, uuids ...UUID) error {
if defaultDevice == nil {
return ErrDefaultDevice
}
defer untrap(trap(ctx))
return defaultDevice.AdvertiseNameAndServices(ctx, name, uuids...)
} | go | func AdvertiseNameAndServices(ctx context.Context, name string, uuids ...UUID) error {
if defaultDevice == nil {
return ErrDefaultDevice
}
defer untrap(trap(ctx))
return defaultDevice.AdvertiseNameAndServices(ctx, name, uuids...)
} | [
"func",
"AdvertiseNameAndServices",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"uuids",
"...",
"UUID",
")",
"error",
"{",
"if",
"defaultDevice",
"==",
"nil",
"{",
"return",
"ErrDefaultDevice",
"\n",
"}",
"\n",
"defer",
"untrap",
"(",
"trap",
"(",
"ctx",
")",
")",
"\n",
"return",
"defaultDevice",
".",
"AdvertiseNameAndServices",
"(",
"ctx",
",",
"name",
",",
"uuids",
"...",
")",
"\n",
"}"
] | // AdvertiseNameAndServices advertises device name, and specified service UUIDs.
// It tres to fit the UUIDs in the advertising packet as much as possi
// If name doesn't fit in the advertising packet, it will be put in scan response. | [
"AdvertiseNameAndServices",
"advertises",
"device",
"name",
"and",
"specified",
"service",
"UUIDs",
".",
"It",
"tres",
"to",
"fit",
"the",
"UUIDs",
"in",
"the",
"advertising",
"packet",
"as",
"much",
"as",
"possi",
"If",
"name",
"doesn",
"t",
"fit",
"in",
"the",
"advertising",
"packet",
"it",
"will",
"be",
"put",
"in",
"scan",
"response",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/gatt.go#L59-L65 |
10,170 | currantlabs/ble | gatt.go | Connect | func Connect(ctx context.Context, f AdvFilter) (Client, error) {
ctx2, cancel := context.WithCancel(ctx)
go func() {
select {
case <-ctx.Done():
cancel()
case <-ctx2.Done():
}
}()
ch := make(chan Advertisement)
fn := func(a Advertisement) {
cancel()
ch <- a
}
if err := Scan(ctx2, false, fn, f); err != nil {
if err != context.Canceled {
return nil, errors.Wrap(err, "can't scan")
}
}
cln, err := Dial(ctx, (<-ch).Address())
return cln, errors.Wrap(err, "can't dial")
} | go | func Connect(ctx context.Context, f AdvFilter) (Client, error) {
ctx2, cancel := context.WithCancel(ctx)
go func() {
select {
case <-ctx.Done():
cancel()
case <-ctx2.Done():
}
}()
ch := make(chan Advertisement)
fn := func(a Advertisement) {
cancel()
ch <- a
}
if err := Scan(ctx2, false, fn, f); err != nil {
if err != context.Canceled {
return nil, errors.Wrap(err, "can't scan")
}
}
cln, err := Dial(ctx, (<-ch).Address())
return cln, errors.Wrap(err, "can't dial")
} | [
"func",
"Connect",
"(",
"ctx",
"context",
".",
"Context",
",",
"f",
"AdvFilter",
")",
"(",
"Client",
",",
"error",
")",
"{",
"ctx2",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"ctx",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"cancel",
"(",
")",
"\n",
"case",
"<-",
"ctx2",
".",
"Done",
"(",
")",
":",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"ch",
":=",
"make",
"(",
"chan",
"Advertisement",
")",
"\n",
"fn",
":=",
"func",
"(",
"a",
"Advertisement",
")",
"{",
"cancel",
"(",
")",
"\n",
"ch",
"<-",
"a",
"\n",
"}",
"\n",
"if",
"err",
":=",
"Scan",
"(",
"ctx2",
",",
"false",
",",
"fn",
",",
"f",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"err",
"!=",
"context",
".",
"Canceled",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"cln",
",",
"err",
":=",
"Dial",
"(",
"ctx",
",",
"(",
"<-",
"ch",
")",
".",
"Address",
"(",
")",
")",
"\n",
"return",
"cln",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Connect searches for and connects to a Peripheral which matches specified condition. | [
"Connect",
"searches",
"for",
"and",
"connects",
"to",
"a",
"Peripheral",
"which",
"matches",
"specified",
"condition",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/gatt.go#L127-L150 |
10,171 | currantlabs/ble | gatt.go | trap | func trap(ctx context.Context) chan<- os.Signal {
v := ctx.Value("sig")
if v == nil {
return nil
}
cancel, ok := v.(func())
if cancel == nil || !ok {
return nil
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
select {
case <-sigs:
cancel()
case <-ctx.Done():
}
}()
return sigs
} | go | func trap(ctx context.Context) chan<- os.Signal {
v := ctx.Value("sig")
if v == nil {
return nil
}
cancel, ok := v.(func())
if cancel == nil || !ok {
return nil
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
select {
case <-sigs:
cancel()
case <-ctx.Done():
}
}()
return sigs
} | [
"func",
"trap",
"(",
"ctx",
"context",
".",
"Context",
")",
"chan",
"<-",
"os",
".",
"Signal",
"{",
"v",
":=",
"ctx",
".",
"Value",
"(",
"\"",
"\"",
")",
"\n",
"if",
"v",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"cancel",
",",
"ok",
":=",
"v",
".",
"(",
"func",
"(",
")",
")",
"\n",
"if",
"cancel",
"==",
"nil",
"||",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"sigs",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal",
",",
"1",
")",
"\n",
"signal",
".",
"Notify",
"(",
"sigs",
",",
"syscall",
".",
"SIGINT",
",",
"syscall",
".",
"SIGTERM",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"select",
"{",
"case",
"<-",
"sigs",
":",
"cancel",
"(",
")",
"\n",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"}",
"\n",
"}",
"(",
")",
"\n",
"return",
"sigs",
"\n",
"}"
] | // Cleanup for the interrupted case. | [
"Cleanup",
"for",
"the",
"interrupted",
"case",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/gatt.go#L161-L181 |
10,172 | currantlabs/ble | linux/hci/adv.go | setScanResponse | func (a *Advertisement) setScanResponse(sr *Advertisement) {
a.sr = sr
a.p = nil // clear the cached.
} | go | func (a *Advertisement) setScanResponse(sr *Advertisement) {
a.sr = sr
a.p = nil // clear the cached.
} | [
"func",
"(",
"a",
"*",
"Advertisement",
")",
"setScanResponse",
"(",
"sr",
"*",
"Advertisement",
")",
"{",
"a",
".",
"sr",
"=",
"sr",
"\n",
"a",
".",
"p",
"=",
"nil",
"// clear the cached.",
"\n",
"}"
] | // setScanResponse ssociate sca response to the existing advertisement. | [
"setScanResponse",
"ssociate",
"sca",
"response",
"to",
"the",
"existing",
"advertisement",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/adv.go#L41-L44 |
10,173 | currantlabs/ble | linux/hci/adv.go | TxPowerLevel | func (a *Advertisement) TxPowerLevel() int {
pwr, _ := a.packets().TxPower()
return pwr
} | go | func (a *Advertisement) TxPowerLevel() int {
pwr, _ := a.packets().TxPower()
return pwr
} | [
"func",
"(",
"a",
"*",
"Advertisement",
")",
"TxPowerLevel",
"(",
")",
"int",
"{",
"pwr",
",",
"_",
":=",
"a",
".",
"packets",
"(",
")",
".",
"TxPower",
"(",
")",
"\n",
"return",
"pwr",
"\n",
"}"
] | // TxPowerLevel returns the tx power level of the remote peripheral. | [
"TxPowerLevel",
"returns",
"the",
"tx",
"power",
"level",
"of",
"the",
"remote",
"peripheral",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/adv.go#L80-L83 |
10,174 | currantlabs/ble | linux/hci/adv.go | Connectable | func (a *Advertisement) Connectable() bool {
return a.EventType() == evtTypAdvDirectInd || a.EventType() == evtTypAdvInd
} | go | func (a *Advertisement) Connectable() bool {
return a.EventType() == evtTypAdvDirectInd || a.EventType() == evtTypAdvInd
} | [
"func",
"(",
"a",
"*",
"Advertisement",
")",
"Connectable",
"(",
")",
"bool",
"{",
"return",
"a",
".",
"EventType",
"(",
")",
"==",
"evtTypAdvDirectInd",
"||",
"a",
".",
"EventType",
"(",
")",
"==",
"evtTypAdvInd",
"\n",
"}"
] | // Connectable indicates weather the remote peripheral is connectable. | [
"Connectable",
"indicates",
"weather",
"the",
"remote",
"peripheral",
"is",
"connectable",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/adv.go#L91-L93 |
10,175 | currantlabs/ble | linux/hci/adv.go | RSSI | func (a *Advertisement) RSSI() int {
return int(a.e.RSSI(a.i))
} | go | func (a *Advertisement) RSSI() int {
return int(a.e.RSSI(a.i))
} | [
"func",
"(",
"a",
"*",
"Advertisement",
")",
"RSSI",
"(",
")",
"int",
"{",
"return",
"int",
"(",
"a",
".",
"e",
".",
"RSSI",
"(",
"a",
".",
"i",
")",
")",
"\n",
"}"
] | // RSSI returns RSSI signal strength. | [
"RSSI",
"returns",
"RSSI",
"signal",
"strength",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/adv.go#L96-L98 |
10,176 | currantlabs/ble | linux/hci/adv.go | Address | func (a *Advertisement) Address() ble.Addr {
b := a.e.Address(a.i)
addr := net.HardwareAddr([]byte{b[5], b[4], b[3], b[2], b[1], b[0]})
if a.e.AddressType(a.i) == 1 {
return RandomAddress{addr}
}
return addr
} | go | func (a *Advertisement) Address() ble.Addr {
b := a.e.Address(a.i)
addr := net.HardwareAddr([]byte{b[5], b[4], b[3], b[2], b[1], b[0]})
if a.e.AddressType(a.i) == 1 {
return RandomAddress{addr}
}
return addr
} | [
"func",
"(",
"a",
"*",
"Advertisement",
")",
"Address",
"(",
")",
"ble",
".",
"Addr",
"{",
"b",
":=",
"a",
".",
"e",
".",
"Address",
"(",
"a",
".",
"i",
")",
"\n",
"addr",
":=",
"net",
".",
"HardwareAddr",
"(",
"[",
"]",
"byte",
"{",
"b",
"[",
"5",
"]",
",",
"b",
"[",
"4",
"]",
",",
"b",
"[",
"3",
"]",
",",
"b",
"[",
"2",
"]",
",",
"b",
"[",
"1",
"]",
",",
"b",
"[",
"0",
"]",
"}",
")",
"\n",
"if",
"a",
".",
"e",
".",
"AddressType",
"(",
"a",
".",
"i",
")",
"==",
"1",
"{",
"return",
"RandomAddress",
"{",
"addr",
"}",
"\n",
"}",
"\n",
"return",
"addr",
"\n",
"}"
] | // Address returns the address of the remote peripheral. | [
"Address",
"returns",
"the",
"address",
"of",
"the",
"remote",
"peripheral",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/adv.go#L101-L108 |
10,177 | currantlabs/ble | linux/hci/adv.go | ScanResponse | func (a *Advertisement) ScanResponse() []byte {
if a.sr == nil {
return nil
}
return a.sr.Data()
} | go | func (a *Advertisement) ScanResponse() []byte {
if a.sr == nil {
return nil
}
return a.sr.Data()
} | [
"func",
"(",
"a",
"*",
"Advertisement",
")",
"ScanResponse",
"(",
")",
"[",
"]",
"byte",
"{",
"if",
"a",
".",
"sr",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"a",
".",
"sr",
".",
"Data",
"(",
")",
"\n",
"}"
] | // ScanResponse returns the scan response of the packet, if it presents.
// This is linux sepcific. | [
"ScanResponse",
"returns",
"the",
"scan",
"response",
"of",
"the",
"packet",
"if",
"it",
"presents",
".",
"This",
"is",
"linux",
"sepcific",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/adv.go#L130-L135 |
10,178 | currantlabs/ble | darwin/device.go | NewDevice | func NewDevice(opts ...Option) (*Device, error) {
d := &Device{
rspc: make(chan msg),
conns: make(map[string]*conn),
chConn: make(chan *conn),
chars: make(map[int]*ble.Characteristic),
base: 1,
}
if err := d.Option(opts...); err != nil {
return nil, err
}
d.pm = xpc.XpcConnect("com.apple.blued", d)
d.cm = xpc.XpcConnect("com.apple.blued", d)
return d, errors.Wrap(d.Init(), "can't init")
} | go | func NewDevice(opts ...Option) (*Device, error) {
d := &Device{
rspc: make(chan msg),
conns: make(map[string]*conn),
chConn: make(chan *conn),
chars: make(map[int]*ble.Characteristic),
base: 1,
}
if err := d.Option(opts...); err != nil {
return nil, err
}
d.pm = xpc.XpcConnect("com.apple.blued", d)
d.cm = xpc.XpcConnect("com.apple.blued", d)
return d, errors.Wrap(d.Init(), "can't init")
} | [
"func",
"NewDevice",
"(",
"opts",
"...",
"Option",
")",
"(",
"*",
"Device",
",",
"error",
")",
"{",
"d",
":=",
"&",
"Device",
"{",
"rspc",
":",
"make",
"(",
"chan",
"msg",
")",
",",
"conns",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"conn",
")",
",",
"chConn",
":",
"make",
"(",
"chan",
"*",
"conn",
")",
",",
"chars",
":",
"make",
"(",
"map",
"[",
"int",
"]",
"*",
"ble",
".",
"Characteristic",
")",
",",
"base",
":",
"1",
",",
"}",
"\n",
"if",
"err",
":=",
"d",
".",
"Option",
"(",
"opts",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"d",
".",
"pm",
"=",
"xpc",
".",
"XpcConnect",
"(",
"\"",
"\"",
",",
"d",
")",
"\n",
"d",
".",
"cm",
"=",
"xpc",
".",
"XpcConnect",
"(",
"\"",
"\"",
",",
"d",
")",
"\n\n",
"return",
"d",
",",
"errors",
".",
"Wrap",
"(",
"d",
".",
"Init",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // NewDevice returns a BLE device. | [
"NewDevice",
"returns",
"a",
"BLE",
"device",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/darwin/device.go#L68-L84 |
10,179 | currantlabs/ble | darwin/device.go | AdvertiseNameAndServices | func (d *Device) AdvertiseNameAndServices(ctx context.Context, name string, ss ...ble.UUID) error {
if err := d.sendReq(d.pm, 8, xpc.Dict{
"kCBAdvDataLocalName": name,
"kCBAdvDataServiceUUIDs": uuidSlice(ss)},
).err(); err != nil {
return err
}
<-ctx.Done()
d.stopAdvertising()
return ctx.Err()
} | go | func (d *Device) AdvertiseNameAndServices(ctx context.Context, name string, ss ...ble.UUID) error {
if err := d.sendReq(d.pm, 8, xpc.Dict{
"kCBAdvDataLocalName": name,
"kCBAdvDataServiceUUIDs": uuidSlice(ss)},
).err(); err != nil {
return err
}
<-ctx.Done()
d.stopAdvertising()
return ctx.Err()
} | [
"func",
"(",
"d",
"*",
"Device",
")",
"AdvertiseNameAndServices",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"ss",
"...",
"ble",
".",
"UUID",
")",
"error",
"{",
"if",
"err",
":=",
"d",
".",
"sendReq",
"(",
"d",
".",
"pm",
",",
"8",
",",
"xpc",
".",
"Dict",
"{",
"\"",
"\"",
":",
"name",
",",
"\"",
"\"",
":",
"uuidSlice",
"(",
"ss",
")",
"}",
",",
")",
".",
"err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"<-",
"ctx",
".",
"Done",
"(",
")",
"\n",
"d",
".",
"stopAdvertising",
"(",
")",
"\n",
"return",
"ctx",
".",
"Err",
"(",
")",
"\n",
"}"
] | // AdvertiseNameAndServices advertises name and specifid service UUIDs. | [
"AdvertiseNameAndServices",
"advertises",
"name",
"and",
"specifid",
"service",
"UUIDs",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/darwin/device.go#L153-L163 |
10,180 | currantlabs/ble | darwin/device.go | AdvertiseIBeaconData | func (d *Device) AdvertiseIBeaconData(ctx context.Context, md []byte) error {
var utsname xpc.Utsname
xpc.Uname(&utsname)
if utsname.Release >= "14." {
ibeaconCode := []byte{0x02, 0x15}
return d.AdvertiseMfgData(ctx, 0x004C, append(ibeaconCode, md...))
}
if err := d.sendReq(d.pm, 8, xpc.Dict{"kCBAdvDataAppleBeaconKey": md}).err(); err != nil {
return err
}
<-ctx.Done()
return d.stopAdvertising()
} | go | func (d *Device) AdvertiseIBeaconData(ctx context.Context, md []byte) error {
var utsname xpc.Utsname
xpc.Uname(&utsname)
if utsname.Release >= "14." {
ibeaconCode := []byte{0x02, 0x15}
return d.AdvertiseMfgData(ctx, 0x004C, append(ibeaconCode, md...))
}
if err := d.sendReq(d.pm, 8, xpc.Dict{"kCBAdvDataAppleBeaconKey": md}).err(); err != nil {
return err
}
<-ctx.Done()
return d.stopAdvertising()
} | [
"func",
"(",
"d",
"*",
"Device",
")",
"AdvertiseIBeaconData",
"(",
"ctx",
"context",
".",
"Context",
",",
"md",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"utsname",
"xpc",
".",
"Utsname",
"\n",
"xpc",
".",
"Uname",
"(",
"&",
"utsname",
")",
"\n\n",
"if",
"utsname",
".",
"Release",
">=",
"\"",
"\"",
"{",
"ibeaconCode",
":=",
"[",
"]",
"byte",
"{",
"0x02",
",",
"0x15",
"}",
"\n",
"return",
"d",
".",
"AdvertiseMfgData",
"(",
"ctx",
",",
"0x004C",
",",
"append",
"(",
"ibeaconCode",
",",
"md",
"...",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"d",
".",
"sendReq",
"(",
"d",
".",
"pm",
",",
"8",
",",
"xpc",
".",
"Dict",
"{",
"\"",
"\"",
":",
"md",
"}",
")",
".",
"err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"<-",
"ctx",
".",
"Done",
"(",
")",
"\n",
"return",
"d",
".",
"stopAdvertising",
"(",
")",
"\n",
"}"
] | // AdvertiseIBeaconData advertises iBeacon packet with specified manufacturer data. | [
"AdvertiseIBeaconData",
"advertises",
"iBeacon",
"packet",
"with",
"specified",
"manufacturer",
"data",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/darwin/device.go#L166-L179 |
10,181 | currantlabs/ble | darwin/device.go | AdvertiseIBeacon | func (d *Device) AdvertiseIBeacon(ctx context.Context, u ble.UUID, major, minor uint16, pwr int8) error {
b := make([]byte, 21)
copy(b, ble.Reverse(u)) // Big endian
binary.BigEndian.PutUint16(b[16:], major) // Big endian
binary.BigEndian.PutUint16(b[18:], minor) // Big endian
b[20] = uint8(pwr) // Measured Tx Power
return d.AdvertiseIBeaconData(ctx, b)
} | go | func (d *Device) AdvertiseIBeacon(ctx context.Context, u ble.UUID, major, minor uint16, pwr int8) error {
b := make([]byte, 21)
copy(b, ble.Reverse(u)) // Big endian
binary.BigEndian.PutUint16(b[16:], major) // Big endian
binary.BigEndian.PutUint16(b[18:], minor) // Big endian
b[20] = uint8(pwr) // Measured Tx Power
return d.AdvertiseIBeaconData(ctx, b)
} | [
"func",
"(",
"d",
"*",
"Device",
")",
"AdvertiseIBeacon",
"(",
"ctx",
"context",
".",
"Context",
",",
"u",
"ble",
".",
"UUID",
",",
"major",
",",
"minor",
"uint16",
",",
"pwr",
"int8",
")",
"error",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"21",
")",
"\n",
"copy",
"(",
"b",
",",
"ble",
".",
"Reverse",
"(",
"u",
")",
")",
"// Big endian",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"b",
"[",
"16",
":",
"]",
",",
"major",
")",
"// Big endian",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"b",
"[",
"18",
":",
"]",
",",
"minor",
")",
"// Big endian",
"\n",
"b",
"[",
"20",
"]",
"=",
"uint8",
"(",
"pwr",
")",
"// Measured Tx Power",
"\n",
"return",
"d",
".",
"AdvertiseIBeaconData",
"(",
"ctx",
",",
"b",
")",
"\n",
"}"
] | // AdvertiseIBeacon advertises iBeacon packet. | [
"AdvertiseIBeacon",
"advertises",
"iBeacon",
"packet",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/darwin/device.go#L182-L189 |
10,182 | currantlabs/ble | darwin/device.go | sendReq | func (d *Device) sendReq(x xpc.XPC, id int, args xpc.Dict) msg {
d.sendCmd(x, id, args)
return <-d.rspc
} | go | func (d *Device) sendReq(x xpc.XPC, id int, args xpc.Dict) msg {
d.sendCmd(x, id, args)
return <-d.rspc
} | [
"func",
"(",
"d",
"*",
"Device",
")",
"sendReq",
"(",
"x",
"xpc",
".",
"XPC",
",",
"id",
"int",
",",
"args",
"xpc",
".",
"Dict",
")",
"msg",
"{",
"d",
".",
"sendCmd",
"(",
"x",
",",
"id",
",",
"args",
")",
"\n",
"return",
"<-",
"d",
".",
"rspc",
"\n",
"}"
] | // sendReq sends a message and waits for its reply. | [
"sendReq",
"sends",
"a",
"message",
"and",
"waits",
"for",
"its",
"reply",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/darwin/device.go#L512-L515 |
10,183 | currantlabs/ble | linux/hci/gap.go | Scan | func (h *HCI) Scan(allowDup bool) error {
h.params.scanEnable.FilterDuplicates = 1
if allowDup {
h.params.scanEnable.FilterDuplicates = 0
}
h.params.scanEnable.LEScanEnable = 1
h.adHist = make([]*Advertisement, 128)
h.adLast = 0
return h.Send(&h.params.scanEnable, nil)
} | go | func (h *HCI) Scan(allowDup bool) error {
h.params.scanEnable.FilterDuplicates = 1
if allowDup {
h.params.scanEnable.FilterDuplicates = 0
}
h.params.scanEnable.LEScanEnable = 1
h.adHist = make([]*Advertisement, 128)
h.adLast = 0
return h.Send(&h.params.scanEnable, nil)
} | [
"func",
"(",
"h",
"*",
"HCI",
")",
"Scan",
"(",
"allowDup",
"bool",
")",
"error",
"{",
"h",
".",
"params",
".",
"scanEnable",
".",
"FilterDuplicates",
"=",
"1",
"\n",
"if",
"allowDup",
"{",
"h",
".",
"params",
".",
"scanEnable",
".",
"FilterDuplicates",
"=",
"0",
"\n",
"}",
"\n",
"h",
".",
"params",
".",
"scanEnable",
".",
"LEScanEnable",
"=",
"1",
"\n",
"h",
".",
"adHist",
"=",
"make",
"(",
"[",
"]",
"*",
"Advertisement",
",",
"128",
")",
"\n",
"h",
".",
"adLast",
"=",
"0",
"\n",
"return",
"h",
".",
"Send",
"(",
"&",
"h",
".",
"params",
".",
"scanEnable",
",",
"nil",
")",
"\n",
"}"
] | // Scan starts scanning. | [
"Scan",
"starts",
"scanning",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/gap.go#L26-L35 |
10,184 | currantlabs/ble | linux/hci/gap.go | StopScanning | func (h *HCI) StopScanning() error {
h.params.scanEnable.LEScanEnable = 0
return h.Send(&h.params.scanEnable, nil)
} | go | func (h *HCI) StopScanning() error {
h.params.scanEnable.LEScanEnable = 0
return h.Send(&h.params.scanEnable, nil)
} | [
"func",
"(",
"h",
"*",
"HCI",
")",
"StopScanning",
"(",
")",
"error",
"{",
"h",
".",
"params",
".",
"scanEnable",
".",
"LEScanEnable",
"=",
"0",
"\n",
"return",
"h",
".",
"Send",
"(",
"&",
"h",
".",
"params",
".",
"scanEnable",
",",
"nil",
")",
"\n",
"}"
] | // StopScanning stops scanning. | [
"StopScanning",
"stops",
"scanning",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/gap.go#L38-L41 |
10,185 | currantlabs/ble | linux/hci/gap.go | AdvertiseNameAndServices | func (h *HCI) AdvertiseNameAndServices(name string, uuids ...ble.UUID) error {
ad, err := adv.NewPacket(adv.Flags(adv.FlagGeneralDiscoverable | adv.FlagLEOnly))
if err != nil {
return err
}
f := adv.AllUUID
// Current length of ad packet plus two bytes of length and tag.
l := ad.Len() + 1 + 1
for _, u := range uuids {
l += u.Len()
}
if l > adv.MaxEIRPacketLength {
f = adv.SomeUUID
}
for _, u := range uuids {
if err := ad.Append(f(u)); err != nil {
if err == adv.ErrNotFit {
break
}
return err
}
}
sr, _ := adv.NewPacket()
switch {
case ad.Append(adv.CompleteName(name)) == nil:
case sr.Append(adv.CompleteName(name)) == nil:
case sr.Append(adv.ShortName(name)) == nil:
}
if err := h.SetAdvertisement(ad.Bytes(), sr.Bytes()); err != nil {
return nil
}
return h.Advertise()
} | go | func (h *HCI) AdvertiseNameAndServices(name string, uuids ...ble.UUID) error {
ad, err := adv.NewPacket(adv.Flags(adv.FlagGeneralDiscoverable | adv.FlagLEOnly))
if err != nil {
return err
}
f := adv.AllUUID
// Current length of ad packet plus two bytes of length and tag.
l := ad.Len() + 1 + 1
for _, u := range uuids {
l += u.Len()
}
if l > adv.MaxEIRPacketLength {
f = adv.SomeUUID
}
for _, u := range uuids {
if err := ad.Append(f(u)); err != nil {
if err == adv.ErrNotFit {
break
}
return err
}
}
sr, _ := adv.NewPacket()
switch {
case ad.Append(adv.CompleteName(name)) == nil:
case sr.Append(adv.CompleteName(name)) == nil:
case sr.Append(adv.ShortName(name)) == nil:
}
if err := h.SetAdvertisement(ad.Bytes(), sr.Bytes()); err != nil {
return nil
}
return h.Advertise()
} | [
"func",
"(",
"h",
"*",
"HCI",
")",
"AdvertiseNameAndServices",
"(",
"name",
"string",
",",
"uuids",
"...",
"ble",
".",
"UUID",
")",
"error",
"{",
"ad",
",",
"err",
":=",
"adv",
".",
"NewPacket",
"(",
"adv",
".",
"Flags",
"(",
"adv",
".",
"FlagGeneralDiscoverable",
"|",
"adv",
".",
"FlagLEOnly",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"f",
":=",
"adv",
".",
"AllUUID",
"\n\n",
"// Current length of ad packet plus two bytes of length and tag.",
"l",
":=",
"ad",
".",
"Len",
"(",
")",
"+",
"1",
"+",
"1",
"\n",
"for",
"_",
",",
"u",
":=",
"range",
"uuids",
"{",
"l",
"+=",
"u",
".",
"Len",
"(",
")",
"\n",
"}",
"\n",
"if",
"l",
">",
"adv",
".",
"MaxEIRPacketLength",
"{",
"f",
"=",
"adv",
".",
"SomeUUID",
"\n",
"}",
"\n",
"for",
"_",
",",
"u",
":=",
"range",
"uuids",
"{",
"if",
"err",
":=",
"ad",
".",
"Append",
"(",
"f",
"(",
"u",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"adv",
".",
"ErrNotFit",
"{",
"break",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"sr",
",",
"_",
":=",
"adv",
".",
"NewPacket",
"(",
")",
"\n",
"switch",
"{",
"case",
"ad",
".",
"Append",
"(",
"adv",
".",
"CompleteName",
"(",
"name",
")",
")",
"==",
"nil",
":",
"case",
"sr",
".",
"Append",
"(",
"adv",
".",
"CompleteName",
"(",
"name",
")",
")",
"==",
"nil",
":",
"case",
"sr",
".",
"Append",
"(",
"adv",
".",
"ShortName",
"(",
"name",
")",
")",
"==",
"nil",
":",
"}",
"\n",
"if",
"err",
":=",
"h",
".",
"SetAdvertisement",
"(",
"ad",
".",
"Bytes",
"(",
")",
",",
"sr",
".",
"Bytes",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"h",
".",
"Advertise",
"(",
")",
"\n",
"}"
] | // AdvertiseNameAndServices advertises device name, and specified service UUIDs.
// It tries to fit the UUIDs in the advertising data as much as possible.
// If name doesn't fit in the advertising data, it will be put in scan response. | [
"AdvertiseNameAndServices",
"advertises",
"device",
"name",
"and",
"specified",
"service",
"UUIDs",
".",
"It",
"tries",
"to",
"fit",
"the",
"UUIDs",
"in",
"the",
"advertising",
"data",
"as",
"much",
"as",
"possible",
".",
"If",
"name",
"doesn",
"t",
"fit",
"in",
"the",
"advertising",
"data",
"it",
"will",
"be",
"put",
"in",
"scan",
"response",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/gap.go#L46-L79 |
10,186 | currantlabs/ble | linux/hci/gap.go | StopAdvertising | func (h *HCI) StopAdvertising() error {
h.params.advEnable.AdvertisingEnable = 0
return h.Send(&h.params.advEnable, nil)
} | go | func (h *HCI) StopAdvertising() error {
h.params.advEnable.AdvertisingEnable = 0
return h.Send(&h.params.advEnable, nil)
} | [
"func",
"(",
"h",
"*",
"HCI",
")",
"StopAdvertising",
"(",
")",
"error",
"{",
"h",
".",
"params",
".",
"advEnable",
".",
"AdvertisingEnable",
"=",
"0",
"\n",
"return",
"h",
".",
"Send",
"(",
"&",
"h",
".",
"params",
".",
"advEnable",
",",
"nil",
")",
"\n",
"}"
] | // StopAdvertising stops advertising. | [
"StopAdvertising",
"stops",
"advertising",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/gap.go#L130-L133 |
10,187 | currantlabs/ble | linux/hci/gap.go | Accept | func (h *HCI) Accept() (ble.Conn, error) {
var tmo <-chan time.Time
if h.listenerTmo != time.Duration(0) {
tmo = time.After(h.listenerTmo)
}
select {
case <-h.done:
return nil, h.err
case c := <-h.chSlaveConn:
return c, nil
case <-tmo:
return nil, fmt.Errorf("listner timed out")
}
} | go | func (h *HCI) Accept() (ble.Conn, error) {
var tmo <-chan time.Time
if h.listenerTmo != time.Duration(0) {
tmo = time.After(h.listenerTmo)
}
select {
case <-h.done:
return nil, h.err
case c := <-h.chSlaveConn:
return c, nil
case <-tmo:
return nil, fmt.Errorf("listner timed out")
}
} | [
"func",
"(",
"h",
"*",
"HCI",
")",
"Accept",
"(",
")",
"(",
"ble",
".",
"Conn",
",",
"error",
")",
"{",
"var",
"tmo",
"<-",
"chan",
"time",
".",
"Time",
"\n",
"if",
"h",
".",
"listenerTmo",
"!=",
"time",
".",
"Duration",
"(",
"0",
")",
"{",
"tmo",
"=",
"time",
".",
"After",
"(",
"h",
".",
"listenerTmo",
")",
"\n",
"}",
"\n",
"select",
"{",
"case",
"<-",
"h",
".",
"done",
":",
"return",
"nil",
",",
"h",
".",
"err",
"\n",
"case",
"c",
":=",
"<-",
"h",
".",
"chSlaveConn",
":",
"return",
"c",
",",
"nil",
"\n",
"case",
"<-",
"tmo",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // Accept starts advertising and accepts connection. | [
"Accept",
"starts",
"advertising",
"and",
"accepts",
"connection",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/gap.go#L136-L149 |
10,188 | currantlabs/ble | linux/hci/gap.go | SetAdvertisement | func (h *HCI) SetAdvertisement(ad []byte, sr []byte) error {
if len(ad) > adv.MaxEIRPacketLength || len(sr) > adv.MaxEIRPacketLength {
return ble.ErrEIRPacketTooLong
}
h.params.advData.AdvertisingDataLength = uint8(len(ad))
copy(h.params.advData.AdvertisingData[:], ad)
if err := h.Send(&h.params.advData, nil); err != nil {
return err
}
h.params.scanResp.ScanResponseDataLength = uint8(len(sr))
copy(h.params.scanResp.ScanResponseData[:], sr)
if err := h.Send(&h.params.scanResp, nil); err != nil {
return err
}
return nil
} | go | func (h *HCI) SetAdvertisement(ad []byte, sr []byte) error {
if len(ad) > adv.MaxEIRPacketLength || len(sr) > adv.MaxEIRPacketLength {
return ble.ErrEIRPacketTooLong
}
h.params.advData.AdvertisingDataLength = uint8(len(ad))
copy(h.params.advData.AdvertisingData[:], ad)
if err := h.Send(&h.params.advData, nil); err != nil {
return err
}
h.params.scanResp.ScanResponseDataLength = uint8(len(sr))
copy(h.params.scanResp.ScanResponseData[:], sr)
if err := h.Send(&h.params.scanResp, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"h",
"*",
"HCI",
")",
"SetAdvertisement",
"(",
"ad",
"[",
"]",
"byte",
",",
"sr",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"ad",
")",
">",
"adv",
".",
"MaxEIRPacketLength",
"||",
"len",
"(",
"sr",
")",
">",
"adv",
".",
"MaxEIRPacketLength",
"{",
"return",
"ble",
".",
"ErrEIRPacketTooLong",
"\n",
"}",
"\n\n",
"h",
".",
"params",
".",
"advData",
".",
"AdvertisingDataLength",
"=",
"uint8",
"(",
"len",
"(",
"ad",
")",
")",
"\n",
"copy",
"(",
"h",
".",
"params",
".",
"advData",
".",
"AdvertisingData",
"[",
":",
"]",
",",
"ad",
")",
"\n",
"if",
"err",
":=",
"h",
".",
"Send",
"(",
"&",
"h",
".",
"params",
".",
"advData",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"h",
".",
"params",
".",
"scanResp",
".",
"ScanResponseDataLength",
"=",
"uint8",
"(",
"len",
"(",
"sr",
")",
")",
"\n",
"copy",
"(",
"h",
".",
"params",
".",
"scanResp",
".",
"ScanResponseData",
"[",
":",
"]",
",",
"sr",
")",
"\n",
"if",
"err",
":=",
"h",
".",
"Send",
"(",
"&",
"h",
".",
"params",
".",
"scanResp",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetAdvertisement sets advertising data and scanResp. | [
"SetAdvertisement",
"sets",
"advertising",
"data",
"and",
"scanResp",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/gap.go#L197-L214 |
10,189 | currantlabs/ble | linux/hci/signal_gen.go | Marshal | func (s *CommandReject) Marshal() []byte {
buf := bytes.NewBuffer(make([]byte, 0))
binary.Write(buf, binary.LittleEndian, s)
return buf.Bytes()
} | go | func (s *CommandReject) Marshal() []byte {
buf := bytes.NewBuffer(make([]byte, 0))
binary.Write(buf, binary.LittleEndian, s)
return buf.Bytes()
} | [
"func",
"(",
"s",
"*",
"CommandReject",
")",
"Marshal",
"(",
")",
"[",
"]",
"byte",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
")",
")",
"\n",
"binary",
".",
"Write",
"(",
"buf",
",",
"binary",
".",
"LittleEndian",
",",
"s",
")",
"\n",
"return",
"buf",
".",
"Bytes",
"(",
")",
"\n",
"}"
] | // Marshal serializes the command parameters into binary form. | [
"Marshal",
"serializes",
"the",
"command",
"parameters",
"into",
"binary",
"form",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/signal_gen.go#L21-L25 |
10,190 | currantlabs/ble | linux/hci/signal_gen.go | Unmarshal | func (s *CommandReject) Unmarshal(b []byte) error {
return binary.Read(bytes.NewBuffer(b), binary.LittleEndian, s)
} | go | func (s *CommandReject) Unmarshal(b []byte) error {
return binary.Read(bytes.NewBuffer(b), binary.LittleEndian, s)
} | [
"func",
"(",
"s",
"*",
"CommandReject",
")",
"Unmarshal",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"binary",
".",
"Read",
"(",
"bytes",
".",
"NewBuffer",
"(",
"b",
")",
",",
"binary",
".",
"LittleEndian",
",",
"s",
")",
"\n",
"}"
] | // Unmarshal de-serializes the binary data and stores the result in the receiver. | [
"Unmarshal",
"de",
"-",
"serializes",
"the",
"binary",
"data",
"and",
"stores",
"the",
"result",
"in",
"the",
"receiver",
"."
] | c1d21c164cf83d3360fd5abd73a3405cb588c06c | https://github.com/currantlabs/ble/blob/c1d21c164cf83d3360fd5abd73a3405cb588c06c/linux/hci/signal_gen.go#L28-L30 |
10,191 | elithrar/simple-scrypt | scrypt.go | CompareHashAndPassword | func CompareHashAndPassword(hash []byte, password []byte) error {
// Decode existing hash, retrieve params and salt.
params, salt, dk, err := decodeHash(hash)
if err != nil {
return err
}
// scrypt the cleartext password with the same parameters and salt
other, err := scrypt.Key(password, salt, params.N, params.R, params.P, params.DKLen)
if err != nil {
return err
}
// Constant time comparison
if subtle.ConstantTimeCompare(dk, other) == 1 {
return nil
}
return ErrMismatchedHashAndPassword
} | go | func CompareHashAndPassword(hash []byte, password []byte) error {
// Decode existing hash, retrieve params and salt.
params, salt, dk, err := decodeHash(hash)
if err != nil {
return err
}
// scrypt the cleartext password with the same parameters and salt
other, err := scrypt.Key(password, salt, params.N, params.R, params.P, params.DKLen)
if err != nil {
return err
}
// Constant time comparison
if subtle.ConstantTimeCompare(dk, other) == 1 {
return nil
}
return ErrMismatchedHashAndPassword
} | [
"func",
"CompareHashAndPassword",
"(",
"hash",
"[",
"]",
"byte",
",",
"password",
"[",
"]",
"byte",
")",
"error",
"{",
"// Decode existing hash, retrieve params and salt.",
"params",
",",
"salt",
",",
"dk",
",",
"err",
":=",
"decodeHash",
"(",
"hash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// scrypt the cleartext password with the same parameters and salt",
"other",
",",
"err",
":=",
"scrypt",
".",
"Key",
"(",
"password",
",",
"salt",
",",
"params",
".",
"N",
",",
"params",
".",
"R",
",",
"params",
".",
"P",
",",
"params",
".",
"DKLen",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Constant time comparison",
"if",
"subtle",
".",
"ConstantTimeCompare",
"(",
"dk",
",",
"other",
")",
"==",
"1",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"ErrMismatchedHashAndPassword",
"\n",
"}"
] | // CompareHashAndPassword compares a derived key with the possible cleartext
// equivalent. The parameters used in the provided derived key are used.
// The comparison performed by this function is constant-time. It returns nil
// on success, and an error if the derived keys do not match. | [
"CompareHashAndPassword",
"compares",
"a",
"derived",
"key",
"with",
"the",
"possible",
"cleartext",
"equivalent",
".",
"The",
"parameters",
"used",
"in",
"the",
"provided",
"derived",
"key",
"are",
"used",
".",
"The",
"comparison",
"performed",
"by",
"this",
"function",
"is",
"constant",
"-",
"time",
".",
"It",
"returns",
"nil",
"on",
"success",
"and",
"an",
"error",
"if",
"the",
"derived",
"keys",
"do",
"not",
"match",
"."
] | 28a8a89db0e1201d1b61b8ee90597fd7d035c0d5 | https://github.com/elithrar/simple-scrypt/blob/28a8a89db0e1201d1b61b8ee90597fd7d035c0d5/scrypt.go#L102-L121 |
10,192 | elithrar/simple-scrypt | scrypt.go | Check | func (p *Params) Check() error {
// Validate N
if p.N > maxInt || p.N <= 1 || p.N%2 != 0 {
return ErrInvalidParams
}
// Validate r
if p.R < 1 || p.R > maxInt {
return ErrInvalidParams
}
// Validate p
if p.P < 1 || p.P > maxInt {
return ErrInvalidParams
}
// Validate that r & p don't exceed 2^30 and that N, r, p values don't
// exceed the limits defined by the scrypt algorithm.
if uint64(p.R)*uint64(p.P) >= 1<<30 || p.R > maxInt/128/p.P || p.R > maxInt/256 || p.N > maxInt/128/p.R {
return ErrInvalidParams
}
// Validate the salt length
if p.SaltLen < minSaltLen || p.SaltLen > maxInt {
return ErrInvalidParams
}
// Validate the derived key length
if p.DKLen < minDKLen || p.DKLen > maxInt {
return ErrInvalidParams
}
return nil
} | go | func (p *Params) Check() error {
// Validate N
if p.N > maxInt || p.N <= 1 || p.N%2 != 0 {
return ErrInvalidParams
}
// Validate r
if p.R < 1 || p.R > maxInt {
return ErrInvalidParams
}
// Validate p
if p.P < 1 || p.P > maxInt {
return ErrInvalidParams
}
// Validate that r & p don't exceed 2^30 and that N, r, p values don't
// exceed the limits defined by the scrypt algorithm.
if uint64(p.R)*uint64(p.P) >= 1<<30 || p.R > maxInt/128/p.P || p.R > maxInt/256 || p.N > maxInt/128/p.R {
return ErrInvalidParams
}
// Validate the salt length
if p.SaltLen < minSaltLen || p.SaltLen > maxInt {
return ErrInvalidParams
}
// Validate the derived key length
if p.DKLen < minDKLen || p.DKLen > maxInt {
return ErrInvalidParams
}
return nil
} | [
"func",
"(",
"p",
"*",
"Params",
")",
"Check",
"(",
")",
"error",
"{",
"// Validate N",
"if",
"p",
".",
"N",
">",
"maxInt",
"||",
"p",
".",
"N",
"<=",
"1",
"||",
"p",
".",
"N",
"%",
"2",
"!=",
"0",
"{",
"return",
"ErrInvalidParams",
"\n",
"}",
"\n\n",
"// Validate r",
"if",
"p",
".",
"R",
"<",
"1",
"||",
"p",
".",
"R",
">",
"maxInt",
"{",
"return",
"ErrInvalidParams",
"\n",
"}",
"\n\n",
"// Validate p",
"if",
"p",
".",
"P",
"<",
"1",
"||",
"p",
".",
"P",
">",
"maxInt",
"{",
"return",
"ErrInvalidParams",
"\n",
"}",
"\n\n",
"// Validate that r & p don't exceed 2^30 and that N, r, p values don't",
"// exceed the limits defined by the scrypt algorithm.",
"if",
"uint64",
"(",
"p",
".",
"R",
")",
"*",
"uint64",
"(",
"p",
".",
"P",
")",
">=",
"1",
"<<",
"30",
"||",
"p",
".",
"R",
">",
"maxInt",
"/",
"128",
"/",
"p",
".",
"P",
"||",
"p",
".",
"R",
">",
"maxInt",
"/",
"256",
"||",
"p",
".",
"N",
">",
"maxInt",
"/",
"128",
"/",
"p",
".",
"R",
"{",
"return",
"ErrInvalidParams",
"\n",
"}",
"\n\n",
"// Validate the salt length",
"if",
"p",
".",
"SaltLen",
"<",
"minSaltLen",
"||",
"p",
".",
"SaltLen",
">",
"maxInt",
"{",
"return",
"ErrInvalidParams",
"\n",
"}",
"\n\n",
"// Validate the derived key length",
"if",
"p",
".",
"DKLen",
"<",
"minDKLen",
"||",
"p",
".",
"DKLen",
">",
"maxInt",
"{",
"return",
"ErrInvalidParams",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Check checks that the parameters are valid for input into the
// scrypt key derivation function. | [
"Check",
"checks",
"that",
"the",
"parameters",
"are",
"valid",
"for",
"input",
"into",
"the",
"scrypt",
"key",
"derivation",
"function",
"."
] | 28a8a89db0e1201d1b61b8ee90597fd7d035c0d5 | https://github.com/elithrar/simple-scrypt/blob/28a8a89db0e1201d1b61b8ee90597fd7d035c0d5/scrypt.go#L125-L158 |
10,193 | djherbis/buffer | list.go | Pop | func (l *List) Pop() (b Buffer) {
b = (*l)[0]
*l = (*l)[1:]
return b
} | go | func (l *List) Pop() (b Buffer) {
b = (*l)[0]
*l = (*l)[1:]
return b
} | [
"func",
"(",
"l",
"*",
"List",
")",
"Pop",
"(",
")",
"(",
"b",
"Buffer",
")",
"{",
"b",
"=",
"(",
"*",
"l",
")",
"[",
"0",
"]",
"\n",
"*",
"l",
"=",
"(",
"*",
"l",
")",
"[",
"1",
":",
"]",
"\n",
"return",
"b",
"\n",
"}"
] | // Pop removes and returns a Buffer from the front of the List | [
"Pop",
"removes",
"and",
"returns",
"a",
"Buffer",
"from",
"the",
"front",
"of",
"the",
"List"
] | 3c732ee9b562a82a6e1354ea29bbc7ddd9f333b3 | https://github.com/djherbis/buffer/blob/3c732ee9b562a82a6e1354ea29bbc7ddd9f333b3/list.go#L43-L47 |
10,194 | djherbis/buffer | limio/limit.go | LimitWriter | func LimitWriter(w io.Writer, n int64) io.Writer {
return &limitedWriter{W: w, N: n}
} | go | func LimitWriter(w io.Writer, n int64) io.Writer {
return &limitedWriter{W: w, N: n}
} | [
"func",
"LimitWriter",
"(",
"w",
"io",
".",
"Writer",
",",
"n",
"int64",
")",
"io",
".",
"Writer",
"{",
"return",
"&",
"limitedWriter",
"{",
"W",
":",
"w",
",",
"N",
":",
"n",
"}",
"\n",
"}"
] | // LimitWriter works like io.LimitReader. It writes at most n bytes
// to the underlying Writer. It returns io.ErrShortWrite if more than n
// bytes are attempted to be written. | [
"LimitWriter",
"works",
"like",
"io",
".",
"LimitReader",
".",
"It",
"writes",
"at",
"most",
"n",
"bytes",
"to",
"the",
"underlying",
"Writer",
".",
"It",
"returns",
"io",
".",
"ErrShortWrite",
"if",
"more",
"than",
"n",
"bytes",
"are",
"attempted",
"to",
"be",
"written",
"."
] | 3c732ee9b562a82a6e1354ea29bbc7ddd9f333b3 | https://github.com/djherbis/buffer/blob/3c732ee9b562a82a6e1354ea29bbc7ddd9f333b3/limio/limit.go#L29-L31 |
10,195 | djherbis/buffer | wrapio/limitwrap.go | NewWrapper | func NewWrapper(rwa ReadWriterAt, L, O, N int64) *Wrapper {
return &Wrapper{
L: L,
O: O,
N: N,
rwa: rwa,
}
} | go | func NewWrapper(rwa ReadWriterAt, L, O, N int64) *Wrapper {
return &Wrapper{
L: L,
O: O,
N: N,
rwa: rwa,
}
} | [
"func",
"NewWrapper",
"(",
"rwa",
"ReadWriterAt",
",",
"L",
",",
"O",
",",
"N",
"int64",
")",
"*",
"Wrapper",
"{",
"return",
"&",
"Wrapper",
"{",
"L",
":",
"L",
",",
"O",
":",
"O",
",",
"N",
":",
"N",
",",
"rwa",
":",
"rwa",
",",
"}",
"\n",
"}"
] | // NewWrapper creates a Wrapper based on ReadWriterAt rwa.
// L is the current length, O is the current offset, and N is offset at which we "wrap". | [
"NewWrapper",
"creates",
"a",
"Wrapper",
"based",
"on",
"ReadWriterAt",
"rwa",
".",
"L",
"is",
"the",
"current",
"length",
"O",
"is",
"the",
"current",
"offset",
"and",
"N",
"is",
"offset",
"at",
"which",
"we",
"wrap",
"."
] | 3c732ee9b562a82a6e1354ea29bbc7ddd9f333b3 | https://github.com/djherbis/buffer/blob/3c732ee9b562a82a6e1354ea29bbc7ddd9f333b3/wrapio/limitwrap.go#L30-L37 |
10,196 | djherbis/buffer | wrapio/wrap.go | NewWrapWriter | func NewWrapWriter(w io.WriterAt, off int64, wrapAt int64) *WrapWriter {
return &WrapWriter{
&wrapper{
doat: w.WriteAt,
off: (off % wrapAt),
wrapAt: wrapAt,
},
}
} | go | func NewWrapWriter(w io.WriterAt, off int64, wrapAt int64) *WrapWriter {
return &WrapWriter{
&wrapper{
doat: w.WriteAt,
off: (off % wrapAt),
wrapAt: wrapAt,
},
}
} | [
"func",
"NewWrapWriter",
"(",
"w",
"io",
".",
"WriterAt",
",",
"off",
"int64",
",",
"wrapAt",
"int64",
")",
"*",
"WrapWriter",
"{",
"return",
"&",
"WrapWriter",
"{",
"&",
"wrapper",
"{",
"doat",
":",
"w",
".",
"WriteAt",
",",
"off",
":",
"(",
"off",
"%",
"wrapAt",
")",
",",
"wrapAt",
":",
"wrapAt",
",",
"}",
",",
"}",
"\n",
"}"
] | // NewWrapWriter creates a WrapWriter starting at offset off, and wrapping at offset wrapAt. | [
"NewWrapWriter",
"creates",
"a",
"WrapWriter",
"starting",
"at",
"offset",
"off",
"and",
"wrapping",
"at",
"offset",
"wrapAt",
"."
] | 3c732ee9b562a82a6e1354ea29bbc7ddd9f333b3 | https://github.com/djherbis/buffer/blob/3c732ee9b562a82a6e1354ea29bbc7ddd9f333b3/wrapio/wrap.go#L46-L54 |
10,197 | djherbis/buffer | wrapio/wrap.go | Write | func (w *WrapWriter) Write(p []byte) (n int, err error) {
n, err = Wrap(w, p, w.off, w.wrapAt)
w.off = (w.off + int64(n)) % w.wrapAt
return n, err
} | go | func (w *WrapWriter) Write(p []byte) (n int, err error) {
n, err = Wrap(w, p, w.off, w.wrapAt)
w.off = (w.off + int64(n)) % w.wrapAt
return n, err
} | [
"func",
"(",
"w",
"*",
"WrapWriter",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"n",
",",
"err",
"=",
"Wrap",
"(",
"w",
",",
"p",
",",
"w",
".",
"off",
",",
"w",
".",
"wrapAt",
")",
"\n",
"w",
".",
"off",
"=",
"(",
"w",
".",
"off",
"+",
"int64",
"(",
"n",
")",
")",
"%",
"w",
".",
"wrapAt",
"\n",
"return",
"n",
",",
"err",
"\n",
"}"
] | // Write writes p starting at the current offset, wrapping when it reaches the end.
// The current offset is shifted forward by the amount written. | [
"Write",
"writes",
"p",
"starting",
"at",
"the",
"current",
"offset",
"wrapping",
"when",
"it",
"reaches",
"the",
"end",
".",
"The",
"current",
"offset",
"is",
"shifted",
"forward",
"by",
"the",
"amount",
"written",
"."
] | 3c732ee9b562a82a6e1354ea29bbc7ddd9f333b3 | https://github.com/djherbis/buffer/blob/3c732ee9b562a82a6e1354ea29bbc7ddd9f333b3/wrapio/wrap.go#L58-L62 |
10,198 | djherbis/buffer | wrapio/wrap.go | WriteAt | func (w *WrapWriter) WriteAt(p []byte, off int64) (n int, err error) {
return Wrap(w, p, off, w.wrapAt)
} | go | func (w *WrapWriter) WriteAt(p []byte, off int64) (n int, err error) {
return Wrap(w, p, off, w.wrapAt)
} | [
"func",
"(",
"w",
"*",
"WrapWriter",
")",
"WriteAt",
"(",
"p",
"[",
"]",
"byte",
",",
"off",
"int64",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"return",
"Wrap",
"(",
"w",
",",
"p",
",",
"off",
",",
"w",
".",
"wrapAt",
")",
"\n",
"}"
] | // WriteAt writes p starting at offset off, wrapping when it reaches the end. | [
"WriteAt",
"writes",
"p",
"starting",
"at",
"offset",
"off",
"wrapping",
"when",
"it",
"reaches",
"the",
"end",
"."
] | 3c732ee9b562a82a6e1354ea29bbc7ddd9f333b3 | https://github.com/djherbis/buffer/blob/3c732ee9b562a82a6e1354ea29bbc7ddd9f333b3/wrapio/wrap.go#L65-L67 |
10,199 | djherbis/buffer | wrapio/wrap.go | NewWrapReader | func NewWrapReader(r io.ReaderAt, off int64, wrapAt int64) *WrapReader {
return &WrapReader{
&wrapper{
doat: r.ReadAt,
off: (off % wrapAt),
wrapAt: wrapAt,
},
}
} | go | func NewWrapReader(r io.ReaderAt, off int64, wrapAt int64) *WrapReader {
return &WrapReader{
&wrapper{
doat: r.ReadAt,
off: (off % wrapAt),
wrapAt: wrapAt,
},
}
} | [
"func",
"NewWrapReader",
"(",
"r",
"io",
".",
"ReaderAt",
",",
"off",
"int64",
",",
"wrapAt",
"int64",
")",
"*",
"WrapReader",
"{",
"return",
"&",
"WrapReader",
"{",
"&",
"wrapper",
"{",
"doat",
":",
"r",
".",
"ReadAt",
",",
"off",
":",
"(",
"off",
"%",
"wrapAt",
")",
",",
"wrapAt",
":",
"wrapAt",
",",
"}",
",",
"}",
"\n",
"}"
] | // NewWrapReader creates a WrapReader starting at offset off, and wrapping at offset wrapAt. | [
"NewWrapReader",
"creates",
"a",
"WrapReader",
"starting",
"at",
"offset",
"off",
"and",
"wrapping",
"at",
"offset",
"wrapAt",
"."
] | 3c732ee9b562a82a6e1354ea29bbc7ddd9f333b3 | https://github.com/djherbis/buffer/blob/3c732ee9b562a82a6e1354ea29bbc7ddd9f333b3/wrapio/wrap.go#L75-L83 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.