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
partition
stringclasses
1 value
ipfs/go-datastore
delayed/delayed.go
Put
func (dds *Delayed) Put(key ds.Key, value []byte) (err error) { dds.delay.Wait() return dds.ds.Put(key, value) }
go
func (dds *Delayed) Put(key ds.Key, value []byte) (err error) { dds.delay.Wait() return dds.ds.Put(key, value) }
[ "func", "(", "dds", "*", "Delayed", ")", "Put", "(", "key", "ds", ".", "Key", ",", "value", "[", "]", "byte", ")", "(", "err", "error", ")", "{", "dds", ".", "delay", ".", "Wait", "(", ")", "\n", "return", "dds", ".", "ds", ".", "Put", "(", "key", ",", "value", ")", "\n", "}" ]
// Put implements the ds.Datastore interface.
[ "Put", "implements", "the", "ds", ".", "Datastore", "interface", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/delayed/delayed.go#L28-L31
train
ipfs/go-datastore
delayed/delayed.go
Has
func (dds *Delayed) Has(key ds.Key) (exists bool, err error) { dds.delay.Wait() return dds.ds.Has(key) }
go
func (dds *Delayed) Has(key ds.Key) (exists bool, err error) { dds.delay.Wait() return dds.ds.Has(key) }
[ "func", "(", "dds", "*", "Delayed", ")", "Has", "(", "key", "ds", ".", "Key", ")", "(", "exists", "bool", ",", "err", "error", ")", "{", "dds", ".", "delay", ".", "Wait", "(", ")", "\n", "return", "dds", ".", "ds", ".", "Has", "(", "key", ")", "\n", "}" ]
// Has implements the ds.Datastore interface.
[ "Has", "implements", "the", "ds", ".", "Datastore", "interface", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/delayed/delayed.go#L40-L43
train
ipfs/go-datastore
delayed/delayed.go
GetSize
func (dds *Delayed) GetSize(key ds.Key) (size int, err error) { dds.delay.Wait() return dds.ds.GetSize(key) }
go
func (dds *Delayed) GetSize(key ds.Key) (size int, err error) { dds.delay.Wait() return dds.ds.GetSize(key) }
[ "func", "(", "dds", "*", "Delayed", ")", "GetSize", "(", "key", "ds", ".", "Key", ")", "(", "size", "int", ",", "err", "error", ")", "{", "dds", ".", "delay", ".", "Wait", "(", ")", "\n", "return", "dds", ".", "ds", ".", "GetSize", "(", "key", ")", "\n", "}" ]
// GetSize implements the ds.Datastore interface.
[ "GetSize", "implements", "the", "ds", ".", "Datastore", "interface", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/delayed/delayed.go#L46-L49
train
ipfs/go-datastore
delayed/delayed.go
Delete
func (dds *Delayed) Delete(key ds.Key) (err error) { dds.delay.Wait() return dds.ds.Delete(key) }
go
func (dds *Delayed) Delete(key ds.Key) (err error) { dds.delay.Wait() return dds.ds.Delete(key) }
[ "func", "(", "dds", "*", "Delayed", ")", "Delete", "(", "key", "ds", ".", "Key", ")", "(", "err", "error", ")", "{", "dds", ".", "delay", ".", "Wait", "(", ")", "\n", "return", "dds", ".", "ds", ".", "Delete", "(", "key", ")", "\n", "}" ]
// Delete implements the ds.Datastore interface.
[ "Delete", "implements", "the", "ds", ".", "Datastore", "interface", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/delayed/delayed.go#L52-L55
train
ipfs/go-datastore
delayed/delayed.go
Query
func (dds *Delayed) Query(q dsq.Query) (dsq.Results, error) { dds.delay.Wait() return dds.ds.Query(q) }
go
func (dds *Delayed) Query(q dsq.Query) (dsq.Results, error) { dds.delay.Wait() return dds.ds.Query(q) }
[ "func", "(", "dds", "*", "Delayed", ")", "Query", "(", "q", "dsq", ".", "Query", ")", "(", "dsq", ".", "Results", ",", "error", ")", "{", "dds", ".", "delay", ".", "Wait", "(", ")", "\n", "return", "dds", ".", "ds", ".", "Query", "(", "q", ")", "\n", "}" ]
// Query implements the ds.Datastore interface.
[ "Query", "implements", "the", "ds", ".", "Datastore", "interface", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/delayed/delayed.go#L58-L61
train
ipfs/go-datastore
delayed/delayed.go
Batch
func (dds *Delayed) Batch() (ds.Batch, error) { return ds.NewBasicBatch(dds), nil }
go
func (dds *Delayed) Batch() (ds.Batch, error) { return ds.NewBasicBatch(dds), nil }
[ "func", "(", "dds", "*", "Delayed", ")", "Batch", "(", ")", "(", "ds", ".", "Batch", ",", "error", ")", "{", "return", "ds", ".", "NewBasicBatch", "(", "dds", ")", ",", "nil", "\n", "}" ]
// Batch implements the ds.Batching interface.
[ "Batch", "implements", "the", "ds", ".", "Batching", "interface", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/delayed/delayed.go#L64-L66
train
ipfs/go-datastore
delayed/delayed.go
DiskUsage
func (dds *Delayed) DiskUsage() (uint64, error) { dds.delay.Wait() return ds.DiskUsage(dds.ds) }
go
func (dds *Delayed) DiskUsage() (uint64, error) { dds.delay.Wait() return ds.DiskUsage(dds.ds) }
[ "func", "(", "dds", "*", "Delayed", ")", "DiskUsage", "(", ")", "(", "uint64", ",", "error", ")", "{", "dds", ".", "delay", ".", "Wait", "(", ")", "\n", "return", "ds", ".", "DiskUsage", "(", "dds", ".", "ds", ")", "\n", "}" ]
// DiskUsage implements the ds.PersistentDatastore interface.
[ "DiskUsage", "implements", "the", "ds", ".", "PersistentDatastore", "interface", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/delayed/delayed.go#L69-L72
train
ipfs/go-datastore
query/query.go
Results
func (rb *ResultBuilder) Results() Results { return &results{ query: rb.Query, proc: rb.Process, res: rb.Output, } }
go
func (rb *ResultBuilder) Results() Results { return &results{ query: rb.Query, proc: rb.Process, res: rb.Output, } }
[ "func", "(", "rb", "*", "ResultBuilder", ")", "Results", "(", ")", "Results", "{", "return", "&", "results", "{", "query", ":", "rb", ".", "Query", ",", "proc", ":", "rb", ".", "Process", ",", "res", ":", "rb", ".", "Output", ",", "}", "\n", "}" ]
// Results returns a Results to to this builder.
[ "Results", "returns", "a", "Results", "to", "to", "this", "builder", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/query/query.go#L179-L185
train
ipfs/go-datastore
query/query.go
ResultsWithProcess
func ResultsWithProcess(q Query, proc func(goprocess.Process, chan<- Result)) Results { b := NewResultBuilder(q) // go consume all the entries and add them to the results. b.Process.Go(func(worker goprocess.Process) { proc(worker, b.Output) }) go b.Process.CloseAfterChildren() return b.Results() }
go
func ResultsWithProcess(q Query, proc func(goprocess.Process, chan<- Result)) Results { b := NewResultBuilder(q) // go consume all the entries and add them to the results. b.Process.Go(func(worker goprocess.Process) { proc(worker, b.Output) }) go b.Process.CloseAfterChildren() return b.Results() }
[ "func", "ResultsWithProcess", "(", "q", "Query", ",", "proc", "func", "(", "goprocess", ".", "Process", ",", "chan", "<-", "Result", ")", ")", "Results", "{", "b", ":=", "NewResultBuilder", "(", "q", ")", "\n\n", "// go consume all the entries and add them to the results.", "b", ".", "Process", ".", "Go", "(", "func", "(", "worker", "goprocess", ".", "Process", ")", "{", "proc", "(", "worker", ",", "b", ".", "Output", ")", "\n", "}", ")", "\n\n", "go", "b", ".", "Process", ".", "CloseAfterChildren", "(", ")", "\n", "return", "b", ".", "Results", "(", ")", "\n", "}" ]
// ResultsWithProcess returns a Results object with the results generated by the // passed subprocess.
[ "ResultsWithProcess", "returns", "a", "Results", "object", "with", "the", "results", "generated", "by", "the", "passed", "subprocess", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/query/query.go#L234-L244
train
ipfs/go-datastore
query/query.go
ResultsWithEntries
func ResultsWithEntries(q Query, res []Entry) Results { i := 0 return ResultsFromIterator(q, Iterator{ Next: func() (Result, bool) { if i >= len(res) { return Result{}, false } next := res[i] i++ return Result{Entry: next}, true }, }) }
go
func ResultsWithEntries(q Query, res []Entry) Results { i := 0 return ResultsFromIterator(q, Iterator{ Next: func() (Result, bool) { if i >= len(res) { return Result{}, false } next := res[i] i++ return Result{Entry: next}, true }, }) }
[ "func", "ResultsWithEntries", "(", "q", "Query", ",", "res", "[", "]", "Entry", ")", "Results", "{", "i", ":=", "0", "\n", "return", "ResultsFromIterator", "(", "q", ",", "Iterator", "{", "Next", ":", "func", "(", ")", "(", "Result", ",", "bool", ")", "{", "if", "i", ">=", "len", "(", "res", ")", "{", "return", "Result", "{", "}", ",", "false", "\n", "}", "\n", "next", ":=", "res", "[", "i", "]", "\n", "i", "++", "\n", "return", "Result", "{", "Entry", ":", "next", "}", ",", "true", "\n", "}", ",", "}", ")", "\n", "}" ]
// ResultsWithEntries returns a Results object from a list of entries
[ "ResultsWithEntries", "returns", "a", "Results", "object", "from", "a", "list", "of", "entries" ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/query/query.go#L247-L259
train
ipfs/go-datastore
query/query.go
ResultsFromIterator
func ResultsFromIterator(q Query, iter Iterator) Results { if iter.Close == nil { iter.Close = noopClose } return &resultsIter{ query: q, next: iter.Next, close: iter.Close, } }
go
func ResultsFromIterator(q Query, iter Iterator) Results { if iter.Close == nil { iter.Close = noopClose } return &resultsIter{ query: q, next: iter.Next, close: iter.Close, } }
[ "func", "ResultsFromIterator", "(", "q", "Query", ",", "iter", "Iterator", ")", "Results", "{", "if", "iter", ".", "Close", "==", "nil", "{", "iter", ".", "Close", "=", "noopClose", "\n", "}", "\n", "return", "&", "resultsIter", "{", "query", ":", "q", ",", "next", ":", "iter", ".", "Next", ",", "close", ":", "iter", ".", "Close", ",", "}", "\n", "}" ]
// // ResultFromIterator provides an alternative way to to construct // results without the use of channels. //
[ "ResultFromIterator", "provides", "an", "alternative", "way", "to", "to", "construct", "results", "without", "the", "use", "of", "channels", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/query/query.go#L283-L292
train
ipfs/go-datastore
keytransform/keytransform.go
Wrap
func Wrap(child ds.Datastore, t KeyTransform) *Datastore { if t == nil { panic("t (KeyTransform) is nil") } if child == nil { panic("child (ds.Datastore) is nil") } return &Datastore{child: child, KeyTransform: t} }
go
func Wrap(child ds.Datastore, t KeyTransform) *Datastore { if t == nil { panic("t (KeyTransform) is nil") } if child == nil { panic("child (ds.Datastore) is nil") } return &Datastore{child: child, KeyTransform: t} }
[ "func", "Wrap", "(", "child", "ds", ".", "Datastore", ",", "t", "KeyTransform", ")", "*", "Datastore", "{", "if", "t", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "child", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "&", "Datastore", "{", "child", ":", "child", ",", "KeyTransform", ":", "t", "}", "\n", "}" ]
// Wrap wraps a given datastore with a KeyTransform function. // The resulting wrapped datastore will use the transform on all Datastore // operations.
[ "Wrap", "wraps", "a", "given", "datastore", "with", "a", "KeyTransform", "function", ".", "The", "resulting", "wrapped", "datastore", "will", "use", "the", "transform", "on", "all", "Datastore", "operations", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/keytransform/keytransform.go#L11-L21
train
ipfs/go-datastore
keytransform/keytransform.go
Put
func (d *Datastore) Put(key ds.Key, value []byte) (err error) { return d.child.Put(d.ConvertKey(key), value) }
go
func (d *Datastore) Put(key ds.Key, value []byte) (err error) { return d.child.Put(d.ConvertKey(key), value) }
[ "func", "(", "d", "*", "Datastore", ")", "Put", "(", "key", "ds", ".", "Key", ",", "value", "[", "]", "byte", ")", "(", "err", "error", ")", "{", "return", "d", ".", "child", ".", "Put", "(", "d", ".", "ConvertKey", "(", "key", ")", ",", "value", ")", "\n", "}" ]
// Put stores the given value, transforming the key first.
[ "Put", "stores", "the", "given", "value", "transforming", "the", "key", "first", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/keytransform/keytransform.go#L36-L38
train
ipfs/go-datastore
keytransform/keytransform.go
Has
func (d *Datastore) Has(key ds.Key) (exists bool, err error) { return d.child.Has(d.ConvertKey(key)) }
go
func (d *Datastore) Has(key ds.Key) (exists bool, err error) { return d.child.Has(d.ConvertKey(key)) }
[ "func", "(", "d", "*", "Datastore", ")", "Has", "(", "key", "ds", ".", "Key", ")", "(", "exists", "bool", ",", "err", "error", ")", "{", "return", "d", ".", "child", ".", "Has", "(", "d", ".", "ConvertKey", "(", "key", ")", ")", "\n", "}" ]
// Has returns whether the datastore has a value for a given key, transforming // the key first.
[ "Has", "returns", "whether", "the", "datastore", "has", "a", "value", "for", "a", "given", "key", "transforming", "the", "key", "first", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/keytransform/keytransform.go#L47-L49
train
ipfs/go-datastore
keytransform/keytransform.go
GetSize
func (d *Datastore) GetSize(key ds.Key) (size int, err error) { return d.child.GetSize(d.ConvertKey(key)) }
go
func (d *Datastore) GetSize(key ds.Key) (size int, err error) { return d.child.GetSize(d.ConvertKey(key)) }
[ "func", "(", "d", "*", "Datastore", ")", "GetSize", "(", "key", "ds", ".", "Key", ")", "(", "size", "int", ",", "err", "error", ")", "{", "return", "d", ".", "child", ".", "GetSize", "(", "d", ".", "ConvertKey", "(", "key", ")", ")", "\n", "}" ]
// GetSize returns the size of the value named by the given key, transforming // the key first.
[ "GetSize", "returns", "the", "size", "of", "the", "value", "named", "by", "the", "given", "key", "transforming", "the", "key", "first", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/keytransform/keytransform.go#L53-L55
train
ipfs/go-datastore
keytransform/keytransform.go
Query
func (d *Datastore) Query(q dsq.Query) (dsq.Results, error) { nq, cq := d.prepareQuery(q) cqr, err := d.child.Query(cq) if err != nil { return nil, err } qr := dsq.ResultsFromIterator(q, dsq.Iterator{ Next: func() (dsq.Result, bool) { r, ok := cqr.NextSync() if !ok { return r, false } if r.Error == nil { r.Entry.Key = d.InvertKey(ds.RawKey(r.Entry.Key)).String() } return r, true }, Close: func() error { return cqr.Close() }, }) return dsq.NaiveQueryApply(nq, qr), nil }
go
func (d *Datastore) Query(q dsq.Query) (dsq.Results, error) { nq, cq := d.prepareQuery(q) cqr, err := d.child.Query(cq) if err != nil { return nil, err } qr := dsq.ResultsFromIterator(q, dsq.Iterator{ Next: func() (dsq.Result, bool) { r, ok := cqr.NextSync() if !ok { return r, false } if r.Error == nil { r.Entry.Key = d.InvertKey(ds.RawKey(r.Entry.Key)).String() } return r, true }, Close: func() error { return cqr.Close() }, }) return dsq.NaiveQueryApply(nq, qr), nil }
[ "func", "(", "d", "*", "Datastore", ")", "Query", "(", "q", "dsq", ".", "Query", ")", "(", "dsq", ".", "Results", ",", "error", ")", "{", "nq", ",", "cq", ":=", "d", ".", "prepareQuery", "(", "q", ")", "\n\n", "cqr", ",", "err", ":=", "d", ".", "child", ".", "Query", "(", "cq", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "qr", ":=", "dsq", ".", "ResultsFromIterator", "(", "q", ",", "dsq", ".", "Iterator", "{", "Next", ":", "func", "(", ")", "(", "dsq", ".", "Result", ",", "bool", ")", "{", "r", ",", "ok", ":=", "cqr", ".", "NextSync", "(", ")", "\n", "if", "!", "ok", "{", "return", "r", ",", "false", "\n", "}", "\n", "if", "r", ".", "Error", "==", "nil", "{", "r", ".", "Entry", ".", "Key", "=", "d", ".", "InvertKey", "(", "ds", ".", "RawKey", "(", "r", ".", "Entry", ".", "Key", ")", ")", ".", "String", "(", ")", "\n", "}", "\n", "return", "r", ",", "true", "\n", "}", ",", "Close", ":", "func", "(", ")", "error", "{", "return", "cqr", ".", "Close", "(", ")", "\n", "}", ",", "}", ")", "\n", "return", "dsq", ".", "NaiveQueryApply", "(", "nq", ",", "qr", ")", ",", "nil", "\n", "}" ]
// Query implements Query, inverting keys on the way back out.
[ "Query", "implements", "Query", "inverting", "keys", "on", "the", "way", "back", "out", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/keytransform/keytransform.go#L63-L87
train
ipfs/go-datastore
keytransform/keytransform.go
prepareQuery
func (d *Datastore) prepareQuery(q dsq.Query) (naive, child dsq.Query) { // First, put everything in the child query. Then, start taking things // out. child = q // Always let the child handle the key prefix. child.Prefix = d.ConvertKey(ds.NewKey(child.Prefix)).String() // Check if the key transform is order-preserving so we can use the // child datastore's built-in ordering. orderPreserving := false switch d.KeyTransform.(type) { case PrefixTransform, *PrefixTransform: orderPreserving = true } // Try to let the child handle ordering. orders: for i, o := range child.Orders { switch o.(type) { case dsq.OrderByValue, *dsq.OrderByValue, dsq.OrderByValueDescending, *dsq.OrderByValueDescending: // Key doesn't matter. continue case dsq.OrderByKey, *dsq.OrderByKey, dsq.OrderByKeyDescending, *dsq.OrderByKeyDescending: // if the key transform preserves order, we can delegate // to the child datastore. if orderPreserving { // When sorting, we compare with the first // Order, then, if equal, we compare with the // second Order, etc. However, keys are _unique_ // so we'll never apply any additional orders // after ordering by key. child.Orders = child.Orders[:i+1] break orders } } // Can't handle this order under transform, punt it to a naive // ordering. naive.Orders = q.Orders child.Orders = nil naive.Offset = q.Offset child.Offset = 0 naive.Limit = q.Limit child.Limit = 0 break } // Try to let the child handle the filters. // don't modify the original filters. child.Filters = append([]dsq.Filter(nil), child.Filters...) for i, f := range child.Filters { switch f := f.(type) { case dsq.FilterValueCompare, *dsq.FilterValueCompare: continue case dsq.FilterKeyCompare: child.Filters[i] = dsq.FilterKeyCompare{ Op: f.Op, Key: d.ConvertKey(ds.NewKey(f.Key)).String(), } continue case *dsq.FilterKeyCompare: child.Filters[i] = &dsq.FilterKeyCompare{ Op: f.Op, Key: d.ConvertKey(ds.NewKey(f.Key)).String(), } continue case dsq.FilterKeyPrefix: child.Filters[i] = dsq.FilterKeyPrefix{ Prefix: d.ConvertKey(ds.NewKey(f.Prefix)).String(), } continue case *dsq.FilterKeyPrefix: child.Filters[i] = &dsq.FilterKeyPrefix{ Prefix: d.ConvertKey(ds.NewKey(f.Prefix)).String(), } continue } // Not a known filter, defer to the naive implementation. naive.Filters = q.Filters child.Filters = nil naive.Offset = q.Offset child.Offset = 0 naive.Limit = q.Limit child.Limit = 0 break } return }
go
func (d *Datastore) prepareQuery(q dsq.Query) (naive, child dsq.Query) { // First, put everything in the child query. Then, start taking things // out. child = q // Always let the child handle the key prefix. child.Prefix = d.ConvertKey(ds.NewKey(child.Prefix)).String() // Check if the key transform is order-preserving so we can use the // child datastore's built-in ordering. orderPreserving := false switch d.KeyTransform.(type) { case PrefixTransform, *PrefixTransform: orderPreserving = true } // Try to let the child handle ordering. orders: for i, o := range child.Orders { switch o.(type) { case dsq.OrderByValue, *dsq.OrderByValue, dsq.OrderByValueDescending, *dsq.OrderByValueDescending: // Key doesn't matter. continue case dsq.OrderByKey, *dsq.OrderByKey, dsq.OrderByKeyDescending, *dsq.OrderByKeyDescending: // if the key transform preserves order, we can delegate // to the child datastore. if orderPreserving { // When sorting, we compare with the first // Order, then, if equal, we compare with the // second Order, etc. However, keys are _unique_ // so we'll never apply any additional orders // after ordering by key. child.Orders = child.Orders[:i+1] break orders } } // Can't handle this order under transform, punt it to a naive // ordering. naive.Orders = q.Orders child.Orders = nil naive.Offset = q.Offset child.Offset = 0 naive.Limit = q.Limit child.Limit = 0 break } // Try to let the child handle the filters. // don't modify the original filters. child.Filters = append([]dsq.Filter(nil), child.Filters...) for i, f := range child.Filters { switch f := f.(type) { case dsq.FilterValueCompare, *dsq.FilterValueCompare: continue case dsq.FilterKeyCompare: child.Filters[i] = dsq.FilterKeyCompare{ Op: f.Op, Key: d.ConvertKey(ds.NewKey(f.Key)).String(), } continue case *dsq.FilterKeyCompare: child.Filters[i] = &dsq.FilterKeyCompare{ Op: f.Op, Key: d.ConvertKey(ds.NewKey(f.Key)).String(), } continue case dsq.FilterKeyPrefix: child.Filters[i] = dsq.FilterKeyPrefix{ Prefix: d.ConvertKey(ds.NewKey(f.Prefix)).String(), } continue case *dsq.FilterKeyPrefix: child.Filters[i] = &dsq.FilterKeyPrefix{ Prefix: d.ConvertKey(ds.NewKey(f.Prefix)).String(), } continue } // Not a known filter, defer to the naive implementation. naive.Filters = q.Filters child.Filters = nil naive.Offset = q.Offset child.Offset = 0 naive.Limit = q.Limit child.Limit = 0 break } return }
[ "func", "(", "d", "*", "Datastore", ")", "prepareQuery", "(", "q", "dsq", ".", "Query", ")", "(", "naive", ",", "child", "dsq", ".", "Query", ")", "{", "// First, put everything in the child query. Then, start taking things", "// out.", "child", "=", "q", "\n\n", "// Always let the child handle the key prefix.", "child", ".", "Prefix", "=", "d", ".", "ConvertKey", "(", "ds", ".", "NewKey", "(", "child", ".", "Prefix", ")", ")", ".", "String", "(", ")", "\n\n", "// Check if the key transform is order-preserving so we can use the", "// child datastore's built-in ordering.", "orderPreserving", ":=", "false", "\n", "switch", "d", ".", "KeyTransform", ".", "(", "type", ")", "{", "case", "PrefixTransform", ",", "*", "PrefixTransform", ":", "orderPreserving", "=", "true", "\n", "}", "\n\n", "// Try to let the child handle ordering.", "orders", ":", "for", "i", ",", "o", ":=", "range", "child", ".", "Orders", "{", "switch", "o", ".", "(", "type", ")", "{", "case", "dsq", ".", "OrderByValue", ",", "*", "dsq", ".", "OrderByValue", ",", "dsq", ".", "OrderByValueDescending", ",", "*", "dsq", ".", "OrderByValueDescending", ":", "// Key doesn't matter.", "continue", "\n", "case", "dsq", ".", "OrderByKey", ",", "*", "dsq", ".", "OrderByKey", ",", "dsq", ".", "OrderByKeyDescending", ",", "*", "dsq", ".", "OrderByKeyDescending", ":", "// if the key transform preserves order, we can delegate", "// to the child datastore.", "if", "orderPreserving", "{", "// When sorting, we compare with the first", "// Order, then, if equal, we compare with the", "// second Order, etc. However, keys are _unique_", "// so we'll never apply any additional orders", "// after ordering by key.", "child", ".", "Orders", "=", "child", ".", "Orders", "[", ":", "i", "+", "1", "]", "\n", "break", "orders", "\n", "}", "\n", "}", "\n\n", "// Can't handle this order under transform, punt it to a naive", "// ordering.", "naive", ".", "Orders", "=", "q", ".", "Orders", "\n", "child", ".", "Orders", "=", "nil", "\n", "naive", ".", "Offset", "=", "q", ".", "Offset", "\n", "child", ".", "Offset", "=", "0", "\n", "naive", ".", "Limit", "=", "q", ".", "Limit", "\n", "child", ".", "Limit", "=", "0", "\n", "break", "\n", "}", "\n\n", "// Try to let the child handle the filters.", "// don't modify the original filters.", "child", ".", "Filters", "=", "append", "(", "[", "]", "dsq", ".", "Filter", "(", "nil", ")", ",", "child", ".", "Filters", "...", ")", "\n\n", "for", "i", ",", "f", ":=", "range", "child", ".", "Filters", "{", "switch", "f", ":=", "f", ".", "(", "type", ")", "{", "case", "dsq", ".", "FilterValueCompare", ",", "*", "dsq", ".", "FilterValueCompare", ":", "continue", "\n", "case", "dsq", ".", "FilterKeyCompare", ":", "child", ".", "Filters", "[", "i", "]", "=", "dsq", ".", "FilterKeyCompare", "{", "Op", ":", "f", ".", "Op", ",", "Key", ":", "d", ".", "ConvertKey", "(", "ds", ".", "NewKey", "(", "f", ".", "Key", ")", ")", ".", "String", "(", ")", ",", "}", "\n", "continue", "\n", "case", "*", "dsq", ".", "FilterKeyCompare", ":", "child", ".", "Filters", "[", "i", "]", "=", "&", "dsq", ".", "FilterKeyCompare", "{", "Op", ":", "f", ".", "Op", ",", "Key", ":", "d", ".", "ConvertKey", "(", "ds", ".", "NewKey", "(", "f", ".", "Key", ")", ")", ".", "String", "(", ")", ",", "}", "\n", "continue", "\n", "case", "dsq", ".", "FilterKeyPrefix", ":", "child", ".", "Filters", "[", "i", "]", "=", "dsq", ".", "FilterKeyPrefix", "{", "Prefix", ":", "d", ".", "ConvertKey", "(", "ds", ".", "NewKey", "(", "f", ".", "Prefix", ")", ")", ".", "String", "(", ")", ",", "}", "\n", "continue", "\n", "case", "*", "dsq", ".", "FilterKeyPrefix", ":", "child", ".", "Filters", "[", "i", "]", "=", "&", "dsq", ".", "FilterKeyPrefix", "{", "Prefix", ":", "d", ".", "ConvertKey", "(", "ds", ".", "NewKey", "(", "f", ".", "Prefix", ")", ")", ".", "String", "(", ")", ",", "}", "\n", "continue", "\n", "}", "\n\n", "// Not a known filter, defer to the naive implementation.", "naive", ".", "Filters", "=", "q", ".", "Filters", "\n", "child", ".", "Filters", "=", "nil", "\n", "naive", ".", "Offset", "=", "q", ".", "Offset", "\n", "child", ".", "Offset", "=", "0", "\n", "naive", ".", "Limit", "=", "q", ".", "Limit", "\n", "child", ".", "Limit", "=", "0", "\n", "break", "\n", "}", "\n", "return", "\n", "}" ]
// Split the query into a child query and a naive query. That way, we can make // the child datastore do as much work as possible.
[ "Split", "the", "query", "into", "a", "child", "query", "and", "a", "naive", "query", ".", "That", "way", "we", "can", "make", "the", "child", "datastore", "do", "as", "much", "work", "as", "possible", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/keytransform/keytransform.go#L91-L185
train
ipfs/go-datastore
mount/mount.go
DiskUsage
func (d *Datastore) DiskUsage() (uint64, error) { var duTotal uint64 = 0 for _, d := range d.mounts { du, err := ds.DiskUsage(d.Datastore) duTotal += du if err != nil { return duTotal, err } } return duTotal, nil }
go
func (d *Datastore) DiskUsage() (uint64, error) { var duTotal uint64 = 0 for _, d := range d.mounts { du, err := ds.DiskUsage(d.Datastore) duTotal += du if err != nil { return duTotal, err } } return duTotal, nil }
[ "func", "(", "d", "*", "Datastore", ")", "DiskUsage", "(", ")", "(", "uint64", ",", "error", ")", "{", "var", "duTotal", "uint64", "=", "0", "\n", "for", "_", ",", "d", ":=", "range", "d", ".", "mounts", "{", "du", ",", "err", ":=", "ds", ".", "DiskUsage", "(", "d", ".", "Datastore", ")", "\n", "duTotal", "+=", "du", "\n", "if", "err", "!=", "nil", "{", "return", "duTotal", ",", "err", "\n", "}", "\n", "}", "\n", "return", "duTotal", ",", "nil", "\n", "}" ]
// DiskUsage returns the sum of DiskUsages for the mounted datastores. // Non PersistentDatastores will not be accounted.
[ "DiskUsage", "returns", "the", "sum", "of", "DiskUsages", "for", "the", "mounted", "datastores", ".", "Non", "PersistentDatastores", "will", "not", "be", "accounted", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/mount/mount.go#L291-L301
train
ipfs/go-datastore
namespace/namespace.go
Wrap
func Wrap(child ds.Datastore, prefix ds.Key) *ktds.Datastore { if child == nil { panic("child (ds.Datastore) is nil") } return ktds.Wrap(child, PrefixTransform(prefix)) }
go
func Wrap(child ds.Datastore, prefix ds.Key) *ktds.Datastore { if child == nil { panic("child (ds.Datastore) is nil") } return ktds.Wrap(child, PrefixTransform(prefix)) }
[ "func", "Wrap", "(", "child", "ds", ".", "Datastore", ",", "prefix", "ds", ".", "Key", ")", "*", "ktds", ".", "Datastore", "{", "if", "child", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "ktds", ".", "Wrap", "(", "child", ",", "PrefixTransform", "(", "prefix", ")", ")", "\n", "}" ]
// Wrap wraps a given datastore with a key-prefix.
[ "Wrap", "wraps", "a", "given", "datastore", "with", "a", "key", "-", "prefix", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/namespace/namespace.go#L20-L26
train
ipfs/go-datastore
failstore/failstore.go
Get
func (d *Failstore) Get(k ds.Key) ([]byte, error) { err := d.errfunc("get") if err != nil { return nil, err } return d.child.Get(k) }
go
func (d *Failstore) Get(k ds.Key) ([]byte, error) { err := d.errfunc("get") if err != nil { return nil, err } return d.child.Get(k) }
[ "func", "(", "d", "*", "Failstore", ")", "Get", "(", "k", "ds", ".", "Key", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "err", ":=", "d", ".", "errfunc", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "d", ".", "child", ".", "Get", "(", "k", ")", "\n", "}" ]
// Get retrieves a value from the datastore.
[ "Get", "retrieves", "a", "value", "from", "the", "datastore", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/failstore/failstore.go#L40-L47
train
ipfs/go-datastore
failstore/failstore.go
Query
func (d *Failstore) Query(q dsq.Query) (dsq.Results, error) { err := d.errfunc("query") if err != nil { return nil, err } return d.child.Query(q) }
go
func (d *Failstore) Query(q dsq.Query) (dsq.Results, error) { err := d.errfunc("query") if err != nil { return nil, err } return d.child.Query(q) }
[ "func", "(", "d", "*", "Failstore", ")", "Query", "(", "q", "dsq", ".", "Query", ")", "(", "dsq", ".", "Results", ",", "error", ")", "{", "err", ":=", "d", ".", "errfunc", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "d", ".", "child", ".", "Query", "(", "q", ")", "\n", "}" ]
// Query performs a query on the datastore.
[ "Query", "performs", "a", "query", "on", "the", "datastore", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/failstore/failstore.go#L80-L87
train
ipfs/go-datastore
failstore/failstore.go
Batch
func (d *Failstore) Batch() (ds.Batch, error) { if err := d.errfunc("batch"); err != nil { return nil, err } b, err := d.child.(ds.Batching).Batch() if err != nil { return nil, err } return &FailBatch{ cb: b, dstore: d, }, nil }
go
func (d *Failstore) Batch() (ds.Batch, error) { if err := d.errfunc("batch"); err != nil { return nil, err } b, err := d.child.(ds.Batching).Batch() if err != nil { return nil, err } return &FailBatch{ cb: b, dstore: d, }, nil }
[ "func", "(", "d", "*", "Failstore", ")", "Batch", "(", ")", "(", "ds", ".", "Batch", ",", "error", ")", "{", "if", "err", ":=", "d", ".", "errfunc", "(", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "b", ",", "err", ":=", "d", ".", "child", ".", "(", "ds", ".", "Batching", ")", ".", "Batch", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "FailBatch", "{", "cb", ":", "b", ",", "dstore", ":", "d", ",", "}", ",", "nil", "\n", "}" ]
// Batch returns a new Batch Failstore.
[ "Batch", "returns", "a", "new", "Batch", "Failstore", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/failstore/failstore.go#L109-L123
train
ipfs/go-datastore
failstore/failstore.go
Put
func (b *FailBatch) Put(k ds.Key, val []byte) error { if err := b.dstore.errfunc("batch-put"); err != nil { return err } return b.cb.Put(k, val) }
go
func (b *FailBatch) Put(k ds.Key, val []byte) error { if err := b.dstore.errfunc("batch-put"); err != nil { return err } return b.cb.Put(k, val) }
[ "func", "(", "b", "*", "FailBatch", ")", "Put", "(", "k", "ds", ".", "Key", ",", "val", "[", "]", "byte", ")", "error", "{", "if", "err", ":=", "b", ".", "dstore", ".", "errfunc", "(", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "b", ".", "cb", ".", "Put", "(", "k", ",", "val", ")", "\n", "}" ]
// Put does a batch put.
[ "Put", "does", "a", "batch", "put", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/failstore/failstore.go#L126-L132
train
ipfs/go-datastore
failstore/failstore.go
Delete
func (b *FailBatch) Delete(k ds.Key) error { if err := b.dstore.errfunc("batch-delete"); err != nil { return err } return b.cb.Delete(k) }
go
func (b *FailBatch) Delete(k ds.Key) error { if err := b.dstore.errfunc("batch-delete"); err != nil { return err } return b.cb.Delete(k) }
[ "func", "(", "b", "*", "FailBatch", ")", "Delete", "(", "k", "ds", ".", "Key", ")", "error", "{", "if", "err", ":=", "b", ".", "dstore", ".", "errfunc", "(", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "b", ".", "cb", ".", "Delete", "(", "k", ")", "\n", "}" ]
// Delete does a batch delete.
[ "Delete", "does", "a", "batch", "delete", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/failstore/failstore.go#L135-L141
train
ipfs/go-datastore
failstore/failstore.go
Commit
func (b *FailBatch) Commit() error { if err := b.dstore.errfunc("batch-commit"); err != nil { return err } return b.cb.Commit() }
go
func (b *FailBatch) Commit() error { if err := b.dstore.errfunc("batch-commit"); err != nil { return err } return b.cb.Commit() }
[ "func", "(", "b", "*", "FailBatch", ")", "Commit", "(", ")", "error", "{", "if", "err", ":=", "b", ".", "dstore", ".", "errfunc", "(", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "b", ".", "cb", ".", "Commit", "(", ")", "\n", "}" ]
// Commit commits all operations in the batch.
[ "Commit", "commits", "all", "operations", "in", "the", "batch", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/failstore/failstore.go#L144-L150
train
ipfs/go-datastore
autobatch/autobatch.go
NewAutoBatching
func NewAutoBatching(d ds.Batching, size int) *Datastore { return &Datastore{ child: d, buffer: make(map[ds.Key]op, size), maxBufferEntries: size, } }
go
func NewAutoBatching(d ds.Batching, size int) *Datastore { return &Datastore{ child: d, buffer: make(map[ds.Key]op, size), maxBufferEntries: size, } }
[ "func", "NewAutoBatching", "(", "d", "ds", ".", "Batching", ",", "size", "int", ")", "*", "Datastore", "{", "return", "&", "Datastore", "{", "child", ":", "d", ",", "buffer", ":", "make", "(", "map", "[", "ds", ".", "Key", "]", "op", ",", "size", ")", ",", "maxBufferEntries", ":", "size", ",", "}", "\n", "}" ]
// NewAutoBatching returns a new datastore that automatically // batches writes using the given Batching datastore. The size // of the memory pool is given by size.
[ "NewAutoBatching", "returns", "a", "new", "datastore", "that", "automatically", "batches", "writes", "using", "the", "given", "Batching", "datastore", ".", "The", "size", "of", "the", "memory", "pool", "is", "given", "by", "size", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/autobatch/autobatch.go#L28-L34
train
ipfs/go-datastore
autobatch/autobatch.go
Flush
func (d *Datastore) Flush() error { b, err := d.child.Batch() if err != nil { return err } for k, o := range d.buffer { var err error if o.delete { err = b.Delete(k) if err == ds.ErrNotFound { // Ignore these, let delete be idempotent. err = nil } } else { err = b.Put(k, o.value) } if err != nil { return err } } // clear out buffer d.buffer = make(map[ds.Key]op, d.maxBufferEntries) return b.Commit() }
go
func (d *Datastore) Flush() error { b, err := d.child.Batch() if err != nil { return err } for k, o := range d.buffer { var err error if o.delete { err = b.Delete(k) if err == ds.ErrNotFound { // Ignore these, let delete be idempotent. err = nil } } else { err = b.Put(k, o.value) } if err != nil { return err } } // clear out buffer d.buffer = make(map[ds.Key]op, d.maxBufferEntries) return b.Commit() }
[ "func", "(", "d", "*", "Datastore", ")", "Flush", "(", ")", "error", "{", "b", ",", "err", ":=", "d", ".", "child", ".", "Batch", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "for", "k", ",", "o", ":=", "range", "d", ".", "buffer", "{", "var", "err", "error", "\n", "if", "o", ".", "delete", "{", "err", "=", "b", ".", "Delete", "(", "k", ")", "\n", "if", "err", "==", "ds", ".", "ErrNotFound", "{", "// Ignore these, let delete be idempotent.", "err", "=", "nil", "\n", "}", "\n", "}", "else", "{", "err", "=", "b", ".", "Put", "(", "k", ",", "o", ".", "value", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "// clear out buffer", "d", ".", "buffer", "=", "make", "(", "map", "[", "ds", ".", "Key", "]", "op", ",", "d", ".", "maxBufferEntries", ")", "\n\n", "return", "b", ".", "Commit", "(", ")", "\n", "}" ]
// Flush flushes the current batch to the underlying datastore.
[ "Flush", "flushes", "the", "current", "batch", "to", "the", "underlying", "datastore", "." ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/autobatch/autobatch.go#L68-L93
train
ipfs/go-datastore
autobatch/autobatch.go
Query
func (d *Datastore) Query(q dsq.Query) (dsq.Results, error) { err := d.Flush() if err != nil { return nil, err } return d.child.Query(q) }
go
func (d *Datastore) Query(q dsq.Query) (dsq.Results, error) { err := d.Flush() if err != nil { return nil, err } return d.child.Query(q) }
[ "func", "(", "d", "*", "Datastore", ")", "Query", "(", "q", "dsq", ".", "Query", ")", "(", "dsq", ".", "Results", ",", "error", ")", "{", "err", ":=", "d", ".", "Flush", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "d", ".", "child", ".", "Query", "(", "q", ")", "\n", "}" ]
// Query performs a query
[ "Query", "performs", "a", "query" ]
aa9190c18f1576be98e974359fd08c64ca0b5a94
https://github.com/ipfs/go-datastore/blob/aa9190c18f1576be98e974359fd08c64ca0b5a94/autobatch/autobatch.go#L119-L126
train
apache/qpid-proton
go/src/qpid.apache.org/electron/receiver.go
newReceiver
func newReceiver(ls linkSettings) *receiver { r := &receiver{link: link{linkSettings: ls}} r.endpoint.init(r.link.pLink.String()) if r.capacity < 1 { r.capacity = 1 } r.buffer = make(chan ReceivedMessage, r.capacity) r.handler().addLink(r.pLink, r) r.link.pLink.Open() if r.prefetch { r.flow(r.maxFlow()) } return r }
go
func newReceiver(ls linkSettings) *receiver { r := &receiver{link: link{linkSettings: ls}} r.endpoint.init(r.link.pLink.String()) if r.capacity < 1 { r.capacity = 1 } r.buffer = make(chan ReceivedMessage, r.capacity) r.handler().addLink(r.pLink, r) r.link.pLink.Open() if r.prefetch { r.flow(r.maxFlow()) } return r }
[ "func", "newReceiver", "(", "ls", "linkSettings", ")", "*", "receiver", "{", "r", ":=", "&", "receiver", "{", "link", ":", "link", "{", "linkSettings", ":", "ls", "}", "}", "\n", "r", ".", "endpoint", ".", "init", "(", "r", ".", "link", ".", "pLink", ".", "String", "(", ")", ")", "\n", "if", "r", ".", "capacity", "<", "1", "{", "r", ".", "capacity", "=", "1", "\n", "}", "\n", "r", ".", "buffer", "=", "make", "(", "chan", "ReceivedMessage", ",", "r", ".", "capacity", ")", "\n", "r", ".", "handler", "(", ")", ".", "addLink", "(", "r", ".", "pLink", ",", "r", ")", "\n", "r", ".", "link", ".", "pLink", ".", "Open", "(", ")", "\n", "if", "r", ".", "prefetch", "{", "r", ".", "flow", "(", "r", ".", "maxFlow", "(", ")", ")", "\n", "}", "\n", "return", "r", "\n", "}" ]
// Call in proton goroutine
[ "Call", "in", "proton", "goroutine" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/receiver.go#L80-L93
train
apache/qpid-proton
go/src/qpid.apache.org/electron/receiver.go
caller
func (r *receiver) caller(inc int) { _ = r.engine().Inject(func() { r.callers += inc need := r.callers - (len(r.buffer) + r.pLink.Credit()) max := r.maxFlow() if need > max { need = max } r.flow(need) }) }
go
func (r *receiver) caller(inc int) { _ = r.engine().Inject(func() { r.callers += inc need := r.callers - (len(r.buffer) + r.pLink.Credit()) max := r.maxFlow() if need > max { need = max } r.flow(need) }) }
[ "func", "(", "r", "*", "receiver", ")", "caller", "(", "inc", "int", ")", "{", "_", "=", "r", ".", "engine", "(", ")", ".", "Inject", "(", "func", "(", ")", "{", "r", ".", "callers", "+=", "inc", "\n", "need", ":=", "r", ".", "callers", "-", "(", "len", "(", "r", ".", "buffer", ")", "+", "r", ".", "pLink", ".", "Credit", "(", ")", ")", "\n", "max", ":=", "r", ".", "maxFlow", "(", ")", "\n", "if", "need", ">", "max", "{", "need", "=", "max", "\n", "}", "\n", "r", ".", "flow", "(", "need", ")", "\n", "}", ")", "\n", "}" ]
// Inject flow check per-caller call when prefetch is off. // Called with inc=1 at start of call, inc = -1 at end
[ "Inject", "flow", "check", "per", "-", "caller", "call", "when", "prefetch", "is", "off", ".", "Called", "with", "inc", "=", "1", "at", "start", "of", "call", "inc", "=", "-", "1", "at", "end" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/receiver.go#L106-L116
train
apache/qpid-proton
go/src/qpid.apache.org/electron/receiver.go
flowTopUp
func (r *receiver) flowTopUp() { if r.prefetch { _ = r.engine().Inject(func() { r.flow(r.maxFlow()) }) } }
go
func (r *receiver) flowTopUp() { if r.prefetch { _ = r.engine().Inject(func() { r.flow(r.maxFlow()) }) } }
[ "func", "(", "r", "*", "receiver", ")", "flowTopUp", "(", ")", "{", "if", "r", ".", "prefetch", "{", "_", "=", "r", ".", "engine", "(", ")", ".", "Inject", "(", "func", "(", ")", "{", "r", ".", "flow", "(", "r", ".", "maxFlow", "(", ")", ")", "}", ")", "\n", "}", "\n", "}" ]
// Inject flow top-up if prefetch is enabled
[ "Inject", "flow", "top", "-", "up", "if", "prefetch", "is", "enabled" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/receiver.go#L119-L123
train
apache/qpid-proton
go/src/qpid.apache.org/electron/receiver.go
message
func (r *receiver) message(delivery proton.Delivery) { if r.pLink.State().RemoteClosed() { localClose(r.pLink, r.pLink.RemoteCondition().Error()) return } if delivery.HasMessage() { bytes, err := delivery.MessageBytes() var m amqp.Message if err == nil { m = amqp.NewMessage() err = r.session.connection.mc.Decode(m, bytes) } if err != nil { localClose(r.pLink, err) return } r.pLink.Advance() if r.pLink.Credit() < 0 { localClose(r.pLink, fmt.Errorf("received message in excess of credit limit")) } else { // We never issue more credit than cap(buffer) so this will not block. r.buffer <- ReceivedMessage{m, delivery, r} } } }
go
func (r *receiver) message(delivery proton.Delivery) { if r.pLink.State().RemoteClosed() { localClose(r.pLink, r.pLink.RemoteCondition().Error()) return } if delivery.HasMessage() { bytes, err := delivery.MessageBytes() var m amqp.Message if err == nil { m = amqp.NewMessage() err = r.session.connection.mc.Decode(m, bytes) } if err != nil { localClose(r.pLink, err) return } r.pLink.Advance() if r.pLink.Credit() < 0 { localClose(r.pLink, fmt.Errorf("received message in excess of credit limit")) } else { // We never issue more credit than cap(buffer) so this will not block. r.buffer <- ReceivedMessage{m, delivery, r} } } }
[ "func", "(", "r", "*", "receiver", ")", "message", "(", "delivery", "proton", ".", "Delivery", ")", "{", "if", "r", ".", "pLink", ".", "State", "(", ")", ".", "RemoteClosed", "(", ")", "{", "localClose", "(", "r", ".", "pLink", ",", "r", ".", "pLink", ".", "RemoteCondition", "(", ")", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n", "if", "delivery", ".", "HasMessage", "(", ")", "{", "bytes", ",", "err", ":=", "delivery", ".", "MessageBytes", "(", ")", "\n", "var", "m", "amqp", ".", "Message", "\n", "if", "err", "==", "nil", "{", "m", "=", "amqp", ".", "NewMessage", "(", ")", "\n", "err", "=", "r", ".", "session", ".", "connection", ".", "mc", ".", "Decode", "(", "m", ",", "bytes", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "localClose", "(", "r", ".", "pLink", ",", "err", ")", "\n", "return", "\n", "}", "\n", "r", ".", "pLink", ".", "Advance", "(", ")", "\n", "if", "r", ".", "pLink", ".", "Credit", "(", ")", "<", "0", "{", "localClose", "(", "r", ".", "pLink", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", ")", "\n", "}", "else", "{", "// We never issue more credit than cap(buffer) so this will not block.", "r", ".", "buffer", "<-", "ReceivedMessage", "{", "m", ",", "delivery", ",", "r", "}", "\n", "}", "\n", "}", "\n", "}" ]
// Called in proton goroutine on MMessage event.
[ "Called", "in", "proton", "goroutine", "on", "MMessage", "event", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/receiver.go#L159-L183
train
apache/qpid-proton
go/src/qpid.apache.org/electron/receiver.go
acknowledge
func (rm *ReceivedMessage) acknowledge(status uint64) error { return rm.receiver.(*receiver).engine().Inject(func() { // Deliveries are valid as long as the connection is, unless settled. rm.pDelivery.SettleAs(uint64(status)) }) }
go
func (rm *ReceivedMessage) acknowledge(status uint64) error { return rm.receiver.(*receiver).engine().Inject(func() { // Deliveries are valid as long as the connection is, unless settled. rm.pDelivery.SettleAs(uint64(status)) }) }
[ "func", "(", "rm", "*", "ReceivedMessage", ")", "acknowledge", "(", "status", "uint64", ")", "error", "{", "return", "rm", ".", "receiver", ".", "(", "*", "receiver", ")", ".", "engine", "(", ")", ".", "Inject", "(", "func", "(", ")", "{", "// Deliveries are valid as long as the connection is, unless settled.", "rm", ".", "pDelivery", ".", "SettleAs", "(", "uint64", "(", "status", ")", ")", "\n", "}", ")", "\n", "}" ]
// Acknowledge a ReceivedMessage with the given delivery status.
[ "Acknowledge", "a", "ReceivedMessage", "with", "the", "given", "delivery", "status", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/receiver.go#L203-L208
train
apache/qpid-proton
go/src/qpid.apache.org/electron/receiver.go
Accept
func (in *IncomingReceiver) Accept() Endpoint { return in.accept(func() Endpoint { return newReceiver(in.linkSettings) }) }
go
func (in *IncomingReceiver) Accept() Endpoint { return in.accept(func() Endpoint { return newReceiver(in.linkSettings) }) }
[ "func", "(", "in", "*", "IncomingReceiver", ")", "Accept", "(", ")", "Endpoint", "{", "return", "in", ".", "accept", "(", "func", "(", ")", "Endpoint", "{", "return", "newReceiver", "(", "in", ".", "linkSettings", ")", "}", ")", "\n", "}" ]
// Accept accepts an incoming receiver endpoint
[ "Accept", "accepts", "an", "incoming", "receiver", "endpoint" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/receiver.go#L241-L243
train
apache/qpid-proton
go/src/qpid.apache.org/proton/wrappers.go
EndpointError
func EndpointError(e Endpoint) error { err := e.RemoteCondition().Error() if err == nil { err = e.Condition().Error() } return err }
go
func EndpointError(e Endpoint) error { err := e.RemoteCondition().Error() if err == nil { err = e.Condition().Error() } return err }
[ "func", "EndpointError", "(", "e", "Endpoint", ")", "error", "{", "err", ":=", "e", ".", "RemoteCondition", "(", ")", ".", "Error", "(", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "e", ".", "Condition", "(", ")", ".", "Error", "(", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// EndpointError returns the remote error if there is one, the local error if not // nil if there is no error.
[ "EndpointError", "returns", "the", "remote", "error", "if", "there", "is", "one", "the", "local", "error", "if", "not", "nil", "if", "there", "is", "no", "error", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/wrappers.go#L206-L212
train
apache/qpid-proton
go/src/qpid.apache.org/proton/wrappers.go
Release
func (d Delivery) Release(delivered bool) { if delivered { d.SettleAs(Modified) } else { d.SettleAs(Released) } }
go
func (d Delivery) Release(delivered bool) { if delivered { d.SettleAs(Modified) } else { d.SettleAs(Released) } }
[ "func", "(", "d", "Delivery", ")", "Release", "(", "delivered", "bool", ")", "{", "if", "delivered", "{", "d", ".", "SettleAs", "(", "Modified", ")", "\n", "}", "else", "{", "d", ".", "SettleAs", "(", "Released", ")", "\n", "}", "\n", "}" ]
// Release releases and settles a delivery // If delivered is true the delivery count for the message will be increased.
[ "Release", "releases", "and", "settles", "a", "delivery", "If", "delivered", "is", "true", "the", "delivery", "count", "for", "the", "message", "will", "be", "increased", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/wrappers.go#L236-L242
train
apache/qpid-proton
go/src/qpid.apache.org/proton/wrappers.go
String
func (l Link) String() string { switch { case l.IsNil(): return fmt.Sprintf("<nil-link>") case l.IsSender(): return fmt.Sprintf("%s(%s->%s)", l.Name(), l.Source().Address(), l.Target().Address()) default: return fmt.Sprintf("%s(%s<-%s)", l.Name(), l.Target().Address(), l.Source().Address()) } }
go
func (l Link) String() string { switch { case l.IsNil(): return fmt.Sprintf("<nil-link>") case l.IsSender(): return fmt.Sprintf("%s(%s->%s)", l.Name(), l.Source().Address(), l.Target().Address()) default: return fmt.Sprintf("%s(%s<-%s)", l.Name(), l.Target().Address(), l.Source().Address()) } }
[ "func", "(", "l", "Link", ")", "String", "(", ")", "string", "{", "switch", "{", "case", "l", ".", "IsNil", "(", ")", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ")", "\n", "case", "l", ".", "IsSender", "(", ")", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "l", ".", "Name", "(", ")", ",", "l", ".", "Source", "(", ")", ".", "Address", "(", ")", ",", "l", ".", "Target", "(", ")", ".", "Address", "(", ")", ")", "\n", "default", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "l", ".", "Name", "(", ")", ",", "l", ".", "Target", "(", ")", ".", "Address", "(", ")", ",", "l", ".", "Source", "(", ")", ".", "Address", "(", ")", ")", "\n", "}", "\n", "}" ]
// Human-readable link description including name, source, target and direction.
[ "Human", "-", "readable", "link", "description", "including", "name", "source", "target", "and", "direction", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/wrappers.go#L271-L280
train
apache/qpid-proton
go/src/qpid.apache.org/proton/wrappers.go
LinkHead
func (c Connection) LinkHead(s State) Link { return Link{C.pn_link_head(c.pn, C.pn_state_t(s))} }
go
func (c Connection) LinkHead(s State) Link { return Link{C.pn_link_head(c.pn, C.pn_state_t(s))} }
[ "func", "(", "c", "Connection", ")", "LinkHead", "(", "s", "State", ")", "Link", "{", "return", "Link", "{", "C", ".", "pn_link_head", "(", "c", ".", "pn", ",", "C", ".", "pn_state_t", "(", "s", ")", ")", "}", "\n", "}" ]
// Head functions don't follow the normal naming conventions so missed by the generator.
[ "Head", "functions", "don", "t", "follow", "the", "normal", "naming", "conventions", "so", "missed", "by", "the", "generator", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/wrappers.go#L334-L336
train
apache/qpid-proton
go/src/qpid.apache.org/proton/wrappers.go
Error
func (c Condition) Error() error { if c.IsNil() || !c.IsSet() { return nil } return amqp.Error{Name: c.Name(), Description: c.Description()} }
go
func (c Condition) Error() error { if c.IsNil() || !c.IsSet() { return nil } return amqp.Error{Name: c.Name(), Description: c.Description()} }
[ "func", "(", "c", "Condition", ")", "Error", "(", ")", "error", "{", "if", "c", ".", "IsNil", "(", ")", "||", "!", "c", ".", "IsSet", "(", ")", "{", "return", "nil", "\n", "}", "\n", "return", "amqp", ".", "Error", "{", "Name", ":", "c", ".", "Name", "(", ")", ",", "Description", ":", "c", ".", "Description", "(", ")", "}", "\n", "}" ]
// Error returns an instance of amqp.Error or nil.
[ "Error", "returns", "an", "instance", "of", "amqp", ".", "Error", "or", "nil", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/wrappers.go#L375-L380
train
apache/qpid-proton
go/src/qpid.apache.org/proton/wrappers.go
SetError
func (c Condition) SetError(err error) { if err != nil { cond := amqp.MakeError(err) c.SetName(cond.Name) c.SetDescription(cond.Description) } }
go
func (c Condition) SetError(err error) { if err != nil { cond := amqp.MakeError(err) c.SetName(cond.Name) c.SetDescription(cond.Description) } }
[ "func", "(", "c", "Condition", ")", "SetError", "(", "err", "error", ")", "{", "if", "err", "!=", "nil", "{", "cond", ":=", "amqp", ".", "MakeError", "(", "err", ")", "\n", "c", ".", "SetName", "(", "cond", ".", "Name", ")", "\n", "c", ".", "SetDescription", "(", "cond", ".", "Description", ")", "\n", "}", "\n", "}" ]
// Set a Go error into a condition, converting to an amqp.Error using amqp.MakeError
[ "Set", "a", "Go", "error", "into", "a", "condition", "converting", "to", "an", "amqp", ".", "Error", "using", "amqp", ".", "MakeError" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/wrappers.go#L383-L389
train
apache/qpid-proton
go/src/qpid.apache.org/proton/wrappers.go
Head
func (t Transport) Head() unsafe.Pointer { return unsafe.Pointer(C.pn_transport_head(t.pn)) }
go
func (t Transport) Head() unsafe.Pointer { return unsafe.Pointer(C.pn_transport_head(t.pn)) }
[ "func", "(", "t", "Transport", ")", "Head", "(", ")", "unsafe", ".", "Pointer", "{", "return", "unsafe", ".", "Pointer", "(", "C", ".", "pn_transport_head", "(", "t", ".", "pn", ")", ")", "\n", "}" ]
// Special treatment for Transport.Head, return value is unsafe.Pointer not string
[ "Special", "treatment", "for", "Transport", ".", "Head", "return", "value", "is", "unsafe", ".", "Pointer", "not", "string" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/wrappers.go#L428-L430
train
apache/qpid-proton
go/src/qpid.apache.org/proton/wrappers.go
Tail
func (t Transport) Tail() unsafe.Pointer { return unsafe.Pointer(C.pn_transport_tail(t.pn)) }
go
func (t Transport) Tail() unsafe.Pointer { return unsafe.Pointer(C.pn_transport_tail(t.pn)) }
[ "func", "(", "t", "Transport", ")", "Tail", "(", ")", "unsafe", ".", "Pointer", "{", "return", "unsafe", ".", "Pointer", "(", "C", ".", "pn_transport_tail", "(", "t", ".", "pn", ")", ")", "\n", "}" ]
// Special treatment for Transport.Tail, return value is unsafe.Pointer not string
[ "Special", "treatment", "for", "Transport", ".", "Tail", "return", "value", "is", "unsafe", ".", "Pointer", "not", "string" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/wrappers.go#L433-L435
train
apache/qpid-proton
go/src/qpid.apache.org/electron/session.go
newSession
func newSession(c *connection, es proton.Session, setting ...SessionOption) *session { s := &session{ connection: c, pSession: es, } s.endpoint.init(es.String()) for _, set := range setting { set(s) } c.handler.sessions[s.pSession] = s s.pSession.SetIncomingCapacity(s.incomingCapacity) s.pSession.SetOutgoingWindow(s.outgoingWindow) s.pSession.Open() return s }
go
func newSession(c *connection, es proton.Session, setting ...SessionOption) *session { s := &session{ connection: c, pSession: es, } s.endpoint.init(es.String()) for _, set := range setting { set(s) } c.handler.sessions[s.pSession] = s s.pSession.SetIncomingCapacity(s.incomingCapacity) s.pSession.SetOutgoingWindow(s.outgoingWindow) s.pSession.Open() return s }
[ "func", "newSession", "(", "c", "*", "connection", ",", "es", "proton", ".", "Session", ",", "setting", "...", "SessionOption", ")", "*", "session", "{", "s", ":=", "&", "session", "{", "connection", ":", "c", ",", "pSession", ":", "es", ",", "}", "\n", "s", ".", "endpoint", ".", "init", "(", "es", ".", "String", "(", ")", ")", "\n", "for", "_", ",", "set", ":=", "range", "setting", "{", "set", "(", "s", ")", "\n", "}", "\n", "c", ".", "handler", ".", "sessions", "[", "s", ".", "pSession", "]", "=", "s", "\n", "s", ".", "pSession", ".", "SetIncomingCapacity", "(", "s", ".", "incomingCapacity", ")", "\n", "s", ".", "pSession", ".", "SetOutgoingWindow", "(", "s", ".", "outgoingWindow", ")", "\n", "s", ".", "pSession", ".", "Open", "(", ")", "\n", "return", "s", "\n", "}" ]
// in proton goroutine
[ "in", "proton", "goroutine" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/session.go#L59-L73
train
apache/qpid-proton
go/src/qpid.apache.org/electron/session.go
Accept
func (in *IncomingSession) Accept() Endpoint { return in.accept(func() Endpoint { return newSession(in.h.connection, in.pSession, IncomingCapacity(in.incomingCapacity), OutgoingWindow(in.outgoingWindow)) }) }
go
func (in *IncomingSession) Accept() Endpoint { return in.accept(func() Endpoint { return newSession(in.h.connection, in.pSession, IncomingCapacity(in.incomingCapacity), OutgoingWindow(in.outgoingWindow)) }) }
[ "func", "(", "in", "*", "IncomingSession", ")", "Accept", "(", ")", "Endpoint", "{", "return", "in", ".", "accept", "(", "func", "(", ")", "Endpoint", "{", "return", "newSession", "(", "in", ".", "h", ".", "connection", ",", "in", ".", "pSession", ",", "IncomingCapacity", "(", "in", ".", "incomingCapacity", ")", ",", "OutgoingWindow", "(", "in", ".", "outgoingWindow", ")", ")", "\n", "}", ")", "\n", "}" ]
// Accept an incoming session endpoint.
[ "Accept", "an", "incoming", "session", "endpoint", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/session.go#L135-L139
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/url.go
splitHostPort
func splitHostPort(hostport string) (string, string, error) { if hostport == "" { return "", "", nil } if hostport[0] == '[' { // There must be a matching ']' as already validated if l := strings.LastIndex(hostport, "]"); len(hostport) == l+1 { // trim off '[' and ']' return hostport[1:l], "", nil } } else if strings.IndexByte(hostport, ':') < 0 { return hostport, "", nil } return net.SplitHostPort(hostport) }
go
func splitHostPort(hostport string) (string, string, error) { if hostport == "" { return "", "", nil } if hostport[0] == '[' { // There must be a matching ']' as already validated if l := strings.LastIndex(hostport, "]"); len(hostport) == l+1 { // trim off '[' and ']' return hostport[1:l], "", nil } } else if strings.IndexByte(hostport, ':') < 0 { return hostport, "", nil } return net.SplitHostPort(hostport) }
[ "func", "splitHostPort", "(", "hostport", "string", ")", "(", "string", ",", "string", ",", "error", ")", "{", "if", "hostport", "==", "\"", "\"", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "nil", "\n", "}", "\n", "if", "hostport", "[", "0", "]", "==", "'['", "{", "// There must be a matching ']' as already validated", "if", "l", ":=", "strings", ".", "LastIndex", "(", "hostport", ",", "\"", "\"", ")", ";", "len", "(", "hostport", ")", "==", "l", "+", "1", "{", "// trim off '[' and ']'", "return", "hostport", "[", "1", ":", "l", "]", ",", "\"", "\"", ",", "nil", "\n", "}", "\n", "}", "else", "if", "strings", ".", "IndexByte", "(", "hostport", ",", "':'", ")", "<", "0", "{", "return", "hostport", ",", "\"", "\"", ",", "nil", "\n", "}", "\n", "return", "net", ".", "SplitHostPort", "(", "hostport", ")", "\n", "}" ]
// The way this is used it can only get a hostport already validated by // the URL parser, so this means we can skip some error checks
[ "The", "way", "this", "is", "used", "it", "can", "only", "get", "a", "hostport", "already", "validated", "by", "the", "URL", "parser", "so", "this", "means", "we", "can", "skip", "some", "error", "checks" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/url.go#L37-L51
train
apache/qpid-proton
go/src/qpid.apache.org/proton/message.go
Message
func (delivery Delivery) Message() (amqp.Message, error) { var err error bytes, err := delivery.MessageBytes() if err == nil { m := amqp.NewMessage() err = m.Decode(bytes) return m, err } return nil, err }
go
func (delivery Delivery) Message() (amqp.Message, error) { var err error bytes, err := delivery.MessageBytes() if err == nil { m := amqp.NewMessage() err = m.Decode(bytes) return m, err } return nil, err }
[ "func", "(", "delivery", "Delivery", ")", "Message", "(", ")", "(", "amqp", ".", "Message", ",", "error", ")", "{", "var", "err", "error", "\n", "bytes", ",", "err", ":=", "delivery", ".", "MessageBytes", "(", ")", "\n", "if", "err", "==", "nil", "{", "m", ":=", "amqp", ".", "NewMessage", "(", ")", "\n", "err", "=", "m", ".", "Decode", "(", "bytes", ")", "\n", "return", "m", ",", "err", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}" ]
// Message decodes the message contained in a delivery. // // Must be called in the correct link context with this delivery as the current message, // handling an MMessage event is always a safe context to call this function. // // Will return an error if message is incomplete or not current.
[ "Message", "decodes", "the", "message", "contained", "in", "a", "delivery", ".", "Must", "be", "called", "in", "the", "correct", "link", "context", "with", "this", "delivery", "as", "the", "current", "message", "handling", "an", "MMessage", "event", "is", "always", "a", "safe", "context", "to", "call", "this", "function", ".", "Will", "return", "an", "error", "if", "message", "is", "incomplete", "or", "not", "current", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/message.go#L45-L54
train
apache/qpid-proton
go/src/qpid.apache.org/proton/message.go
MessageBytes
func (delivery Delivery) MessageBytes() ([]byte, error) { if !delivery.Readable() { return nil, fmt.Errorf("delivery is not readable") } if delivery.Partial() { return nil, fmt.Errorf("delivery has partial message") } data := make([]byte, delivery.Pending()) result := delivery.Link().Recv(data) if result != len(data) { return nil, fmt.Errorf("cannot receive message: %s", PnErrorCode(result)) } return data, nil }
go
func (delivery Delivery) MessageBytes() ([]byte, error) { if !delivery.Readable() { return nil, fmt.Errorf("delivery is not readable") } if delivery.Partial() { return nil, fmt.Errorf("delivery has partial message") } data := make([]byte, delivery.Pending()) result := delivery.Link().Recv(data) if result != len(data) { return nil, fmt.Errorf("cannot receive message: %s", PnErrorCode(result)) } return data, nil }
[ "func", "(", "delivery", "Delivery", ")", "MessageBytes", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "!", "delivery", ".", "Readable", "(", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "delivery", ".", "Partial", "(", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "data", ":=", "make", "(", "[", "]", "byte", ",", "delivery", ".", "Pending", "(", ")", ")", "\n", "result", ":=", "delivery", ".", "Link", "(", ")", ".", "Recv", "(", "data", ")", "\n", "if", "result", "!=", "len", "(", "data", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "PnErrorCode", "(", "result", ")", ")", "\n", "}", "\n", "return", "data", ",", "nil", "\n", "}" ]
// MessageBytes extracts the raw message bytes contained in a delivery. // // Must be called in the correct link context with this delivery as the current message, // handling an MMessage event is always a safe context to call this function. // // Will return an error if message is incomplete or not current.
[ "MessageBytes", "extracts", "the", "raw", "message", "bytes", "contained", "in", "a", "delivery", ".", "Must", "be", "called", "in", "the", "correct", "link", "context", "with", "this", "delivery", "as", "the", "current", "message", "handling", "an", "MMessage", "event", "is", "always", "a", "safe", "context", "to", "call", "this", "function", ".", "Will", "return", "an", "error", "if", "message", "is", "incomplete", "or", "not", "current", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/message.go#L62-L75
train
apache/qpid-proton
go/src/qpid.apache.org/proton/message.go
Send
func (link Link) Send(m amqp.Message) (Delivery, error) { bytes, err := m.Encode(nil) if err != nil { return Delivery{}, err } d, err := link.SendMessageBytes(bytes) return d, err }
go
func (link Link) Send(m amqp.Message) (Delivery, error) { bytes, err := m.Encode(nil) if err != nil { return Delivery{}, err } d, err := link.SendMessageBytes(bytes) return d, err }
[ "func", "(", "link", "Link", ")", "Send", "(", "m", "amqp", ".", "Message", ")", "(", "Delivery", ",", "error", ")", "{", "bytes", ",", "err", ":=", "m", ".", "Encode", "(", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Delivery", "{", "}", ",", "err", "\n", "}", "\n", "d", ",", "err", ":=", "link", ".", "SendMessageBytes", "(", "bytes", ")", "\n", "return", "d", ",", "err", "\n", "}" ]
// Send sends a amqp.Message over a Link. // Returns a Delivery that can be use to determine the outcome of the message.
[ "Send", "sends", "a", "amqp", ".", "Message", "over", "a", "Link", ".", "Returns", "a", "Delivery", "that", "can", "be", "use", "to", "determine", "the", "outcome", "of", "the", "message", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/message.go#L86-L93
train
apache/qpid-proton
go/src/qpid.apache.org/proton/message.go
SendMessageBytes
func (link Link) SendMessageBytes(bytes []byte) (Delivery, error) { if !link.IsSender() { return Delivery{}, fmt.Errorf("attempt to send message on receiving link") } delivery := link.Delivery(nextTag()) result := link.SendBytes(bytes) link.Advance() if result != len(bytes) { if result < 0 { return delivery, fmt.Errorf("send failed %v", PnErrorCode(result)) } else { return delivery, fmt.Errorf("send incomplete %v of %v", result, len(bytes)) } } if link.RemoteSndSettleMode() == SndSettled { delivery.Settle() } return delivery, nil }
go
func (link Link) SendMessageBytes(bytes []byte) (Delivery, error) { if !link.IsSender() { return Delivery{}, fmt.Errorf("attempt to send message on receiving link") } delivery := link.Delivery(nextTag()) result := link.SendBytes(bytes) link.Advance() if result != len(bytes) { if result < 0 { return delivery, fmt.Errorf("send failed %v", PnErrorCode(result)) } else { return delivery, fmt.Errorf("send incomplete %v of %v", result, len(bytes)) } } if link.RemoteSndSettleMode() == SndSettled { delivery.Settle() } return delivery, nil }
[ "func", "(", "link", "Link", ")", "SendMessageBytes", "(", "bytes", "[", "]", "byte", ")", "(", "Delivery", ",", "error", ")", "{", "if", "!", "link", ".", "IsSender", "(", ")", "{", "return", "Delivery", "{", "}", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "delivery", ":=", "link", ".", "Delivery", "(", "nextTag", "(", ")", ")", "\n", "result", ":=", "link", ".", "SendBytes", "(", "bytes", ")", "\n", "link", ".", "Advance", "(", ")", "\n", "if", "result", "!=", "len", "(", "bytes", ")", "{", "if", "result", "<", "0", "{", "return", "delivery", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "PnErrorCode", "(", "result", ")", ")", "\n", "}", "else", "{", "return", "delivery", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "result", ",", "len", "(", "bytes", ")", ")", "\n", "}", "\n", "}", "\n", "if", "link", ".", "RemoteSndSettleMode", "(", ")", "==", "SndSettled", "{", "delivery", ".", "Settle", "(", ")", "\n", "}", "\n", "return", "delivery", ",", "nil", "\n", "}" ]
// SendMessageBytes sends encoded bytes of an amqp.Message over a Link. // Returns a Delivery that can be use to determine the outcome of the message.
[ "SendMessageBytes", "sends", "encoded", "bytes", "of", "an", "amqp", ".", "Message", "over", "a", "Link", ".", "Returns", "a", "Delivery", "that", "can", "be", "use", "to", "determine", "the", "outcome", "of", "the", "message", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/message.go#L97-L115
train
apache/qpid-proton
go/src/qpid.apache.org/electron/time.go
After
func After(timeout time.Duration) <-chan time.Time { if timeout == Forever { return nil } else { return time.After(timeout) } }
go
func After(timeout time.Duration) <-chan time.Time { if timeout == Forever { return nil } else { return time.After(timeout) } }
[ "func", "After", "(", "timeout", "time", ".", "Duration", ")", "<-", "chan", "time", ".", "Time", "{", "if", "timeout", "==", "Forever", "{", "return", "nil", "\n", "}", "else", "{", "return", "time", ".", "After", "(", "timeout", ")", "\n", "}", "\n", "}" ]
// After is like time.After but returns a nil channel if timeout == Forever // since selecting on a nil channel will never return.
[ "After", "is", "like", "time", ".", "After", "but", "returns", "a", "nil", "channel", "if", "timeout", "==", "Forever", "since", "selecting", "on", "a", "nil", "channel", "will", "never", "return", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/time.go#L77-L83
train
apache/qpid-proton
go/src/qpid.apache.org/electron/endpoint.go
localClose
func localClose(ep proton.Endpoint, err error) { if ep.State().LocalActive() { proton.CloseError(ep, err) } }
go
func localClose(ep proton.Endpoint, err error) { if ep.State().LocalActive() { proton.CloseError(ep, err) } }
[ "func", "localClose", "(", "ep", "proton", ".", "Endpoint", ",", "err", "error", ")", "{", "if", "ep", ".", "State", "(", ")", ".", "LocalActive", "(", ")", "{", "proton", ".", "CloseError", "(", "ep", ",", "err", ")", "\n", "}", "\n", "}" ]
// Call in proton goroutine to initiate closing an endpoint locally // handler will complete the close when remote end closes.
[ "Call", "in", "proton", "goroutine", "to", "initiate", "closing", "an", "endpoint", "locally", "handler", "will", "complete", "the", "close", "when", "remote", "end", "closes", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/endpoint.go#L135-L139
train
apache/qpid-proton
go/src/qpid.apache.org/electron/endpoint.go
accept
func (in *incoming) accept(f func() Endpoint) Endpoint { done := make(chan Endpoint) in.acceptCh <- func() error { ep := f() done <- ep return nil } return <-done }
go
func (in *incoming) accept(f func() Endpoint) Endpoint { done := make(chan Endpoint) in.acceptCh <- func() error { ep := f() done <- ep return nil } return <-done }
[ "func", "(", "in", "*", "incoming", ")", "accept", "(", "f", "func", "(", ")", "Endpoint", ")", "Endpoint", "{", "done", ":=", "make", "(", "chan", "Endpoint", ")", "\n", "in", ".", "acceptCh", "<-", "func", "(", ")", "error", "{", "ep", ":=", "f", "(", ")", "\n", "done", "<-", "ep", "\n", "return", "nil", "\n", "}", "\n", "return", "<-", "done", "\n", "}" ]
// Called in app goroutine to send an accept function to proton and return the resulting endpoint.
[ "Called", "in", "app", "goroutine", "to", "send", "an", "accept", "function", "to", "proton", "and", "return", "the", "resulting", "endpoint", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/endpoint.go#L180-L188
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/message.go
NewMessageCopy
func NewMessageCopy(m Message) Message { m2 := NewMessage() m2.Copy(m) return m2 }
go
func NewMessageCopy(m Message) Message { m2 := NewMessage() m2.Copy(m) return m2 }
[ "func", "NewMessageCopy", "(", "m", "Message", ")", "Message", "{", "m2", ":=", "NewMessage", "(", ")", "\n", "m2", ".", "Copy", "(", "m", ")", "\n", "return", "m2", "\n", "}" ]
// NewMessageCopy creates a copy of an existing message.
[ "NewMessageCopy", "creates", "a", "copy", "of", "an", "existing", "message", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/message.go#L202-L206
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/message.go
Copy
func (m *message) Copy(x Message) error { var mc MessageCodec bytes, err := mc.Encode(x, nil) if err == nil { err = mc.Decode(m, bytes) } return err }
go
func (m *message) Copy(x Message) error { var mc MessageCodec bytes, err := mc.Encode(x, nil) if err == nil { err = mc.Decode(m, bytes) } return err }
[ "func", "(", "m", "*", "message", ")", "Copy", "(", "x", "Message", ")", "error", "{", "var", "mc", "MessageCodec", "\n", "bytes", ",", "err", ":=", "mc", ".", "Encode", "(", "x", ",", "nil", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "mc", ".", "Decode", "(", "m", ",", "bytes", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// Copy makes a deep copy of message x
[ "Copy", "makes", "a", "deep", "copy", "of", "message", "x" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/message.go#L212-L219
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/message.go
Encode
func (mc *MessageCodec) Encode(m Message, buffer []byte) ([]byte, error) { pn := mc.pnMessage() m.(*message).put(pn) encode := func(buf []byte) ([]byte, error) { len := cLen(buf) result := C.pn_message_encode(pn, cPtr(buf), &len) switch { case result == C.PN_OVERFLOW: return buf, overflow case result < 0: return buf, fmt.Errorf("cannot encode message: %s", PnErrorCode(result)) default: return buf[:len], nil } } return encodeGrow(buffer, encode) }
go
func (mc *MessageCodec) Encode(m Message, buffer []byte) ([]byte, error) { pn := mc.pnMessage() m.(*message).put(pn) encode := func(buf []byte) ([]byte, error) { len := cLen(buf) result := C.pn_message_encode(pn, cPtr(buf), &len) switch { case result == C.PN_OVERFLOW: return buf, overflow case result < 0: return buf, fmt.Errorf("cannot encode message: %s", PnErrorCode(result)) default: return buf[:len], nil } } return encodeGrow(buffer, encode) }
[ "func", "(", "mc", "*", "MessageCodec", ")", "Encode", "(", "m", "Message", ",", "buffer", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "pn", ":=", "mc", ".", "pnMessage", "(", ")", "\n", "m", ".", "(", "*", "message", ")", ".", "put", "(", "pn", ")", "\n", "encode", ":=", "func", "(", "buf", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "len", ":=", "cLen", "(", "buf", ")", "\n", "result", ":=", "C", ".", "pn_message_encode", "(", "pn", ",", "cPtr", "(", "buf", ")", ",", "&", "len", ")", "\n", "switch", "{", "case", "result", "==", "C", ".", "PN_OVERFLOW", ":", "return", "buf", ",", "overflow", "\n", "case", "result", "<", "0", ":", "return", "buf", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "PnErrorCode", "(", "result", ")", ")", "\n", "default", ":", "return", "buf", "[", ":", "len", "]", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "encodeGrow", "(", "buffer", ",", "encode", ")", "\n", "}" ]
// Encode m using buffer. Return the final buffer used to hold m, // may be different if the initial buffer was not large enough.
[ "Encode", "m", "using", "buffer", ".", "Return", "the", "final", "buffer", "used", "to", "hold", "m", "may", "be", "different", "if", "the", "initial", "buffer", "was", "not", "large", "enough", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/message.go#L377-L393
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/message.go
String
func (m *message) String() string { var b stringBuilder b.WriteString("Message{") b.field("address", m.address, isEmpty) b.field("durable", m.durable, isZero) // Priority has weird default b.field("priority", m.priority, func(v interface{}) bool { return v.(uint8) == 4 }) b.field("ttl", m.ttl, isZero) b.field("first-acquirer", m.firstAcquirer, isZero) b.field("delivery-count", m.deliveryCount, isZero) b.field("message-id", m.messageId, isNil) b.field("user-id", m.userId, isEmpty) b.field("subject", m.subject, isEmpty) b.field("reply-to", m.replyTo, isEmpty) b.field("correlation-id", m.correlationId, isNil) b.field("content-type", m.contentType, isEmpty) b.field("content-encoding", m.contentEncoding, isEmpty) b.field("expiry-time", m.expiryTime, isZero) b.field("creation-time", m.creationTime, isZero) b.field("group-id", m.groupId, isEmpty) b.field("group-sequence", m.groupSequence, isZero) b.field("reply-to-group-id", m.replyToGroupId, isEmpty) b.field("inferred", m.inferred, isZero) b.field("delivery-annotations", m.deliveryAnnotations, isEmpty) b.field("message-annotations", m.messageAnnotations, isEmpty) b.field("application-properties", m.applicationProperties, isEmpty) b.field("body", m.body, isNil) b.WriteString("}") return b.String() }
go
func (m *message) String() string { var b stringBuilder b.WriteString("Message{") b.field("address", m.address, isEmpty) b.field("durable", m.durable, isZero) // Priority has weird default b.field("priority", m.priority, func(v interface{}) bool { return v.(uint8) == 4 }) b.field("ttl", m.ttl, isZero) b.field("first-acquirer", m.firstAcquirer, isZero) b.field("delivery-count", m.deliveryCount, isZero) b.field("message-id", m.messageId, isNil) b.field("user-id", m.userId, isEmpty) b.field("subject", m.subject, isEmpty) b.field("reply-to", m.replyTo, isEmpty) b.field("correlation-id", m.correlationId, isNil) b.field("content-type", m.contentType, isEmpty) b.field("content-encoding", m.contentEncoding, isEmpty) b.field("expiry-time", m.expiryTime, isZero) b.field("creation-time", m.creationTime, isZero) b.field("group-id", m.groupId, isEmpty) b.field("group-sequence", m.groupSequence, isZero) b.field("reply-to-group-id", m.replyToGroupId, isEmpty) b.field("inferred", m.inferred, isZero) b.field("delivery-annotations", m.deliveryAnnotations, isEmpty) b.field("message-annotations", m.messageAnnotations, isEmpty) b.field("application-properties", m.applicationProperties, isEmpty) b.field("body", m.body, isNil) b.WriteString("}") return b.String() }
[ "func", "(", "m", "*", "message", ")", "String", "(", ")", "string", "{", "var", "b", "stringBuilder", "\n", "b", ".", "WriteString", "(", "\"", "\"", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "address", ",", "isEmpty", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "durable", ",", "isZero", ")", "\n", "// Priority has weird default", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "priority", ",", "func", "(", "v", "interface", "{", "}", ")", "bool", "{", "return", "v", ".", "(", "uint8", ")", "==", "4", "}", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "ttl", ",", "isZero", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "firstAcquirer", ",", "isZero", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "deliveryCount", ",", "isZero", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "messageId", ",", "isNil", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "userId", ",", "isEmpty", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "subject", ",", "isEmpty", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "replyTo", ",", "isEmpty", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "correlationId", ",", "isNil", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "contentType", ",", "isEmpty", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "contentEncoding", ",", "isEmpty", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "expiryTime", ",", "isZero", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "creationTime", ",", "isZero", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "groupId", ",", "isEmpty", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "groupSequence", ",", "isZero", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "replyToGroupId", ",", "isEmpty", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "inferred", ",", "isZero", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "deliveryAnnotations", ",", "isEmpty", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "messageAnnotations", ",", "isEmpty", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "applicationProperties", ",", "isEmpty", ")", "\n", "b", ".", "field", "(", "\"", "\"", ",", "m", ".", "body", ",", "isNil", ")", "\n", "b", ".", "WriteString", "(", "\"", "\"", ")", "\n", "return", "b", ".", "String", "(", ")", "\n", "}" ]
// Human-readable string describing message. // Includes only message fields with non-default values.
[ "Human", "-", "readable", "string", "describing", "message", ".", "Includes", "only", "message", "fields", "with", "non", "-", "default", "values", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/message.go#L426-L455
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/message.go
newAnnotations
func newAnnotations(in map[string]interface{}) (out map[AnnotationKey]interface{}) { if len(in) == 0 { return nil } out = make(map[AnnotationKey]interface{}) for k, v := range in { out[AnnotationKeyString(k)] = v } return }
go
func newAnnotations(in map[string]interface{}) (out map[AnnotationKey]interface{}) { if len(in) == 0 { return nil } out = make(map[AnnotationKey]interface{}) for k, v := range in { out[AnnotationKeyString(k)] = v } return }
[ "func", "newAnnotations", "(", "in", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "out", "map", "[", "AnnotationKey", "]", "interface", "{", "}", ")", "{", "if", "len", "(", "in", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "out", "=", "make", "(", "map", "[", "AnnotationKey", "]", "interface", "{", "}", ")", "\n", "for", "k", ",", "v", ":=", "range", "in", "{", "out", "[", "AnnotationKeyString", "(", "k", ")", "]", "=", "v", "\n", "}", "\n", "return", "\n", "}" ]
// Convert old string-keyed annotations to an AnnotationKey map
[ "Convert", "old", "string", "-", "keyed", "annotations", "to", "an", "AnnotationKey", "map" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/message.go#L586-L595
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/types.go
GoString
func (m Map) GoString() string { out := &bytes.Buffer{} fmt.Fprintf(out, "%T{", m) i := len(m) for k, v := range m { fmt.Fprintf(out, "%T(%#v): %T(%#v)", k, k, v, v) i-- if i > 0 { fmt.Fprint(out, ", ") } } fmt.Fprint(out, "}") return out.String() }
go
func (m Map) GoString() string { out := &bytes.Buffer{} fmt.Fprintf(out, "%T{", m) i := len(m) for k, v := range m { fmt.Fprintf(out, "%T(%#v): %T(%#v)", k, k, v, v) i-- if i > 0 { fmt.Fprint(out, ", ") } } fmt.Fprint(out, "}") return out.String() }
[ "func", "(", "m", "Map", ")", "GoString", "(", ")", "string", "{", "out", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ",", "m", ")", "\n", "i", ":=", "len", "(", "m", ")", "\n", "for", "k", ",", "v", ":=", "range", "m", "{", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ",", "k", ",", "k", ",", "v", ",", "v", ")", "\n", "i", "--", "\n", "if", "i", ">", "0", "{", "fmt", ".", "Fprint", "(", "out", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "out", ",", "\"", "\"", ")", "\n", "return", "out", ".", "String", "(", ")", "\n", "}" ]
// GoString for Map prints values with their types, useful for debugging.
[ "GoString", "for", "Map", "prints", "values", "with", "their", "types", "useful", "for", "debugging", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/types.go#L136-L149
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/types.go
GoString
func (l List) GoString() string { out := &bytes.Buffer{} fmt.Fprintf(out, "%T{", l) for i := 0; i < len(l); i++ { fmt.Fprintf(out, "%T(%#v)", l[i], l[i]) if i == len(l)-1 { fmt.Fprint(out, ", ") } } fmt.Fprint(out, "}") return out.String() }
go
func (l List) GoString() string { out := &bytes.Buffer{} fmt.Fprintf(out, "%T{", l) for i := 0; i < len(l); i++ { fmt.Fprintf(out, "%T(%#v)", l[i], l[i]) if i == len(l)-1 { fmt.Fprint(out, ", ") } } fmt.Fprint(out, "}") return out.String() }
[ "func", "(", "l", "List", ")", "GoString", "(", ")", "string", "{", "out", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ",", "l", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "l", ")", ";", "i", "++", "{", "fmt", ".", "Fprintf", "(", "out", ",", "\"", "\"", ",", "l", "[", "i", "]", ",", "l", "[", "i", "]", ")", "\n", "if", "i", "==", "len", "(", "l", ")", "-", "1", "{", "fmt", ".", "Fprint", "(", "out", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "out", ",", "\"", "\"", ")", "\n", "return", "out", ".", "String", "(", ")", "\n", "}" ]
// GoString for List prints values with their types, useful for debugging.
[ "GoString", "for", "List", "prints", "values", "with", "their", "types", "useful", "for", "debugging", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/types.go#L152-L163
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/types.go
pnTime
func pnTime(t time.Time) C.pn_timestamp_t { if t.IsZero() { return C.pn_timestamp_t(0) } return C.pn_timestamp_t(t.UnixNano() / int64(time.Millisecond)) }
go
func pnTime(t time.Time) C.pn_timestamp_t { if t.IsZero() { return C.pn_timestamp_t(0) } return C.pn_timestamp_t(t.UnixNano() / int64(time.Millisecond)) }
[ "func", "pnTime", "(", "t", "time", ".", "Time", ")", "C", ".", "pn_timestamp_t", "{", "if", "t", ".", "IsZero", "(", ")", "{", "return", "C", ".", "pn_timestamp_t", "(", "0", ")", "\n", "}", "\n", "return", "C", ".", "pn_timestamp_t", "(", "t", ".", "UnixNano", "(", ")", "/", "int64", "(", "time", ".", "Millisecond", ")", ")", "\n", "}" ]
// pnTime converts Go time.Time to Proton millisecond Unix time. // Take care to convert zero values to zero values.
[ "pnTime", "converts", "Go", "time", ".", "Time", "to", "Proton", "millisecond", "Unix", "time", ".", "Take", "care", "to", "convert", "zero", "values", "to", "zero", "values", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/types.go#L167-L172
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/types.go
goTime
func goTime(t C.pn_timestamp_t) time.Time { if t == 0 { return time.Time{} } return time.Unix(0, int64(t)*int64(time.Millisecond)) }
go
func goTime(t C.pn_timestamp_t) time.Time { if t == 0 { return time.Time{} } return time.Unix(0, int64(t)*int64(time.Millisecond)) }
[ "func", "goTime", "(", "t", "C", ".", "pn_timestamp_t", ")", "time", ".", "Time", "{", "if", "t", "==", "0", "{", "return", "time", ".", "Time", "{", "}", "\n", "}", "\n", "return", "time", ".", "Unix", "(", "0", ",", "int64", "(", "t", ")", "*", "int64", "(", "time", ".", "Millisecond", ")", ")", "\n", "}" ]
// goTime converts a pn_timestamp_t to a Go time.Time. // Take care to convert zero values to zero values.
[ "goTime", "converts", "a", "pn_timestamp_t", "to", "a", "Go", "time", ".", "Time", ".", "Take", "care", "to", "convert", "zero", "values", "to", "zero", "values", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/types.go#L176-L181
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/error.go
Errorf
func Errorf(name, format string, arg ...interface{}) Error { return Error{name, fmt.Sprintf(format, arg...)} }
go
func Errorf(name, format string, arg ...interface{}) Error { return Error{name, fmt.Sprintf(format, arg...)} }
[ "func", "Errorf", "(", "name", ",", "format", "string", ",", "arg", "...", "interface", "{", "}", ")", "Error", "{", "return", "Error", "{", "name", ",", "fmt", ".", "Sprintf", "(", "format", ",", "arg", "...", ")", "}", "\n", "}" ]
// Errorf makes a Error with name and formatted description as per fmt.Sprintf
[ "Errorf", "makes", "a", "Error", "with", "name", "and", "formatted", "description", "as", "per", "fmt", ".", "Sprintf" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/error.go#L44-L46
train
apache/qpid-proton
go/examples/electron/broker.go
run
func (b *broker) run() error { listener, err := net.Listen("tcp", *addr) if err != nil { return err } defer listener.Close() fmt.Printf("Listening on %v\n", listener.Addr()) go b.acknowledgements() // Handles acknowledgements for all connections. // Start a goroutine for each new connections for { c, err := b.container.Accept(listener) if err != nil { debugf("Accept error: %v", err) continue } cc := &connection{b, c} go cc.run() // Handle the connection debugf("Accepted %v", c) } }
go
func (b *broker) run() error { listener, err := net.Listen("tcp", *addr) if err != nil { return err } defer listener.Close() fmt.Printf("Listening on %v\n", listener.Addr()) go b.acknowledgements() // Handles acknowledgements for all connections. // Start a goroutine for each new connections for { c, err := b.container.Accept(listener) if err != nil { debugf("Accept error: %v", err) continue } cc := &connection{b, c} go cc.run() // Handle the connection debugf("Accepted %v", c) } }
[ "func", "(", "b", "*", "broker", ")", "run", "(", ")", "error", "{", "listener", ",", "err", ":=", "net", ".", "Listen", "(", "\"", "\"", ",", "*", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "listener", ".", "Close", "(", ")", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "listener", ".", "Addr", "(", ")", ")", "\n\n", "go", "b", ".", "acknowledgements", "(", ")", "// Handles acknowledgements for all connections.", "\n\n", "// Start a goroutine for each new connections", "for", "{", "c", ",", "err", ":=", "b", ".", "container", ".", "Accept", "(", "listener", ")", "\n", "if", "err", "!=", "nil", "{", "debugf", "(", "\"", "\"", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "cc", ":=", "&", "connection", "{", "b", ",", "c", "}", "\n", "go", "cc", ".", "run", "(", ")", "// Handle the connection", "\n", "debugf", "(", "\"", "\"", ",", "c", ")", "\n", "}", "\n", "}" ]
// run listens for incoming net.Conn connections and starts an electron.Connection for each one.
[ "run", "listens", "for", "incoming", "net", ".", "Conn", "connections", "and", "starts", "an", "electron", ".", "Connection", "for", "each", "one", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/examples/electron/broker.go#L91-L112
train
apache/qpid-proton
go/examples/electron/broker.go
receiver
func (c *connection) receiver(receiver electron.Receiver) { q := c.broker.queues.Get(receiver.Target()) for { if rm, err := receiver.Receive(); err == nil { debugf("%v: received %v", receiver, rm.Message.Body()) q <- rm.Message rm.Accept() } else { debugf("%v error: %v", receiver, err) break } } }
go
func (c *connection) receiver(receiver electron.Receiver) { q := c.broker.queues.Get(receiver.Target()) for { if rm, err := receiver.Receive(); err == nil { debugf("%v: received %v", receiver, rm.Message.Body()) q <- rm.Message rm.Accept() } else { debugf("%v error: %v", receiver, err) break } } }
[ "func", "(", "c", "*", "connection", ")", "receiver", "(", "receiver", "electron", ".", "Receiver", ")", "{", "q", ":=", "c", ".", "broker", ".", "queues", ".", "Get", "(", "receiver", ".", "Target", "(", ")", ")", "\n", "for", "{", "if", "rm", ",", "err", ":=", "receiver", ".", "Receive", "(", ")", ";", "err", "==", "nil", "{", "debugf", "(", "\"", "\"", ",", "receiver", ",", "rm", ".", "Message", ".", "Body", "(", ")", ")", "\n", "q", "<-", "rm", ".", "Message", "\n", "rm", ".", "Accept", "(", ")", "\n", "}", "else", "{", "debugf", "(", "\"", "\"", ",", "receiver", ",", "err", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "}" ]
// receiver receives messages and pushes to a queue.
[ "receiver", "receives", "messages", "and", "pushes", "to", "a", "queue", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/examples/electron/broker.go#L146-L158
train
apache/qpid-proton
go/examples/electron/broker.go
sender
func (c *connection) sender(sender electron.Sender) { q := c.broker.queues.Get(sender.Source()) for { if sender.Error() != nil { debugf("%v closed: %v", sender, sender.Error()) return } select { case m := <-q: debugf("%v: sent %v", sender, m.Body()) sm := sentMessage{m, q} c.broker.sent <- sm // Record sent message sender.SendAsync(m, c.broker.acks, sm) // Receive outcome on c.broker.acks with Value sm case <-sender.Done(): // break if sender is closed break } } }
go
func (c *connection) sender(sender electron.Sender) { q := c.broker.queues.Get(sender.Source()) for { if sender.Error() != nil { debugf("%v closed: %v", sender, sender.Error()) return } select { case m := <-q: debugf("%v: sent %v", sender, m.Body()) sm := sentMessage{m, q} c.broker.sent <- sm // Record sent message sender.SendAsync(m, c.broker.acks, sm) // Receive outcome on c.broker.acks with Value sm case <-sender.Done(): // break if sender is closed break } } }
[ "func", "(", "c", "*", "connection", ")", "sender", "(", "sender", "electron", ".", "Sender", ")", "{", "q", ":=", "c", ".", "broker", ".", "queues", ".", "Get", "(", "sender", ".", "Source", "(", ")", ")", "\n", "for", "{", "if", "sender", ".", "Error", "(", ")", "!=", "nil", "{", "debugf", "(", "\"", "\"", ",", "sender", ",", "sender", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n", "select", "{", "case", "m", ":=", "<-", "q", ":", "debugf", "(", "\"", "\"", ",", "sender", ",", "m", ".", "Body", "(", ")", ")", "\n", "sm", ":=", "sentMessage", "{", "m", ",", "q", "}", "\n", "c", ".", "broker", ".", "sent", "<-", "sm", "// Record sent message", "\n", "sender", ".", "SendAsync", "(", "m", ",", "c", ".", "broker", ".", "acks", ",", "sm", ")", "// Receive outcome on c.broker.acks with Value sm", "\n\n", "case", "<-", "sender", ".", "Done", "(", ")", ":", "// break if sender is closed", "break", "\n", "}", "\n", "}", "\n", "}" ]
// sender pops messages from a queue and sends them.
[ "sender", "pops", "messages", "from", "a", "queue", "and", "sends", "them", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/examples/electron/broker.go#L161-L180
train
apache/qpid-proton
go/examples/electron/broker.go
acknowledgements
func (b *broker) acknowledgements() { sentMap := make(map[sentMessage]bool) for { select { case sm, ok := <-b.sent: // A local sender records that it has sent a message. if ok { sentMap[sm] = true } else { return // Closed } case outcome := <-b.acks: // The message outcome is available sm := outcome.Value.(sentMessage) delete(sentMap, sm) if outcome.Status != electron.Accepted { // Error, release or rejection sm.q.PutBack(sm.m) // Put the message back on the queue. debugf("message %v put back, status %v, error %v", sm.m.Body(), outcome.Status, outcome.Error) } } } }
go
func (b *broker) acknowledgements() { sentMap := make(map[sentMessage]bool) for { select { case sm, ok := <-b.sent: // A local sender records that it has sent a message. if ok { sentMap[sm] = true } else { return // Closed } case outcome := <-b.acks: // The message outcome is available sm := outcome.Value.(sentMessage) delete(sentMap, sm) if outcome.Status != electron.Accepted { // Error, release or rejection sm.q.PutBack(sm.m) // Put the message back on the queue. debugf("message %v put back, status %v, error %v", sm.m.Body(), outcome.Status, outcome.Error) } } } }
[ "func", "(", "b", "*", "broker", ")", "acknowledgements", "(", ")", "{", "sentMap", ":=", "make", "(", "map", "[", "sentMessage", "]", "bool", ")", "\n", "for", "{", "select", "{", "case", "sm", ",", "ok", ":=", "<-", "b", ".", "sent", ":", "// A local sender records that it has sent a message.", "if", "ok", "{", "sentMap", "[", "sm", "]", "=", "true", "\n", "}", "else", "{", "return", "// Closed", "\n", "}", "\n", "case", "outcome", ":=", "<-", "b", ".", "acks", ":", "// The message outcome is available", "sm", ":=", "outcome", ".", "Value", ".", "(", "sentMessage", ")", "\n", "delete", "(", "sentMap", ",", "sm", ")", "\n", "if", "outcome", ".", "Status", "!=", "electron", ".", "Accepted", "{", "// Error, release or rejection", "sm", ".", "q", ".", "PutBack", "(", "sm", ".", "m", ")", "// Put the message back on the queue.", "\n", "debugf", "(", "\"", "\"", ",", "sm", ".", "m", ".", "Body", "(", ")", ",", "outcome", ".", "Status", ",", "outcome", ".", "Error", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// acknowledgements keeps track of sent messages and receives outcomes. // // We could have handled outcomes separately per-connection, per-sender or even // per-message. Message outcomes are returned via channels defined by the user // so they can be grouped in any way that suits the application.
[ "acknowledgements", "keeps", "track", "of", "sent", "messages", "and", "receives", "outcomes", ".", "We", "could", "have", "handled", "outcomes", "separately", "per", "-", "connection", "per", "-", "sender", "or", "even", "per", "-", "message", ".", "Message", "outcomes", "are", "returned", "via", "channels", "defined", "by", "the", "user", "so", "they", "can", "be", "grouped", "in", "any", "way", "that", "suits", "the", "application", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/examples/electron/broker.go#L187-L206
train
apache/qpid-proton
go/examples/electron/broker.go
PutBack
func (q queue) PutBack(m amqp.Message) { select { case q <- m: default: // Not an efficient implementation but ensures we don't block the caller. go func() { q <- m }() } }
go
func (q queue) PutBack(m amqp.Message) { select { case q <- m: default: // Not an efficient implementation but ensures we don't block the caller. go func() { q <- m }() } }
[ "func", "(", "q", "queue", ")", "PutBack", "(", "m", "amqp", ".", "Message", ")", "{", "select", "{", "case", "q", "<-", "m", ":", "default", ":", "// Not an efficient implementation but ensures we don't block the caller.", "go", "func", "(", ")", "{", "q", "<-", "m", "}", "(", ")", "\n", "}", "\n", "}" ]
// Put a message back on the queue, does not block.
[ "Put", "a", "message", "back", "on", "the", "queue", "does", "not", "block", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/examples/electron/broker.go#L212-L219
train
apache/qpid-proton
go/examples/electron/broker.go
Get
func (qs *queues) Get(name string) queue { qs.lock.Lock() defer qs.lock.Unlock() q := qs.m[name] if q == nil { q = make(queue, qs.queueSize) qs.m[name] = q } return q }
go
func (qs *queues) Get(name string) queue { qs.lock.Lock() defer qs.lock.Unlock() q := qs.m[name] if q == nil { q = make(queue, qs.queueSize) qs.m[name] = q } return q }
[ "func", "(", "qs", "*", "queues", ")", "Get", "(", "name", "string", ")", "queue", "{", "qs", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "qs", ".", "lock", ".", "Unlock", "(", ")", "\n", "q", ":=", "qs", ".", "m", "[", "name", "]", "\n", "if", "q", "==", "nil", "{", "q", "=", "make", "(", "queue", ",", "qs", ".", "queueSize", ")", "\n", "qs", ".", "m", "[", "name", "]", "=", "q", "\n", "}", "\n", "return", "q", "\n", "}" ]
// Create a queue if not found.
[ "Create", "a", "queue", "if", "not", "found", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/examples/electron/broker.go#L233-L242
train
apache/qpid-proton
go/src/qpid.apache.org/electron/link.go
AtMostOnce
func AtMostOnce() LinkOption { return func(l *linkSettings) { SndSettle(SndSettled)(l) RcvSettle(RcvFirst)(l) } }
go
func AtMostOnce() LinkOption { return func(l *linkSettings) { SndSettle(SndSettled)(l) RcvSettle(RcvFirst)(l) } }
[ "func", "AtMostOnce", "(", ")", "LinkOption", "{", "return", "func", "(", "l", "*", "linkSettings", ")", "{", "SndSettle", "(", "SndSettled", ")", "(", "l", ")", "\n", "RcvSettle", "(", "RcvFirst", ")", "(", "l", ")", "\n", "}", "\n", "}" ]
// AtMostOnce returns a LinkOption that sets "fire and forget" mode, messages // are sent but no acknowledgment is received, messages can be lost if there is // a network failure. Sets SndSettleMode=SendSettled and RcvSettleMode=RcvFirst
[ "AtMostOnce", "returns", "a", "LinkOption", "that", "sets", "fire", "and", "forget", "mode", "messages", "are", "sent", "but", "no", "acknowledgment", "is", "received", "messages", "can", "be", "lost", "if", "there", "is", "a", "network", "failure", ".", "Sets", "SndSettleMode", "=", "SendSettled", "and", "RcvSettleMode", "=", "RcvFirst" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/link.go#L104-L109
train
apache/qpid-proton
go/src/qpid.apache.org/electron/link.go
AtLeastOnce
func AtLeastOnce() LinkOption { return func(l *linkSettings) { SndSettle(SndUnsettled)(l) RcvSettle(RcvFirst)(l) } }
go
func AtLeastOnce() LinkOption { return func(l *linkSettings) { SndSettle(SndUnsettled)(l) RcvSettle(RcvFirst)(l) } }
[ "func", "AtLeastOnce", "(", ")", "LinkOption", "{", "return", "func", "(", "l", "*", "linkSettings", ")", "{", "SndSettle", "(", "SndUnsettled", ")", "(", "l", ")", "\n", "RcvSettle", "(", "RcvFirst", ")", "(", "l", ")", "\n", "}", "\n", "}" ]
// AtLeastOnce returns a LinkOption that requests acknowledgment for every // message, acknowledgment indicates the message was definitely received. In the // event of a failure, unacknowledged messages can be re-sent but there is a // chance that the message will be received twice in this case. Sets // SndSettleMode=SndUnsettled and RcvSettleMode=RcvFirst
[ "AtLeastOnce", "returns", "a", "LinkOption", "that", "requests", "acknowledgment", "for", "every", "message", "acknowledgment", "indicates", "the", "message", "was", "definitely", "received", ".", "In", "the", "event", "of", "a", "failure", "unacknowledged", "messages", "can", "be", "re", "-", "sent", "but", "there", "is", "a", "chance", "that", "the", "message", "will", "be", "received", "twice", "in", "this", "case", ".", "Sets", "SndSettleMode", "=", "SndUnsettled", "and", "RcvSettleMode", "=", "RcvFirst" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/link.go#L116-L121
train
apache/qpid-proton
go/src/qpid.apache.org/electron/link.go
Filter
func Filter(m map[amqp.Symbol]interface{}) LinkOption { return func(l *linkSettings) { l.filter = m } }
go
func Filter(m map[amqp.Symbol]interface{}) LinkOption { return func(l *linkSettings) { l.filter = m } }
[ "func", "Filter", "(", "m", "map", "[", "amqp", ".", "Symbol", "]", "interface", "{", "}", ")", "LinkOption", "{", "return", "func", "(", "l", "*", "linkSettings", ")", "{", "l", ".", "filter", "=", "m", "}", "\n", "}" ]
// Filter returns a LinkOption that sets a filter.
[ "Filter", "returns", "a", "LinkOption", "that", "sets", "a", "filter", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/link.go#L124-L126
train
apache/qpid-proton
go/src/qpid.apache.org/electron/link.go
makeLocalLink
func makeLocalLink(sn *session, isSender bool, setting ...LinkOption) (linkSettings, error) { l := linkSettings{ isSender: isSender, capacity: 1, prefetch: false, session: sn, } for _, set := range setting { set(&l) } if l.linkName == "" { l.linkName = l.session.connection.container.nextLinkName() } if l.IsSender() { l.pLink = l.session.pSession.Sender(l.linkName) } else { l.pLink = l.session.pSession.Receiver(l.linkName) } if l.pLink.IsNil() { return l, fmt.Errorf("cannot create link %s", l.pLink) } l.pLink.Source().SetAddress(l.source) if len(l.filter) > 0 { if err := l.pLink.Source().Filter().Marshal(l.filter); err != nil { panic(err) // Shouldn't happen } } l.pLink.Source().SetDurability(l.sourceSettings.Durability) l.pLink.Source().SetExpiryPolicy(l.sourceSettings.Expiry) l.pLink.Source().SetTimeout(l.sourceSettings.Timeout) l.pLink.Source().SetDynamic(l.sourceSettings.Dynamic) l.pLink.Target().SetAddress(l.target) l.pLink.Target().SetDurability(l.targetSettings.Durability) l.pLink.Target().SetExpiryPolicy(l.targetSettings.Expiry) l.pLink.Target().SetTimeout(l.targetSettings.Timeout) l.pLink.Target().SetDynamic(l.targetSettings.Dynamic) l.pLink.SetSndSettleMode(proton.SndSettleMode(l.sndSettle)) l.pLink.SetRcvSettleMode(proton.RcvSettleMode(l.rcvSettle)) l.pLink.Open() return l, nil }
go
func makeLocalLink(sn *session, isSender bool, setting ...LinkOption) (linkSettings, error) { l := linkSettings{ isSender: isSender, capacity: 1, prefetch: false, session: sn, } for _, set := range setting { set(&l) } if l.linkName == "" { l.linkName = l.session.connection.container.nextLinkName() } if l.IsSender() { l.pLink = l.session.pSession.Sender(l.linkName) } else { l.pLink = l.session.pSession.Receiver(l.linkName) } if l.pLink.IsNil() { return l, fmt.Errorf("cannot create link %s", l.pLink) } l.pLink.Source().SetAddress(l.source) if len(l.filter) > 0 { if err := l.pLink.Source().Filter().Marshal(l.filter); err != nil { panic(err) // Shouldn't happen } } l.pLink.Source().SetDurability(l.sourceSettings.Durability) l.pLink.Source().SetExpiryPolicy(l.sourceSettings.Expiry) l.pLink.Source().SetTimeout(l.sourceSettings.Timeout) l.pLink.Source().SetDynamic(l.sourceSettings.Dynamic) l.pLink.Target().SetAddress(l.target) l.pLink.Target().SetDurability(l.targetSettings.Durability) l.pLink.Target().SetExpiryPolicy(l.targetSettings.Expiry) l.pLink.Target().SetTimeout(l.targetSettings.Timeout) l.pLink.Target().SetDynamic(l.targetSettings.Dynamic) l.pLink.SetSndSettleMode(proton.SndSettleMode(l.sndSettle)) l.pLink.SetRcvSettleMode(proton.RcvSettleMode(l.rcvSettle)) l.pLink.Open() return l, nil }
[ "func", "makeLocalLink", "(", "sn", "*", "session", ",", "isSender", "bool", ",", "setting", "...", "LinkOption", ")", "(", "linkSettings", ",", "error", ")", "{", "l", ":=", "linkSettings", "{", "isSender", ":", "isSender", ",", "capacity", ":", "1", ",", "prefetch", ":", "false", ",", "session", ":", "sn", ",", "}", "\n", "for", "_", ",", "set", ":=", "range", "setting", "{", "set", "(", "&", "l", ")", "\n", "}", "\n", "if", "l", ".", "linkName", "==", "\"", "\"", "{", "l", ".", "linkName", "=", "l", ".", "session", ".", "connection", ".", "container", ".", "nextLinkName", "(", ")", "\n", "}", "\n", "if", "l", ".", "IsSender", "(", ")", "{", "l", ".", "pLink", "=", "l", ".", "session", ".", "pSession", ".", "Sender", "(", "l", ".", "linkName", ")", "\n", "}", "else", "{", "l", ".", "pLink", "=", "l", ".", "session", ".", "pSession", ".", "Receiver", "(", "l", ".", "linkName", ")", "\n", "}", "\n", "if", "l", ".", "pLink", ".", "IsNil", "(", ")", "{", "return", "l", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "l", ".", "pLink", ")", "\n", "}", "\n", "l", ".", "pLink", ".", "Source", "(", ")", ".", "SetAddress", "(", "l", ".", "source", ")", "\n\n", "if", "len", "(", "l", ".", "filter", ")", ">", "0", "{", "if", "err", ":=", "l", ".", "pLink", ".", "Source", "(", ")", ".", "Filter", "(", ")", ".", "Marshal", "(", "l", ".", "filter", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "// Shouldn't happen", "\n", "}", "\n", "}", "\n", "l", ".", "pLink", ".", "Source", "(", ")", ".", "SetDurability", "(", "l", ".", "sourceSettings", ".", "Durability", ")", "\n", "l", ".", "pLink", ".", "Source", "(", ")", ".", "SetExpiryPolicy", "(", "l", ".", "sourceSettings", ".", "Expiry", ")", "\n", "l", ".", "pLink", ".", "Source", "(", ")", ".", "SetTimeout", "(", "l", ".", "sourceSettings", ".", "Timeout", ")", "\n", "l", ".", "pLink", ".", "Source", "(", ")", ".", "SetDynamic", "(", "l", ".", "sourceSettings", ".", "Dynamic", ")", "\n\n", "l", ".", "pLink", ".", "Target", "(", ")", ".", "SetAddress", "(", "l", ".", "target", ")", "\n", "l", ".", "pLink", ".", "Target", "(", ")", ".", "SetDurability", "(", "l", ".", "targetSettings", ".", "Durability", ")", "\n", "l", ".", "pLink", ".", "Target", "(", ")", ".", "SetExpiryPolicy", "(", "l", ".", "targetSettings", ".", "Expiry", ")", "\n", "l", ".", "pLink", ".", "Target", "(", ")", ".", "SetTimeout", "(", "l", ".", "targetSettings", ".", "Timeout", ")", "\n", "l", ".", "pLink", ".", "Target", "(", ")", ".", "SetDynamic", "(", "l", ".", "targetSettings", ".", "Dynamic", ")", "\n\n", "l", ".", "pLink", ".", "SetSndSettleMode", "(", "proton", ".", "SndSettleMode", "(", "l", ".", "sndSettle", ")", ")", "\n", "l", ".", "pLink", ".", "SetRcvSettleMode", "(", "proton", ".", "RcvSettleMode", "(", "l", ".", "rcvSettle", ")", ")", "\n", "l", ".", "pLink", ".", "Open", "(", ")", "\n", "return", "l", ",", "nil", "\n", "}" ]
// Open a link and return the linkSettings.
[ "Open", "a", "link", "and", "return", "the", "linkSettings", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/link.go#L219-L262
train
apache/qpid-proton
go/src/qpid.apache.org/electron/link.go
Credit
func (l *link) Credit() (credit int, err error) { err = l.engine().InjectWait(func() error { if l.Error() != nil { return l.Error() } credit = l.pLink.Credit() return nil }) return }
go
func (l *link) Credit() (credit int, err error) { err = l.engine().InjectWait(func() error { if l.Error() != nil { return l.Error() } credit = l.pLink.Credit() return nil }) return }
[ "func", "(", "l", "*", "link", ")", "Credit", "(", ")", "(", "credit", "int", ",", "err", "error", ")", "{", "err", "=", "l", ".", "engine", "(", ")", ".", "InjectWait", "(", "func", "(", ")", "error", "{", "if", "l", ".", "Error", "(", ")", "!=", "nil", "{", "return", "l", ".", "Error", "(", ")", "\n", "}", "\n", "credit", "=", "l", ".", "pLink", ".", "Credit", "(", ")", "\n", "return", "nil", "\n", "}", ")", "\n", "return", "\n", "}" ]
// Not part of Link interface but use by Sender and Receiver.
[ "Not", "part", "of", "Link", "interface", "but", "use", "by", "Sender", "and", "Receiver", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/link.go#L287-L296
train
apache/qpid-proton
go/genwrap.go
findEnums
func findEnums(header string) (enums []enumType) { for _, enum := range enumDefRe.FindAllStringSubmatch(header, -1) { enums = append(enums, enumType{enum[2], enumValRe.FindAllString(enum[1], -1)}) } return enums }
go
func findEnums(header string) (enums []enumType) { for _, enum := range enumDefRe.FindAllStringSubmatch(header, -1) { enums = append(enums, enumType{enum[2], enumValRe.FindAllString(enum[1], -1)}) } return enums }
[ "func", "findEnums", "(", "header", "string", ")", "(", "enums", "[", "]", "enumType", ")", "{", "for", "_", ",", "enum", ":=", "range", "enumDefRe", ".", "FindAllStringSubmatch", "(", "header", ",", "-", "1", ")", "{", "enums", "=", "append", "(", "enums", ",", "enumType", "{", "enum", "[", "2", "]", ",", "enumValRe", ".", "FindAllString", "(", "enum", "[", "1", "]", ",", "-", "1", ")", "}", ")", "\n", "}", "\n", "return", "enums", "\n", "}" ]
// Find enums in a header file return map of enum name to values.
[ "Find", "enums", "in", "a", "header", "file", "return", "map", "of", "enum", "name", "to", "values", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/genwrap.go#L182-L187
train
apache/qpid-proton
go/genwrap.go
event
func event(out io.Writer) { event_h := readHeader("event") // Event is implemented by hand in wrappers.go // Get all the pn_event_type_t enum values var etypes []eventType enums := findEnums(event_h) for _, e := range enums[0].Values { if skipEventRe.FindStringSubmatch(e) == nil { etypes = append(etypes, newEventType(e)) } } doTemplate(out, etypes, ` type EventType int const ({{range .}} E{{.Name}} EventType = C.{{.Cname}}{{end}} ) `) doTemplate(out, etypes, ` func (e EventType) String() string { switch e { {{range .}} case C.{{.Cname}}: return "{{.Name}}"{{end}} } return "Unknown" } `) }
go
func event(out io.Writer) { event_h := readHeader("event") // Event is implemented by hand in wrappers.go // Get all the pn_event_type_t enum values var etypes []eventType enums := findEnums(event_h) for _, e := range enums[0].Values { if skipEventRe.FindStringSubmatch(e) == nil { etypes = append(etypes, newEventType(e)) } } doTemplate(out, etypes, ` type EventType int const ({{range .}} E{{.Name}} EventType = C.{{.Cname}}{{end}} ) `) doTemplate(out, etypes, ` func (e EventType) String() string { switch e { {{range .}} case C.{{.Cname}}: return "{{.Name}}"{{end}} } return "Unknown" } `) }
[ "func", "event", "(", "out", "io", ".", "Writer", ")", "{", "event_h", ":=", "readHeader", "(", "\"", "\"", ")", "\n\n", "// Event is implemented by hand in wrappers.go", "// Get all the pn_event_type_t enum values", "var", "etypes", "[", "]", "eventType", "\n", "enums", ":=", "findEnums", "(", "event_h", ")", "\n", "for", "_", ",", "e", ":=", "range", "enums", "[", "0", "]", ".", "Values", "{", "if", "skipEventRe", ".", "FindStringSubmatch", "(", "e", ")", "==", "nil", "{", "etypes", "=", "append", "(", "etypes", ",", "newEventType", "(", "e", ")", ")", "\n", "}", "\n", "}", "\n\n", "doTemplate", "(", "out", ",", "etypes", ",", "`\ntype EventType int\nconst ({{range .}}\n\t E{{.Name}} EventType = C.{{.Cname}}{{end}}\n)\n`", ")", "\n\n", "doTemplate", "(", "out", ",", "etypes", ",", "`\nfunc (e EventType) String() string {\n\tswitch e {\n{{range .}}\n\tcase C.{{.Cname}}: return \"{{.Name}}\"{{end}}\n\t}\n\treturn \"Unknown\"\n}\n`", ")", "\n", "}" ]
// Generate event wrappers.
[ "Generate", "event", "wrappers", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/genwrap.go#L272-L302
train
apache/qpid-proton
go/genwrap.go
goFnName
func goFnName(api, fname string) string { // Skip class, context and attachment functions. if skipFnRe.FindStringSubmatch(api+"_"+fname) != nil { return "" } return mixedCaseTrim(fname, "get_") }
go
func goFnName(api, fname string) string { // Skip class, context and attachment functions. if skipFnRe.FindStringSubmatch(api+"_"+fname) != nil { return "" } return mixedCaseTrim(fname, "get_") }
[ "func", "goFnName", "(", "api", ",", "fname", "string", ")", "string", "{", "// Skip class, context and attachment functions.", "if", "skipFnRe", ".", "FindStringSubmatch", "(", "api", "+", "\"", "\"", "+", "fname", ")", "!=", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "mixedCaseTrim", "(", "fname", ",", "\"", "\"", ")", "\n", "}" ]
// Return the go name of the function or "" to skip the function.
[ "Return", "the", "go", "name", "of", "the", "function", "or", "to", "skip", "the", "function", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/genwrap.go#L468-L474
train
apache/qpid-proton
go/examples/proton/broker.go
run
func (b *broker) run() error { listener, err := net.Listen("tcp", *addr) if err != nil { return err } defer listener.Close() fmt.Printf("Listening on %s\n", listener.Addr()) for { conn, err := listener.Accept() if err != nil { debugf("Accept error: %v", err) continue } adapter := proton.NewMessagingAdapter(newHandler(&b.queues)) // We want to accept messages when they are enqueued, not just when they // are received, so we turn off auto-accept and prefetch by the adapter. adapter.Prefetch = 0 adapter.AutoAccept = false engine, err := proton.NewEngine(conn, adapter) if err != nil { debugf("Connection error: %v", err) continue } engine.Server() // Enable server-side protocol negotiation. debugf("Accepted connection %s", engine) go func() { // Start goroutine to run the engine event loop engine.Run() debugf("Closed %s", engine) }() } }
go
func (b *broker) run() error { listener, err := net.Listen("tcp", *addr) if err != nil { return err } defer listener.Close() fmt.Printf("Listening on %s\n", listener.Addr()) for { conn, err := listener.Accept() if err != nil { debugf("Accept error: %v", err) continue } adapter := proton.NewMessagingAdapter(newHandler(&b.queues)) // We want to accept messages when they are enqueued, not just when they // are received, so we turn off auto-accept and prefetch by the adapter. adapter.Prefetch = 0 adapter.AutoAccept = false engine, err := proton.NewEngine(conn, adapter) if err != nil { debugf("Connection error: %v", err) continue } engine.Server() // Enable server-side protocol negotiation. debugf("Accepted connection %s", engine) go func() { // Start goroutine to run the engine event loop engine.Run() debugf("Closed %s", engine) }() } }
[ "func", "(", "b", "*", "broker", ")", "run", "(", ")", "error", "{", "listener", ",", "err", ":=", "net", ".", "Listen", "(", "\"", "\"", ",", "*", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "listener", ".", "Close", "(", ")", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "listener", ".", "Addr", "(", ")", ")", "\n", "for", "{", "conn", ",", "err", ":=", "listener", ".", "Accept", "(", ")", "\n", "if", "err", "!=", "nil", "{", "debugf", "(", "\"", "\"", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "adapter", ":=", "proton", ".", "NewMessagingAdapter", "(", "newHandler", "(", "&", "b", ".", "queues", ")", ")", "\n", "// We want to accept messages when they are enqueued, not just when they", "// are received, so we turn off auto-accept and prefetch by the adapter.", "adapter", ".", "Prefetch", "=", "0", "\n", "adapter", ".", "AutoAccept", "=", "false", "\n", "engine", ",", "err", ":=", "proton", ".", "NewEngine", "(", "conn", ",", "adapter", ")", "\n", "if", "err", "!=", "nil", "{", "debugf", "(", "\"", "\"", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "engine", ".", "Server", "(", ")", "// Enable server-side protocol negotiation.", "\n", "debugf", "(", "\"", "\"", ",", "engine", ")", "\n", "go", "func", "(", ")", "{", "// Start goroutine to run the engine event loop", "engine", ".", "Run", "(", ")", "\n", "debugf", "(", "\"", "\"", ",", "engine", ")", "\n", "}", "(", ")", "\n", "}", "\n", "}" ]
// Listens for connections and starts a proton.Engine for each one.
[ "Listens", "for", "connections", "and", "starts", "a", "proton", ".", "Engine", "for", "each", "one", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/examples/proton/broker.go#L76-L106
train
apache/qpid-proton
go/examples/proton/broker.go
HandleMessagingEvent
func (h *handler) HandleMessagingEvent(t proton.MessagingEvent, e proton.Event) { switch t { case proton.MStart: h.injecter = e.Injecter() case proton.MLinkOpening: if e.Link().IsReceiver() { h.startReceiver(e) } else { h.startSender(e) } case proton.MLinkClosed: h.linkClosed(e.Link(), e.Link().RemoteCondition().Error()) case proton.MSendable: if s, ok := h.senders[e.Link()]; ok { s.sendable() // Signal the send goroutine that we have credit. } else { proton.CloseError(e.Link(), amqp.Errorf(amqp.NotFound, "link %s sender not found", e.Link())) } case proton.MMessage: m, err := e.Delivery().Message() // Message() must be called while handling the MMessage event. if err != nil { proton.CloseError(e.Link(), err) break } r, ok := h.receivers[e.Link()] if !ok { proton.CloseError(e.Link(), amqp.Errorf(amqp.NotFound, "link %s receiver not found", e.Link())) break } // This will not block as AMQP credit is set to the buffer capacity. r.buffer <- receivedMessage{e.Delivery(), m} debugf("link %s received %#v", e.Link(), m) case proton.MConnectionClosed, proton.MDisconnected: for l, _ := range h.receivers { h.linkClosed(l, nil) } for l, _ := range h.senders { h.linkClosed(l, nil) } } }
go
func (h *handler) HandleMessagingEvent(t proton.MessagingEvent, e proton.Event) { switch t { case proton.MStart: h.injecter = e.Injecter() case proton.MLinkOpening: if e.Link().IsReceiver() { h.startReceiver(e) } else { h.startSender(e) } case proton.MLinkClosed: h.linkClosed(e.Link(), e.Link().RemoteCondition().Error()) case proton.MSendable: if s, ok := h.senders[e.Link()]; ok { s.sendable() // Signal the send goroutine that we have credit. } else { proton.CloseError(e.Link(), amqp.Errorf(amqp.NotFound, "link %s sender not found", e.Link())) } case proton.MMessage: m, err := e.Delivery().Message() // Message() must be called while handling the MMessage event. if err != nil { proton.CloseError(e.Link(), err) break } r, ok := h.receivers[e.Link()] if !ok { proton.CloseError(e.Link(), amqp.Errorf(amqp.NotFound, "link %s receiver not found", e.Link())) break } // This will not block as AMQP credit is set to the buffer capacity. r.buffer <- receivedMessage{e.Delivery(), m} debugf("link %s received %#v", e.Link(), m) case proton.MConnectionClosed, proton.MDisconnected: for l, _ := range h.receivers { h.linkClosed(l, nil) } for l, _ := range h.senders { h.linkClosed(l, nil) } } }
[ "func", "(", "h", "*", "handler", ")", "HandleMessagingEvent", "(", "t", "proton", ".", "MessagingEvent", ",", "e", "proton", ".", "Event", ")", "{", "switch", "t", "{", "case", "proton", ".", "MStart", ":", "h", ".", "injecter", "=", "e", ".", "Injecter", "(", ")", "\n\n", "case", "proton", ".", "MLinkOpening", ":", "if", "e", ".", "Link", "(", ")", ".", "IsReceiver", "(", ")", "{", "h", ".", "startReceiver", "(", "e", ")", "\n", "}", "else", "{", "h", ".", "startSender", "(", "e", ")", "\n", "}", "\n\n", "case", "proton", ".", "MLinkClosed", ":", "h", ".", "linkClosed", "(", "e", ".", "Link", "(", ")", ",", "e", ".", "Link", "(", ")", ".", "RemoteCondition", "(", ")", ".", "Error", "(", ")", ")", "\n\n", "case", "proton", ".", "MSendable", ":", "if", "s", ",", "ok", ":=", "h", ".", "senders", "[", "e", ".", "Link", "(", ")", "]", ";", "ok", "{", "s", ".", "sendable", "(", ")", "// Signal the send goroutine that we have credit.", "\n", "}", "else", "{", "proton", ".", "CloseError", "(", "e", ".", "Link", "(", ")", ",", "amqp", ".", "Errorf", "(", "amqp", ".", "NotFound", ",", "\"", "\"", ",", "e", ".", "Link", "(", ")", ")", ")", "\n", "}", "\n\n", "case", "proton", ".", "MMessage", ":", "m", ",", "err", ":=", "e", ".", "Delivery", "(", ")", ".", "Message", "(", ")", "// Message() must be called while handling the MMessage event.", "\n", "if", "err", "!=", "nil", "{", "proton", ".", "CloseError", "(", "e", ".", "Link", "(", ")", ",", "err", ")", "\n", "break", "\n", "}", "\n", "r", ",", "ok", ":=", "h", ".", "receivers", "[", "e", ".", "Link", "(", ")", "]", "\n", "if", "!", "ok", "{", "proton", ".", "CloseError", "(", "e", ".", "Link", "(", ")", ",", "amqp", ".", "Errorf", "(", "amqp", ".", "NotFound", ",", "\"", "\"", ",", "e", ".", "Link", "(", ")", ")", ")", "\n", "break", "\n", "}", "\n", "// This will not block as AMQP credit is set to the buffer capacity.", "r", ".", "buffer", "<-", "receivedMessage", "{", "e", ".", "Delivery", "(", ")", ",", "m", "}", "\n", "debugf", "(", "\"", "\"", ",", "e", ".", "Link", "(", ")", ",", "m", ")", "\n\n", "case", "proton", ".", "MConnectionClosed", ",", "proton", ".", "MDisconnected", ":", "for", "l", ",", "_", ":=", "range", "h", ".", "receivers", "{", "h", ".", "linkClosed", "(", "l", ",", "nil", ")", "\n", "}", "\n", "for", "l", ",", "_", ":=", "range", "h", ".", "senders", "{", "h", ".", "linkClosed", "(", "l", ",", "nil", ")", "\n", "}", "\n", "}", "\n", "}" ]
// HandleMessagingEvent handles an event, called in the handler goroutine.
[ "HandleMessagingEvent", "handles", "an", "event", "called", "in", "the", "handler", "goroutine", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/examples/proton/broker.go#L128-L174
train
apache/qpid-proton
go/examples/proton/broker.go
linkClosed
func (h *handler) linkClosed(l proton.Link, err error) { if s, ok := h.senders[l]; ok { s.stop() delete(h.senders, l) } else if r, ok := h.receivers[l]; ok { r.stop() delete(h.receivers, l) } }
go
func (h *handler) linkClosed(l proton.Link, err error) { if s, ok := h.senders[l]; ok { s.stop() delete(h.senders, l) } else if r, ok := h.receivers[l]; ok { r.stop() delete(h.receivers, l) } }
[ "func", "(", "h", "*", "handler", ")", "linkClosed", "(", "l", "proton", ".", "Link", ",", "err", "error", ")", "{", "if", "s", ",", "ok", ":=", "h", ".", "senders", "[", "l", "]", ";", "ok", "{", "s", ".", "stop", "(", ")", "\n", "delete", "(", "h", ".", "senders", ",", "l", ")", "\n", "}", "else", "if", "r", ",", "ok", ":=", "h", ".", "receivers", "[", "l", "]", ";", "ok", "{", "r", ".", "stop", "(", ")", "\n", "delete", "(", "h", ".", "receivers", ",", "l", ")", "\n", "}", "\n", "}" ]
// linkClosed is called when a link has been closed by both ends. // It removes the link from the handlers maps and stops its goroutine.
[ "linkClosed", "is", "called", "when", "a", "link", "has", "been", "closed", "by", "both", "ends", ".", "It", "removes", "the", "link", "from", "the", "handlers", "maps", "and", "stops", "its", "goroutine", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/examples/proton/broker.go#L178-L186
train
apache/qpid-proton
go/examples/proton/broker.go
run
func (r *receiver) run() { for rm := range r.buffer { r.q <- rm.message d := rm.delivery // We are not in the handler goroutine so we Inject the accept function as a closure. r.h.injecter.Inject(func() { // Check that the receiver is still open, it may have been closed by the remote end. if r == r.h.receivers[r.l] { d.Accept() // Accept the delivery r.l.Flow(1) // Add one credit } }) } }
go
func (r *receiver) run() { for rm := range r.buffer { r.q <- rm.message d := rm.delivery // We are not in the handler goroutine so we Inject the accept function as a closure. r.h.injecter.Inject(func() { // Check that the receiver is still open, it may have been closed by the remote end. if r == r.h.receivers[r.l] { d.Accept() // Accept the delivery r.l.Flow(1) // Add one credit } }) } }
[ "func", "(", "r", "*", "receiver", ")", "run", "(", ")", "{", "for", "rm", ":=", "range", "r", ".", "buffer", "{", "r", ".", "q", "<-", "rm", ".", "message", "\n", "d", ":=", "rm", ".", "delivery", "\n", "// We are not in the handler goroutine so we Inject the accept function as a closure.", "r", ".", "h", ".", "injecter", ".", "Inject", "(", "func", "(", ")", "{", "// Check that the receiver is still open, it may have been closed by the remote end.", "if", "r", "==", "r", ".", "h", ".", "receivers", "[", "r", ".", "l", "]", "{", "d", ".", "Accept", "(", ")", "// Accept the delivery", "\n", "r", ".", "l", ".", "Flow", "(", "1", ")", "// Add one credit", "\n", "}", "\n", "}", ")", "\n", "}", "\n", "}" ]
// run runs in a separate goroutine. It moves messages from the buffer to the // queue for a receiver link, and injects a handler function to acknowledge the // message and send a credit.
[ "run", "runs", "in", "a", "separate", "goroutine", ".", "It", "moves", "messages", "from", "the", "buffer", "to", "the", "queue", "for", "a", "receiver", "link", "and", "injects", "a", "handler", "function", "to", "acknowledge", "the", "message", "and", "send", "a", "credit", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/examples/proton/broker.go#L234-L247
train
apache/qpid-proton
go/examples/proton/broker.go
run
func (s *sender) run() { var q queue // q is nil initially as we have no credit. for { select { case _, ok := <-s.credit: if !ok { // sender closed return } q = s.q // We have credit, enable selecting on the queue. case m, ok := <-q: // q is only enabled when we have credit. if !ok { // queue closed return } q = nil // Assume all credit will be used used, will be signaled otherwise. s.h.injecter.Inject(func() { // Inject handler function to actually send if s.h.senders[s.l] != s { // The sender has been closed by the remote end. q.PutBack(m) // Put the message back on the queue but don't block return } if s.sendOne(m) != nil { return } // Send as many more messages as we can without blocking for s.l.Credit() > 0 { select { // Non blocking receive from q case m, ok := <-s.q: if ok { s.sendOne(m) } default: // Queue is empty but we have credit, signal the run() goroutine. s.sendable() } } }) } } }
go
func (s *sender) run() { var q queue // q is nil initially as we have no credit. for { select { case _, ok := <-s.credit: if !ok { // sender closed return } q = s.q // We have credit, enable selecting on the queue. case m, ok := <-q: // q is only enabled when we have credit. if !ok { // queue closed return } q = nil // Assume all credit will be used used, will be signaled otherwise. s.h.injecter.Inject(func() { // Inject handler function to actually send if s.h.senders[s.l] != s { // The sender has been closed by the remote end. q.PutBack(m) // Put the message back on the queue but don't block return } if s.sendOne(m) != nil { return } // Send as many more messages as we can without blocking for s.l.Credit() > 0 { select { // Non blocking receive from q case m, ok := <-s.q: if ok { s.sendOne(m) } default: // Queue is empty but we have credit, signal the run() goroutine. s.sendable() } } }) } } }
[ "func", "(", "s", "*", "sender", ")", "run", "(", ")", "{", "var", "q", "queue", "// q is nil initially as we have no credit.", "\n", "for", "{", "select", "{", "case", "_", ",", "ok", ":=", "<-", "s", ".", "credit", ":", "if", "!", "ok", "{", "// sender closed", "return", "\n", "}", "\n", "q", "=", "s", ".", "q", "// We have credit, enable selecting on the queue.", "\n\n", "case", "m", ",", "ok", ":=", "<-", "q", ":", "// q is only enabled when we have credit.", "if", "!", "ok", "{", "// queue closed", "return", "\n", "}", "\n", "q", "=", "nil", "// Assume all credit will be used used, will be signaled otherwise.", "\n", "s", ".", "h", ".", "injecter", ".", "Inject", "(", "func", "(", ")", "{", "// Inject handler function to actually send", "if", "s", ".", "h", ".", "senders", "[", "s", ".", "l", "]", "!=", "s", "{", "// The sender has been closed by the remote end.", "q", ".", "PutBack", "(", "m", ")", "// Put the message back on the queue but don't block", "\n", "return", "\n", "}", "\n", "if", "s", ".", "sendOne", "(", "m", ")", "!=", "nil", "{", "return", "\n", "}", "\n", "// Send as many more messages as we can without blocking", "for", "s", ".", "l", ".", "Credit", "(", ")", ">", "0", "{", "select", "{", "// Non blocking receive from q", "case", "m", ",", "ok", ":=", "<-", "s", ".", "q", ":", "if", "ok", "{", "s", ".", "sendOne", "(", "m", ")", "\n", "}", "\n", "default", ":", "// Queue is empty but we have credit, signal the run() goroutine.", "s", ".", "sendable", "(", ")", "\n", "}", "\n", "}", "\n", "}", ")", "\n", "}", "\n", "}", "\n", "}" ]
// run runs in a separate goroutine. It monitors the queue for messages and injects // a function to send them when there is credit
[ "run", "runs", "in", "a", "separate", "goroutine", ".", "It", "monitors", "the", "queue", "for", "messages", "and", "injects", "a", "function", "to", "send", "them", "when", "there", "is", "credit" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/examples/proton/broker.go#L287-L324
train
apache/qpid-proton
go/examples/proton/broker.go
sendOne
func (s *sender) sendOne(m amqp.Message) error { delivery, err := s.l.Send(m) if err == nil { delivery.Settle() // Pre-settled, unreliable. debugf("link %s sent %#v", s.l, m) } else { s.q.PutBack(m) // Put the message back on the queue, don't block } return err }
go
func (s *sender) sendOne(m amqp.Message) error { delivery, err := s.l.Send(m) if err == nil { delivery.Settle() // Pre-settled, unreliable. debugf("link %s sent %#v", s.l, m) } else { s.q.PutBack(m) // Put the message back on the queue, don't block } return err }
[ "func", "(", "s", "*", "sender", ")", "sendOne", "(", "m", "amqp", ".", "Message", ")", "error", "{", "delivery", ",", "err", ":=", "s", ".", "l", ".", "Send", "(", "m", ")", "\n", "if", "err", "==", "nil", "{", "delivery", ".", "Settle", "(", ")", "// Pre-settled, unreliable.", "\n", "debugf", "(", "\"", "\"", ",", "s", ".", "l", ",", "m", ")", "\n", "}", "else", "{", "s", ".", "q", ".", "PutBack", "(", "m", ")", "// Put the message back on the queue, don't block", "\n", "}", "\n", "return", "err", "\n", "}" ]
// sendOne runs in the handler goroutine. It sends a single message.
[ "sendOne", "runs", "in", "the", "handler", "goroutine", ".", "It", "sends", "a", "single", "message", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/examples/proton/broker.go#L327-L336
train
apache/qpid-proton
go/src/qpid.apache.org/proton/error.go
Set
func (e *ErrorHolder) Set(err error) { if err != nil { e.once.Do(func() { e.value.Store(err) }) } }
go
func (e *ErrorHolder) Set(err error) { if err != nil { e.once.Do(func() { e.value.Store(err) }) } }
[ "func", "(", "e", "*", "ErrorHolder", ")", "Set", "(", "err", "error", ")", "{", "if", "err", "!=", "nil", "{", "e", ".", "once", ".", "Do", "(", "func", "(", ")", "{", "e", ".", "value", ".", "Store", "(", "err", ")", "}", ")", "\n", "}", "\n", "}" ]
// Set the error if not already set
[ "Set", "the", "error", "if", "not", "already", "set" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/error.go#L75-L79
train
apache/qpid-proton
go/src/qpid.apache.org/proton/error.go
Get
func (e *ErrorHolder) Get() (err error) { err, _ = e.value.Load().(error) return }
go
func (e *ErrorHolder) Get() (err error) { err, _ = e.value.Load().(error) return }
[ "func", "(", "e", "*", "ErrorHolder", ")", "Get", "(", ")", "(", "err", "error", ")", "{", "err", ",", "_", "=", "e", ".", "value", ".", "Load", "(", ")", ".", "(", "error", ")", "\n", "return", "\n", "}" ]
// Get the error.
[ "Get", "the", "error", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/error.go#L82-L85
train
apache/qpid-proton
go/src/qpid.apache.org/electron/connection.go
User
func User(user string) ConnectionOption { return func(c *connection) { c.user = user c.pConnection.SetUser(user) } }
go
func User(user string) ConnectionOption { return func(c *connection) { c.user = user c.pConnection.SetUser(user) } }
[ "func", "User", "(", "user", "string", ")", "ConnectionOption", "{", "return", "func", "(", "c", "*", "connection", ")", "{", "c", ".", "user", "=", "user", "\n", "c", ".", "pConnection", ".", "SetUser", "(", "user", ")", "\n", "}", "\n", "}" ]
// User returns a ConnectionOption sets the user name for a connection
[ "User", "returns", "a", "ConnectionOption", "sets", "the", "user", "name", "for", "a", "connection" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/connection.go#L118-L123
train
apache/qpid-proton
go/src/qpid.apache.org/electron/connection.go
VirtualHost
func VirtualHost(virtualHost string) ConnectionOption { return func(c *connection) { c.virtualHost = virtualHost c.pConnection.SetHostname(virtualHost) } }
go
func VirtualHost(virtualHost string) ConnectionOption { return func(c *connection) { c.virtualHost = virtualHost c.pConnection.SetHostname(virtualHost) } }
[ "func", "VirtualHost", "(", "virtualHost", "string", ")", "ConnectionOption", "{", "return", "func", "(", "c", "*", "connection", ")", "{", "c", ".", "virtualHost", "=", "virtualHost", "\n", "c", ".", "pConnection", ".", "SetHostname", "(", "virtualHost", ")", "\n", "}", "\n", "}" ]
// VirtualHost returns a ConnectionOption to set the AMQP virtual host for the connection. // Only applies to outbound client connection.
[ "VirtualHost", "returns", "a", "ConnectionOption", "to", "set", "the", "AMQP", "virtual", "host", "for", "the", "connection", ".", "Only", "applies", "to", "outbound", "client", "connection", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/connection.go#L127-L132
train
apache/qpid-proton
go/src/qpid.apache.org/electron/connection.go
Password
func Password(password []byte) ConnectionOption { return func(c *connection) { c.pConnection.SetPassword(password) } }
go
func Password(password []byte) ConnectionOption { return func(c *connection) { c.pConnection.SetPassword(password) } }
[ "func", "Password", "(", "password", "[", "]", "byte", ")", "ConnectionOption", "{", "return", "func", "(", "c", "*", "connection", ")", "{", "c", ".", "pConnection", ".", "SetPassword", "(", "password", ")", "}", "\n", "}" ]
// Password returns a ConnectionOption to set the password used to establish a // connection. Only applies to outbound client connection. // // The connection will erase its copy of the password from memory as soon as it // has been used to authenticate. If you are concerned about passwords staying in // memory you should never store them as strings, and should overwrite your // copy as soon as you are done with it. //
[ "Password", "returns", "a", "ConnectionOption", "to", "set", "the", "password", "used", "to", "establish", "a", "connection", ".", "Only", "applies", "to", "outbound", "client", "connection", ".", "The", "connection", "will", "erase", "its", "copy", "of", "the", "password", "from", "memory", "as", "soon", "as", "it", "has", "been", "used", "to", "authenticate", ".", "If", "you", "are", "concerned", "about", "passwords", "staying", "in", "memory", "you", "should", "never", "store", "them", "as", "strings", "and", "should", "overwrite", "your", "copy", "as", "soon", "as", "you", "are", "done", "with", "it", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/connection.go#L142-L144
train
apache/qpid-proton
go/src/qpid.apache.org/electron/connection.go
Parent
func Parent(cont Container) ConnectionOption { return func(c *connection) { c.container = cont.(*container) } }
go
func Parent(cont Container) ConnectionOption { return func(c *connection) { c.container = cont.(*container) } }
[ "func", "Parent", "(", "cont", "Container", ")", "ConnectionOption", "{", "return", "func", "(", "c", "*", "connection", ")", "{", "c", ".", "container", "=", "cont", ".", "(", "*", "container", ")", "}", "\n", "}" ]
// Parent returns a ConnectionOption that associates the Connection with it's Container // If not set a connection will create its own default container.
[ "Parent", "returns", "a", "ConnectionOption", "that", "associates", "the", "Connection", "with", "it", "s", "Container", "If", "not", "set", "a", "connection", "will", "create", "its", "own", "default", "container", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/connection.go#L164-L166
train
apache/qpid-proton
go/src/qpid.apache.org/electron/connection.go
ContainerId
func ContainerId(id string) ConnectionOption { return func(c *connection) { c.container = NewContainer(id).(*container) } }
go
func ContainerId(id string) ConnectionOption { return func(c *connection) { c.container = NewContainer(id).(*container) } }
[ "func", "ContainerId", "(", "id", "string", ")", "ConnectionOption", "{", "return", "func", "(", "c", "*", "connection", ")", "{", "c", ".", "container", "=", "NewContainer", "(", "id", ")", ".", "(", "*", "container", ")", "}", "\n", "}" ]
// ContainerId returns a ConnectionOption that creates a new Container // with id and associates it with the connection
[ "ContainerId", "returns", "a", "ConnectionOption", "that", "creates", "a", "new", "Container", "with", "id", "and", "associates", "it", "with", "the", "connection" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/connection.go#L170-L172
train
apache/qpid-proton
go/src/qpid.apache.org/electron/connection.go
NewConnection
func NewConnection(conn net.Conn, opts ...ConnectionOption) (*connection, error) { c := &connection{ conn: conn, } c.handler = newHandler(c) var err error c.engine, err = proton.NewEngine(c.conn, c.handler.delegator) if err != nil { return nil, err } c.pConnection = c.engine.Connection() for _, opt := range opts { opt(c) // If the first option is not Server(), then we are a client. // Applying Server() after other options is an error if !c.server { c.client = true } } if c.container == nil { // Generate a random container-id. Not an RFC4122-compliant UUID but probably-unique id := make([]byte, 16) if _, err = rand.Read(id); err != nil { return nil, err } c.container = NewContainer(hex.EncodeToString(id)).(*container) } c.pConnection.SetContainer(c.container.Id()) saslConfig.setup(c.engine) c.endpoint.init(c.engine.String()) go c.run() return c, nil }
go
func NewConnection(conn net.Conn, opts ...ConnectionOption) (*connection, error) { c := &connection{ conn: conn, } c.handler = newHandler(c) var err error c.engine, err = proton.NewEngine(c.conn, c.handler.delegator) if err != nil { return nil, err } c.pConnection = c.engine.Connection() for _, opt := range opts { opt(c) // If the first option is not Server(), then we are a client. // Applying Server() after other options is an error if !c.server { c.client = true } } if c.container == nil { // Generate a random container-id. Not an RFC4122-compliant UUID but probably-unique id := make([]byte, 16) if _, err = rand.Read(id); err != nil { return nil, err } c.container = NewContainer(hex.EncodeToString(id)).(*container) } c.pConnection.SetContainer(c.container.Id()) saslConfig.setup(c.engine) c.endpoint.init(c.engine.String()) go c.run() return c, nil }
[ "func", "NewConnection", "(", "conn", "net", ".", "Conn", ",", "opts", "...", "ConnectionOption", ")", "(", "*", "connection", ",", "error", ")", "{", "c", ":=", "&", "connection", "{", "conn", ":", "conn", ",", "}", "\n", "c", ".", "handler", "=", "newHandler", "(", "c", ")", "\n", "var", "err", "error", "\n", "c", ".", "engine", ",", "err", "=", "proton", ".", "NewEngine", "(", "c", ".", "conn", ",", "c", ".", "handler", ".", "delegator", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "c", ".", "pConnection", "=", "c", ".", "engine", ".", "Connection", "(", ")", "\n", "for", "_", ",", "opt", ":=", "range", "opts", "{", "opt", "(", "c", ")", "\n", "// If the first option is not Server(), then we are a client.", "// Applying Server() after other options is an error", "if", "!", "c", ".", "server", "{", "c", ".", "client", "=", "true", "\n", "}", "\n", "}", "\n", "if", "c", ".", "container", "==", "nil", "{", "// Generate a random container-id. Not an RFC4122-compliant UUID but probably-unique", "id", ":=", "make", "(", "[", "]", "byte", ",", "16", ")", "\n", "if", "_", ",", "err", "=", "rand", ".", "Read", "(", "id", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "c", ".", "container", "=", "NewContainer", "(", "hex", ".", "EncodeToString", "(", "id", ")", ")", ".", "(", "*", "container", ")", "\n", "}", "\n", "c", ".", "pConnection", ".", "SetContainer", "(", "c", ".", "container", ".", "Id", "(", ")", ")", "\n", "saslConfig", ".", "setup", "(", "c", ".", "engine", ")", "\n", "c", ".", "endpoint", ".", "init", "(", "c", ".", "engine", ".", "String", "(", ")", ")", "\n", "go", "c", ".", "run", "(", ")", "\n", "return", "c", ",", "nil", "\n", "}" ]
// NewConnection creates a connection with the given options. // Options are applied in order.
[ "NewConnection", "creates", "a", "connection", "with", "the", "given", "options", ".", "Options", "are", "applied", "in", "order", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/connection.go#L194-L226
train
apache/qpid-proton
go/src/qpid.apache.org/electron/connection.go
SASLAllowInsecure
func SASLAllowInsecure(b bool) ConnectionOption { return func(c *connection) { sasl(c).SetAllowInsecureMechs(b) } }
go
func SASLAllowInsecure(b bool) ConnectionOption { return func(c *connection) { sasl(c).SetAllowInsecureMechs(b) } }
[ "func", "SASLAllowInsecure", "(", "b", "bool", ")", "ConnectionOption", "{", "return", "func", "(", "c", "*", "connection", ")", "{", "sasl", "(", "c", ")", ".", "SetAllowInsecureMechs", "(", "b", ")", "}", "\n", "}" ]
// SASLAllowInsecure returns a ConnectionOption that allows or disallows clear // text SASL authentication mechanisms // // By default the SASL layer is configured not to allow mechanisms that disclose // the clear text of the password over an unencrypted AMQP connection. This specifically // will disallow the use of the PLAIN mechanism without using SSL encryption. // // This default is to avoid disclosing password information accidentally over an // insecure network. //
[ "SASLAllowInsecure", "returns", "a", "ConnectionOption", "that", "allows", "or", "disallows", "clear", "text", "SASL", "authentication", "mechanisms", "By", "default", "the", "SASL", "layer", "is", "configured", "not", "to", "allow", "mechanisms", "that", "disclose", "the", "clear", "text", "of", "the", "password", "over", "an", "unencrypted", "AMQP", "connection", ".", "This", "specifically", "will", "disallow", "the", "use", "of", "the", "PLAIN", "mechanism", "without", "using", "SSL", "encryption", ".", "This", "default", "is", "to", "avoid", "disclosing", "password", "information", "accidentally", "over", "an", "insecure", "network", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/connection.go#L394-L396
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/marshal.go
MarshalUnsafe
func MarshalUnsafe(v interface{}, pnData unsafe.Pointer) (err error) { return recoverMarshal(v, (*C.pn_data_t)(pnData)) }
go
func MarshalUnsafe(v interface{}, pnData unsafe.Pointer) (err error) { return recoverMarshal(v, (*C.pn_data_t)(pnData)) }
[ "func", "MarshalUnsafe", "(", "v", "interface", "{", "}", ",", "pnData", "unsafe", ".", "Pointer", ")", "(", "err", "error", ")", "{", "return", "recoverMarshal", "(", "v", ",", "(", "*", "C", ".", "pn_data_t", ")", "(", "pnData", ")", ")", "\n", "}" ]
// Internal use only
[ "Internal", "use", "only" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/marshal.go#L128-L130
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/marshal.go
NewEncoder
func NewEncoder(w io.Writer) *Encoder { return &Encoder{w, make([]byte, minEncode)} }
go
func NewEncoder(w io.Writer) *Encoder { return &Encoder{w, make([]byte, minEncode)} }
[ "func", "NewEncoder", "(", "w", "io", ".", "Writer", ")", "*", "Encoder", "{", "return", "&", "Encoder", "{", "w", ",", "make", "(", "[", "]", "byte", ",", "minEncode", ")", "}", "\n", "}" ]
// New encoder returns a new encoder that writes to w.
[ "New", "encoder", "returns", "a", "new", "encoder", "that", "writes", "to", "w", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/marshal.go#L349-L351
train
apache/qpid-proton
go/src/qpid.apache.org/electron/container.go
NewContainer
func NewContainer(id string) Container { if id == "" { id = proton.UUID4().String() } cont := &container{id: id} return cont }
go
func NewContainer(id string) Container { if id == "" { id = proton.UUID4().String() } cont := &container{id: id} return cont }
[ "func", "NewContainer", "(", "id", "string", ")", "Container", "{", "if", "id", "==", "\"", "\"", "{", "id", "=", "proton", ".", "UUID4", "(", ")", ".", "String", "(", ")", "\n", "}", "\n", "cont", ":=", "&", "container", "{", "id", ":", "id", "}", "\n", "return", "cont", "\n", "}" ]
// NewContainer creates a new container. The id must be unique in your // distributed application, all connections created by the container // will have this container-id. // // If id == "" a random UUID will be generated for the id.
[ "NewContainer", "creates", "a", "new", "container", ".", "The", "id", "must", "be", "unique", "in", "your", "distributed", "application", "all", "connections", "created", "by", "the", "container", "will", "have", "this", "container", "-", "id", ".", "If", "id", "==", "a", "random", "UUID", "will", "be", "generated", "for", "the", "id", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/container.go#L72-L78
train
apache/qpid-proton
go/src/qpid.apache.org/proton/engine.go
Close
func (eng *Engine) Close(err error) { _ = eng.Inject(func() { CloseError(eng.Connection(), err) }) <-eng.running }
go
func (eng *Engine) Close(err error) { _ = eng.Inject(func() { CloseError(eng.Connection(), err) }) <-eng.running }
[ "func", "(", "eng", "*", "Engine", ")", "Close", "(", "err", "error", ")", "{", "_", "=", "eng", ".", "Inject", "(", "func", "(", ")", "{", "CloseError", "(", "eng", ".", "Connection", "(", ")", ",", "err", ")", "}", ")", "\n", "<-", "eng", ".", "running", "\n", "}" ]
// Close the engine's connection. // If err != nil pass it to the remote end as the close condition. // Returns when the remote end closes or disconnects.
[ "Close", "the", "engine", "s", "connection", ".", "If", "err", "!", "=", "nil", "pass", "it", "to", "the", "remote", "end", "as", "the", "close", "condition", ".", "Returns", "when", "the", "remote", "end", "closes", "or", "disconnects", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/engine.go#L237-L240
train
apache/qpid-proton
go/src/qpid.apache.org/proton/engine.go
CloseTimeout
func (eng *Engine) CloseTimeout(err error, timeout time.Duration) { _ = eng.Inject(func() { CloseError(eng.Connection(), err) }) select { case <-eng.running: case <-time.After(timeout): eng.Disconnect(err) } }
go
func (eng *Engine) CloseTimeout(err error, timeout time.Duration) { _ = eng.Inject(func() { CloseError(eng.Connection(), err) }) select { case <-eng.running: case <-time.After(timeout): eng.Disconnect(err) } }
[ "func", "(", "eng", "*", "Engine", ")", "CloseTimeout", "(", "err", "error", ",", "timeout", "time", ".", "Duration", ")", "{", "_", "=", "eng", ".", "Inject", "(", "func", "(", ")", "{", "CloseError", "(", "eng", ".", "Connection", "(", ")", ",", "err", ")", "}", ")", "\n", "select", "{", "case", "<-", "eng", ".", "running", ":", "case", "<-", "time", ".", "After", "(", "timeout", ")", ":", "eng", ".", "Disconnect", "(", "err", ")", "\n", "}", "\n", "}" ]
// CloseTimeout like Close but disconnect if the remote end doesn't close within timeout.
[ "CloseTimeout", "like", "Close", "but", "disconnect", "if", "the", "remote", "end", "doesn", "t", "close", "within", "timeout", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/engine.go#L243-L250
train
apache/qpid-proton
go/src/qpid.apache.org/proton/engine.go
Disconnect
func (eng *Engine) Disconnect(err error) { _ = eng.Inject(func() { eng.disconnect(err) }) <-eng.running }
go
func (eng *Engine) Disconnect(err error) { _ = eng.Inject(func() { eng.disconnect(err) }) <-eng.running }
[ "func", "(", "eng", "*", "Engine", ")", "Disconnect", "(", "err", "error", ")", "{", "_", "=", "eng", ".", "Inject", "(", "func", "(", ")", "{", "eng", ".", "disconnect", "(", "err", ")", "}", ")", "\n", "<-", "eng", ".", "running", "\n", "}" ]
// Disconnect the engine's connection immediately without an AMQP close. // Process any termination events before returning.
[ "Disconnect", "the", "engine", "s", "connection", "immediately", "without", "an", "AMQP", "close", ".", "Process", "any", "termination", "events", "before", "returning", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/engine.go#L254-L257
train
apache/qpid-proton
go/src/qpid.apache.org/proton/engine.go
tick
func (eng *Engine) tick() { // Proton wants millisecond monotonic time now := int64(elapsed() / time.Millisecond) next := eng.Transport().Tick(now) if next != 0 { eng.timer.Reset(time.Duration((next - now) * int64(time.Millisecond))) } }
go
func (eng *Engine) tick() { // Proton wants millisecond monotonic time now := int64(elapsed() / time.Millisecond) next := eng.Transport().Tick(now) if next != 0 { eng.timer.Reset(time.Duration((next - now) * int64(time.Millisecond))) } }
[ "func", "(", "eng", "*", "Engine", ")", "tick", "(", ")", "{", "// Proton wants millisecond monotonic time", "now", ":=", "int64", "(", "elapsed", "(", ")", "/", "time", ".", "Millisecond", ")", "\n", "next", ":=", "eng", ".", "Transport", "(", ")", ".", "Tick", "(", "now", ")", "\n", "if", "next", "!=", "0", "{", "eng", ".", "timer", ".", "Reset", "(", "time", ".", "Duration", "(", "(", "next", "-", "now", ")", "*", "int64", "(", "time", ".", "Millisecond", ")", ")", ")", "\n", "}", "\n", "}" ]
// Let proton run timed activity and set up the next tick
[ "Let", "proton", "run", "timed", "activity", "and", "set", "up", "the", "next", "tick" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/proton/engine.go#L274-L281
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/unmarshal.go
Decode
func (d *Decoder) Decode(v interface{}) (err error) { data := C.pn_data(0) defer C.pn_data_free(data) var n int for n, err = decode(data, d.buffer.Bytes()); err == EndOfData; { err = d.more() if err == nil { n, err = decode(data, d.buffer.Bytes()) } } if err == nil { if err = recoverUnmarshal(v, data); err == nil { d.buffer.Next(n) } } return }
go
func (d *Decoder) Decode(v interface{}) (err error) { data := C.pn_data(0) defer C.pn_data_free(data) var n int for n, err = decode(data, d.buffer.Bytes()); err == EndOfData; { err = d.more() if err == nil { n, err = decode(data, d.buffer.Bytes()) } } if err == nil { if err = recoverUnmarshal(v, data); err == nil { d.buffer.Next(n) } } return }
[ "func", "(", "d", "*", "Decoder", ")", "Decode", "(", "v", "interface", "{", "}", ")", "(", "err", "error", ")", "{", "data", ":=", "C", ".", "pn_data", "(", "0", ")", "\n", "defer", "C", ".", "pn_data_free", "(", "data", ")", "\n", "var", "n", "int", "\n", "for", "n", ",", "err", "=", "decode", "(", "data", ",", "d", ".", "buffer", ".", "Bytes", "(", ")", ")", ";", "err", "==", "EndOfData", ";", "{", "err", "=", "d", ".", "more", "(", ")", "\n", "if", "err", "==", "nil", "{", "n", ",", "err", "=", "decode", "(", "data", ",", "d", ".", "buffer", ".", "Bytes", "(", ")", ")", "\n", "}", "\n", "}", "\n", "if", "err", "==", "nil", "{", "if", "err", "=", "recoverUnmarshal", "(", "v", ",", "data", ")", ";", "err", "==", "nil", "{", "d", ".", "buffer", ".", "Next", "(", "n", ")", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// Decode reads the next AMQP value from the Reader and stores it in the value pointed to by v. // // See the documentation for Unmarshal for details about the conversion of AMQP into a Go value. //
[ "Decode", "reads", "the", "next", "AMQP", "value", "from", "the", "Reader", "and", "stores", "it", "in", "the", "value", "pointed", "to", "by", "v", ".", "See", "the", "documentation", "for", "Unmarshal", "for", "details", "about", "the", "conversion", "of", "AMQP", "into", "a", "Go", "value", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/unmarshal.go#L130-L146
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/unmarshal.go
more
func (d *Decoder) more() error { var readSize int64 = minDecode if int64(d.buffer.Len()) > readSize { // Grow by doubling readSize = int64(d.buffer.Len()) } var n int64 n, err := d.buffer.ReadFrom(io.LimitReader(d.reader, readSize)) if n == 0 && err == nil { // ReadFrom won't report io.EOF, just returns 0 err = io.EOF } return err }
go
func (d *Decoder) more() error { var readSize int64 = minDecode if int64(d.buffer.Len()) > readSize { // Grow by doubling readSize = int64(d.buffer.Len()) } var n int64 n, err := d.buffer.ReadFrom(io.LimitReader(d.reader, readSize)) if n == 0 && err == nil { // ReadFrom won't report io.EOF, just returns 0 err = io.EOF } return err }
[ "func", "(", "d", "*", "Decoder", ")", "more", "(", ")", "error", "{", "var", "readSize", "int64", "=", "minDecode", "\n", "if", "int64", "(", "d", ".", "buffer", ".", "Len", "(", ")", ")", ">", "readSize", "{", "// Grow by doubling", "readSize", "=", "int64", "(", "d", ".", "buffer", ".", "Len", "(", ")", ")", "\n", "}", "\n", "var", "n", "int64", "\n", "n", ",", "err", ":=", "d", ".", "buffer", ".", "ReadFrom", "(", "io", ".", "LimitReader", "(", "d", ".", "reader", ",", "readSize", ")", ")", "\n", "if", "n", "==", "0", "&&", "err", "==", "nil", "{", "// ReadFrom won't report io.EOF, just returns 0", "err", "=", "io", ".", "EOF", "\n", "}", "\n", "return", "err", "\n", "}" ]
// more reads more data when we can't parse a complete AMQP type
[ "more", "reads", "more", "data", "when", "we", "can", "t", "parse", "a", "complete", "AMQP", "type" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/unmarshal.go#L261-L272
train