id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
12,600 | FDio/govpp | extras/libmemif/packethandle.go | WritePacketData | func (handle *MemifPacketHandle) WritePacketData(data []byte) (err error) {
handle.writeMu.Lock()
defer handle.writeMu.Unlock()
if handle.stop {
err = io.EOF
return
}
count, err := handle.memif.TxBurst(handle.queueId, []RawPacketData{data})
if err != nil {
return
}
if count == 0 {
err = io.EOF
}
... | go | func (handle *MemifPacketHandle) WritePacketData(data []byte) (err error) {
handle.writeMu.Lock()
defer handle.writeMu.Unlock()
if handle.stop {
err = io.EOF
return
}
count, err := handle.memif.TxBurst(handle.queueId, []RawPacketData{data})
if err != nil {
return
}
if count == 0 {
err = io.EOF
}
... | [
"func",
"(",
"handle",
"*",
"MemifPacketHandle",
")",
"WritePacketData",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"handle",
".",
"writeMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"handle",
".",
"writeMu",
".",
"Unlock",
"(",
... | // Writes packet data to memif in burst of 1 packet. In case no packet is sent, this method throws io.EOF error and
// called should stop trying to write packets. | [
"Writes",
"packet",
"data",
"to",
"memif",
"in",
"burst",
"of",
"1",
"packet",
".",
"In",
"case",
"no",
"packet",
"is",
"sent",
"this",
"method",
"throws",
"io",
".",
"EOF",
"error",
"and",
"called",
"should",
"stop",
"trying",
"to",
"write",
"packets",
... | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/packethandle.go#L112-L132 |
12,601 | FDio/govpp | extras/libmemif/packethandle.go | Close | func (handle *MemifPacketHandle) Close() {
handle.closeMu.Lock()
defer handle.closeMu.Unlock()
// wait for packet reader to stop
handle.readMu.Lock()
defer handle.readMu.Unlock()
// wait for packet writer to stop
handle.writeMu.Lock()
defer handle.writeMu.Unlock()
// stop reading and writing
handle.stop = ... | go | func (handle *MemifPacketHandle) Close() {
handle.closeMu.Lock()
defer handle.closeMu.Unlock()
// wait for packet reader to stop
handle.readMu.Lock()
defer handle.readMu.Unlock()
// wait for packet writer to stop
handle.writeMu.Lock()
defer handle.writeMu.Unlock()
// stop reading and writing
handle.stop = ... | [
"func",
"(",
"handle",
"*",
"MemifPacketHandle",
")",
"Close",
"(",
")",
"{",
"handle",
".",
"closeMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"handle",
".",
"closeMu",
".",
"Unlock",
"(",
")",
"\n\n",
"// wait for packet reader to stop",
"handle",
".",
"re... | // Waits for all read and write operations to finish and then prevents more from occurring. Handle can be closed only
// once and then can never be opened again. | [
"Waits",
"for",
"all",
"read",
"and",
"write",
"operations",
"to",
"finish",
"and",
"then",
"prevents",
"more",
"from",
"occurring",
".",
"Handle",
"can",
"be",
"closed",
"only",
"once",
"and",
"then",
"can",
"never",
"be",
"opened",
"again",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/packethandle.go#L136-L150 |
12,602 | FDio/govpp | api/binapi.go | RegisterMessage | func RegisterMessage(x Message, name string) {
name = x.GetMessageName() + "_" + x.GetCrcString()
/*if _, ok := registeredMessages[name]; ok {
panic(fmt.Errorf("govpp: duplicate message registered: %s (%s)", name, x.GetCrcString()))
}*/
registeredMessages[name] = x
} | go | func RegisterMessage(x Message, name string) {
name = x.GetMessageName() + "_" + x.GetCrcString()
/*if _, ok := registeredMessages[name]; ok {
panic(fmt.Errorf("govpp: duplicate message registered: %s (%s)", name, x.GetCrcString()))
}*/
registeredMessages[name] = x
} | [
"func",
"RegisterMessage",
"(",
"x",
"Message",
",",
"name",
"string",
")",
"{",
"name",
"=",
"x",
".",
"GetMessageName",
"(",
")",
"+",
"\"",
"\"",
"+",
"x",
".",
"GetCrcString",
"(",
")",
"\n",
"/*if _, ok := registeredMessages[name]; ok {\n\t\tpanic(fmt.Error... | // RegisterMessage is called from generated code to register message. | [
"RegisterMessage",
"is",
"called",
"from",
"generated",
"code",
"to",
"register",
"message",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/api/binapi.go#L124-L130 |
12,603 | FDio/govpp | core/stats.go | ConnectStats | func ConnectStats(stats adapter.StatsAPI) (*StatsConnection, error) {
c := newStatsConnection(stats)
if err := c.connectClient(); err != nil {
return nil, err
}
return c, nil
} | go | func ConnectStats(stats adapter.StatsAPI) (*StatsConnection, error) {
c := newStatsConnection(stats)
if err := c.connectClient(); err != nil {
return nil, err
}
return c, nil
} | [
"func",
"ConnectStats",
"(",
"stats",
"adapter",
".",
"StatsAPI",
")",
"(",
"*",
"StatsConnection",
",",
"error",
")",
"{",
"c",
":=",
"newStatsConnection",
"(",
"stats",
")",
"\n\n",
"if",
"err",
":=",
"c",
".",
"connectClient",
"(",
")",
";",
"err",
... | // Connect connects to Stats API using specified adapter and returns a connection handle.
// This call blocks until it is either connected, or an error occurs.
// Only one connection attempt will be performed. | [
"Connect",
"connects",
"to",
"Stats",
"API",
"using",
"specified",
"adapter",
"and",
"returns",
"a",
"connection",
"handle",
".",
"This",
"call",
"blocks",
"until",
"it",
"is",
"either",
"connected",
"or",
"an",
"error",
"occurs",
".",
"Only",
"one",
"connec... | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/stats.go#L78-L86 |
12,604 | FDio/govpp | core/stats.go | Disconnect | func (c *StatsConnection) Disconnect() {
if c == nil {
return
}
if c.statsClient != nil {
c.disconnectClient()
}
} | go | func (c *StatsConnection) Disconnect() {
if c == nil {
return
}
if c.statsClient != nil {
c.disconnectClient()
}
} | [
"func",
"(",
"c",
"*",
"StatsConnection",
")",
"Disconnect",
"(",
")",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"statsClient",
"!=",
"nil",
"{",
"c",
".",
"disconnectClient",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Disconnect disconnects from Stats API and releases all connection-related resources. | [
"Disconnect",
"disconnects",
"from",
"Stats",
"API",
"and",
"releases",
"all",
"connection",
"-",
"related",
"resources",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/stats.go#L104-L112 |
12,605 | FDio/govpp | core/stats.go | GetSystemStats | func (c *StatsConnection) GetSystemStats() (*api.SystemStats, error) {
stats, err := c.statsClient.DumpStats(SystemStatsPrefix)
if err != nil {
return nil, err
}
sysStats := &api.SystemStats{}
for _, stat := range stats {
switch stat.Name {
case SystemStats_VectorRate:
sysStats.VectorRate = scalarStatTo... | go | func (c *StatsConnection) GetSystemStats() (*api.SystemStats, error) {
stats, err := c.statsClient.DumpStats(SystemStatsPrefix)
if err != nil {
return nil, err
}
sysStats := &api.SystemStats{}
for _, stat := range stats {
switch stat.Name {
case SystemStats_VectorRate:
sysStats.VectorRate = scalarStatTo... | [
"func",
"(",
"c",
"*",
"StatsConnection",
")",
"GetSystemStats",
"(",
")",
"(",
"*",
"api",
".",
"SystemStats",
",",
"error",
")",
"{",
"stats",
",",
"err",
":=",
"c",
".",
"statsClient",
".",
"DumpStats",
"(",
"SystemStatsPrefix",
")",
"\n",
"if",
"er... | // GetSystemStats retrieves VPP system stats. | [
"GetSystemStats",
"retrieves",
"VPP",
"system",
"stats",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/stats.go#L121-L145 |
12,606 | FDio/govpp | core/stats.go | GetErrorStats | func (c *StatsConnection) GetErrorStats(names ...string) (*api.ErrorStats, error) {
var patterns []string
if len(names) > 0 {
patterns = make([]string, len(names))
for i, name := range names {
patterns[i] = CounterStatsPrefix + name
}
} else {
// retrieve all error counters by default
patterns = []strin... | go | func (c *StatsConnection) GetErrorStats(names ...string) (*api.ErrorStats, error) {
var patterns []string
if len(names) > 0 {
patterns = make([]string, len(names))
for i, name := range names {
patterns[i] = CounterStatsPrefix + name
}
} else {
// retrieve all error counters by default
patterns = []strin... | [
"func",
"(",
"c",
"*",
"StatsConnection",
")",
"GetErrorStats",
"(",
"names",
"...",
"string",
")",
"(",
"*",
"api",
".",
"ErrorStats",
",",
"error",
")",
"{",
"var",
"patterns",
"[",
"]",
"string",
"\n",
"if",
"len",
"(",
"names",
")",
">",
"0",
"... | // GetErrorStats retrieves VPP error stats. | [
"GetErrorStats",
"retrieves",
"VPP",
"error",
"stats",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/stats.go#L148-L188 |
12,607 | FDio/govpp | core/stats.go | GetNodeStats | func (c *StatsConnection) GetNodeStats() (*api.NodeStats, error) {
stats, err := c.statsClient.DumpStats(NodeStatsPrefix)
if err != nil {
return nil, err
}
nodeStats := &api.NodeStats{}
var setPerNode = func(perNode []uint64, fn func(c *api.NodeCounters, v uint64)) {
if nodeStats.Nodes == nil {
nodeStats.... | go | func (c *StatsConnection) GetNodeStats() (*api.NodeStats, error) {
stats, err := c.statsClient.DumpStats(NodeStatsPrefix)
if err != nil {
return nil, err
}
nodeStats := &api.NodeStats{}
var setPerNode = func(perNode []uint64, fn func(c *api.NodeCounters, v uint64)) {
if nodeStats.Nodes == nil {
nodeStats.... | [
"func",
"(",
"c",
"*",
"StatsConnection",
")",
"GetNodeStats",
"(",
")",
"(",
"*",
"api",
".",
"NodeStats",
",",
"error",
")",
"{",
"stats",
",",
"err",
":=",
"c",
".",
"statsClient",
".",
"DumpStats",
"(",
"NodeStatsPrefix",
")",
"\n",
"if",
"err",
... | // GetNodeStats retrieves VPP per node stats. | [
"GetNodeStats",
"retrieves",
"VPP",
"per",
"node",
"stats",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/stats.go#L191-L252 |
12,608 | FDio/govpp | core/stats.go | GetBufferStats | func (c *StatsConnection) GetBufferStats() (*api.BufferStats, error) {
stats, err := c.statsClient.DumpStats(BufferStatsPrefix)
if err != nil {
return nil, err
}
bufStats := &api.BufferStats{
Buffer: map[string]api.BufferPool{},
}
for _, stat := range stats {
d, f := path.Split(stat.Name)
d = strings.Tr... | go | func (c *StatsConnection) GetBufferStats() (*api.BufferStats, error) {
stats, err := c.statsClient.DumpStats(BufferStatsPrefix)
if err != nil {
return nil, err
}
bufStats := &api.BufferStats{
Buffer: map[string]api.BufferPool{},
}
for _, stat := range stats {
d, f := path.Split(stat.Name)
d = strings.Tr... | [
"func",
"(",
"c",
"*",
"StatsConnection",
")",
"GetBufferStats",
"(",
")",
"(",
"*",
"api",
".",
"BufferStats",
",",
"error",
")",
"{",
"stats",
",",
"err",
":=",
"c",
".",
"statsClient",
".",
"DumpStats",
"(",
"BufferStatsPrefix",
")",
"\n",
"if",
"er... | // GetBufferStats retrieves VPP buffer pools stats. | [
"GetBufferStats",
"retrieves",
"VPP",
"buffer",
"pools",
"stats",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/stats.go#L399-L432 |
12,609 | FDio/govpp | codec/msg_codec.go | EncodeMsg | func (*MsgCodec) EncodeMsg(msg api.Message, msgID uint16) (data []byte, err error) {
if msg == nil {
return nil, errors.New("nil message passed in")
}
// try to recover panic which might possibly occur in struc.Pack call
defer func() {
if r := recover(); r != nil {
var ok bool
if err, ok = r.(error); !ok... | go | func (*MsgCodec) EncodeMsg(msg api.Message, msgID uint16) (data []byte, err error) {
if msg == nil {
return nil, errors.New("nil message passed in")
}
// try to recover panic which might possibly occur in struc.Pack call
defer func() {
if r := recover(); r != nil {
var ok bool
if err, ok = r.(error); !ok... | [
"func",
"(",
"*",
"MsgCodec",
")",
"EncodeMsg",
"(",
"msg",
"api",
".",
"Message",
",",
"msgID",
"uint16",
")",
"(",
"data",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"if",
"msg",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New... | // EncodeMsg encodes provided `Message` structure into its binary-encoded data representation. | [
"EncodeMsg",
"encodes",
"provided",
"Message",
"structure",
"into",
"its",
"binary",
"-",
"encoded",
"data",
"representation",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/codec/msg_codec.go#L56-L101 |
12,610 | FDio/govpp | codec/msg_codec.go | DecodeMsg | func (*MsgCodec) DecodeMsg(data []byte, msg api.Message) error {
if msg == nil {
return errors.New("nil message passed in")
}
var header interface{}
// check which header is expected
switch msg.GetMessageType() {
case api.RequestMessage:
header = new(VppRequestHeader)
case api.ReplyMessage:
header = new(... | go | func (*MsgCodec) DecodeMsg(data []byte, msg api.Message) error {
if msg == nil {
return errors.New("nil message passed in")
}
var header interface{}
// check which header is expected
switch msg.GetMessageType() {
case api.RequestMessage:
header = new(VppRequestHeader)
case api.ReplyMessage:
header = new(... | [
"func",
"(",
"*",
"MsgCodec",
")",
"DecodeMsg",
"(",
"data",
"[",
"]",
"byte",
",",
"msg",
"api",
".",
"Message",
")",
"error",
"{",
"if",
"msg",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
... | // DecodeMsg decodes binary-encoded data of a message into provided `Message` structure. | [
"DecodeMsg",
"decodes",
"binary",
"-",
"encoded",
"data",
"of",
"a",
"message",
"into",
"provided",
"Message",
"structure",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/codec/msg_codec.go#L104-L136 |
12,611 | FDio/govpp | adapter/mock/binapi/binapi_reflect.go | findFieldOfType | func findFieldOfType(reply reflect.Type, fieldName string) (reflect.StructField, bool) {
for reply.Kind() == reflect.Ptr {
reply = reply.Elem()
}
if reply.Kind() == reflect.Struct {
field, found := reply.FieldByName(fieldName)
return field, found
}
return reflect.StructField{}, false
} | go | func findFieldOfType(reply reflect.Type, fieldName string) (reflect.StructField, bool) {
for reply.Kind() == reflect.Ptr {
reply = reply.Elem()
}
if reply.Kind() == reflect.Struct {
field, found := reply.FieldByName(fieldName)
return field, found
}
return reflect.StructField{}, false
} | [
"func",
"findFieldOfType",
"(",
"reply",
"reflect",
".",
"Type",
",",
"fieldName",
"string",
")",
"(",
"reflect",
".",
"StructField",
",",
"bool",
")",
"{",
"for",
"reply",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"reply",
"=",
"reply",... | // findFieldOfType finds the field specified by its name in provided message defined as reflect.Type data type. | [
"findFieldOfType",
"finds",
"the",
"field",
"specified",
"by",
"its",
"name",
"in",
"provided",
"message",
"defined",
"as",
"reflect",
".",
"Type",
"data",
"type",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/mock/binapi/binapi_reflect.go#L28-L37 |
12,612 | FDio/govpp | adapter/mock/binapi/binapi_reflect.go | findFieldOfValue | func findFieldOfValue(reply reflect.Value, fieldName string) (reflect.Value, bool) {
if reply.Kind() == reflect.Struct {
field := reply.FieldByName(fieldName)
return field, field.IsValid()
} else if reply.Kind() == reflect.Ptr && reply.Elem().Kind() == reflect.Struct {
field := reply.Elem().FieldByName(fieldNam... | go | func findFieldOfValue(reply reflect.Value, fieldName string) (reflect.Value, bool) {
if reply.Kind() == reflect.Struct {
field := reply.FieldByName(fieldName)
return field, field.IsValid()
} else if reply.Kind() == reflect.Ptr && reply.Elem().Kind() == reflect.Struct {
field := reply.Elem().FieldByName(fieldNam... | [
"func",
"findFieldOfValue",
"(",
"reply",
"reflect",
".",
"Value",
",",
"fieldName",
"string",
")",
"(",
"reflect",
".",
"Value",
",",
"bool",
")",
"{",
"if",
"reply",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Struct",
"{",
"field",
":=",
"reply",
... | // findFieldOfValue finds the field specified by its name in provided message defined as reflect.Value data type. | [
"findFieldOfValue",
"finds",
"the",
"field",
"specified",
"by",
"its",
"name",
"in",
"provided",
"message",
"defined",
"as",
"reflect",
".",
"Value",
"data",
"type",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/mock/binapi/binapi_reflect.go#L40-L49 |
12,613 | FDio/govpp | adapter/mock/binapi/binapi_reflect.go | HasSwIfIdx | func HasSwIfIdx(msg reflect.Type) bool {
_, found := findFieldOfType(msg, swIfIndexName)
return found
} | go | func HasSwIfIdx(msg reflect.Type) bool {
_, found := findFieldOfType(msg, swIfIndexName)
return found
} | [
"func",
"HasSwIfIdx",
"(",
"msg",
"reflect",
".",
"Type",
")",
"bool",
"{",
"_",
",",
"found",
":=",
"findFieldOfType",
"(",
"msg",
",",
"swIfIndexName",
")",
"\n",
"return",
"found",
"\n",
"}"
] | // HasSwIfIdx checks whether provided message has the swIfIndex field. | [
"HasSwIfIdx",
"checks",
"whether",
"provided",
"message",
"has",
"the",
"swIfIndex",
"field",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/mock/binapi/binapi_reflect.go#L52-L55 |
12,614 | FDio/govpp | adapter/mock/binapi/binapi_reflect.go | SetSwIfIdx | func SetSwIfIdx(msg reflect.Value, swIfIndex uint32) {
if field, found := findFieldOfValue(msg, swIfIndexName); found {
field.Set(reflect.ValueOf(swIfIndex))
}
} | go | func SetSwIfIdx(msg reflect.Value, swIfIndex uint32) {
if field, found := findFieldOfValue(msg, swIfIndexName); found {
field.Set(reflect.ValueOf(swIfIndex))
}
} | [
"func",
"SetSwIfIdx",
"(",
"msg",
"reflect",
".",
"Value",
",",
"swIfIndex",
"uint32",
")",
"{",
"if",
"field",
",",
"found",
":=",
"findFieldOfValue",
"(",
"msg",
",",
"swIfIndexName",
")",
";",
"found",
"{",
"field",
".",
"Set",
"(",
"reflect",
".",
... | // SetSwIfIdx sets the swIfIndex field of provided message to provided value. | [
"SetSwIfIdx",
"sets",
"the",
"swIfIndex",
"field",
"of",
"provided",
"message",
"to",
"provided",
"value",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/mock/binapi/binapi_reflect.go#L58-L62 |
12,615 | FDio/govpp | adapter/mock/binapi/binapi_reflect.go | SetRetval | func SetRetval(msg reflect.Value, retVal int32) {
if field, found := findFieldOfValue(msg, retvalName); found {
field.Set(reflect.ValueOf(retVal))
}
} | go | func SetRetval(msg reflect.Value, retVal int32) {
if field, found := findFieldOfValue(msg, retvalName); found {
field.Set(reflect.ValueOf(retVal))
}
} | [
"func",
"SetRetval",
"(",
"msg",
"reflect",
".",
"Value",
",",
"retVal",
"int32",
")",
"{",
"if",
"field",
",",
"found",
":=",
"findFieldOfValue",
"(",
"msg",
",",
"retvalName",
")",
";",
"found",
"{",
"field",
".",
"Set",
"(",
"reflect",
".",
"ValueOf... | // SetRetval sets the retval field of provided message to provided value. | [
"SetRetval",
"sets",
"the",
"retval",
"field",
"of",
"provided",
"message",
"to",
"provided",
"value",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/mock/binapi/binapi_reflect.go#L65-L69 |
12,616 | FDio/govpp | cmd/binapi-generator/generate.go | getContext | func getContext(inputFile, outputDir string) (*context, error) {
if !strings.HasSuffix(inputFile, inputFileExt) {
return nil, fmt.Errorf("invalid input file name: %q", inputFile)
}
ctx := &context{
inputFile: inputFile,
}
// package name
inputFileName := filepath.Base(inputFile)
ctx.moduleName = inputFileN... | go | func getContext(inputFile, outputDir string) (*context, error) {
if !strings.HasSuffix(inputFile, inputFileExt) {
return nil, fmt.Errorf("invalid input file name: %q", inputFile)
}
ctx := &context{
inputFile: inputFile,
}
// package name
inputFileName := filepath.Base(inputFile)
ctx.moduleName = inputFileN... | [
"func",
"getContext",
"(",
"inputFile",
",",
"outputDir",
"string",
")",
"(",
"*",
"context",
",",
"error",
")",
"{",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"inputFile",
",",
"inputFileExt",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"... | // getContext returns context details of the code generation task | [
"getContext",
"returns",
"context",
"details",
"of",
"the",
"code",
"generation",
"task"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L52-L81 |
12,617 | FDio/govpp | cmd/binapi-generator/generate.go | generatePackage | func generatePackage(ctx *context, w *bufio.Writer) error {
logf("generating package %q", ctx.packageName)
// generate file header
generateHeader(ctx, w)
generateImports(ctx, w)
if ctx.includeAPIVersionCrc {
fmt.Fprintf(w, "// %s defines API version CRC of the VPP binary API module.\n", constAPIVersionCrc)
f... | go | func generatePackage(ctx *context, w *bufio.Writer) error {
logf("generating package %q", ctx.packageName)
// generate file header
generateHeader(ctx, w)
generateImports(ctx, w)
if ctx.includeAPIVersionCrc {
fmt.Fprintf(w, "// %s defines API version CRC of the VPP binary API module.\n", constAPIVersionCrc)
f... | [
"func",
"generatePackage",
"(",
"ctx",
"*",
"context",
",",
"w",
"*",
"bufio",
".",
"Writer",
")",
"error",
"{",
"logf",
"(",
"\"",
"\"",
",",
"ctx",
".",
"packageName",
")",
"\n\n",
"// generate file header",
"generateHeader",
"(",
"ctx",
",",
"w",
")",... | // generatePackage generates code for the parsed package data and writes it into w | [
"generatePackage",
"generates",
"code",
"for",
"the",
"parsed",
"package",
"data",
"and",
"writes",
"it",
"into",
"w"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L84-L171 |
12,618 | FDio/govpp | cmd/binapi-generator/generate.go | generateHeader | func generateHeader(ctx *context, w io.Writer) {
fmt.Fprintln(w, "// Code generated by GoVPP binapi-generator. DO NOT EDIT.")
fmt.Fprintf(w, "// source: %s\n", ctx.inputFile)
fmt.Fprintln(w)
fmt.Fprintln(w, "/*")
fmt.Fprintf(w, " Package %s is a generated from VPP binary API module '%s'.\n", ctx.packageName, ctx... | go | func generateHeader(ctx *context, w io.Writer) {
fmt.Fprintln(w, "// Code generated by GoVPP binapi-generator. DO NOT EDIT.")
fmt.Fprintf(w, "// source: %s\n", ctx.inputFile)
fmt.Fprintln(w)
fmt.Fprintln(w, "/*")
fmt.Fprintf(w, " Package %s is a generated from VPP binary API module '%s'.\n", ctx.packageName, ctx... | [
"func",
"generateHeader",
"(",
"ctx",
"*",
"context",
",",
"w",
"io",
".",
"Writer",
")",
"{",
"fmt",
".",
"Fprintln",
"(",
"w",
",",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\n",
"\"",
",",
"ctx",
".",
"inputFile",
... | // generateHeader writes generated package header into w | [
"generateHeader",
"writes",
"generated",
"package",
"header",
"into",
"w"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L174-L205 |
12,619 | FDio/govpp | cmd/binapi-generator/generate.go | generateImports | func generateImports(ctx *context, w io.Writer) {
fmt.Fprintf(w, "import api \"%s\"\n", govppApiImportPath)
fmt.Fprintf(w, "import struc \"%s\"\n", "github.com/lunixbochs/struc")
fmt.Fprintf(w, "import bytes \"%s\"\n", "bytes")
fmt.Fprintln(w)
fmt.Fprintf(w, "// Reference imports to suppress errors if they are no... | go | func generateImports(ctx *context, w io.Writer) {
fmt.Fprintf(w, "import api \"%s\"\n", govppApiImportPath)
fmt.Fprintf(w, "import struc \"%s\"\n", "github.com/lunixbochs/struc")
fmt.Fprintf(w, "import bytes \"%s\"\n", "bytes")
fmt.Fprintln(w)
fmt.Fprintf(w, "// Reference imports to suppress errors if they are no... | [
"func",
"generateImports",
"(",
"ctx",
"*",
"context",
",",
"w",
"io",
".",
"Writer",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"govppApiImportPath",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"... | // generateImports writes generated package imports into w | [
"generateImports",
"writes",
"generated",
"package",
"imports",
"into",
"w"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L208-L226 |
12,620 | FDio/govpp | cmd/binapi-generator/generate.go | generateComment | func generateComment(ctx *context, w io.Writer, goName string, vppName string, objKind string) {
if objKind == "service" {
fmt.Fprintf(w, "// %s represents VPP binary API services:\n", goName)
} else {
fmt.Fprintf(w, "// %s represents VPP binary API %s '%s':\n", goName, objKind, vppName)
}
if !ctx.includeComme... | go | func generateComment(ctx *context, w io.Writer, goName string, vppName string, objKind string) {
if objKind == "service" {
fmt.Fprintf(w, "// %s represents VPP binary API services:\n", goName)
} else {
fmt.Fprintf(w, "// %s represents VPP binary API %s '%s':\n", goName, objKind, vppName)
}
if !ctx.includeComme... | [
"func",
"generateComment",
"(",
"ctx",
"*",
"context",
",",
"w",
"io",
".",
"Writer",
",",
"goName",
"string",
",",
"vppName",
"string",
",",
"objKind",
"string",
")",
"{",
"if",
"objKind",
"==",
"\"",
"\"",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",... | // generateComment writes generated comment for the object into w | [
"generateComment",
"writes",
"generated",
"comment",
"for",
"the",
"object",
"into",
"w"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L229-L288 |
12,621 | FDio/govpp | cmd/binapi-generator/generate.go | generateServices | func generateServices(ctx *context, w *bufio.Writer, services []Service) {
// generate services comment
generateComment(ctx, w, "Services", "services", "service")
// generate interface
fmt.Fprintf(w, "type %s interface {\n", "Services")
for _, svc := range services {
generateService(ctx, w, &svc)
}
fmt.Fprint... | go | func generateServices(ctx *context, w *bufio.Writer, services []Service) {
// generate services comment
generateComment(ctx, w, "Services", "services", "service")
// generate interface
fmt.Fprintf(w, "type %s interface {\n", "Services")
for _, svc := range services {
generateService(ctx, w, &svc)
}
fmt.Fprint... | [
"func",
"generateServices",
"(",
"ctx",
"*",
"context",
",",
"w",
"*",
"bufio",
".",
"Writer",
",",
"services",
"[",
"]",
"Service",
")",
"{",
"// generate services comment",
"generateComment",
"(",
"ctx",
",",
"w",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",... | // generateServices writes generated code for the Services interface into w | [
"generateServices",
"writes",
"generated",
"code",
"for",
"the",
"Services",
"interface",
"into",
"w"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L291-L303 |
12,622 | FDio/govpp | cmd/binapi-generator/generate.go | generateService | func generateService(ctx *context, w io.Writer, svc *Service) {
reqTyp := camelCaseName(svc.RequestType)
// method name is same as parameter type name by default
method := reqTyp
if svc.Stream {
// use Dump as prefix instead of suffix for stream services
if m := strings.TrimSuffix(method, "Dump"); method != m ... | go | func generateService(ctx *context, w io.Writer, svc *Service) {
reqTyp := camelCaseName(svc.RequestType)
// method name is same as parameter type name by default
method := reqTyp
if svc.Stream {
// use Dump as prefix instead of suffix for stream services
if m := strings.TrimSuffix(method, "Dump"); method != m ... | [
"func",
"generateService",
"(",
"ctx",
"*",
"context",
",",
"w",
"io",
".",
"Writer",
",",
"svc",
"*",
"Service",
")",
"{",
"reqTyp",
":=",
"camelCaseName",
"(",
"svc",
".",
"RequestType",
")",
"\n\n",
"// method name is same as parameter type name by default",
... | // generateService writes generated code for the service into w | [
"generateService",
"writes",
"generated",
"code",
"for",
"the",
"service",
"into",
"w"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L306-L329 |
12,623 | FDio/govpp | cmd/binapi-generator/generate.go | generateEnum | func generateEnum(ctx *context, w io.Writer, enum *Enum) {
name := camelCaseName(enum.Name)
typ := binapiTypes[enum.Type]
logf(" writing enum %q (%s) with %d entries", enum.Name, name, len(enum.Entries))
// generate enum comment
generateComment(ctx, w, name, enum.Name, "enum")
// generate enum definition
fmt.... | go | func generateEnum(ctx *context, w io.Writer, enum *Enum) {
name := camelCaseName(enum.Name)
typ := binapiTypes[enum.Type]
logf(" writing enum %q (%s) with %d entries", enum.Name, name, len(enum.Entries))
// generate enum comment
generateComment(ctx, w, name, enum.Name, "enum")
// generate enum definition
fmt.... | [
"func",
"generateEnum",
"(",
"ctx",
"*",
"context",
",",
"w",
"io",
".",
"Writer",
",",
"enum",
"*",
"Enum",
")",
"{",
"name",
":=",
"camelCaseName",
"(",
"enum",
".",
"Name",
")",
"\n",
"typ",
":=",
"binapiTypes",
"[",
"enum",
".",
"Type",
"]",
"\... | // generateEnum writes generated code for the enum into w | [
"generateEnum",
"writes",
"generated",
"code",
"for",
"the",
"enum",
"into",
"w"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L332-L355 |
12,624 | FDio/govpp | cmd/binapi-generator/generate.go | generateAlias | func generateAlias(ctx *context, w io.Writer, alias *Alias) {
name := camelCaseName(alias.Name)
logf(" writing type %q (%s), length: %d", alias.Name, name, alias.Length)
// generate struct comment
generateComment(ctx, w, name, alias.Name, "alias")
// generate struct definition
fmt.Fprintf(w, "type %s ", name)
... | go | func generateAlias(ctx *context, w io.Writer, alias *Alias) {
name := camelCaseName(alias.Name)
logf(" writing type %q (%s), length: %d", alias.Name, name, alias.Length)
// generate struct comment
generateComment(ctx, w, name, alias.Name, "alias")
// generate struct definition
fmt.Fprintf(w, "type %s ", name)
... | [
"func",
"generateAlias",
"(",
"ctx",
"*",
"context",
",",
"w",
"io",
".",
"Writer",
",",
"alias",
"*",
"Alias",
")",
"{",
"name",
":=",
"camelCaseName",
"(",
"alias",
".",
"Name",
")",
"\n\n",
"logf",
"(",
"\"",
"\"",
",",
"alias",
".",
"Name",
","... | // generateAlias writes generated code for the alias into w | [
"generateAlias",
"writes",
"generated",
"code",
"for",
"the",
"alias",
"into",
"w"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L358-L377 |
12,625 | FDio/govpp | cmd/binapi-generator/generate.go | generateUnion | func generateUnion(ctx *context, w io.Writer, union *Union) {
name := camelCaseName(union.Name)
logf(" writing union %q (%s) with %d fields", union.Name, name, len(union.Fields))
// generate struct comment
generateComment(ctx, w, name, union.Name, "union")
// generate struct definition
fmt.Fprintln(w, "type", ... | go | func generateUnion(ctx *context, w io.Writer, union *Union) {
name := camelCaseName(union.Name)
logf(" writing union %q (%s) with %d fields", union.Name, name, len(union.Fields))
// generate struct comment
generateComment(ctx, w, name, union.Name, "union")
// generate struct definition
fmt.Fprintln(w, "type", ... | [
"func",
"generateUnion",
"(",
"ctx",
"*",
"context",
",",
"w",
"io",
".",
"Writer",
",",
"union",
"*",
"Union",
")",
"{",
"name",
":=",
"camelCaseName",
"(",
"union",
".",
"Name",
")",
"\n\n",
"logf",
"(",
"\"",
"\"",
",",
"union",
".",
"Name",
","... | // generateUnion writes generated code for the union into w | [
"generateUnion",
"writes",
"generated",
"code",
"for",
"the",
"union",
"into",
"w"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L380-L418 |
12,626 | FDio/govpp | cmd/binapi-generator/generate.go | generateType | func generateType(ctx *context, w io.Writer, typ *Type) {
name := camelCaseName(typ.Name)
logf(" writing type %q (%s) with %d fields", typ.Name, name, len(typ.Fields))
// generate struct comment
generateComment(ctx, w, name, typ.Name, "type")
// generate struct definition
fmt.Fprintf(w, "type %s struct {\n", n... | go | func generateType(ctx *context, w io.Writer, typ *Type) {
name := camelCaseName(typ.Name)
logf(" writing type %q (%s) with %d fields", typ.Name, name, len(typ.Fields))
// generate struct comment
generateComment(ctx, w, name, typ.Name, "type")
// generate struct definition
fmt.Fprintf(w, "type %s struct {\n", n... | [
"func",
"generateType",
"(",
"ctx",
"*",
"context",
",",
"w",
"io",
".",
"Writer",
",",
"typ",
"*",
"Type",
")",
"{",
"name",
":=",
"camelCaseName",
"(",
"typ",
".",
"Name",
")",
"\n\n",
"logf",
"(",
"\"",
"\"",
",",
"typ",
".",
"Name",
",",
"nam... | // generateType writes generated code for the type into w | [
"generateType",
"writes",
"generated",
"code",
"for",
"the",
"type",
"into",
"w"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L468-L500 |
12,627 | FDio/govpp | cmd/binapi-generator/generate.go | generateMessage | func generateMessage(ctx *context, w io.Writer, msg *Message) {
name := camelCaseName(msg.Name)
logf(" writing message %q (%s) with %d fields", msg.Name, name, len(msg.Fields))
// generate struct comment
generateComment(ctx, w, name, msg.Name, "message")
// generate struct definition
fmt.Fprintf(w, "type %s st... | go | func generateMessage(ctx *context, w io.Writer, msg *Message) {
name := camelCaseName(msg.Name)
logf(" writing message %q (%s) with %d fields", msg.Name, name, len(msg.Fields))
// generate struct comment
generateComment(ctx, w, name, msg.Name, "message")
// generate struct definition
fmt.Fprintf(w, "type %s st... | [
"func",
"generateMessage",
"(",
"ctx",
"*",
"context",
",",
"w",
"io",
".",
"Writer",
",",
"msg",
"*",
"Message",
")",
"{",
"name",
":=",
"camelCaseName",
"(",
"msg",
".",
"Name",
")",
"\n\n",
"logf",
"(",
"\"",
"\"",
",",
"msg",
".",
"Name",
",",
... | // generateMessage writes generated code for the message into w | [
"generateMessage",
"writes",
"generated",
"code",
"for",
"the",
"message",
"into",
"w"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L503-L568 |
12,628 | FDio/govpp | cmd/binapi-generator/generate.go | generateField | func generateField(ctx *context, w io.Writer, fields []Field, i int) {
field := fields[i]
fieldName := strings.TrimPrefix(field.Name, "_")
fieldName = camelCaseName(fieldName)
// generate length field for strings
if field.Type == "string" {
fmt.Fprintf(w, "\tXXX_%sLen uint32 `struc:\"sizeof=%s\"`\n", fieldName... | go | func generateField(ctx *context, w io.Writer, fields []Field, i int) {
field := fields[i]
fieldName := strings.TrimPrefix(field.Name, "_")
fieldName = camelCaseName(fieldName)
// generate length field for strings
if field.Type == "string" {
fmt.Fprintf(w, "\tXXX_%sLen uint32 `struc:\"sizeof=%s\"`\n", fieldName... | [
"func",
"generateField",
"(",
"ctx",
"*",
"context",
",",
"w",
"io",
".",
"Writer",
",",
"fields",
"[",
"]",
"Field",
",",
"i",
"int",
")",
"{",
"field",
":=",
"fields",
"[",
"i",
"]",
"\n\n",
"fieldName",
":=",
"strings",
".",
"TrimPrefix",
"(",
"... | // generateField writes generated code for the field into w | [
"generateField",
"writes",
"generated",
"code",
"for",
"the",
"field",
"into",
"w"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L571-L608 |
12,629 | FDio/govpp | cmd/binapi-generator/generate.go | generateTypeNameGetter | func generateTypeNameGetter(w io.Writer, structName, msgName string) {
fmt.Fprintf(w, `func (*%s) GetTypeName() string {
return %q
}
`, structName, msgName)
} | go | func generateTypeNameGetter(w io.Writer, structName, msgName string) {
fmt.Fprintf(w, `func (*%s) GetTypeName() string {
return %q
}
`, structName, msgName)
} | [
"func",
"generateTypeNameGetter",
"(",
"w",
"io",
".",
"Writer",
",",
"structName",
",",
"msgName",
"string",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"`func (*%s) GetTypeName() string {\n\treturn %q\n}\n`",
",",
"structName",
",",
"msgName",
")",
"\n",
"... | // generateTypeNameGetter generates getter for original VPP type name into the provider writer | [
"generateTypeNameGetter",
"generates",
"getter",
"for",
"original",
"VPP",
"type",
"name",
"into",
"the",
"provider",
"writer"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L619-L624 |
12,630 | FDio/govpp | cmd/binapi-generator/generate.go | generateCrcGetter | func generateCrcGetter(w io.Writer, structName, crc string) {
crc = strings.TrimPrefix(crc, "0x")
fmt.Fprintf(w, `func (*%s) GetCrcString() string {
return %q
}
`, structName, crc)
} | go | func generateCrcGetter(w io.Writer, structName, crc string) {
crc = strings.TrimPrefix(crc, "0x")
fmt.Fprintf(w, `func (*%s) GetCrcString() string {
return %q
}
`, structName, crc)
} | [
"func",
"generateCrcGetter",
"(",
"w",
"io",
".",
"Writer",
",",
"structName",
",",
"crc",
"string",
")",
"{",
"crc",
"=",
"strings",
".",
"TrimPrefix",
"(",
"crc",
",",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"`func (*%s) GetCrcSt... | // generateCrcGetter generates getter for CRC checksum of the message definition into the provider writer | [
"generateCrcGetter",
"generates",
"getter",
"for",
"CRC",
"checksum",
"of",
"the",
"message",
"definition",
"into",
"the",
"provider",
"writer"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L627-L633 |
12,631 | FDio/govpp | cmd/binapi-generator/generate.go | generateMessageTypeGetter | func generateMessageTypeGetter(w io.Writer, structName string, msgType MessageType) {
fmt.Fprintln(w, "func (*"+structName+") GetMessageType() api.MessageType {")
if msgType == requestMessage {
fmt.Fprintln(w, "\treturn api.RequestMessage")
} else if msgType == replyMessage {
fmt.Fprintln(w, "\treturn api.ReplyM... | go | func generateMessageTypeGetter(w io.Writer, structName string, msgType MessageType) {
fmt.Fprintln(w, "func (*"+structName+") GetMessageType() api.MessageType {")
if msgType == requestMessage {
fmt.Fprintln(w, "\treturn api.RequestMessage")
} else if msgType == replyMessage {
fmt.Fprintln(w, "\treturn api.ReplyM... | [
"func",
"generateMessageTypeGetter",
"(",
"w",
"io",
".",
"Writer",
",",
"structName",
"string",
",",
"msgType",
"MessageType",
")",
"{",
"fmt",
".",
"Fprintln",
"(",
"w",
",",
"\"",
"\"",
"+",
"structName",
"+",
"\"",
"\"",
")",
"\n",
"if",
"msgType",
... | // generateMessageTypeGetter generates message factory for the generated message into the provider writer | [
"generateMessageTypeGetter",
"generates",
"message",
"factory",
"for",
"the",
"generated",
"message",
"into",
"the",
"provider",
"writer"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/generate.go#L636-L648 |
12,632 | FDio/govpp | extras/libmemif/examples/raw-data/raw-data.go | SendPackets | func SendPackets(memif *libmemif.Memif, queueID uint8) {
defer wg.Done()
counter := 0
for {
select {
case <-time.After(3 * time.Second):
counter++
// Prepare fake packets.
packets := []libmemif.RawPacketData{
libmemif.RawPacketData("Packet #1 in burst number " + strconv.Itoa(counter)),
libmemif... | go | func SendPackets(memif *libmemif.Memif, queueID uint8) {
defer wg.Done()
counter := 0
for {
select {
case <-time.After(3 * time.Second):
counter++
// Prepare fake packets.
packets := []libmemif.RawPacketData{
libmemif.RawPacketData("Packet #1 in burst number " + strconv.Itoa(counter)),
libmemif... | [
"func",
"SendPackets",
"(",
"memif",
"*",
"libmemif",
".",
"Memif",
",",
"queueID",
"uint8",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n\n",
"counter",
":=",
"0",
"\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"time",
".",
"After",
"(",
"3"... | // SendPackets keeps sending bursts of 3 raw-data packets every 3 seconds into
// the selected queue. | [
"SendPackets",
"keeps",
"sending",
"bursts",
"of",
"3",
"raw",
"-",
"data",
"packets",
"every",
"3",
"seconds",
"into",
"the",
"selected",
"queue",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/examples/raw-data/raw-data.go#L139-L173 |
12,633 | FDio/govpp | adapter/vppapiclient/vppapiclient.go | NewVppClientWithInputQueueSize | func NewVppClientWithInputQueueSize(shmPrefix string, inputQueueSize uint16) adapter.VppAPI {
return &vppClient{
shmPrefix: shmPrefix,
inputQueueSize: inputQueueSize,
}
} | go | func NewVppClientWithInputQueueSize(shmPrefix string, inputQueueSize uint16) adapter.VppAPI {
return &vppClient{
shmPrefix: shmPrefix,
inputQueueSize: inputQueueSize,
}
} | [
"func",
"NewVppClientWithInputQueueSize",
"(",
"shmPrefix",
"string",
",",
"inputQueueSize",
"uint16",
")",
"adapter",
".",
"VppAPI",
"{",
"return",
"&",
"vppClient",
"{",
"shmPrefix",
":",
"shmPrefix",
",",
"inputQueueSize",
":",
"inputQueueSize",
",",
"}",
"\n",... | // NewVppClientWithInputQueueSize returns a new VPP binary API client with a custom input queue size. | [
"NewVppClientWithInputQueueSize",
"returns",
"a",
"new",
"VPP",
"binary",
"API",
"client",
"with",
"a",
"custom",
"input",
"queue",
"size",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/vppapiclient/vppapiclient.go#L118-L123 |
12,634 | FDio/govpp | adapter/vppapiclient/vppapiclient.go | Connect | func (a *vppClient) Connect() error {
if globalVppClient != nil {
return fmt.Errorf("already connected to binary API, disconnect first")
}
rxQlen := C.int(a.inputQueueSize)
var rc C.int
if a.shmPrefix == "" {
rc = C.govpp_connect(nil, rxQlen)
} else {
shm := C.CString(a.shmPrefix)
rc = C.govpp_connect(sh... | go | func (a *vppClient) Connect() error {
if globalVppClient != nil {
return fmt.Errorf("already connected to binary API, disconnect first")
}
rxQlen := C.int(a.inputQueueSize)
var rc C.int
if a.shmPrefix == "" {
rc = C.govpp_connect(nil, rxQlen)
} else {
shm := C.CString(a.shmPrefix)
rc = C.govpp_connect(sh... | [
"func",
"(",
"a",
"*",
"vppClient",
")",
"Connect",
"(",
")",
"error",
"{",
"if",
"globalVppClient",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"rxQlen",
":=",
"C",
".",
"int",
"(",
"a",
".",
"input... | // Connect connects the process to VPP. | [
"Connect",
"connects",
"the",
"process",
"to",
"VPP",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/vppapiclient/vppapiclient.go#L126-L145 |
12,635 | FDio/govpp | adapter/vppapiclient/vppapiclient.go | Disconnect | func (a *vppClient) Disconnect() error {
globalVppClient = nil
rc := C.govpp_disconnect()
if rc != 0 {
return fmt.Errorf("disconnecting from VPP binary API failed (rc=%v)", rc)
}
return nil
} | go | func (a *vppClient) Disconnect() error {
globalVppClient = nil
rc := C.govpp_disconnect()
if rc != 0 {
return fmt.Errorf("disconnecting from VPP binary API failed (rc=%v)", rc)
}
return nil
} | [
"func",
"(",
"a",
"*",
"vppClient",
")",
"Disconnect",
"(",
")",
"error",
"{",
"globalVppClient",
"=",
"nil",
"\n\n",
"rc",
":=",
"C",
".",
"govpp_disconnect",
"(",
")",
"\n",
"if",
"rc",
"!=",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"... | // Disconnect disconnects the process from VPP. | [
"Disconnect",
"disconnects",
"the",
"process",
"from",
"VPP",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/vppapiclient/vppapiclient.go#L148-L157 |
12,636 | FDio/govpp | adapter/vppapiclient/vppapiclient.go | GetMsgID | func (a *vppClient) GetMsgID(msgName string, msgCrc string) (uint16, error) {
nameAndCrc := C.CString(msgName + "_" + msgCrc)
defer C.free(unsafe.Pointer(nameAndCrc))
msgID := uint16(C.govpp_get_msg_index(nameAndCrc))
if msgID == ^uint16(0) {
// VPP does not know this message
return msgID, fmt.Errorf("unknown ... | go | func (a *vppClient) GetMsgID(msgName string, msgCrc string) (uint16, error) {
nameAndCrc := C.CString(msgName + "_" + msgCrc)
defer C.free(unsafe.Pointer(nameAndCrc))
msgID := uint16(C.govpp_get_msg_index(nameAndCrc))
if msgID == ^uint16(0) {
// VPP does not know this message
return msgID, fmt.Errorf("unknown ... | [
"func",
"(",
"a",
"*",
"vppClient",
")",
"GetMsgID",
"(",
"msgName",
"string",
",",
"msgCrc",
"string",
")",
"(",
"uint16",
",",
"error",
")",
"{",
"nameAndCrc",
":=",
"C",
".",
"CString",
"(",
"msgName",
"+",
"\"",
"\"",
"+",
"msgCrc",
")",
"\n",
... | // GetMsgID returns a runtime message ID for the given message name and CRC. | [
"GetMsgID",
"returns",
"a",
"runtime",
"message",
"ID",
"for",
"the",
"given",
"message",
"name",
"and",
"CRC",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/vppapiclient/vppapiclient.go#L160-L171 |
12,637 | FDio/govpp | adapter/vppapiclient/vppapiclient.go | SendMsg | func (a *vppClient) SendMsg(context uint32, data []byte) error {
rc := C.govpp_send(C.uint32_t(context), unsafe.Pointer(&data[0]), C.size_t(len(data)))
if rc != 0 {
return fmt.Errorf("unable to send the message (rc=%v)", rc)
}
return nil
} | go | func (a *vppClient) SendMsg(context uint32, data []byte) error {
rc := C.govpp_send(C.uint32_t(context), unsafe.Pointer(&data[0]), C.size_t(len(data)))
if rc != 0 {
return fmt.Errorf("unable to send the message (rc=%v)", rc)
}
return nil
} | [
"func",
"(",
"a",
"*",
"vppClient",
")",
"SendMsg",
"(",
"context",
"uint32",
",",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"rc",
":=",
"C",
".",
"govpp_send",
"(",
"C",
".",
"uint32_t",
"(",
"context",
")",
",",
"unsafe",
".",
"Pointer",
"(",
... | // SendMsg sends a binary-encoded message to VPP. | [
"SendMsg",
"sends",
"a",
"binary",
"-",
"encoded",
"message",
"to",
"VPP",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/vppapiclient/vppapiclient.go#L174-L180 |
12,638 | FDio/govpp | adapter/vppapiclient/vppapiclient.go | WaitReady | func (a *vppClient) WaitReady() error {
// join the path to the shared memory segment
var path string
if a.shmPrefix == "" {
path = filepath.Join(shmDir, vppShmFile)
} else {
path = filepath.Join(shmDir, a.shmPrefix+"-"+vppShmFile)
}
// check if file at the path already exists
if _, err := os.Stat(path); er... | go | func (a *vppClient) WaitReady() error {
// join the path to the shared memory segment
var path string
if a.shmPrefix == "" {
path = filepath.Join(shmDir, vppShmFile)
} else {
path = filepath.Join(shmDir, a.shmPrefix+"-"+vppShmFile)
}
// check if file at the path already exists
if _, err := os.Stat(path); er... | [
"func",
"(",
"a",
"*",
"vppClient",
")",
"WaitReady",
"(",
")",
"error",
"{",
"// join the path to the shared memory segment",
"var",
"path",
"string",
"\n",
"if",
"a",
".",
"shmPrefix",
"==",
"\"",
"\"",
"{",
"path",
"=",
"filepath",
".",
"Join",
"(",
"sh... | // WaitReady blocks until shared memory for sending
// binary api calls is present on the file system. | [
"WaitReady",
"blocks",
"until",
"shared",
"memory",
"for",
"sending",
"binary",
"api",
"calls",
"is",
"present",
"on",
"the",
"file",
"system",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/vppapiclient/vppapiclient.go#L190-L234 |
12,639 | FDio/govpp | extras/libmemif/error.go | newMemifError | func newMemifError(code int, desc ...string) *MemifError {
var err *MemifError
if len(desc) > 0 {
err = &MemifError{code: code, description: "libmemif: " + desc[0]}
} else {
err = &MemifError{code: code, description: "libmemif: " + C.GoString(C.memif_strerror(C.int(code)))}
}
errorRegistry[code] = err
return ... | go | func newMemifError(code int, desc ...string) *MemifError {
var err *MemifError
if len(desc) > 0 {
err = &MemifError{code: code, description: "libmemif: " + desc[0]}
} else {
err = &MemifError{code: code, description: "libmemif: " + C.GoString(C.memif_strerror(C.int(code)))}
}
errorRegistry[code] = err
return ... | [
"func",
"newMemifError",
"(",
"code",
"int",
",",
"desc",
"...",
"string",
")",
"*",
"MemifError",
"{",
"var",
"err",
"*",
"MemifError",
"\n",
"if",
"len",
"(",
"desc",
")",
">",
"0",
"{",
"err",
"=",
"&",
"MemifError",
"{",
"code",
":",
"code",
",... | // newMemifError builds and registers a new MemifError. | [
"newMemifError",
"builds",
"and",
"registers",
"a",
"new",
"MemifError",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/error.go#L102-L111 |
12,640 | FDio/govpp | extras/libmemif/error.go | getMemifError | func getMemifError(code int) error {
if code == 0 {
return nil /* success */
}
err, known := errorRegistry[code]
if !known {
return ErrUnknown
}
return err
} | go | func getMemifError(code int) error {
if code == 0 {
return nil /* success */
}
err, known := errorRegistry[code]
if !known {
return ErrUnknown
}
return err
} | [
"func",
"getMemifError",
"(",
"code",
"int",
")",
"error",
"{",
"if",
"code",
"==",
"0",
"{",
"return",
"nil",
"/* success */",
"\n",
"}",
"\n",
"err",
",",
"known",
":=",
"errorRegistry",
"[",
"code",
"]",
"\n",
"if",
"!",
"known",
"{",
"return",
"E... | // getMemifError returns the MemifError associated with the given C-libmemif
// error code. | [
"getMemifError",
"returns",
"the",
"MemifError",
"associated",
"with",
"the",
"given",
"C",
"-",
"libmemif",
"error",
"code",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/error.go#L115-L124 |
12,641 | FDio/govpp | extras/libmemif/adapter.go | Cleanup | func Cleanup() error {
context.lock.Lock()
defer context.lock.Unlock()
if !context.initialized {
return ErrNotInit
}
log.Debug("Closing libmemif library")
// Delete all active interfaces.
for _, memif := range context.memifs {
memif.Close()
}
// Stop the event loop (if supported by C-libmemif).
errCod... | go | func Cleanup() error {
context.lock.Lock()
defer context.lock.Unlock()
if !context.initialized {
return ErrNotInit
}
log.Debug("Closing libmemif library")
// Delete all active interfaces.
for _, memif := range context.memifs {
memif.Close()
}
// Stop the event loop (if supported by C-libmemif).
errCod... | [
"func",
"Cleanup",
"(",
")",
"error",
"{",
"context",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"context",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"!",
"context",
".",
"initialized",
"{",
"return",
"ErrNotInit",
"\n",
"}",
"\n\n"... | // Cleanup cleans up all the resources allocated by libmemif. | [
"Cleanup",
"cleans",
"up",
"all",
"the",
"resources",
"allocated",
"by",
"libmemif",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/adapter.go#L505-L538 |
12,642 | FDio/govpp | extras/libmemif/adapter.go | SetRxMode | func (memif *Memif) SetRxMode(queueID uint8, rxMode RxMode) (err error) {
var cRxMode C.memif_rx_mode_t
switch rxMode {
case RxModeInterrupt:
cRxMode = C.MEMIF_RX_MODE_INTERRUPT
case RxModePolling:
cRxMode = C.MEMIF_RX_MODE_POLLING
default:
cRxMode = C.MEMIF_RX_MODE_INTERRUPT
}
errCode := C.memif_set_rx_mo... | go | func (memif *Memif) SetRxMode(queueID uint8, rxMode RxMode) (err error) {
var cRxMode C.memif_rx_mode_t
switch rxMode {
case RxModeInterrupt:
cRxMode = C.MEMIF_RX_MODE_INTERRUPT
case RxModePolling:
cRxMode = C.MEMIF_RX_MODE_POLLING
default:
cRxMode = C.MEMIF_RX_MODE_INTERRUPT
}
errCode := C.memif_set_rx_mo... | [
"func",
"(",
"memif",
"*",
"Memif",
")",
"SetRxMode",
"(",
"queueID",
"uint8",
",",
"rxMode",
"RxMode",
")",
"(",
"err",
"error",
")",
"{",
"var",
"cRxMode",
"C",
".",
"memif_rx_mode_t",
"\n",
"switch",
"rxMode",
"{",
"case",
"RxModeInterrupt",
":",
"cRx... | // SetRxMode allows to switch between the interrupt and the polling mode for Rx.
// The method is thread-safe. | [
"SetRxMode",
"allows",
"to",
"switch",
"between",
"the",
"interrupt",
"and",
"the",
"polling",
"mode",
"for",
"Rx",
".",
"The",
"method",
"is",
"thread",
"-",
"safe",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/adapter.go#L680-L692 |
12,643 | FDio/govpp | extras/libmemif/adapter.go | GetDetails | func (memif *Memif) GetDetails() (details *MemifDetails, err error) {
cDetails := C.govpp_memif_details_t{}
var buf *C.char
// Get memif details from C-libmemif.
errCode := C.govpp_memif_get_details(memif.cHandle, &cDetails, &buf)
err = getMemifError(int(errCode))
if err != nil {
return nil, err
}
defer C.fr... | go | func (memif *Memif) GetDetails() (details *MemifDetails, err error) {
cDetails := C.govpp_memif_details_t{}
var buf *C.char
// Get memif details from C-libmemif.
errCode := C.govpp_memif_get_details(memif.cHandle, &cDetails, &buf)
err = getMemifError(int(errCode))
if err != nil {
return nil, err
}
defer C.fr... | [
"func",
"(",
"memif",
"*",
"Memif",
")",
"GetDetails",
"(",
")",
"(",
"details",
"*",
"MemifDetails",
",",
"err",
"error",
")",
"{",
"cDetails",
":=",
"C",
".",
"govpp_memif_details_t",
"{",
"}",
"\n",
"var",
"buf",
"*",
"C",
".",
"char",
"\n\n",
"//... | // GetDetails returns a detailed runtime information about this memif.
// The method is thread-safe. | [
"GetDetails",
"returns",
"a",
"detailed",
"runtime",
"information",
"about",
"this",
"memif",
".",
"The",
"method",
"is",
"thread",
"-",
"safe",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/adapter.go#L696-L756 |
12,644 | FDio/govpp | extras/libmemif/adapter.go | Close | func (memif *Memif) Close() error {
log.WithField("ifName", memif.IfName).Debug("Closing the memif interface")
// Delete memif from C-libmemif.
err := getMemifError(int(C.memif_delete(&memif.cHandle)))
if err != nil {
// Close memif-global interrupt channel.
close(memif.intCh)
// Close file descriptor stopQ... | go | func (memif *Memif) Close() error {
log.WithField("ifName", memif.IfName).Debug("Closing the memif interface")
// Delete memif from C-libmemif.
err := getMemifError(int(C.memif_delete(&memif.cHandle)))
if err != nil {
// Close memif-global interrupt channel.
close(memif.intCh)
// Close file descriptor stopQ... | [
"func",
"(",
"memif",
"*",
"Memif",
")",
"Close",
"(",
")",
"error",
"{",
"log",
".",
"WithField",
"(",
"\"",
"\"",
",",
"memif",
".",
"IfName",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"// Delete memif from C-libmemif.",
"err",
":=",
"getMemif... | // Close removes the memif interface. If the memif is in the connected state,
// the connection is first properly closed.
// Do not access memif after it is closed, let garbage collector to remove it. | [
"Close",
"removes",
"the",
"memif",
"interface",
".",
"If",
"the",
"memif",
"is",
"in",
"the",
"connected",
"state",
"the",
"connection",
"is",
"first",
"properly",
"closed",
".",
"Do",
"not",
"access",
"memif",
"after",
"it",
"is",
"closed",
"let",
"garba... | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/adapter.go#L1005-L1025 |
12,645 | FDio/govpp | extras/libmemif/adapter.go | pollEvents | func pollEvents() {
defer context.wg.Done()
for {
errCode := C.memif_poll_event(C.int(-1))
err := getMemifError(int(errCode))
if err == ErrPollCanceled {
return
}
}
} | go | func pollEvents() {
defer context.wg.Done()
for {
errCode := C.memif_poll_event(C.int(-1))
err := getMemifError(int(errCode))
if err == ErrPollCanceled {
return
}
}
} | [
"func",
"pollEvents",
"(",
")",
"{",
"defer",
"context",
".",
"wg",
".",
"Done",
"(",
")",
"\n",
"for",
"{",
"errCode",
":=",
"C",
".",
"memif_poll_event",
"(",
"C",
".",
"int",
"(",
"-",
"1",
")",
")",
"\n",
"err",
":=",
"getMemifError",
"(",
"i... | // pollEvents repeatedly polls for a libmemif event. | [
"pollEvents",
"repeatedly",
"polls",
"for",
"a",
"libmemif",
"event",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/adapter.go#L1092-L1101 |
12,646 | FDio/govpp | extras/libmemif/adapter.go | pollRxQueue | func pollRxQueue(memif *Memif, queueID uint8) {
defer memif.wg.Done()
log.WithFields(logger.Fields{
"ifName": memif.IfName,
"queue-ID": queueID,
}).Debug("Started queue interrupt polling.")
var qfd C.int
errCode := C.memif_get_queue_efd(memif.cHandle, C.uint16_t(queueID), &qfd)
err := getMemifError(int(er... | go | func pollRxQueue(memif *Memif, queueID uint8) {
defer memif.wg.Done()
log.WithFields(logger.Fields{
"ifName": memif.IfName,
"queue-ID": queueID,
}).Debug("Started queue interrupt polling.")
var qfd C.int
errCode := C.memif_get_queue_efd(memif.cHandle, C.uint16_t(queueID), &qfd)
err := getMemifError(int(er... | [
"func",
"pollRxQueue",
"(",
"memif",
"*",
"Memif",
",",
"queueID",
"uint8",
")",
"{",
"defer",
"memif",
".",
"wg",
".",
"Done",
"(",
")",
"\n\n",
"log",
".",
"WithFields",
"(",
"logger",
".",
"Fields",
"{",
"\"",
"\"",
":",
"memif",
".",
"IfName",
... | // pollRxQueue repeatedly polls an Rx queue for interrupts. | [
"pollRxQueue",
"repeatedly",
"polls",
"an",
"Rx",
"queue",
"for",
"interrupts",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/adapter.go#L1104-L1188 |
12,647 | FDio/govpp | extras/libmemif/examples/icmp-responder/icmp-responder.go | IcmpResponder | func IcmpResponder(memif *libmemif.Memif, queueID uint8) {
defer wg.Done()
// Get channel which fires every time there are packets to read on the queue.
interruptCh, err := memif.GetQueueInterruptChan(queueID)
if err != nil {
// Example of libmemif error handling code:
switch err {
case libmemif.ErrQueueID:
... | go | func IcmpResponder(memif *libmemif.Memif, queueID uint8) {
defer wg.Done()
// Get channel which fires every time there are packets to read on the queue.
interruptCh, err := memif.GetQueueInterruptChan(queueID)
if err != nil {
// Example of libmemif error handling code:
switch err {
case libmemif.ErrQueueID:
... | [
"func",
"IcmpResponder",
"(",
"memif",
"*",
"libmemif",
".",
"Memif",
",",
"queueID",
"uint8",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n\n",
"// Get channel which fires every time there are packets to read on the queue.",
"interruptCh",
",",
"err",
":=",
"... | // IcmpResponder answers to ICMP pings with ICMP pongs. | [
"IcmpResponder",
"answers",
"to",
"ICMP",
"pings",
"with",
"ICMP",
"pongs",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/examples/icmp-responder/icmp-responder.go#L120-L193 |
12,648 | FDio/govpp | extras/libmemif/examples/icmp-responder/icmp-responder.go | DumpPacket | func DumpPacket(packetData libmemif.RawPacketData) {
packet := gopacket.NewPacket(packetData, layers.LayerTypeEthernet, gopacket.Default)
fmt.Println(packet.Dump())
} | go | func DumpPacket(packetData libmemif.RawPacketData) {
packet := gopacket.NewPacket(packetData, layers.LayerTypeEthernet, gopacket.Default)
fmt.Println(packet.Dump())
} | [
"func",
"DumpPacket",
"(",
"packetData",
"libmemif",
".",
"RawPacketData",
")",
"{",
"packet",
":=",
"gopacket",
".",
"NewPacket",
"(",
"packetData",
",",
"layers",
".",
"LayerTypeEthernet",
",",
"gopacket",
".",
"Default",
")",
"\n",
"fmt",
".",
"Println",
... | // DumpPacket prints a human-readable description of the packet. | [
"DumpPacket",
"prints",
"a",
"human",
"-",
"readable",
"description",
"of",
"the",
"packet",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/examples/icmp-responder/icmp-responder.go#L196-L199 |
12,649 | FDio/govpp | core/channel.go | receiveReplyInternal | func (ch *Channel) receiveReplyInternal(msg api.Message, expSeqNum uint16) (lastReplyReceived bool, err error) {
if msg == nil {
return false, errors.New("nil message passed in")
}
var ignore bool
if vppReply := ch.delayedReply; vppReply != nil {
// try the delayed reply
ch.delayedReply = nil
ignore, last... | go | func (ch *Channel) receiveReplyInternal(msg api.Message, expSeqNum uint16) (lastReplyReceived bool, err error) {
if msg == nil {
return false, errors.New("nil message passed in")
}
var ignore bool
if vppReply := ch.delayedReply; vppReply != nil {
// try the delayed reply
ch.delayedReply = nil
ignore, last... | [
"func",
"(",
"ch",
"*",
"Channel",
")",
"receiveReplyInternal",
"(",
"msg",
"api",
".",
"Message",
",",
"expSeqNum",
"uint16",
")",
"(",
"lastReplyReceived",
"bool",
",",
"err",
"error",
")",
"{",
"if",
"msg",
"==",
"nil",
"{",
"return",
"false",
",",
... | // receiveReplyInternal receives a reply from the reply channel into the provided msg structure. | [
"receiveReplyInternal",
"receives",
"a",
"reply",
"from",
"the",
"reply",
"channel",
"into",
"the",
"provided",
"msg",
"structure",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/channel.go#L235-L269 |
12,650 | FDio/govpp | adapter/mock/mock_stats_adapter.go | ListStats | func (a *StatsAdapter) ListStats(patterns ...string) ([]string, error) {
var statNames []string
for _, stat := range a.entries {
statNames = append(statNames, stat.Name)
}
return statNames, nil
} | go | func (a *StatsAdapter) ListStats(patterns ...string) ([]string, error) {
var statNames []string
for _, stat := range a.entries {
statNames = append(statNames, stat.Name)
}
return statNames, nil
} | [
"func",
"(",
"a",
"*",
"StatsAdapter",
")",
"ListStats",
"(",
"patterns",
"...",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"statNames",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"stat",
":=",
"range",
"a",
".",
"entrie... | // ListStats mocks name listing for all stats. | [
"ListStats",
"mocks",
"name",
"listing",
"for",
"all",
"stats",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/mock/mock_stats_adapter.go#L45-L51 |
12,651 | FDio/govpp | adapter/mock/mock_stats_adapter.go | DumpStats | func (a *StatsAdapter) DumpStats(patterns ...string) ([]*adapter.StatEntry, error) {
return a.entries, nil
} | go | func (a *StatsAdapter) DumpStats(patterns ...string) ([]*adapter.StatEntry, error) {
return a.entries, nil
} | [
"func",
"(",
"a",
"*",
"StatsAdapter",
")",
"DumpStats",
"(",
"patterns",
"...",
"string",
")",
"(",
"[",
"]",
"*",
"adapter",
".",
"StatEntry",
",",
"error",
")",
"{",
"return",
"a",
".",
"entries",
",",
"nil",
"\n",
"}"
] | // DumpStats mocks all stat entries dump. | [
"DumpStats",
"mocks",
"all",
"stat",
"entries",
"dump",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/mock/mock_stats_adapter.go#L54-L56 |
12,652 | FDio/govpp | cmd/binapi-generator/types.go | convertToGoType | func convertToGoType(ctx *context, binapiType string) (typ string) {
if t, ok := binapiTypes[binapiType]; ok {
// basic types
typ = t
} else if r, ok := ctx.packageData.RefMap[binapiType]; ok {
// specific types (enums/types/unions)
typ = camelCaseName(r)
} else {
switch binapiType {
case "bool", "string... | go | func convertToGoType(ctx *context, binapiType string) (typ string) {
if t, ok := binapiTypes[binapiType]; ok {
// basic types
typ = t
} else if r, ok := ctx.packageData.RefMap[binapiType]; ok {
// specific types (enums/types/unions)
typ = camelCaseName(r)
} else {
switch binapiType {
case "bool", "string... | [
"func",
"convertToGoType",
"(",
"ctx",
"*",
"context",
",",
"binapiType",
"string",
")",
"(",
"typ",
"string",
")",
"{",
"if",
"t",
",",
"ok",
":=",
"binapiTypes",
"[",
"binapiType",
"]",
";",
"ok",
"{",
"// basic types",
"typ",
"=",
"t",
"\n",
"}",
... | // convertToGoType translates the VPP binary API type into Go type | [
"convertToGoType",
"translates",
"the",
"VPP",
"binary",
"API",
"type",
"into",
"Go",
"type"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/types.go#L52-L70 |
12,653 | FDio/govpp | cmd/binapi-generator/parse.go | printPackage | func printPackage(pkg *Package) {
if len(pkg.Enums) > 0 {
logf("loaded %d enums:", len(pkg.Enums))
for k, enum := range pkg.Enums {
logf(" - enum #%d\t%+v", k, enum)
}
}
if len(pkg.Unions) > 0 {
logf("loaded %d unions:", len(pkg.Unions))
for k, union := range pkg.Unions {
logf(" - union #%d\t%+v", k,... | go | func printPackage(pkg *Package) {
if len(pkg.Enums) > 0 {
logf("loaded %d enums:", len(pkg.Enums))
for k, enum := range pkg.Enums {
logf(" - enum #%d\t%+v", k, enum)
}
}
if len(pkg.Unions) > 0 {
logf("loaded %d unions:", len(pkg.Unions))
for k, union := range pkg.Unions {
logf(" - union #%d\t%+v", k,... | [
"func",
"printPackage",
"(",
"pkg",
"*",
"Package",
")",
"{",
"if",
"len",
"(",
"pkg",
".",
"Enums",
")",
">",
"0",
"{",
"logf",
"(",
"\"",
"\"",
",",
"len",
"(",
"pkg",
".",
"Enums",
")",
")",
"\n",
"for",
"k",
",",
"enum",
":=",
"range",
"p... | // printPackage prints all loaded objects for package | [
"printPackage",
"prints",
"all",
"loaded",
"objects",
"for",
"package"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/parse.go#L200-L237 |
12,654 | FDio/govpp | cmd/binapi-generator/parse.go | parseEnum | func parseEnum(ctx *context, enumNode *jsongo.JSONNode) (*Enum, error) {
if enumNode.Len() == 0 || enumNode.At(0).GetType() != jsongo.TypeValue {
return nil, errors.New("invalid JSON for enum specified")
}
enumName, ok := enumNode.At(0).Get().(string)
if !ok {
return nil, fmt.Errorf("enum name is %T, not a str... | go | func parseEnum(ctx *context, enumNode *jsongo.JSONNode) (*Enum, error) {
if enumNode.Len() == 0 || enumNode.At(0).GetType() != jsongo.TypeValue {
return nil, errors.New("invalid JSON for enum specified")
}
enumName, ok := enumNode.At(0).Get().(string)
if !ok {
return nil, fmt.Errorf("enum name is %T, not a str... | [
"func",
"parseEnum",
"(",
"ctx",
"*",
"context",
",",
"enumNode",
"*",
"jsongo",
".",
"JSONNode",
")",
"(",
"*",
"Enum",
",",
"error",
")",
"{",
"if",
"enumNode",
".",
"Len",
"(",
")",
"==",
"0",
"||",
"enumNode",
".",
"At",
"(",
"0",
")",
".",
... | // parseEnum parses VPP binary API enum object from JSON node | [
"parseEnum",
"parses",
"VPP",
"binary",
"API",
"enum",
"object",
"from",
"JSON",
"node"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/parse.go#L240-L282 |
12,655 | FDio/govpp | cmd/binapi-generator/parse.go | parseUnion | func parseUnion(ctx *context, unionNode *jsongo.JSONNode) (*Union, error) {
if unionNode.Len() == 0 || unionNode.At(0).GetType() != jsongo.TypeValue {
return nil, errors.New("invalid JSON for union specified")
}
unionName, ok := unionNode.At(0).Get().(string)
if !ok {
return nil, fmt.Errorf("union name is %T, ... | go | func parseUnion(ctx *context, unionNode *jsongo.JSONNode) (*Union, error) {
if unionNode.Len() == 0 || unionNode.At(0).GetType() != jsongo.TypeValue {
return nil, errors.New("invalid JSON for union specified")
}
unionName, ok := unionNode.At(0).Get().(string)
if !ok {
return nil, fmt.Errorf("union name is %T, ... | [
"func",
"parseUnion",
"(",
"ctx",
"*",
"context",
",",
"unionNode",
"*",
"jsongo",
".",
"JSONNode",
")",
"(",
"*",
"Union",
",",
"error",
")",
"{",
"if",
"unionNode",
".",
"Len",
"(",
")",
"==",
"0",
"||",
"unionNode",
".",
"At",
"(",
"0",
")",
"... | // parseUnion parses VPP binary API union object from JSON node | [
"parseUnion",
"parses",
"VPP",
"binary",
"API",
"union",
"object",
"from",
"JSON",
"node"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/parse.go#L285-L319 |
12,656 | FDio/govpp | cmd/binapi-generator/parse.go | parseType | func parseType(ctx *context, typeNode *jsongo.JSONNode) (*Type, error) {
if typeNode.Len() == 0 || typeNode.At(0).GetType() != jsongo.TypeValue {
return nil, errors.New("invalid JSON for type specified")
}
typeName, ok := typeNode.At(0).Get().(string)
if !ok {
return nil, fmt.Errorf("type name is %T, not a str... | go | func parseType(ctx *context, typeNode *jsongo.JSONNode) (*Type, error) {
if typeNode.Len() == 0 || typeNode.At(0).GetType() != jsongo.TypeValue {
return nil, errors.New("invalid JSON for type specified")
}
typeName, ok := typeNode.At(0).Get().(string)
if !ok {
return nil, fmt.Errorf("type name is %T, not a str... | [
"func",
"parseType",
"(",
"ctx",
"*",
"context",
",",
"typeNode",
"*",
"jsongo",
".",
"JSONNode",
")",
"(",
"*",
"Type",
",",
"error",
")",
"{",
"if",
"typeNode",
".",
"Len",
"(",
")",
"==",
"0",
"||",
"typeNode",
".",
"At",
"(",
"0",
")",
".",
... | // parseType parses VPP binary API type object from JSON node | [
"parseType",
"parses",
"VPP",
"binary",
"API",
"type",
"object",
"from",
"JSON",
"node"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/parse.go#L322-L356 |
12,657 | FDio/govpp | cmd/binapi-generator/parse.go | parseAlias | func parseAlias(ctx *context, aliasName string, aliasNode *jsongo.JSONNode) (*Alias, error) {
if aliasNode.Len() == 0 || aliasNode.At(aliasTypeField).GetType() != jsongo.TypeValue {
return nil, errors.New("invalid JSON for alias specified")
}
alias := Alias{
Name: aliasName,
}
if typeNode := aliasNode.At(ali... | go | func parseAlias(ctx *context, aliasName string, aliasNode *jsongo.JSONNode) (*Alias, error) {
if aliasNode.Len() == 0 || aliasNode.At(aliasTypeField).GetType() != jsongo.TypeValue {
return nil, errors.New("invalid JSON for alias specified")
}
alias := Alias{
Name: aliasName,
}
if typeNode := aliasNode.At(ali... | [
"func",
"parseAlias",
"(",
"ctx",
"*",
"context",
",",
"aliasName",
"string",
",",
"aliasNode",
"*",
"jsongo",
".",
"JSONNode",
")",
"(",
"*",
"Alias",
",",
"error",
")",
"{",
"if",
"aliasNode",
".",
"Len",
"(",
")",
"==",
"0",
"||",
"aliasNode",
"."... | // parseAlias parses VPP binary API alias object from JSON node | [
"parseAlias",
"parses",
"VPP",
"binary",
"API",
"alias",
"object",
"from",
"JSON",
"node"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/parse.go#L359-L387 |
12,658 | FDio/govpp | cmd/binapi-generator/parse.go | parseMessage | func parseMessage(ctx *context, msgNode *jsongo.JSONNode) (*Message, error) {
if msgNode.Len() == 0 || msgNode.At(0).GetType() != jsongo.TypeValue {
return nil, errors.New("invalid JSON for message specified")
}
msgName, ok := msgNode.At(0).Get().(string)
if !ok {
return nil, fmt.Errorf("message name is %T, no... | go | func parseMessage(ctx *context, msgNode *jsongo.JSONNode) (*Message, error) {
if msgNode.Len() == 0 || msgNode.At(0).GetType() != jsongo.TypeValue {
return nil, errors.New("invalid JSON for message specified")
}
msgName, ok := msgNode.At(0).Get().(string)
if !ok {
return nil, fmt.Errorf("message name is %T, no... | [
"func",
"parseMessage",
"(",
"ctx",
"*",
"context",
",",
"msgNode",
"*",
"jsongo",
".",
"JSONNode",
")",
"(",
"*",
"Message",
",",
"error",
")",
"{",
"if",
"msgNode",
".",
"Len",
"(",
")",
"==",
"0",
"||",
"msgNode",
".",
"At",
"(",
"0",
")",
"."... | // parseMessage parses VPP binary API message object from JSON node | [
"parseMessage",
"parses",
"VPP",
"binary",
"API",
"message",
"object",
"from",
"JSON",
"node"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/parse.go#L390-L425 |
12,659 | FDio/govpp | cmd/binapi-generator/parse.go | parseField | func parseField(ctx *context, field *jsongo.JSONNode) (*Field, error) {
if field.Len() < 2 || field.At(0).GetType() != jsongo.TypeValue || field.At(1).GetType() != jsongo.TypeValue {
return nil, errors.New("invalid JSON for field specified")
}
fieldType, ok := field.At(0).Get().(string)
if !ok {
return nil, fm... | go | func parseField(ctx *context, field *jsongo.JSONNode) (*Field, error) {
if field.Len() < 2 || field.At(0).GetType() != jsongo.TypeValue || field.At(1).GetType() != jsongo.TypeValue {
return nil, errors.New("invalid JSON for field specified")
}
fieldType, ok := field.At(0).Get().(string)
if !ok {
return nil, fm... | [
"func",
"parseField",
"(",
"ctx",
"*",
"context",
",",
"field",
"*",
"jsongo",
".",
"JSONNode",
")",
"(",
"*",
"Field",
",",
"error",
")",
"{",
"if",
"field",
".",
"Len",
"(",
")",
"<",
"2",
"||",
"field",
".",
"At",
"(",
"0",
")",
".",
"GetTyp... | // parseField parses VPP binary API object field from JSON node | [
"parseField",
"parses",
"VPP",
"binary",
"API",
"object",
"field",
"from",
"JSON",
"node"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/parse.go#L428-L462 |
12,660 | FDio/govpp | cmd/binapi-generator/parse.go | parseService | func parseService(ctx *context, svcName string, svcNode *jsongo.JSONNode) (*Service, error) {
if svcNode.Len() == 0 || svcNode.At(replyField).GetType() != jsongo.TypeValue {
return nil, errors.New("invalid JSON for service specified")
}
svc := Service{
Name: ctx.moduleName + "." + svcName,
RequestType:... | go | func parseService(ctx *context, svcName string, svcNode *jsongo.JSONNode) (*Service, error) {
if svcNode.Len() == 0 || svcNode.At(replyField).GetType() != jsongo.TypeValue {
return nil, errors.New("invalid JSON for service specified")
}
svc := Service{
Name: ctx.moduleName + "." + svcName,
RequestType:... | [
"func",
"parseService",
"(",
"ctx",
"*",
"context",
",",
"svcName",
"string",
",",
"svcNode",
"*",
"jsongo",
".",
"JSONNode",
")",
"(",
"*",
"Service",
",",
"error",
")",
"{",
"if",
"svcNode",
".",
"Len",
"(",
")",
"==",
"0",
"||",
"svcNode",
".",
... | // parseService parses VPP binary API service object from JSON node | [
"parseService",
"parses",
"VPP",
"binary",
"API",
"service",
"object",
"from",
"JSON",
"node"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/parse.go#L465-L529 |
12,661 | FDio/govpp | adapter/socketclient/socketclient.go | WaitReady | func (c *vppClient) WaitReady() error {
// check if file at the path already exists
if _, err := os.Stat(c.sockAddr); err == nil {
return nil
} else if os.IsExist(err) {
return err
}
// if not, watch for it
watcher, err := fsnotify.NewWatcher()
if err != nil {
return err
}
defer func() {
if err := wat... | go | func (c *vppClient) WaitReady() error {
// check if file at the path already exists
if _, err := os.Stat(c.sockAddr); err == nil {
return nil
} else if os.IsExist(err) {
return err
}
// if not, watch for it
watcher, err := fsnotify.NewWatcher()
if err != nil {
return err
}
defer func() {
if err := wat... | [
"func",
"(",
"c",
"*",
"vppClient",
")",
"WaitReady",
"(",
")",
"error",
"{",
"// check if file at the path already exists",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"c",
".",
"sockAddr",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"nil",
... | // WaitReady checks socket file existence and waits for it if necessary | [
"WaitReady",
"checks",
"socket",
"file",
"existence",
"and",
"waits",
"for",
"it",
"if",
"necessary"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/socketclient/socketclient.go#L102-L142 |
12,662 | FDio/govpp | examples/simple-client/simple_client.go | aclVersion | func aclVersion(ch api.Channel) {
fmt.Println("ACL getting version")
req := &acl.ACLPluginGetVersion{}
reply := &acl.ACLPluginGetVersionReply{}
if err := ch.SendRequest(req).ReceiveReply(reply); err != nil {
fmt.Println("ERROR:", err)
} else {
fmt.Printf("ACL version reply: %+v\n", reply)
}
} | go | func aclVersion(ch api.Channel) {
fmt.Println("ACL getting version")
req := &acl.ACLPluginGetVersion{}
reply := &acl.ACLPluginGetVersionReply{}
if err := ch.SendRequest(req).ReceiveReply(reply); err != nil {
fmt.Println("ERROR:", err)
} else {
fmt.Printf("ACL version reply: %+v\n", reply)
}
} | [
"func",
"aclVersion",
"(",
"ch",
"api",
".",
"Channel",
")",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n\n",
"req",
":=",
"&",
"acl",
".",
"ACLPluginGetVersion",
"{",
"}",
"\n",
"reply",
":=",
"&",
"acl",
".",
"ACLPluginGetVersionReply",
"{",... | // aclVersion is the simplest API example - one empty request message and one reply message. | [
"aclVersion",
"is",
"the",
"simplest",
"API",
"example",
"-",
"one",
"empty",
"request",
"message",
"and",
"one",
"reply",
"message",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/examples/simple-client/simple_client.go#L73-L84 |
12,663 | FDio/govpp | examples/simple-client/simple_client.go | aclConfig | func aclConfig(ch api.Channel) {
fmt.Println("ACL adding replace")
req := &acl.ACLAddReplace{
ACLIndex: ^uint32(0),
Tag: []byte("access list 1"),
R: []acl.ACLRule{
{
IsPermit: 1,
SrcIPAddr: net.ParseIP("10.0.0.0").To4(),
SrcIPPrefixLen: 8,
DstIPAddr: net.ParseIP("192.168... | go | func aclConfig(ch api.Channel) {
fmt.Println("ACL adding replace")
req := &acl.ACLAddReplace{
ACLIndex: ^uint32(0),
Tag: []byte("access list 1"),
R: []acl.ACLRule{
{
IsPermit: 1,
SrcIPAddr: net.ParseIP("10.0.0.0").To4(),
SrcIPPrefixLen: 8,
DstIPAddr: net.ParseIP("192.168... | [
"func",
"aclConfig",
"(",
"ch",
"api",
".",
"Channel",
")",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n\n",
"req",
":=",
"&",
"acl",
".",
"ACLAddReplace",
"{",
"ACLIndex",
":",
"^",
"uint32",
"(",
"0",
")",
",",
"Tag",
":",
"[",
"]",
... | // aclConfig is another simple API example - in this case, the request contains structured data. | [
"aclConfig",
"is",
"another",
"simple",
"API",
"example",
"-",
"in",
"this",
"case",
"the",
"request",
"contains",
"structured",
"data",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/examples/simple-client/simple_client.go#L87-L125 |
12,664 | FDio/govpp | examples/simple-client/simple_client.go | interfaceNotifications | func interfaceNotifications(ch api.Channel) {
fmt.Println("Subscribing to notificaiton events")
notifChan := make(chan api.Message, 100)
// subscribe for specific notification message
sub, err := ch.SubscribeNotification(notifChan, &interfaces.SwInterfaceEvent{})
if err != nil {
panic(err)
}
// enable inter... | go | func interfaceNotifications(ch api.Channel) {
fmt.Println("Subscribing to notificaiton events")
notifChan := make(chan api.Message, 100)
// subscribe for specific notification message
sub, err := ch.SubscribeNotification(notifChan, &interfaces.SwInterfaceEvent{})
if err != nil {
panic(err)
}
// enable inter... | [
"func",
"interfaceNotifications",
"(",
"ch",
"api",
".",
"Channel",
")",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n\n",
"notifChan",
":=",
"make",
"(",
"chan",
"api",
".",
"Message",
",",
"100",
")",
"\n\n",
"// subscribe for specific notification... | // interfaceNotifications shows the usage of notification API. Note that for notifications,
// you are supposed to create your own Go channel with your preferred buffer size. If the channel's
// buffer is full, the notifications will not be delivered into it. | [
"interfaceNotifications",
"shows",
"the",
"usage",
"of",
"notification",
"API",
".",
"Note",
"that",
"for",
"notifications",
"you",
"are",
"supposed",
"to",
"create",
"your",
"own",
"Go",
"channel",
"with",
"your",
"preferred",
"buffer",
"size",
".",
"If",
"th... | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/examples/simple-client/simple_client.go#L225-L279 |
12,665 | FDio/govpp | cmd/binapi-generator/main.go | getInputFiles | func getInputFiles(inputDir string) (res []string, err error) {
files, err := ioutil.ReadDir(inputDir)
if err != nil {
return nil, fmt.Errorf("reading directory %s failed: %v", inputDir, err)
}
for _, f := range files {
if strings.HasSuffix(f.Name(), inputFileExt) {
res = append(res, filepath.Join(inputDir, ... | go | func getInputFiles(inputDir string) (res []string, err error) {
files, err := ioutil.ReadDir(inputDir)
if err != nil {
return nil, fmt.Errorf("reading directory %s failed: %v", inputDir, err)
}
for _, f := range files {
if strings.HasSuffix(f.Name(), inputFileExt) {
res = append(res, filepath.Join(inputDir, ... | [
"func",
"getInputFiles",
"(",
"inputDir",
"string",
")",
"(",
"res",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"files",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"inputDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // getInputFiles returns all input files located in specified directory | [
"getInputFiles",
"returns",
"all",
"input",
"files",
"located",
"in",
"specified",
"directory"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/main.go#L85-L96 |
12,666 | FDio/govpp | cmd/binapi-generator/main.go | generateFromFile | func generateFromFile(inputFile, outputDir string) error {
logf("generating from file: %q", inputFile)
defer logf("--------------------------------------")
ctx, err := getContext(inputFile, outputDir)
if err != nil {
return err
}
ctx.includeAPIVersionCrc = *includeAPIVer
ctx.includeComments = *includeComment... | go | func generateFromFile(inputFile, outputDir string) error {
logf("generating from file: %q", inputFile)
defer logf("--------------------------------------")
ctx, err := getContext(inputFile, outputDir)
if err != nil {
return err
}
ctx.includeAPIVersionCrc = *includeAPIVer
ctx.includeComments = *includeComment... | [
"func",
"generateFromFile",
"(",
"inputFile",
",",
"outputDir",
"string",
")",
"error",
"{",
"logf",
"(",
"\"",
"\"",
",",
"inputFile",
")",
"\n",
"defer",
"logf",
"(",
"\"",
"\"",
")",
"\n\n",
"ctx",
",",
"err",
":=",
"getContext",
"(",
"inputFile",
"... | // generateFromFile generates Go package from one input JSON file | [
"generateFromFile",
"generates",
"Go",
"package",
"from",
"one",
"input",
"JSON",
"file"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/main.go#L99-L159 |
12,667 | FDio/govpp | cmd/binapi-generator/main.go | readFile | func readFile(inputFile string) ([]byte, error) {
inputData, err := ioutil.ReadFile(inputFile)
if err != nil {
return nil, fmt.Errorf("reading data from file failed: %v", err)
}
return inputData, nil
} | go | func readFile(inputFile string) ([]byte, error) {
inputData, err := ioutil.ReadFile(inputFile)
if err != nil {
return nil, fmt.Errorf("reading data from file failed: %v", err)
}
return inputData, nil
} | [
"func",
"readFile",
"(",
"inputFile",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"inputData",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"inputFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
"... | // readFile reads content of a file into memory | [
"readFile",
"reads",
"content",
"of",
"a",
"file",
"into",
"memory"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/main.go#L162-L169 |
12,668 | FDio/govpp | cmd/binapi-generator/main.go | parseJSON | func parseJSON(inputData []byte) (*jsongo.JSONNode, error) {
root := jsongo.JSONNode{}
if err := json.Unmarshal(inputData, &root); err != nil {
return nil, fmt.Errorf("unmarshalling JSON failed: %v", err)
}
return &root, nil
} | go | func parseJSON(inputData []byte) (*jsongo.JSONNode, error) {
root := jsongo.JSONNode{}
if err := json.Unmarshal(inputData, &root); err != nil {
return nil, fmt.Errorf("unmarshalling JSON failed: %v", err)
}
return &root, nil
} | [
"func",
"parseJSON",
"(",
"inputData",
"[",
"]",
"byte",
")",
"(",
"*",
"jsongo",
".",
"JSONNode",
",",
"error",
")",
"{",
"root",
":=",
"jsongo",
".",
"JSONNode",
"{",
"}",
"\n\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"inputData",
",",
... | // parseJSON parses a JSON data into an in-memory tree | [
"parseJSON",
"parses",
"a",
"JSON",
"data",
"into",
"an",
"in",
"-",
"memory",
"tree"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/cmd/binapi-generator/main.go#L172-L180 |
12,669 | FDio/govpp | adapter/mock/mock_vpp_adapter.go | NewVppAdapter | func NewVppAdapter() *VppAdapter {
a := &VppAdapter{
msgIDSeq: 1000,
msgIDsToName: make(map[uint16]string),
msgNameToIds: make(map[string]uint16),
binAPITypes: make(map[string]reflect.Type),
}
a.registerBinAPITypes()
return a
} | go | func NewVppAdapter() *VppAdapter {
a := &VppAdapter{
msgIDSeq: 1000,
msgIDsToName: make(map[uint16]string),
msgNameToIds: make(map[string]uint16),
binAPITypes: make(map[string]reflect.Type),
}
a.registerBinAPITypes()
return a
} | [
"func",
"NewVppAdapter",
"(",
")",
"*",
"VppAdapter",
"{",
"a",
":=",
"&",
"VppAdapter",
"{",
"msgIDSeq",
":",
"1000",
",",
"msgIDsToName",
":",
"make",
"(",
"map",
"[",
"uint16",
"]",
"string",
")",
",",
"msgNameToIds",
":",
"make",
"(",
"map",
"[",
... | // NewVppAdapter returns a new mock adapter. | [
"NewVppAdapter",
"returns",
"a",
"new",
"mock",
"adapter",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/mock/mock_vpp_adapter.go#L93-L102 |
12,670 | FDio/govpp | adapter/mock/mock_vpp_adapter.go | GetMsgNameByID | func (a *VppAdapter) GetMsgNameByID(msgID uint16) (string, bool) {
switch msgID {
case 100:
return "control_ping", true
case 101:
return "control_ping_reply", true
case 200:
return "sw_interface_dump", true
case 201:
return "sw_interface_details", true
}
a.access.Lock()
defer a.access.Unlock()
msgName... | go | func (a *VppAdapter) GetMsgNameByID(msgID uint16) (string, bool) {
switch msgID {
case 100:
return "control_ping", true
case 101:
return "control_ping_reply", true
case 200:
return "sw_interface_dump", true
case 201:
return "sw_interface_details", true
}
a.access.Lock()
defer a.access.Unlock()
msgName... | [
"func",
"(",
"a",
"*",
"VppAdapter",
")",
"GetMsgNameByID",
"(",
"msgID",
"uint16",
")",
"(",
"string",
",",
"bool",
")",
"{",
"switch",
"msgID",
"{",
"case",
"100",
":",
"return",
"\"",
"\"",
",",
"true",
"\n",
"case",
"101",
":",
"return",
"\"",
... | // GetMsgNameByID returns message name for specified message ID. | [
"GetMsgNameByID",
"returns",
"message",
"name",
"for",
"specified",
"message",
"ID",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/mock/mock_vpp_adapter.go#L115-L132 |
12,671 | FDio/govpp | adapter/mock/mock_vpp_adapter.go | ReplyTypeFor | func (a *VppAdapter) ReplyTypeFor(requestMsgName string) (reflect.Type, uint16, bool) {
replyName, foundName := binapi.ReplyNameFor(requestMsgName)
if foundName {
if reply, found := a.binAPITypes[replyName]; found {
msgID, err := a.GetMsgID(replyName, "")
if err == nil {
return reply, msgID, found
}
... | go | func (a *VppAdapter) ReplyTypeFor(requestMsgName string) (reflect.Type, uint16, bool) {
replyName, foundName := binapi.ReplyNameFor(requestMsgName)
if foundName {
if reply, found := a.binAPITypes[replyName]; found {
msgID, err := a.GetMsgID(replyName, "")
if err == nil {
return reply, msgID, found
}
... | [
"func",
"(",
"a",
"*",
"VppAdapter",
")",
"ReplyTypeFor",
"(",
"requestMsgName",
"string",
")",
"(",
"reflect",
".",
"Type",
",",
"uint16",
",",
"bool",
")",
"{",
"replyName",
",",
"foundName",
":=",
"binapi",
".",
"ReplyNameFor",
"(",
"requestMsgName",
")... | // ReplyTypeFor returns reply message type for given request message name. | [
"ReplyTypeFor",
"returns",
"reply",
"message",
"type",
"for",
"given",
"request",
"message",
"name",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/mock/mock_vpp_adapter.go#L143-L155 |
12,672 | FDio/govpp | adapter/mock/mock_vpp_adapter.go | ReplyFor | func (a *VppAdapter) ReplyFor(requestMsgName string) (api.Message, uint16, bool) {
replType, msgID, foundReplType := a.ReplyTypeFor(requestMsgName)
if foundReplType {
msgVal := reflect.New(replType)
if msg, ok := msgVal.Interface().(api.Message); ok {
log.Println("FFF ", replType, msgID, foundReplType)
retu... | go | func (a *VppAdapter) ReplyFor(requestMsgName string) (api.Message, uint16, bool) {
replType, msgID, foundReplType := a.ReplyTypeFor(requestMsgName)
if foundReplType {
msgVal := reflect.New(replType)
if msg, ok := msgVal.Interface().(api.Message); ok {
log.Println("FFF ", replType, msgID, foundReplType)
retu... | [
"func",
"(",
"a",
"*",
"VppAdapter",
")",
"ReplyFor",
"(",
"requestMsgName",
"string",
")",
"(",
"api",
".",
"Message",
",",
"uint16",
",",
"bool",
")",
"{",
"replType",
",",
"msgID",
",",
"foundReplType",
":=",
"a",
".",
"ReplyTypeFor",
"(",
"requestMsg... | // ReplyFor returns reply message for given request message name. | [
"ReplyFor",
"returns",
"reply",
"message",
"for",
"given",
"request",
"message",
"name",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/mock/mock_vpp_adapter.go#L158-L169 |
12,673 | FDio/govpp | adapter/mock/mock_vpp_adapter.go | ReplyBytes | func (a *VppAdapter) ReplyBytes(request MessageDTO, reply api.Message) ([]byte, error) {
replyMsgID, err := a.GetMsgID(reply.GetMessageName(), reply.GetCrcString())
if err != nil {
log.Println("ReplyBytesE ", replyMsgID, " ", reply.GetMessageName(), " clientId: ", request.ClientID,
" ", err)
return nil, err
}... | go | func (a *VppAdapter) ReplyBytes(request MessageDTO, reply api.Message) ([]byte, error) {
replyMsgID, err := a.GetMsgID(reply.GetMessageName(), reply.GetCrcString())
if err != nil {
log.Println("ReplyBytesE ", replyMsgID, " ", reply.GetMessageName(), " clientId: ", request.ClientID,
" ", err)
return nil, err
}... | [
"func",
"(",
"a",
"*",
"VppAdapter",
")",
"ReplyBytes",
"(",
"request",
"MessageDTO",
",",
"reply",
"api",
".",
"Message",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"replyMsgID",
",",
"err",
":=",
"a",
".",
"GetMsgID",
"(",
"reply",
".",
... | // ReplyBytes encodes the mocked reply into binary format. | [
"ReplyBytes",
"encodes",
"the",
"mocked",
"reply",
"into",
"binary",
"format",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/mock/mock_vpp_adapter.go#L172-L194 |
12,674 | FDio/govpp | adapter/mock/mock_vpp_adapter.go | GetMsgID | func (a *VppAdapter) GetMsgID(msgName string, msgCrc string) (uint16, error) {
switch msgName {
case "control_ping":
return 100, nil
case "control_ping_reply":
return 101, nil
case "sw_interface_dump":
return 200, nil
case "sw_interface_details":
return 201, nil
}
a.access.Lock()
defer a.access.Unlock(... | go | func (a *VppAdapter) GetMsgID(msgName string, msgCrc string) (uint16, error) {
switch msgName {
case "control_ping":
return 100, nil
case "control_ping_reply":
return 101, nil
case "sw_interface_dump":
return 200, nil
case "sw_interface_details":
return 201, nil
}
a.access.Lock()
defer a.access.Unlock(... | [
"func",
"(",
"a",
"*",
"VppAdapter",
")",
"GetMsgID",
"(",
"msgName",
"string",
",",
"msgCrc",
"string",
")",
"(",
"uint16",
",",
"error",
")",
"{",
"switch",
"msgName",
"{",
"case",
"\"",
"\"",
":",
"return",
"100",
",",
"nil",
"\n",
"case",
"\"",
... | // GetMsgID returns mocked message ID for the given message name and CRC. | [
"GetMsgID",
"returns",
"mocked",
"message",
"ID",
"for",
"the",
"given",
"message",
"name",
"and",
"CRC",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/mock/mock_vpp_adapter.go#L197-L223 |
12,675 | FDio/govpp | adapter/mock/mock_vpp_adapter.go | MockReplyHandler | func (a *VppAdapter) MockReplyHandler(replyHandler ReplyHandler) {
a.repliesLock.Lock()
defer a.repliesLock.Unlock()
a.replyHandlers = append(a.replyHandlers, replyHandler)
a.mode = useReplyHandlers
} | go | func (a *VppAdapter) MockReplyHandler(replyHandler ReplyHandler) {
a.repliesLock.Lock()
defer a.repliesLock.Unlock()
a.replyHandlers = append(a.replyHandlers, replyHandler)
a.mode = useReplyHandlers
} | [
"func",
"(",
"a",
"*",
"VppAdapter",
")",
"MockReplyHandler",
"(",
"replyHandler",
"ReplyHandler",
")",
"{",
"a",
".",
"repliesLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"repliesLock",
".",
"Unlock",
"(",
")",
"\n\n",
"a",
".",
"replyHandlers... | // MockReplyHandler registers a handler function that is supposed to generate mock responses to incoming requests.
// Using of this method automatically switches the mock into th useReplyHandlers mode. | [
"MockReplyHandler",
"registers",
"a",
"handler",
"function",
"that",
"is",
"supposed",
"to",
"generate",
"mock",
"responses",
"to",
"incoming",
"requests",
".",
"Using",
"of",
"this",
"method",
"automatically",
"switches",
"the",
"mock",
"into",
"th",
"useReplyHan... | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/adapter/mock/mock_vpp_adapter.go#L367-L373 |
12,676 | FDio/govpp | extras/libmemif/examples/gopacket/gopacket.go | OnInterrupt | func OnInterrupt(handle *libmemif.MemifPacketHandle) {
source := gopacket.NewPacketSource(handle, layers.LayerTypeEthernet)
var responses []gopacket.Packet
// Process ICMP pings
for packet := range source.Packets() {
fmt.Println("Received new packet:")
fmt.Println(packet.Dump())
response, err := GeneratePac... | go | func OnInterrupt(handle *libmemif.MemifPacketHandle) {
source := gopacket.NewPacketSource(handle, layers.LayerTypeEthernet)
var responses []gopacket.Packet
// Process ICMP pings
for packet := range source.Packets() {
fmt.Println("Received new packet:")
fmt.Println(packet.Dump())
response, err := GeneratePac... | [
"func",
"OnInterrupt",
"(",
"handle",
"*",
"libmemif",
".",
"MemifPacketHandle",
")",
"{",
"source",
":=",
"gopacket",
".",
"NewPacketSource",
"(",
"handle",
",",
"layers",
".",
"LayerTypeEthernet",
")",
"\n",
"var",
"responses",
"[",
"]",
"gopacket",
".",
"... | // OnInterrupt is called when interrupted | [
"OnInterrupt",
"is",
"called",
"when",
"interrupted"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/examples/gopacket/gopacket.go#L107-L140 |
12,677 | FDio/govpp | extras/libmemif/examples/gopacket/gopacket.go | CreateInterruptCallback | func CreateInterruptCallback(handle *libmemif.MemifPacketHandle, interruptCh <-chan struct{}, callback func(handle *libmemif.MemifPacketHandle)) {
for {
select {
case <-interruptCh:
callback(handle)
case <-stopCh:
handle.Close()
return
}
}
} | go | func CreateInterruptCallback(handle *libmemif.MemifPacketHandle, interruptCh <-chan struct{}, callback func(handle *libmemif.MemifPacketHandle)) {
for {
select {
case <-interruptCh:
callback(handle)
case <-stopCh:
handle.Close()
return
}
}
} | [
"func",
"CreateInterruptCallback",
"(",
"handle",
"*",
"libmemif",
".",
"MemifPacketHandle",
",",
"interruptCh",
"<-",
"chan",
"struct",
"{",
"}",
",",
"callback",
"func",
"(",
"handle",
"*",
"libmemif",
".",
"MemifPacketHandle",
")",
")",
"{",
"for",
"{",
"... | // Creates user-friendly memif interrupt callback | [
"Creates",
"user",
"-",
"friendly",
"memif",
"interrupt",
"callback"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/examples/gopacket/gopacket.go#L143-L153 |
12,678 | FDio/govpp | core/connection.go | Connect | func Connect(binapi adapter.VppAPI) (*Connection, error) {
// create new connection handle
c := newConnection(binapi, DefaultMaxReconnectAttempts, DefaultReconnectInterval)
// blocking attempt to connect to VPP
if err := c.connectVPP(); err != nil {
return nil, err
}
return c, nil
} | go | func Connect(binapi adapter.VppAPI) (*Connection, error) {
// create new connection handle
c := newConnection(binapi, DefaultMaxReconnectAttempts, DefaultReconnectInterval)
// blocking attempt to connect to VPP
if err := c.connectVPP(); err != nil {
return nil, err
}
return c, nil
} | [
"func",
"Connect",
"(",
"binapi",
"adapter",
".",
"VppAPI",
")",
"(",
"*",
"Connection",
",",
"error",
")",
"{",
"// create new connection handle",
"c",
":=",
"newConnection",
"(",
"binapi",
",",
"DefaultMaxReconnectAttempts",
",",
"DefaultReconnectInterval",
")",
... | // Connect connects to VPP API using specified adapter and returns a connection handle.
// This call blocks until it is either connected, or an error occurs.
// Only one connection attempt will be performed. | [
"Connect",
"connects",
"to",
"VPP",
"API",
"using",
"specified",
"adapter",
"and",
"returns",
"a",
"connection",
"handle",
".",
"This",
"call",
"blocks",
"until",
"it",
"is",
"either",
"connected",
"or",
"an",
"error",
"occurs",
".",
"Only",
"one",
"connecti... | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/connection.go#L142-L152 |
12,679 | FDio/govpp | core/connection.go | connectVPP | func (c *Connection) connectVPP() error {
log.Debug("Connecting to VPP..")
// blocking connect
if err := c.vppClient.Connect(); err != nil {
return err
}
log.Debugf("Connected to VPP.")
if err := c.retrieveMessageIDs(); err != nil {
c.vppClient.Disconnect()
return fmt.Errorf("VPP is incompatible: %v", er... | go | func (c *Connection) connectVPP() error {
log.Debug("Connecting to VPP..")
// blocking connect
if err := c.vppClient.Connect(); err != nil {
return err
}
log.Debugf("Connected to VPP.")
if err := c.retrieveMessageIDs(); err != nil {
c.vppClient.Disconnect()
return fmt.Errorf("VPP is incompatible: %v", er... | [
"func",
"(",
"c",
"*",
"Connection",
")",
"connectVPP",
"(",
")",
"error",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"// blocking connect",
"if",
"err",
":=",
"c",
".",
"vppClient",
".",
"Connect",
"(",
")",
";",
"err",
"!=",
"nil",
"... | // connectVPP performs blocking attempt to connect to VPP. | [
"connectVPP",
"performs",
"blocking",
"attempt",
"to",
"connect",
"to",
"VPP",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/connection.go#L170-L189 |
12,680 | FDio/govpp | core/connection.go | Disconnect | func (c *Connection) Disconnect() {
if c == nil {
return
}
if c.vppClient != nil {
c.disconnectVPP()
}
} | go | func (c *Connection) Disconnect() {
if c == nil {
return
}
if c.vppClient != nil {
c.disconnectVPP()
}
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"Disconnect",
"(",
")",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"vppClient",
"!=",
"nil",
"{",
"c",
".",
"disconnectVPP",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Disconnect disconnects from VPP API and releases all connection-related resources. | [
"Disconnect",
"disconnects",
"from",
"VPP",
"API",
"and",
"releases",
"all",
"connection",
"-",
"related",
"resources",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/connection.go#L192-L200 |
12,681 | FDio/govpp | core/connection.go | disconnectVPP | func (c *Connection) disconnectVPP() {
if atomic.CompareAndSwapUint32(&c.vppConnected, 1, 0) {
c.vppClient.Disconnect()
}
} | go | func (c *Connection) disconnectVPP() {
if atomic.CompareAndSwapUint32(&c.vppConnected, 1, 0) {
c.vppClient.Disconnect()
}
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"disconnectVPP",
"(",
")",
"{",
"if",
"atomic",
".",
"CompareAndSwapUint32",
"(",
"&",
"c",
".",
"vppConnected",
",",
"1",
",",
"0",
")",
"{",
"c",
".",
"vppClient",
".",
"Disconnect",
"(",
")",
"\n",
"}",
... | // disconnectVPP disconnects from VPP in case it is connected. | [
"disconnectVPP",
"disconnects",
"from",
"VPP",
"in",
"case",
"it",
"is",
"connected",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/connection.go#L203-L207 |
12,682 | FDio/govpp | core/connection.go | newAPIChannel | func (c *Connection) newAPIChannel(reqChanBufSize, replyChanBufSize int) (*Channel, error) {
if c == nil {
return nil, errors.New("nil connection passed in")
}
// create new channel
chID := uint16(atomic.AddUint32(&c.maxChannelID, 1) & 0x7fff)
channel := newChannel(chID, c, c.codec, c, reqChanBufSize, replyChan... | go | func (c *Connection) newAPIChannel(reqChanBufSize, replyChanBufSize int) (*Channel, error) {
if c == nil {
return nil, errors.New("nil connection passed in")
}
// create new channel
chID := uint16(atomic.AddUint32(&c.maxChannelID, 1) & 0x7fff)
channel := newChannel(chID, c, c.codec, c, reqChanBufSize, replyChan... | [
"func",
"(",
"c",
"*",
"Connection",
")",
"newAPIChannel",
"(",
"reqChanBufSize",
",",
"replyChanBufSize",
"int",
")",
"(",
"*",
"Channel",
",",
"error",
")",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\... | // NewAPIChannelBuffered returns a new API channel for communication with VPP via govpp core.
// It allows to specify custom buffer sizes for the request and reply Go channels. | [
"NewAPIChannelBuffered",
"returns",
"a",
"new",
"API",
"channel",
"for",
"communication",
"with",
"VPP",
"via",
"govpp",
"core",
".",
"It",
"allows",
"to",
"specify",
"custom",
"buffer",
"sizes",
"for",
"the",
"request",
"and",
"reply",
"Go",
"channels",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/connection.go#L219-L237 |
12,683 | FDio/govpp | core/connection.go | releaseAPIChannel | func (c *Connection) releaseAPIChannel(ch *Channel) {
log.WithFields(logger.Fields{
"channel": ch.id,
}).Debug("API channel released")
// delete the channel from channels map
c.channelsLock.Lock()
delete(c.channels, ch.id)
c.channelsLock.Unlock()
} | go | func (c *Connection) releaseAPIChannel(ch *Channel) {
log.WithFields(logger.Fields{
"channel": ch.id,
}).Debug("API channel released")
// delete the channel from channels map
c.channelsLock.Lock()
delete(c.channels, ch.id)
c.channelsLock.Unlock()
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"releaseAPIChannel",
"(",
"ch",
"*",
"Channel",
")",
"{",
"log",
".",
"WithFields",
"(",
"logger",
".",
"Fields",
"{",
"\"",
"\"",
":",
"ch",
".",
"id",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
... | // releaseAPIChannel releases API channel that needs to be closed. | [
"releaseAPIChannel",
"releases",
"API",
"channel",
"that",
"needs",
"to",
"be",
"closed",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/connection.go#L240-L249 |
12,684 | FDio/govpp | core/connection.go | connectLoop | func (c *Connection) connectLoop(connChan chan ConnectionEvent) {
reconnectAttempts := 0
// loop until connected
for {
if err := c.vppClient.WaitReady(); err != nil {
log.Warnf("wait ready failed: %v", err)
}
if err := c.connectVPP(); err == nil {
// signal connected event
connChan <- ConnectionEvent... | go | func (c *Connection) connectLoop(connChan chan ConnectionEvent) {
reconnectAttempts := 0
// loop until connected
for {
if err := c.vppClient.WaitReady(); err != nil {
log.Warnf("wait ready failed: %v", err)
}
if err := c.connectVPP(); err == nil {
// signal connected event
connChan <- ConnectionEvent... | [
"func",
"(",
"c",
"*",
"Connection",
")",
"connectLoop",
"(",
"connChan",
"chan",
"ConnectionEvent",
")",
"{",
"reconnectAttempts",
":=",
"0",
"\n\n",
"// loop until connected",
"for",
"{",
"if",
"err",
":=",
"c",
".",
"vppClient",
".",
"WaitReady",
"(",
")"... | // connectLoop attempts to connect to VPP until it succeeds.
// Then it continues with healthCheckLoop. | [
"connectLoop",
"attempts",
"to",
"connect",
"to",
"VPP",
"until",
"it",
"succeeds",
".",
"Then",
"it",
"continues",
"with",
"healthCheckLoop",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/connection.go#L253-L277 |
12,685 | FDio/govpp | core/connection.go | healthCheckLoop | func (c *Connection) healthCheckLoop(connChan chan ConnectionEvent) {
// create a separate API channel for health check probes
ch, err := c.newAPIChannel(1, 1)
if err != nil {
log.Error("Failed to create health check API channel, health check will be disabled:", err)
return
}
var (
sinceLastReply time.Durat... | go | func (c *Connection) healthCheckLoop(connChan chan ConnectionEvent) {
// create a separate API channel for health check probes
ch, err := c.newAPIChannel(1, 1)
if err != nil {
log.Error("Failed to create health check API channel, health check will be disabled:", err)
return
}
var (
sinceLastReply time.Durat... | [
"func",
"(",
"c",
"*",
"Connection",
")",
"healthCheckLoop",
"(",
"connChan",
"chan",
"ConnectionEvent",
")",
"{",
"// create a separate API channel for health check probes",
"ch",
",",
"err",
":=",
"c",
".",
"newAPIChannel",
"(",
"1",
",",
"1",
")",
"\n",
"if",... | // healthCheckLoop checks whether connection to VPP is alive. In case of disconnect,
// it continues with connectLoop and tries to reconnect. | [
"healthCheckLoop",
"checks",
"whether",
"connection",
"to",
"VPP",
"is",
"alive",
".",
"In",
"case",
"of",
"disconnect",
"it",
"continues",
"with",
"connectLoop",
"and",
"tries",
"to",
"reconnect",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/connection.go#L281-L365 |
12,686 | FDio/govpp | core/connection.go | GetMessageID | func (c *Connection) GetMessageID(msg api.Message) (uint16, error) {
if c == nil {
return 0, errors.New("nil connection passed in")
}
if msgID, ok := c.msgIDs[getMsgNameWithCrc(msg)]; ok {
return msgID, nil
}
msgID, err := c.vppClient.GetMsgID(msg.GetMessageName(), msg.GetCrcString())
if err != nil {
retu... | go | func (c *Connection) GetMessageID(msg api.Message) (uint16, error) {
if c == nil {
return 0, errors.New("nil connection passed in")
}
if msgID, ok := c.msgIDs[getMsgNameWithCrc(msg)]; ok {
return msgID, nil
}
msgID, err := c.vppClient.GetMsgID(msg.GetMessageName(), msg.GetCrcString())
if err != nil {
retu... | [
"func",
"(",
"c",
"*",
"Connection",
")",
"GetMessageID",
"(",
"msg",
"api",
".",
"Message",
")",
"(",
"uint16",
",",
"error",
")",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n... | // GetMessageID returns message identifier of given API message. | [
"GetMessageID",
"returns",
"message",
"identifier",
"of",
"given",
"API",
"message",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/connection.go#L378-L396 |
12,687 | FDio/govpp | core/connection.go | LookupByID | func (c *Connection) LookupByID(msgID uint16) (api.Message, error) {
if c == nil {
return nil, errors.New("nil connection passed in")
}
if msg, ok := c.msgMap[msgID]; ok {
return msg, nil
}
return nil, fmt.Errorf("unknown message ID: %d", msgID)
} | go | func (c *Connection) LookupByID(msgID uint16) (api.Message, error) {
if c == nil {
return nil, errors.New("nil connection passed in")
}
if msg, ok := c.msgMap[msgID]; ok {
return msg, nil
}
return nil, fmt.Errorf("unknown message ID: %d", msgID)
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"LookupByID",
"(",
"msgID",
"uint16",
")",
"(",
"api",
".",
"Message",
",",
"error",
")",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"... | // LookupByID looks up message name and crc by ID. | [
"LookupByID",
"looks",
"up",
"message",
"name",
"and",
"crc",
"by",
"ID",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/connection.go#L399-L409 |
12,688 | FDio/govpp | core/connection.go | retrieveMessageIDs | func (c *Connection) retrieveMessageIDs() (err error) {
t := time.Now()
msgs := api.GetRegisteredMessages()
var n int
for name, msg := range msgs {
msgID, err := c.GetMessageID(msg)
if err != nil {
log.Debugf("retrieving msgID for %s failed: %v", name, err)
continue
}
n++
if c.pingReqID == 0 && m... | go | func (c *Connection) retrieveMessageIDs() (err error) {
t := time.Now()
msgs := api.GetRegisteredMessages()
var n int
for name, msg := range msgs {
msgID, err := c.GetMessageID(msg)
if err != nil {
log.Debugf("retrieving msgID for %s failed: %v", name, err)
continue
}
n++
if c.pingReqID == 0 && m... | [
"func",
"(",
"c",
"*",
"Connection",
")",
"retrieveMessageIDs",
"(",
")",
"(",
"err",
"error",
")",
"{",
"t",
":=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"msgs",
":=",
"api",
".",
"GetRegisteredMessages",
"(",
")",
"\n\n",
"var",
"n",
"int",
"\n",
... | // retrieveMessageIDs retrieves IDs for all registered messages and stores them in map | [
"retrieveMessageIDs",
"retrieves",
"IDs",
"for",
"all",
"registered",
"messages",
"and",
"stores",
"them",
"in",
"map"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/connection.go#L412-L441 |
12,689 | mailgun/lemma | httpsign/nonce.go | NewNonceCache | func NewNonceCache(capacity int, cacheTTL int, timeProvider timetools.TimeProvider) (*NonceCache, error) {
c, err := ttlmap.NewMapWithProvider(capacity, timeProvider)
if err != nil {
return nil, err
}
return &NonceCache{
cache: c,
cacheTTL: cacheTTL,
timeProvider: timeProvider,
}, nil
} | go | func NewNonceCache(capacity int, cacheTTL int, timeProvider timetools.TimeProvider) (*NonceCache, error) {
c, err := ttlmap.NewMapWithProvider(capacity, timeProvider)
if err != nil {
return nil, err
}
return &NonceCache{
cache: c,
cacheTTL: cacheTTL,
timeProvider: timeProvider,
}, nil
} | [
"func",
"NewNonceCache",
"(",
"capacity",
"int",
",",
"cacheTTL",
"int",
",",
"timeProvider",
"timetools",
".",
"TimeProvider",
")",
"(",
"*",
"NonceCache",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"ttlmap",
".",
"NewMapWithProvider",
"(",
"capacity",
... | // Return a new NonceCache. Allows you to control cache capacity, ttl, as well as the TimeProvider. | [
"Return",
"a",
"new",
"NonceCache",
".",
"Allows",
"you",
"to",
"control",
"cache",
"capacity",
"ttl",
"as",
"well",
"as",
"the",
"TimeProvider",
"."
] | 4214099fb348c416514bc2c93087fde56216d7b5 | https://github.com/mailgun/lemma/blob/4214099fb348c416514bc2c93087fde56216d7b5/httpsign/nonce.go#L18-L29 |
12,690 | mailgun/lemma | httpsign/auth.go | NewWithProviders | func NewWithProviders(config *Config, timeProvider timetools.TimeProvider,
randomProvider random.RandomProvider) (*Service, error) {
// config is required!
if config == nil {
return nil, fmt.Errorf("config is required.")
}
// set defaults if not set
if config.NonceCacheCapacity < 1 {
config.NonceCacheCapaci... | go | func NewWithProviders(config *Config, timeProvider timetools.TimeProvider,
randomProvider random.RandomProvider) (*Service, error) {
// config is required!
if config == nil {
return nil, fmt.Errorf("config is required.")
}
// set defaults if not set
if config.NonceCacheCapacity < 1 {
config.NonceCacheCapaci... | [
"func",
"NewWithProviders",
"(",
"config",
"*",
"Config",
",",
"timeProvider",
"timetools",
".",
"TimeProvider",
",",
"randomProvider",
"random",
".",
"RandomProvider",
")",
"(",
"*",
"Service",
",",
"error",
")",
"{",
"// config is required!",
"if",
"config",
"... | // Returns a new Service. Provides control over time and random providers. | [
"Returns",
"a",
"new",
"Service",
".",
"Provides",
"control",
"over",
"time",
"and",
"random",
"providers",
"."
] | 4214099fb348c416514bc2c93087fde56216d7b5 | https://github.com/mailgun/lemma/blob/4214099fb348c416514bc2c93087fde56216d7b5/httpsign/auth.go#L77-L157 |
12,691 | mailgun/lemma | httpsign/auth.go | SignRequestWithKey | func (s *Service) SignRequestWithKey(r *http.Request, secretKey []byte) error {
// extract request body bytes
bodyBytes, err := readBody(r)
if err != nil {
return err
}
// extract any headers if requested
headerValues, err := extractHeaderValues(r, s.config.HeadersToSign)
if err != nil {
return err
}
// ... | go | func (s *Service) SignRequestWithKey(r *http.Request, secretKey []byte) error {
// extract request body bytes
bodyBytes, err := readBody(r)
if err != nil {
return err
}
// extract any headers if requested
headerValues, err := extractHeaderValues(r, s.config.HeadersToSign)
if err != nil {
return err
}
// ... | [
"func",
"(",
"s",
"*",
"Service",
")",
"SignRequestWithKey",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"secretKey",
"[",
"]",
"byte",
")",
"error",
"{",
"// extract request body bytes",
"bodyBytes",
",",
"err",
":=",
"readBody",
"(",
"r",
")",
"\n",
"i... | // Signs a given HTTP request with signature, nonce, and timestamp. Signs the
// message with the passed in key not the one initialized with. | [
"Signs",
"a",
"given",
"HTTP",
"request",
"with",
"signature",
"nonce",
"and",
"timestamp",
".",
"Signs",
"the",
"message",
"with",
"the",
"passed",
"in",
"key",
"not",
"the",
"one",
"initialized",
"with",
"."
] | 4214099fb348c416514bc2c93087fde56216d7b5 | https://github.com/mailgun/lemma/blob/4214099fb348c416514bc2c93087fde56216d7b5/httpsign/auth.go#L169-L206 |
12,692 | mailgun/lemma | secret/key.go | NewKey | func NewKey() (*[SecretKeyLength]byte, error) {
// get 32-bytes of random from /dev/urandom
bytes, err := randomProvider.Bytes(SecretKeyLength)
if err != nil {
return nil, fmt.Errorf("unable to generate random: %v", err)
}
return KeySliceToArray(bytes)
} | go | func NewKey() (*[SecretKeyLength]byte, error) {
// get 32-bytes of random from /dev/urandom
bytes, err := randomProvider.Bytes(SecretKeyLength)
if err != nil {
return nil, fmt.Errorf("unable to generate random: %v", err)
}
return KeySliceToArray(bytes)
} | [
"func",
"NewKey",
"(",
")",
"(",
"*",
"[",
"SecretKeyLength",
"]",
"byte",
",",
"error",
")",
"{",
"// get 32-bytes of random from /dev/urandom",
"bytes",
",",
"err",
":=",
"randomProvider",
".",
"Bytes",
"(",
"SecretKeyLength",
")",
"\n",
"if",
"err",
"!=",
... | // NewKey returns a new key that can be used to encrypt and decrypt messages. | [
"NewKey",
"returns",
"a",
"new",
"key",
"that",
"can",
"be",
"used",
"to",
"encrypt",
"and",
"decrypt",
"messages",
"."
] | 4214099fb348c416514bc2c93087fde56216d7b5 | https://github.com/mailgun/lemma/blob/4214099fb348c416514bc2c93087fde56216d7b5/secret/key.go#L10-L18 |
12,693 | xiam/exif | exif.go | Read | func Read(file string) (*Data, error) {
data := New()
if err := data.Open(file); err != nil {
return nil, err
}
return data, nil
} | go | func Read(file string) (*Data, error) {
data := New()
if err := data.Open(file); err != nil {
return nil, err
}
return data, nil
} | [
"func",
"Read",
"(",
"file",
"string",
")",
"(",
"*",
"Data",
",",
"error",
")",
"{",
"data",
":=",
"New",
"(",
")",
"\n",
"if",
"err",
":=",
"data",
".",
"Open",
"(",
"file",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\... | // Read attempts to read EXIF data from a file. | [
"Read",
"attempts",
"to",
"read",
"EXIF",
"data",
"from",
"a",
"file",
"."
] | 33e82e3db72f03c4d55d10b7275d267fc7cd0e45 | https://github.com/xiam/exif/blob/33e82e3db72f03c4d55d10b7275d267fc7cd0e45/exif.go#L66-L72 |
12,694 | xiam/exif | exif.go | Open | func (d *Data) Open(file string) error {
cfile := C.CString(file)
defer C.free(unsafe.Pointer(cfile))
exifData := C.exif_data_new_from_file(cfile)
if exifData == nil {
return ErrNoExifData
}
defer C.exif_data_unref(exifData)
return d.parseExifData(exifData)
} | go | func (d *Data) Open(file string) error {
cfile := C.CString(file)
defer C.free(unsafe.Pointer(cfile))
exifData := C.exif_data_new_from_file(cfile)
if exifData == nil {
return ErrNoExifData
}
defer C.exif_data_unref(exifData)
return d.parseExifData(exifData)
} | [
"func",
"(",
"d",
"*",
"Data",
")",
"Open",
"(",
"file",
"string",
")",
"error",
"{",
"cfile",
":=",
"C",
".",
"CString",
"(",
"file",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cfile",
")",
")",
"\n\n",
"exifData"... | // Open opens a file path and loads its EXIF data. | [
"Open",
"opens",
"a",
"file",
"path",
"and",
"loads",
"its",
"EXIF",
"data",
"."
] | 33e82e3db72f03c4d55d10b7275d267fc7cd0e45 | https://github.com/xiam/exif/blob/33e82e3db72f03c4d55d10b7275d267fc7cd0e45/exif.go#L75-L88 |
12,695 | xiam/exif | exif.go | Write | func (d *Data) Write(p []byte) (n int, err error) {
if d.exifLoader == nil {
d.exifLoader = C.exif_loader_new()
runtime.SetFinalizer(d, (*Data).cleanup)
}
res := C.exif_loader_write(d.exifLoader, (*C.uchar)(unsafe.Pointer(&p[0])), C.uint(len(p)))
if res == 1 {
return len(p), nil
}
return len(p), ErrFoundE... | go | func (d *Data) Write(p []byte) (n int, err error) {
if d.exifLoader == nil {
d.exifLoader = C.exif_loader_new()
runtime.SetFinalizer(d, (*Data).cleanup)
}
res := C.exif_loader_write(d.exifLoader, (*C.uchar)(unsafe.Pointer(&p[0])), C.uint(len(p)))
if res == 1 {
return len(p), nil
}
return len(p), ErrFoundE... | [
"func",
"(",
"d",
"*",
"Data",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"if",
"d",
".",
"exifLoader",
"==",
"nil",
"{",
"d",
".",
"exifLoader",
"=",
"C",
".",
"exif_loader_new",
"(",
")",
... | // Write writes bytes to the exif loader. Sends ErrFoundExifInData error when
// enough bytes have been sent. | [
"Write",
"writes",
"bytes",
"to",
"the",
"exif",
"loader",
".",
"Sends",
"ErrFoundExifInData",
"error",
"when",
"enough",
"bytes",
"have",
"been",
"sent",
"."
] | 33e82e3db72f03c4d55d10b7275d267fc7cd0e45 | https://github.com/xiam/exif/blob/33e82e3db72f03c4d55d10b7275d267fc7cd0e45/exif.go#L109-L121 |
12,696 | xiam/exif | exif.go | Parse | func (d *Data) Parse() error {
defer d.cleanup()
exifData := C.exif_loader_get_data(d.exifLoader)
if exifData == nil {
return fmt.Errorf(ErrNoExifData.Error(), "")
}
defer func() {
C.exif_data_unref(exifData)
}()
return d.parseExifData(exifData)
} | go | func (d *Data) Parse() error {
defer d.cleanup()
exifData := C.exif_loader_get_data(d.exifLoader)
if exifData == nil {
return fmt.Errorf(ErrNoExifData.Error(), "")
}
defer func() {
C.exif_data_unref(exifData)
}()
return d.parseExifData(exifData)
} | [
"func",
"(",
"d",
"*",
"Data",
")",
"Parse",
"(",
")",
"error",
"{",
"defer",
"d",
".",
"cleanup",
"(",
")",
"\n\n",
"exifData",
":=",
"C",
".",
"exif_loader_get_data",
"(",
"d",
".",
"exifLoader",
")",
"\n",
"if",
"exifData",
"==",
"nil",
"{",
"re... | // Parse finalizes the data loader and sets the tags | [
"Parse",
"finalizes",
"the",
"data",
"loader",
"and",
"sets",
"the",
"tags"
] | 33e82e3db72f03c4d55d10b7275d267fc7cd0e45 | https://github.com/xiam/exif/blob/33e82e3db72f03c4d55d10b7275d267fc7cd0e45/exif.go#L124-L137 |
12,697 | tomcraven/goga | bitset.go | Create | func (b *Bitset) Create(size int) {
b.size = size
b.bits = make([]int, size)
} | go | func (b *Bitset) Create(size int) {
b.size = size
b.bits = make([]int, size)
} | [
"func",
"(",
"b",
"*",
"Bitset",
")",
"Create",
"(",
"size",
"int",
")",
"{",
"b",
".",
"size",
"=",
"size",
"\n",
"b",
".",
"bits",
"=",
"make",
"(",
"[",
"]",
"int",
",",
"size",
")",
"\n",
"}"
] | // Create - creates a bitset of length 'size' | [
"Create",
"-",
"creates",
"a",
"bitset",
"of",
"length",
"size"
] | 3b7915ecdd7bb6616dc3ceed450068e092ed87bc | https://github.com/tomcraven/goga/blob/3b7915ecdd7bb6616dc3ceed450068e092ed87bc/bitset.go#L10-L13 |
12,698 | tomcraven/goga | bitset.go | Get | func (b *Bitset) Get(index int) int {
if index < b.size {
return b.bits[index]
}
return -1
} | go | func (b *Bitset) Get(index int) int {
if index < b.size {
return b.bits[index]
}
return -1
} | [
"func",
"(",
"b",
"*",
"Bitset",
")",
"Get",
"(",
"index",
"int",
")",
"int",
"{",
"if",
"index",
"<",
"b",
".",
"size",
"{",
"return",
"b",
".",
"bits",
"[",
"index",
"]",
"\n",
"}",
"\n",
"return",
"-",
"1",
"\n",
"}"
] | // Get returns the value in the bitset at index 'index'
// or -1 if the index is out of range | [
"Get",
"returns",
"the",
"value",
"in",
"the",
"bitset",
"at",
"index",
"index",
"or",
"-",
"1",
"if",
"the",
"index",
"is",
"out",
"of",
"range"
] | 3b7915ecdd7bb6616dc3ceed450068e092ed87bc | https://github.com/tomcraven/goga/blob/3b7915ecdd7bb6616dc3ceed450068e092ed87bc/bitset.go#L22-L27 |
12,699 | tomcraven/goga | bitset.go | Set | func (b *Bitset) Set(index, value int) bool {
if index < b.size {
b.setImpl(index, value)
return true
}
return false
} | go | func (b *Bitset) Set(index, value int) bool {
if index < b.size {
b.setImpl(index, value)
return true
}
return false
} | [
"func",
"(",
"b",
"*",
"Bitset",
")",
"Set",
"(",
"index",
",",
"value",
"int",
")",
"bool",
"{",
"if",
"index",
"<",
"b",
".",
"size",
"{",
"b",
".",
"setImpl",
"(",
"index",
",",
"value",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return"... | // Set assigns value 'value' to the bit at index 'index' | [
"Set",
"assigns",
"value",
"value",
"to",
"the",
"bit",
"at",
"index",
"index"
] | 3b7915ecdd7bb6616dc3ceed450068e092ed87bc | https://github.com/tomcraven/goga/blob/3b7915ecdd7bb6616dc3ceed450068e092ed87bc/bitset.go#L39-L45 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.