id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
148,400 | stripe/stripe-go | transfer.go | UnmarshalJSON | func (t *Transfer) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
t.ID = id
return nil
}
type transfer Transfer
var v transfer
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*t = Transfer(v)
return nil
} | go | func (t *Transfer) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
t.ID = id
return nil
}
type transfer Transfer
var v transfer
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*t = Transfer(v)
return nil
} | [
"func",
"(",
"t",
"*",
"Transfer",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"id",
",",
"ok",
":=",
"ParseID",
"(",
"data",
")",
";",
"ok",
"{",
"t",
".",
"ID",
"=",
"id",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"type",
"transfer",
"Transfer",
"\n",
"var",
"v",
"transfer",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"*",
"t",
"=",
"Transfer",
"(",
"v",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON handles deserialization of a Transfer.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded. | [
"UnmarshalJSON",
"handles",
"deserialization",
"of",
"a",
"Transfer",
".",
"This",
"custom",
"unmarshaling",
"is",
"needed",
"because",
"the",
"resulting",
"property",
"may",
"be",
"an",
"id",
"or",
"the",
"full",
"struct",
"if",
"it",
"was",
"expanded",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/transfer.go#L77-L91 |
148,401 | stripe/stripe-go | transfer.go | UnmarshalJSON | func (d *TransferDestination) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
d.ID = id
return nil
}
type transferDestination TransferDestination
var v transferDestination
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*d = TransferDestination(v)
return json.Unmarshal(data, &d.Account)
} | go | func (d *TransferDestination) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
d.ID = id
return nil
}
type transferDestination TransferDestination
var v transferDestination
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*d = TransferDestination(v)
return json.Unmarshal(data, &d.Account)
} | [
"func",
"(",
"d",
"*",
"TransferDestination",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"id",
",",
"ok",
":=",
"ParseID",
"(",
"data",
")",
";",
"ok",
"{",
"d",
".",
"ID",
"=",
"id",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"type",
"transferDestination",
"TransferDestination",
"\n",
"var",
"v",
"transferDestination",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"*",
"d",
"=",
"TransferDestination",
"(",
"v",
")",
"\n",
"return",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"d",
".",
"Account",
")",
"\n",
"}"
] | // UnmarshalJSON handles deserialization of a TransferDestination.
// This custom unmarshaling is needed because the specific
// type of destination it refers to is specified in the JSON | [
"UnmarshalJSON",
"handles",
"deserialization",
"of",
"a",
"TransferDestination",
".",
"This",
"custom",
"unmarshaling",
"is",
"needed",
"because",
"the",
"specific",
"type",
"of",
"destination",
"it",
"refers",
"to",
"is",
"specified",
"in",
"the",
"JSON"
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/transfer.go#L96-L110 |
148,402 | stripe/stripe-go | invoice/client.go | Pay | func Pay(id string, params *stripe.InvoicePayParams) (*stripe.Invoice, error) {
return getC().Pay(id, params)
} | go | func Pay(id string, params *stripe.InvoicePayParams) (*stripe.Invoice, error) {
return getC().Pay(id, params)
} | [
"func",
"Pay",
"(",
"id",
"string",
",",
"params",
"*",
"stripe",
".",
"InvoicePayParams",
")",
"(",
"*",
"stripe",
".",
"Invoice",
",",
"error",
")",
"{",
"return",
"getC",
"(",
")",
".",
"Pay",
"(",
"id",
",",
"params",
")",
"\n",
"}"
] | // Pay pays an invoice. | [
"Pay",
"pays",
"an",
"invoice",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/invoice/client.go#L56-L58 |
148,403 | stripe/stripe-go | invoice/client.go | Update | func Update(id string, params *stripe.InvoiceParams) (*stripe.Invoice, error) {
return getC().Update(id, params)
} | go | func Update(id string, params *stripe.InvoiceParams) (*stripe.Invoice, error) {
return getC().Update(id, params)
} | [
"func",
"Update",
"(",
"id",
"string",
",",
"params",
"*",
"stripe",
".",
"InvoiceParams",
")",
"(",
"*",
"stripe",
".",
"Invoice",
",",
"error",
")",
"{",
"return",
"getC",
"(",
")",
".",
"Update",
"(",
"id",
",",
"params",
")",
"\n",
"}"
] | // Update updates an invoice. | [
"Update",
"updates",
"an",
"invoice",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/invoice/client.go#L69-L71 |
148,404 | stripe/stripe-go | invoice/client.go | ListLines | func (c Client) ListLines(listParams *stripe.InvoiceLineListParams) *LineIter {
path := stripe.FormatURLPath("/v1/invoices/%s/lines", stripe.StringValue(listParams.ID))
return &LineIter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListMeta, error) {
list := &stripe.InvoiceLineList{}
err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list)
ret := make([]interface{}, len(list.Data))
for i, v := range list.Data {
ret[i] = v
}
return ret, list.ListMeta, err
})}
} | go | func (c Client) ListLines(listParams *stripe.InvoiceLineListParams) *LineIter {
path := stripe.FormatURLPath("/v1/invoices/%s/lines", stripe.StringValue(listParams.ID))
return &LineIter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListMeta, error) {
list := &stripe.InvoiceLineList{}
err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list)
ret := make([]interface{}, len(list.Data))
for i, v := range list.Data {
ret[i] = v
}
return ret, list.ListMeta, err
})}
} | [
"func",
"(",
"c",
"Client",
")",
"ListLines",
"(",
"listParams",
"*",
"stripe",
".",
"InvoiceLineListParams",
")",
"*",
"LineIter",
"{",
"path",
":=",
"stripe",
".",
"FormatURLPath",
"(",
"\"",
"\"",
",",
"stripe",
".",
"StringValue",
"(",
"listParams",
".",
"ID",
")",
")",
"\n",
"return",
"&",
"LineIter",
"{",
"stripe",
".",
"GetIter",
"(",
"listParams",
",",
"func",
"(",
"p",
"*",
"stripe",
".",
"Params",
",",
"b",
"*",
"form",
".",
"Values",
")",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"stripe",
".",
"ListMeta",
",",
"error",
")",
"{",
"list",
":=",
"&",
"stripe",
".",
"InvoiceLineList",
"{",
"}",
"\n",
"err",
":=",
"c",
".",
"B",
".",
"CallRaw",
"(",
"http",
".",
"MethodGet",
",",
"path",
",",
"c",
".",
"Key",
",",
"b",
",",
"p",
",",
"list",
")",
"\n\n",
"ret",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"list",
".",
"Data",
")",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"list",
".",
"Data",
"{",
"ret",
"[",
"i",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"return",
"ret",
",",
"list",
".",
"ListMeta",
",",
"err",
"\n",
"}",
")",
"}",
"\n",
"}"
] | // ListLines returns a list of line items on an invoice. | [
"ListLines",
"returns",
"a",
"list",
"of",
"line",
"items",
"on",
"an",
"invoice",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/invoice/client.go#L119-L132 |
148,405 | stripe/stripe-go | invoice/client.go | FinalizeInvoice | func FinalizeInvoice(id string, params *stripe.InvoiceFinalizeParams) (*stripe.Invoice, error) {
return getC().FinalizeInvoice(id, params)
} | go | func FinalizeInvoice(id string, params *stripe.InvoiceFinalizeParams) (*stripe.Invoice, error) {
return getC().FinalizeInvoice(id, params)
} | [
"func",
"FinalizeInvoice",
"(",
"id",
"string",
",",
"params",
"*",
"stripe",
".",
"InvoiceFinalizeParams",
")",
"(",
"*",
"stripe",
".",
"Invoice",
",",
"error",
")",
"{",
"return",
"getC",
"(",
")",
".",
"FinalizeInvoice",
"(",
"id",
",",
"params",
")",
"\n",
"}"
] | // FinalizeInvoice finalizes an invoice. | [
"FinalizeInvoice",
"finalizes",
"an",
"invoice",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/invoice/client.go#L135-L137 |
148,406 | stripe/stripe-go | invoice/client.go | MarkUncollectible | func MarkUncollectible(id string, params *stripe.InvoiceMarkUncollectibleParams) (*stripe.Invoice, error) {
return getC().MarkUncollectible(id, params)
} | go | func MarkUncollectible(id string, params *stripe.InvoiceMarkUncollectibleParams) (*stripe.Invoice, error) {
return getC().MarkUncollectible(id, params)
} | [
"func",
"MarkUncollectible",
"(",
"id",
"string",
",",
"params",
"*",
"stripe",
".",
"InvoiceMarkUncollectibleParams",
")",
"(",
"*",
"stripe",
".",
"Invoice",
",",
"error",
")",
"{",
"return",
"getC",
"(",
")",
".",
"MarkUncollectible",
"(",
"id",
",",
"params",
")",
"\n",
"}"
] | // MarkUncollectible marks an invoice as uncollectible. | [
"MarkUncollectible",
"marks",
"an",
"invoice",
"as",
"uncollectible",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/invoice/client.go#L148-L150 |
148,407 | stripe/stripe-go | invoice/client.go | SendInvoice | func SendInvoice(id string, params *stripe.InvoiceSendParams) (*stripe.Invoice, error) {
return getC().SendInvoice(id, params)
} | go | func SendInvoice(id string, params *stripe.InvoiceSendParams) (*stripe.Invoice, error) {
return getC().SendInvoice(id, params)
} | [
"func",
"SendInvoice",
"(",
"id",
"string",
",",
"params",
"*",
"stripe",
".",
"InvoiceSendParams",
")",
"(",
"*",
"stripe",
".",
"Invoice",
",",
"error",
")",
"{",
"return",
"getC",
"(",
")",
".",
"SendInvoice",
"(",
"id",
",",
"params",
")",
"\n",
"}"
] | // SendInvoice sends an invoice. | [
"SendInvoice",
"sends",
"an",
"invoice",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/invoice/client.go#L161-L163 |
148,408 | stripe/stripe-go | subschedule/client.go | Cancel | func Cancel(id string, params *stripe.SubscriptionScheduleCancelParams) (*stripe.SubscriptionSchedule, error) {
return getC().Cancel(id, params)
} | go | func Cancel(id string, params *stripe.SubscriptionScheduleCancelParams) (*stripe.SubscriptionSchedule, error) {
return getC().Cancel(id, params)
} | [
"func",
"Cancel",
"(",
"id",
"string",
",",
"params",
"*",
"stripe",
".",
"SubscriptionScheduleCancelParams",
")",
"(",
"*",
"stripe",
".",
"SubscriptionSchedule",
",",
"error",
")",
"{",
"return",
"getC",
"(",
")",
".",
"Cancel",
"(",
"id",
",",
"params",
")",
"\n",
"}"
] | // Cancel removes a subscription schedule. | [
"Cancel",
"removes",
"a",
"subscription",
"schedule",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/subschedule/client.go#L18-L20 |
148,409 | stripe/stripe-go | subschedule/client.go | Update | func Update(id string, params *stripe.SubscriptionScheduleParams) (*stripe.SubscriptionSchedule, error) {
return getC().Update(id, params)
} | go | func Update(id string, params *stripe.SubscriptionScheduleParams) (*stripe.SubscriptionSchedule, error) {
return getC().Update(id, params)
} | [
"func",
"Update",
"(",
"id",
"string",
",",
"params",
"*",
"stripe",
".",
"SubscriptionScheduleParams",
")",
"(",
"*",
"stripe",
".",
"SubscriptionSchedule",
",",
"error",
")",
"{",
"return",
"getC",
"(",
")",
".",
"Update",
"(",
"id",
",",
"params",
")",
"\n",
"}"
] | // Update updates a subscription schedule's properties. | [
"Update",
"updates",
"a",
"subscription",
"schedule",
"s",
"properties",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/subschedule/client.go#L90-L92 |
148,410 | stripe/stripe-go | refund/client.go | Get | func (c Client) Get(id string, params *stripe.RefundParams) (*stripe.Refund, error) {
path := stripe.FormatURLPath("/v1/refunds/%s", id)
refund := &stripe.Refund{}
err := c.B.Call(http.MethodGet, path, c.Key, params, refund)
return refund, err
} | go | func (c Client) Get(id string, params *stripe.RefundParams) (*stripe.Refund, error) {
path := stripe.FormatURLPath("/v1/refunds/%s", id)
refund := &stripe.Refund{}
err := c.B.Call(http.MethodGet, path, c.Key, params, refund)
return refund, err
} | [
"func",
"(",
"c",
"Client",
")",
"Get",
"(",
"id",
"string",
",",
"params",
"*",
"stripe",
".",
"RefundParams",
")",
"(",
"*",
"stripe",
".",
"Refund",
",",
"error",
")",
"{",
"path",
":=",
"stripe",
".",
"FormatURLPath",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"refund",
":=",
"&",
"stripe",
".",
"Refund",
"{",
"}",
"\n",
"err",
":=",
"c",
".",
"B",
".",
"Call",
"(",
"http",
".",
"MethodGet",
",",
"path",
",",
"c",
".",
"Key",
",",
"params",
",",
"refund",
")",
"\n",
"return",
"refund",
",",
"err",
"\n",
"}"
] | // Get returns the details of a refund. | [
"Get",
"returns",
"the",
"details",
"of",
"a",
"refund",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/refund/client.go#L35-L40 |
148,411 | stripe/stripe-go | refund/client.go | Update | func Update(id string, params *stripe.RefundParams) (*stripe.Refund, error) {
return getC().Update(id, params)
} | go | func Update(id string, params *stripe.RefundParams) (*stripe.Refund, error) {
return getC().Update(id, params)
} | [
"func",
"Update",
"(",
"id",
"string",
",",
"params",
"*",
"stripe",
".",
"RefundParams",
")",
"(",
"*",
"stripe",
".",
"Refund",
",",
"error",
")",
"{",
"return",
"getC",
"(",
")",
".",
"Update",
"(",
"id",
",",
"params",
")",
"\n",
"}"
] | // Update updates a refund's properties. | [
"Update",
"updates",
"a",
"refund",
"s",
"properties",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/refund/client.go#L43-L45 |
148,412 | stripe/stripe-go | plan.go | AppendTo | func (p *PlanTierParams) AppendTo(body *form.Values, keyParts []string) {
if BoolValue(p.UpToInf) {
body.Add(form.FormatKey(append(keyParts, "up_to")), "inf")
} else {
body.Add(form.FormatKey(append(keyParts, "up_to")), strconv.FormatInt(Int64Value(p.UpTo), 10))
}
} | go | func (p *PlanTierParams) AppendTo(body *form.Values, keyParts []string) {
if BoolValue(p.UpToInf) {
body.Add(form.FormatKey(append(keyParts, "up_to")), "inf")
} else {
body.Add(form.FormatKey(append(keyParts, "up_to")), strconv.FormatInt(Int64Value(p.UpTo), 10))
}
} | [
"func",
"(",
"p",
"*",
"PlanTierParams",
")",
"AppendTo",
"(",
"body",
"*",
"form",
".",
"Values",
",",
"keyParts",
"[",
"]",
"string",
")",
"{",
"if",
"BoolValue",
"(",
"p",
".",
"UpToInf",
")",
"{",
"body",
".",
"Add",
"(",
"form",
".",
"FormatKey",
"(",
"append",
"(",
"keyParts",
",",
"\"",
"\"",
")",
")",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"body",
".",
"Add",
"(",
"form",
".",
"FormatKey",
"(",
"append",
"(",
"keyParts",
",",
"\"",
"\"",
")",
")",
",",
"strconv",
".",
"FormatInt",
"(",
"Int64Value",
"(",
"p",
".",
"UpTo",
")",
",",
"10",
")",
")",
"\n",
"}",
"\n",
"}"
] | // AppendTo implements custom up_to serialisation logic for tiers configuration | [
"AppendTo",
"implements",
"custom",
"up_to",
"serialisation",
"logic",
"for",
"tiers",
"configuration"
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/plan.go#L159-L165 |
148,413 | stripe/stripe-go | plan.go | UnmarshalJSON | func (s *Plan) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
s.ID = id
return nil
}
type plan Plan
var v plan
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*s = Plan(v)
return nil
} | go | func (s *Plan) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
s.ID = id
return nil
}
type plan Plan
var v plan
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*s = Plan(v)
return nil
} | [
"func",
"(",
"s",
"*",
"Plan",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"id",
",",
"ok",
":=",
"ParseID",
"(",
"data",
")",
";",
"ok",
"{",
"s",
".",
"ID",
"=",
"id",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"type",
"plan",
"Plan",
"\n",
"var",
"v",
"plan",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"*",
"s",
"=",
"Plan",
"(",
"v",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON handles deserialization of a Plan.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded. | [
"UnmarshalJSON",
"handles",
"deserialization",
"of",
"a",
"Plan",
".",
"This",
"custom",
"unmarshaling",
"is",
"needed",
"because",
"the",
"resulting",
"property",
"may",
"be",
"an",
"id",
"or",
"the",
"full",
"struct",
"if",
"it",
"was",
"expanded",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/plan.go#L182-L196 |
148,414 | stripe/stripe-go | invoiceitem/client.go | Del | func (c Client) Del(id string, params *stripe.InvoiceItemParams) (*stripe.InvoiceItem, error) {
path := stripe.FormatURLPath("/v1/invoiceitems/%s", id)
ii := &stripe.InvoiceItem{}
err := c.B.Call(http.MethodDelete, path, c.Key, params, ii)
return ii, err
} | go | func (c Client) Del(id string, params *stripe.InvoiceItemParams) (*stripe.InvoiceItem, error) {
path := stripe.FormatURLPath("/v1/invoiceitems/%s", id)
ii := &stripe.InvoiceItem{}
err := c.B.Call(http.MethodDelete, path, c.Key, params, ii)
return ii, err
} | [
"func",
"(",
"c",
"Client",
")",
"Del",
"(",
"id",
"string",
",",
"params",
"*",
"stripe",
".",
"InvoiceItemParams",
")",
"(",
"*",
"stripe",
".",
"InvoiceItem",
",",
"error",
")",
"{",
"path",
":=",
"stripe",
".",
"FormatURLPath",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"ii",
":=",
"&",
"stripe",
".",
"InvoiceItem",
"{",
"}",
"\n",
"err",
":=",
"c",
".",
"B",
".",
"Call",
"(",
"http",
".",
"MethodDelete",
",",
"path",
",",
"c",
".",
"Key",
",",
"params",
",",
"ii",
")",
"\n",
"return",
"ii",
",",
"err",
"\n",
"}"
] | // Del removes an invoice item. | [
"Del",
"removes",
"an",
"invoice",
"item",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/invoiceitem/client.go#L61-L66 |
148,415 | stripe/stripe-go | applepaydomain/client.go | Get | func Get(id string, params *stripe.ApplePayDomainParams) (*stripe.ApplePayDomain, error) {
return getC().Get(id, params)
} | go | func Get(id string, params *stripe.ApplePayDomainParams) (*stripe.ApplePayDomain, error) {
return getC().Get(id, params)
} | [
"func",
"Get",
"(",
"id",
"string",
",",
"params",
"*",
"stripe",
".",
"ApplePayDomainParams",
")",
"(",
"*",
"stripe",
".",
"ApplePayDomain",
",",
"error",
")",
"{",
"return",
"getC",
"(",
")",
".",
"Get",
"(",
"id",
",",
"params",
")",
"\n",
"}"
] | // Get retrieves an Apple Pay domain. | [
"Get",
"retrieves",
"an",
"Apple",
"Pay",
"domain",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/applepaydomain/client.go#L30-L32 |
148,416 | stripe/stripe-go | applepaydomain/client.go | Del | func (c Client) Del(id string, params *stripe.ApplePayDomainParams) (*stripe.ApplePayDomain, error) {
path := stripe.FormatURLPath("/v1/apple_pay/domains/%s", id)
domain := &stripe.ApplePayDomain{}
err := c.B.Call(http.MethodDelete, path, c.Key, params, domain)
return domain, err
} | go | func (c Client) Del(id string, params *stripe.ApplePayDomainParams) (*stripe.ApplePayDomain, error) {
path := stripe.FormatURLPath("/v1/apple_pay/domains/%s", id)
domain := &stripe.ApplePayDomain{}
err := c.B.Call(http.MethodDelete, path, c.Key, params, domain)
return domain, err
} | [
"func",
"(",
"c",
"Client",
")",
"Del",
"(",
"id",
"string",
",",
"params",
"*",
"stripe",
".",
"ApplePayDomainParams",
")",
"(",
"*",
"stripe",
".",
"ApplePayDomain",
",",
"error",
")",
"{",
"path",
":=",
"stripe",
".",
"FormatURLPath",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"domain",
":=",
"&",
"stripe",
".",
"ApplePayDomain",
"{",
"}",
"\n",
"err",
":=",
"c",
".",
"B",
".",
"Call",
"(",
"http",
".",
"MethodDelete",
",",
"path",
",",
"c",
".",
"Key",
",",
"params",
",",
"domain",
")",
"\n",
"return",
"domain",
",",
"err",
"\n",
"}"
] | // Del removes an Apple Pay domain. | [
"Del",
"removes",
"an",
"Apple",
"Pay",
"domain",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/applepaydomain/client.go#L48-L53 |
148,417 | stripe/stripe-go | log.go | Warnf | func (l *LeveledLogger) Warnf(format string, v ...interface{}) {
if l.Level >= LevelWarn {
fmt.Fprintf(l.stderr(), "[WARN] "+format+"\n", v...)
}
} | go | func (l *LeveledLogger) Warnf(format string, v ...interface{}) {
if l.Level >= LevelWarn {
fmt.Fprintf(l.stderr(), "[WARN] "+format+"\n", v...)
}
} | [
"func",
"(",
"l",
"*",
"LeveledLogger",
")",
"Warnf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"Level",
">=",
"LevelWarn",
"{",
"fmt",
".",
"Fprintf",
"(",
"l",
".",
"stderr",
"(",
")",
",",
"\"",
"\"",
"+",
"format",
"+",
"\"",
"\\n",
"\"",
",",
"v",
"...",
")",
"\n",
"}",
"\n",
"}"
] | // Warnf logs a warning message using Printf conventions. | [
"Warnf",
"logs",
"a",
"warning",
"message",
"using",
"Printf",
"conventions",
"."
] | aa901d66c475fdd6d86581c5e1f2f85ec1f074f6 | https://github.com/stripe/stripe-go/blob/aa901d66c475fdd6d86581c5e1f2f85ec1f074f6/log.go#L123-L127 |
148,418 | faiface/beep | effects/pan.go | Stream | func (p *Pan) Stream(samples [][2]float64) (n int, ok bool) {
n, ok = p.Streamer.Stream(samples)
switch {
case p.Pan < 0:
for i := range samples[:n] {
r := samples[i][1]
samples[i][0] += -p.Pan * r
samples[i][1] -= -p.Pan * r
}
case p.Pan > 0:
for i := range samples[:n] {
l := samples[i][0]
samples[i][0] -= p.Pan * l
samples[i][1] += p.Pan * l
}
}
return n, ok
} | go | func (p *Pan) Stream(samples [][2]float64) (n int, ok bool) {
n, ok = p.Streamer.Stream(samples)
switch {
case p.Pan < 0:
for i := range samples[:n] {
r := samples[i][1]
samples[i][0] += -p.Pan * r
samples[i][1] -= -p.Pan * r
}
case p.Pan > 0:
for i := range samples[:n] {
l := samples[i][0]
samples[i][0] -= p.Pan * l
samples[i][1] += p.Pan * l
}
}
return n, ok
} | [
"func",
"(",
"p",
"*",
"Pan",
")",
"Stream",
"(",
"samples",
"[",
"]",
"[",
"2",
"]",
"float64",
")",
"(",
"n",
"int",
",",
"ok",
"bool",
")",
"{",
"n",
",",
"ok",
"=",
"p",
".",
"Streamer",
".",
"Stream",
"(",
"samples",
")",
"\n",
"switch",
"{",
"case",
"p",
".",
"Pan",
"<",
"0",
":",
"for",
"i",
":=",
"range",
"samples",
"[",
":",
"n",
"]",
"{",
"r",
":=",
"samples",
"[",
"i",
"]",
"[",
"1",
"]",
"\n",
"samples",
"[",
"i",
"]",
"[",
"0",
"]",
"+=",
"-",
"p",
".",
"Pan",
"*",
"r",
"\n",
"samples",
"[",
"i",
"]",
"[",
"1",
"]",
"-=",
"-",
"p",
".",
"Pan",
"*",
"r",
"\n",
"}",
"\n",
"case",
"p",
".",
"Pan",
">",
"0",
":",
"for",
"i",
":=",
"range",
"samples",
"[",
":",
"n",
"]",
"{",
"l",
":=",
"samples",
"[",
"i",
"]",
"[",
"0",
"]",
"\n",
"samples",
"[",
"i",
"]",
"[",
"0",
"]",
"-=",
"p",
".",
"Pan",
"*",
"l",
"\n",
"samples",
"[",
"i",
"]",
"[",
"1",
"]",
"+=",
"p",
".",
"Pan",
"*",
"l",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"n",
",",
"ok",
"\n",
"}"
] | // Stream streams the wrapped Streamer balanced by Pan. | [
"Stream",
"streams",
"the",
"wrapped",
"Streamer",
"balanced",
"by",
"Pan",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/effects/pan.go#L14-L31 |
148,419 | faiface/beep | resample.go | ResampleRatio | func ResampleRatio(quality int, ratio float64, s Streamer) *Resampler {
if quality < 1 || 64 < quality {
panic(fmt.Errorf("resample: invalid quality: %d", quality))
}
return &Resampler{
s: s,
ratio: ratio,
first: true,
buf1: make([][2]float64, 512),
buf2: make([][2]float64, 512),
pts: make([]point, quality*2),
off: 0,
pos: 0,
}
} | go | func ResampleRatio(quality int, ratio float64, s Streamer) *Resampler {
if quality < 1 || 64 < quality {
panic(fmt.Errorf("resample: invalid quality: %d", quality))
}
return &Resampler{
s: s,
ratio: ratio,
first: true,
buf1: make([][2]float64, 512),
buf2: make([][2]float64, 512),
pts: make([]point, quality*2),
off: 0,
pos: 0,
}
} | [
"func",
"ResampleRatio",
"(",
"quality",
"int",
",",
"ratio",
"float64",
",",
"s",
"Streamer",
")",
"*",
"Resampler",
"{",
"if",
"quality",
"<",
"1",
"||",
"64",
"<",
"quality",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"quality",
")",
")",
"\n",
"}",
"\n",
"return",
"&",
"Resampler",
"{",
"s",
":",
"s",
",",
"ratio",
":",
"ratio",
",",
"first",
":",
"true",
",",
"buf1",
":",
"make",
"(",
"[",
"]",
"[",
"2",
"]",
"float64",
",",
"512",
")",
",",
"buf2",
":",
"make",
"(",
"[",
"]",
"[",
"2",
"]",
"float64",
",",
"512",
")",
",",
"pts",
":",
"make",
"(",
"[",
"]",
"point",
",",
"quality",
"*",
"2",
")",
",",
"off",
":",
"0",
",",
"pos",
":",
"0",
",",
"}",
"\n",
"}"
] | // ResampleRatio is same as Resample, except it takes the ratio of the old and the new sample rate,
// specifically, the old sample rate divided by the new sample rate. Aside from correcting the
// sample rate, this can be used to change the speed of the audio. For example, resampling at the
// ratio of 2 and playing at the original sample rate will cause doubled speed in playback. | [
"ResampleRatio",
"is",
"same",
"as",
"Resample",
"except",
"it",
"takes",
"the",
"ratio",
"of",
"the",
"old",
"and",
"the",
"new",
"sample",
"rate",
"specifically",
"the",
"old",
"sample",
"rate",
"divided",
"by",
"the",
"new",
"sample",
"rate",
".",
"Aside",
"from",
"correcting",
"the",
"sample",
"rate",
"this",
"can",
"be",
"used",
"to",
"change",
"the",
"speed",
"of",
"the",
"audio",
".",
"For",
"example",
"resampling",
"at",
"the",
"ratio",
"of",
"2",
"and",
"playing",
"at",
"the",
"original",
"sample",
"rate",
"will",
"cause",
"doubled",
"speed",
"in",
"playback",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/resample.go#L43-L57 |
148,420 | faiface/beep | resample.go | Stream | func (r *Resampler) Stream(samples [][2]float64) (n int, ok bool) {
// if it's the first time, we need to fill buf2 with initial data, buf1 remains zeroed
if r.first {
sn, _ := r.s.Stream(r.buf2)
r.buf2 = r.buf2[:sn]
r.first = false
}
// we start resampling, sample by sample
for len(samples) > 0 {
again:
for c := range samples[0] {
// calculate the current position in the original data
j := float64(r.pos) * r.ratio
// find quality*2 closest samples to j and translate them to points for interpolation
for pi := range r.pts {
// calculate the index of one of the closest samples
k := int(j) + pi - len(r.pts)/2 + 1
var y float64
switch {
// the sample is in buf1
case k < r.off:
y = r.buf1[len(r.buf1)+k-r.off][c]
// the sample is in buf2
case k < r.off+len(r.buf2):
y = r.buf2[k-r.off][c]
// the sample is beyond buf2, so we need to load new data
case k >= r.off+len(r.buf2):
// we load into buf1
sn, _ := r.s.Stream(r.buf1)
// this condition happens when the original Streamer got
// drained and j is after the end of the
// original data
if int(j) >= r.off+len(r.buf2)+sn {
return n, n > 0
}
// this condition happens when the original Streamer got
// drained and this one of the closest samples is after the
// end of the original data
if k >= r.off+len(r.buf2)+sn {
y = 0
break
}
// otherwise everything is fine, we swap buffers and start
// calculating the sample again
r.off += len(r.buf2)
r.buf1 = r.buf1[:sn]
r.buf1, r.buf2 = r.buf2, r.buf1
goto again
}
r.pts[pi] = point{float64(k), y}
}
// calculate the resampled sample using polynomial interpolation from the
// quality*2 closest samples
samples[0][c] = lagrange(r.pts, j)
}
samples = samples[1:]
n++
r.pos++
}
return n, true
} | go | func (r *Resampler) Stream(samples [][2]float64) (n int, ok bool) {
// if it's the first time, we need to fill buf2 with initial data, buf1 remains zeroed
if r.first {
sn, _ := r.s.Stream(r.buf2)
r.buf2 = r.buf2[:sn]
r.first = false
}
// we start resampling, sample by sample
for len(samples) > 0 {
again:
for c := range samples[0] {
// calculate the current position in the original data
j := float64(r.pos) * r.ratio
// find quality*2 closest samples to j and translate them to points for interpolation
for pi := range r.pts {
// calculate the index of one of the closest samples
k := int(j) + pi - len(r.pts)/2 + 1
var y float64
switch {
// the sample is in buf1
case k < r.off:
y = r.buf1[len(r.buf1)+k-r.off][c]
// the sample is in buf2
case k < r.off+len(r.buf2):
y = r.buf2[k-r.off][c]
// the sample is beyond buf2, so we need to load new data
case k >= r.off+len(r.buf2):
// we load into buf1
sn, _ := r.s.Stream(r.buf1)
// this condition happens when the original Streamer got
// drained and j is after the end of the
// original data
if int(j) >= r.off+len(r.buf2)+sn {
return n, n > 0
}
// this condition happens when the original Streamer got
// drained and this one of the closest samples is after the
// end of the original data
if k >= r.off+len(r.buf2)+sn {
y = 0
break
}
// otherwise everything is fine, we swap buffers and start
// calculating the sample again
r.off += len(r.buf2)
r.buf1 = r.buf1[:sn]
r.buf1, r.buf2 = r.buf2, r.buf1
goto again
}
r.pts[pi] = point{float64(k), y}
}
// calculate the resampled sample using polynomial interpolation from the
// quality*2 closest samples
samples[0][c] = lagrange(r.pts, j)
}
samples = samples[1:]
n++
r.pos++
}
return n, true
} | [
"func",
"(",
"r",
"*",
"Resampler",
")",
"Stream",
"(",
"samples",
"[",
"]",
"[",
"2",
"]",
"float64",
")",
"(",
"n",
"int",
",",
"ok",
"bool",
")",
"{",
"// if it's the first time, we need to fill buf2 with initial data, buf1 remains zeroed",
"if",
"r",
".",
"first",
"{",
"sn",
",",
"_",
":=",
"r",
".",
"s",
".",
"Stream",
"(",
"r",
".",
"buf2",
")",
"\n",
"r",
".",
"buf2",
"=",
"r",
".",
"buf2",
"[",
":",
"sn",
"]",
"\n",
"r",
".",
"first",
"=",
"false",
"\n",
"}",
"\n",
"// we start resampling, sample by sample",
"for",
"len",
"(",
"samples",
")",
">",
"0",
"{",
"again",
":",
"for",
"c",
":=",
"range",
"samples",
"[",
"0",
"]",
"{",
"// calculate the current position in the original data",
"j",
":=",
"float64",
"(",
"r",
".",
"pos",
")",
"*",
"r",
".",
"ratio",
"\n\n",
"// find quality*2 closest samples to j and translate them to points for interpolation",
"for",
"pi",
":=",
"range",
"r",
".",
"pts",
"{",
"// calculate the index of one of the closest samples",
"k",
":=",
"int",
"(",
"j",
")",
"+",
"pi",
"-",
"len",
"(",
"r",
".",
"pts",
")",
"/",
"2",
"+",
"1",
"\n\n",
"var",
"y",
"float64",
"\n",
"switch",
"{",
"// the sample is in buf1",
"case",
"k",
"<",
"r",
".",
"off",
":",
"y",
"=",
"r",
".",
"buf1",
"[",
"len",
"(",
"r",
".",
"buf1",
")",
"+",
"k",
"-",
"r",
".",
"off",
"]",
"[",
"c",
"]",
"\n",
"// the sample is in buf2",
"case",
"k",
"<",
"r",
".",
"off",
"+",
"len",
"(",
"r",
".",
"buf2",
")",
":",
"y",
"=",
"r",
".",
"buf2",
"[",
"k",
"-",
"r",
".",
"off",
"]",
"[",
"c",
"]",
"\n",
"// the sample is beyond buf2, so we need to load new data",
"case",
"k",
">=",
"r",
".",
"off",
"+",
"len",
"(",
"r",
".",
"buf2",
")",
":",
"// we load into buf1",
"sn",
",",
"_",
":=",
"r",
".",
"s",
".",
"Stream",
"(",
"r",
".",
"buf1",
")",
"\n",
"// this condition happens when the original Streamer got",
"// drained and j is after the end of the",
"// original data",
"if",
"int",
"(",
"j",
")",
">=",
"r",
".",
"off",
"+",
"len",
"(",
"r",
".",
"buf2",
")",
"+",
"sn",
"{",
"return",
"n",
",",
"n",
">",
"0",
"\n",
"}",
"\n",
"// this condition happens when the original Streamer got",
"// drained and this one of the closest samples is after the",
"// end of the original data",
"if",
"k",
">=",
"r",
".",
"off",
"+",
"len",
"(",
"r",
".",
"buf2",
")",
"+",
"sn",
"{",
"y",
"=",
"0",
"\n",
"break",
"\n",
"}",
"\n",
"// otherwise everything is fine, we swap buffers and start",
"// calculating the sample again",
"r",
".",
"off",
"+=",
"len",
"(",
"r",
".",
"buf2",
")",
"\n",
"r",
".",
"buf1",
"=",
"r",
".",
"buf1",
"[",
":",
"sn",
"]",
"\n",
"r",
".",
"buf1",
",",
"r",
".",
"buf2",
"=",
"r",
".",
"buf2",
",",
"r",
".",
"buf1",
"\n",
"goto",
"again",
"\n",
"}",
"\n\n",
"r",
".",
"pts",
"[",
"pi",
"]",
"=",
"point",
"{",
"float64",
"(",
"k",
")",
",",
"y",
"}",
"\n",
"}",
"\n\n",
"// calculate the resampled sample using polynomial interpolation from the",
"// quality*2 closest samples",
"samples",
"[",
"0",
"]",
"[",
"c",
"]",
"=",
"lagrange",
"(",
"r",
".",
"pts",
",",
"j",
")",
"\n",
"}",
"\n",
"samples",
"=",
"samples",
"[",
"1",
":",
"]",
"\n",
"n",
"++",
"\n",
"r",
".",
"pos",
"++",
"\n",
"}",
"\n",
"return",
"n",
",",
"true",
"\n",
"}"
] | // Stream streams the original audio resampled according to the current ratio. | [
"Stream",
"streams",
"the",
"original",
"audio",
"resampled",
"according",
"to",
"the",
"current",
"ratio",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/resample.go#L73-L137 |
148,421 | faiface/beep | resample.go | SetRatio | func (r *Resampler) SetRatio(ratio float64) {
r.pos = int(float64(r.pos) * r.ratio / ratio)
r.ratio = ratio
} | go | func (r *Resampler) SetRatio(ratio float64) {
r.pos = int(float64(r.pos) * r.ratio / ratio)
r.ratio = ratio
} | [
"func",
"(",
"r",
"*",
"Resampler",
")",
"SetRatio",
"(",
"ratio",
"float64",
")",
"{",
"r",
".",
"pos",
"=",
"int",
"(",
"float64",
"(",
"r",
".",
"pos",
")",
"*",
"r",
".",
"ratio",
"/",
"ratio",
")",
"\n",
"r",
".",
"ratio",
"=",
"ratio",
"\n",
"}"
] | // SetRatio sets the resampling ratio. This does not cause any glitches in the stream. | [
"SetRatio",
"sets",
"the",
"resampling",
"ratio",
".",
"This",
"does",
"not",
"cause",
"any",
"glitches",
"in",
"the",
"stream",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/resample.go#L150-L153 |
148,422 | faiface/beep | ctrl.go | Stream | func (c *Ctrl) Stream(samples [][2]float64) (n int, ok bool) {
if c.Streamer == nil {
return 0, false
}
if c.Paused {
for i := range samples {
samples[i] = [2]float64{}
}
return len(samples), true
}
return c.Streamer.Stream(samples)
} | go | func (c *Ctrl) Stream(samples [][2]float64) (n int, ok bool) {
if c.Streamer == nil {
return 0, false
}
if c.Paused {
for i := range samples {
samples[i] = [2]float64{}
}
return len(samples), true
}
return c.Streamer.Stream(samples)
} | [
"func",
"(",
"c",
"*",
"Ctrl",
")",
"Stream",
"(",
"samples",
"[",
"]",
"[",
"2",
"]",
"float64",
")",
"(",
"n",
"int",
",",
"ok",
"bool",
")",
"{",
"if",
"c",
".",
"Streamer",
"==",
"nil",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"if",
"c",
".",
"Paused",
"{",
"for",
"i",
":=",
"range",
"samples",
"{",
"samples",
"[",
"i",
"]",
"=",
"[",
"2",
"]",
"float64",
"{",
"}",
"\n",
"}",
"\n",
"return",
"len",
"(",
"samples",
")",
",",
"true",
"\n",
"}",
"\n",
"return",
"c",
".",
"Streamer",
".",
"Stream",
"(",
"samples",
")",
"\n",
"}"
] | // Stream streams the wrapped Streamer, if not nil. If the Streamer is nil, Ctrl acts as drained.
// When paused, Ctrl streams silence. | [
"Stream",
"streams",
"the",
"wrapped",
"Streamer",
"if",
"not",
"nil",
".",
"If",
"the",
"Streamer",
"is",
"nil",
"Ctrl",
"acts",
"as",
"drained",
".",
"When",
"paused",
"Ctrl",
"streams",
"silence",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/ctrl.go#L33-L44 |
148,423 | faiface/beep | ctrl.go | Err | func (c *Ctrl) Err() error {
if c.Streamer == nil {
return nil
}
return c.Streamer.Err()
} | go | func (c *Ctrl) Err() error {
if c.Streamer == nil {
return nil
}
return c.Streamer.Err()
} | [
"func",
"(",
"c",
"*",
"Ctrl",
")",
"Err",
"(",
")",
"error",
"{",
"if",
"c",
".",
"Streamer",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"c",
".",
"Streamer",
".",
"Err",
"(",
")",
"\n",
"}"
] | // Err returns the error of the wrapped Streamer, if not nil. | [
"Err",
"returns",
"the",
"error",
"of",
"the",
"wrapped",
"Streamer",
"if",
"not",
"nil",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/ctrl.go#L47-L52 |
148,424 | faiface/beep | buffer.go | D | func (sr SampleRate) D(n int) time.Duration {
return time.Second * time.Duration(n) / time.Duration(sr)
} | go | func (sr SampleRate) D(n int) time.Duration {
return time.Second * time.Duration(n) / time.Duration(sr)
} | [
"func",
"(",
"sr",
"SampleRate",
")",
"D",
"(",
"n",
"int",
")",
"time",
".",
"Duration",
"{",
"return",
"time",
".",
"Second",
"*",
"time",
".",
"Duration",
"(",
"n",
")",
"/",
"time",
".",
"Duration",
"(",
"sr",
")",
"\n",
"}"
] | // D returns the duration of n samples. | [
"D",
"returns",
"the",
"duration",
"of",
"n",
"samples",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/buffer.go#L13-L15 |
148,425 | faiface/beep | buffer.go | N | func (sr SampleRate) N(d time.Duration) int {
return int(d * time.Duration(sr) / time.Second)
} | go | func (sr SampleRate) N(d time.Duration) int {
return int(d * time.Duration(sr) / time.Second)
} | [
"func",
"(",
"sr",
"SampleRate",
")",
"N",
"(",
"d",
"time",
".",
"Duration",
")",
"int",
"{",
"return",
"int",
"(",
"d",
"*",
"time",
".",
"Duration",
"(",
"sr",
")",
"/",
"time",
".",
"Second",
")",
"\n",
"}"
] | // N returns the number of samples that last for d duration. | [
"N",
"returns",
"the",
"number",
"of",
"samples",
"that",
"last",
"for",
"d",
"duration",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/buffer.go#L18-L20 |
148,426 | faiface/beep | buffer.go | NewBuffer | func NewBuffer(f Format) *Buffer {
return &Buffer{f: f, tmp: make([]byte, f.Width())}
} | go | func NewBuffer(f Format) *Buffer {
return &Buffer{f: f, tmp: make([]byte, f.Width())}
} | [
"func",
"NewBuffer",
"(",
"f",
"Format",
")",
"*",
"Buffer",
"{",
"return",
"&",
"Buffer",
"{",
"f",
":",
"f",
",",
"tmp",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"f",
".",
"Width",
"(",
")",
")",
"}",
"\n",
"}"
] | // NewBuffer creates a new empty Buffer which stores samples in the provided format. | [
"NewBuffer",
"creates",
"a",
"new",
"empty",
"Buffer",
"which",
"stores",
"samples",
"in",
"the",
"provided",
"format",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/buffer.go#L171-L173 |
148,427 | faiface/beep | buffer.go | Len | func (b *Buffer) Len() int {
return len(b.data) / b.f.Width()
} | go | func (b *Buffer) Len() int {
return len(b.data) / b.f.Width()
} | [
"func",
"(",
"b",
"*",
"Buffer",
")",
"Len",
"(",
")",
"int",
"{",
"return",
"len",
"(",
"b",
".",
"data",
")",
"/",
"b",
".",
"f",
".",
"Width",
"(",
")",
"\n",
"}"
] | // Len returns the number of samples currently in the Buffer. | [
"Len",
"returns",
"the",
"number",
"of",
"samples",
"currently",
"in",
"the",
"Buffer",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/buffer.go#L181-L183 |
148,428 | faiface/beep | buffer.go | Pop | func (b *Buffer) Pop(n int) {
b.data = b.data[n:]
} | go | func (b *Buffer) Pop(n int) {
b.data = b.data[n:]
} | [
"func",
"(",
"b",
"*",
"Buffer",
")",
"Pop",
"(",
"n",
"int",
")",
"{",
"b",
".",
"data",
"=",
"b",
".",
"data",
"[",
"n",
":",
"]",
"\n",
"}"
] | // Pop removes n samples from the beginning of the Buffer.
//
// Existing Streamers are not affected. | [
"Pop",
"removes",
"n",
"samples",
"from",
"the",
"beginning",
"of",
"the",
"Buffer",
".",
"Existing",
"Streamers",
"are",
"not",
"affected",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/buffer.go#L188-L190 |
148,429 | faiface/beep | buffer.go | Append | func (b *Buffer) Append(s Streamer) {
var samples [512][2]float64
for {
n, ok := s.Stream(samples[:])
if !ok {
break
}
for _, sample := range samples[:n] {
b.f.EncodeSigned(b.tmp, sample)
b.data = append(b.data, b.tmp...)
}
}
} | go | func (b *Buffer) Append(s Streamer) {
var samples [512][2]float64
for {
n, ok := s.Stream(samples[:])
if !ok {
break
}
for _, sample := range samples[:n] {
b.f.EncodeSigned(b.tmp, sample)
b.data = append(b.data, b.tmp...)
}
}
} | [
"func",
"(",
"b",
"*",
"Buffer",
")",
"Append",
"(",
"s",
"Streamer",
")",
"{",
"var",
"samples",
"[",
"512",
"]",
"[",
"2",
"]",
"float64",
"\n",
"for",
"{",
"n",
",",
"ok",
":=",
"s",
".",
"Stream",
"(",
"samples",
"[",
":",
"]",
")",
"\n",
"if",
"!",
"ok",
"{",
"break",
"\n",
"}",
"\n",
"for",
"_",
",",
"sample",
":=",
"range",
"samples",
"[",
":",
"n",
"]",
"{",
"b",
".",
"f",
".",
"EncodeSigned",
"(",
"b",
".",
"tmp",
",",
"sample",
")",
"\n",
"b",
".",
"data",
"=",
"append",
"(",
"b",
".",
"data",
",",
"b",
".",
"tmp",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Append adds all audio data from the given Streamer to the end of the Buffer.
//
// The Streamer will be drained when this method finishes. | [
"Append",
"adds",
"all",
"audio",
"data",
"from",
"the",
"given",
"Streamer",
"to",
"the",
"end",
"of",
"the",
"Buffer",
".",
"The",
"Streamer",
"will",
"be",
"drained",
"when",
"this",
"method",
"finishes",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/buffer.go#L195-L207 |
148,430 | faiface/beep | mp3/decode.go | Decode | func Decode(rc io.ReadCloser) (s beep.StreamSeekCloser, format beep.Format, err error) {
defer func() {
if err != nil {
err = errors.Wrap(err, "mp3")
}
}()
d, err := gomp3.NewDecoder(rc)
if err != nil {
return nil, beep.Format{}, err
}
format = beep.Format{
SampleRate: beep.SampleRate(d.SampleRate()),
NumChannels: gomp3NumChannels,
Precision: gomp3Precision,
}
return &decoder{rc, d, format, 0, nil}, format, nil
} | go | func Decode(rc io.ReadCloser) (s beep.StreamSeekCloser, format beep.Format, err error) {
defer func() {
if err != nil {
err = errors.Wrap(err, "mp3")
}
}()
d, err := gomp3.NewDecoder(rc)
if err != nil {
return nil, beep.Format{}, err
}
format = beep.Format{
SampleRate: beep.SampleRate(d.SampleRate()),
NumChannels: gomp3NumChannels,
Precision: gomp3Precision,
}
return &decoder{rc, d, format, 0, nil}, format, nil
} | [
"func",
"Decode",
"(",
"rc",
"io",
".",
"ReadCloser",
")",
"(",
"s",
"beep",
".",
"StreamSeekCloser",
",",
"format",
"beep",
".",
"Format",
",",
"err",
"error",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"d",
",",
"err",
":=",
"gomp3",
".",
"NewDecoder",
"(",
"rc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"beep",
".",
"Format",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"format",
"=",
"beep",
".",
"Format",
"{",
"SampleRate",
":",
"beep",
".",
"SampleRate",
"(",
"d",
".",
"SampleRate",
"(",
")",
")",
",",
"NumChannels",
":",
"gomp3NumChannels",
",",
"Precision",
":",
"gomp3Precision",
",",
"}",
"\n",
"return",
"&",
"decoder",
"{",
"rc",
",",
"d",
",",
"format",
",",
"0",
",",
"nil",
"}",
",",
"format",
",",
"nil",
"\n",
"}"
] | // Decode takes a ReadCloser containing audio data in MP3 format and returns a StreamSeekCloser,
// which streams that audio. The Seek method will panic if rc is not io.Seeker.
//
// Do not close the supplied ReadSeekCloser, instead, use the Close method of the returned
// StreamSeekCloser when you want to release the resources. | [
"Decode",
"takes",
"a",
"ReadCloser",
"containing",
"audio",
"data",
"in",
"MP3",
"format",
"and",
"returns",
"a",
"StreamSeekCloser",
"which",
"streams",
"that",
"audio",
".",
"The",
"Seek",
"method",
"will",
"panic",
"if",
"rc",
"is",
"not",
"io",
".",
"Seeker",
".",
"Do",
"not",
"close",
"the",
"supplied",
"ReadSeekCloser",
"instead",
"use",
"the",
"Close",
"method",
"of",
"the",
"returned",
"StreamSeekCloser",
"when",
"you",
"want",
"to",
"release",
"the",
"resources",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/mp3/decode.go#L24-L40 |
148,431 | faiface/beep | effects/gain.go | Stream | func (g *Gain) Stream(samples [][2]float64) (n int, ok bool) {
n, ok = g.Streamer.Stream(samples)
for i := range samples[:n] {
samples[i][0] *= 1 + g.Gain
samples[i][1] *= 1 + g.Gain
}
return n, ok
} | go | func (g *Gain) Stream(samples [][2]float64) (n int, ok bool) {
n, ok = g.Streamer.Stream(samples)
for i := range samples[:n] {
samples[i][0] *= 1 + g.Gain
samples[i][1] *= 1 + g.Gain
}
return n, ok
} | [
"func",
"(",
"g",
"*",
"Gain",
")",
"Stream",
"(",
"samples",
"[",
"]",
"[",
"2",
"]",
"float64",
")",
"(",
"n",
"int",
",",
"ok",
"bool",
")",
"{",
"n",
",",
"ok",
"=",
"g",
".",
"Streamer",
".",
"Stream",
"(",
"samples",
")",
"\n",
"for",
"i",
":=",
"range",
"samples",
"[",
":",
"n",
"]",
"{",
"samples",
"[",
"i",
"]",
"[",
"0",
"]",
"*=",
"1",
"+",
"g",
".",
"Gain",
"\n",
"samples",
"[",
"i",
"]",
"[",
"1",
"]",
"*=",
"1",
"+",
"g",
".",
"Gain",
"\n",
"}",
"\n",
"return",
"n",
",",
"ok",
"\n",
"}"
] | // Stream streams the wrapped Streamer amplified by Gain. | [
"Stream",
"streams",
"the",
"wrapped",
"Streamer",
"amplified",
"by",
"Gain",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/effects/gain.go#L16-L23 |
148,432 | faiface/beep | streamers.go | Silence | func Silence(num int) Streamer {
return StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
if num == 0 {
return 0, false
}
if 0 < num && num < len(samples) {
samples = samples[:num]
}
for i := range samples {
samples[i] = [2]float64{}
}
if num > 0 {
num -= len(samples)
}
return len(samples), true
})
} | go | func Silence(num int) Streamer {
return StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
if num == 0 {
return 0, false
}
if 0 < num && num < len(samples) {
samples = samples[:num]
}
for i := range samples {
samples[i] = [2]float64{}
}
if num > 0 {
num -= len(samples)
}
return len(samples), true
})
} | [
"func",
"Silence",
"(",
"num",
"int",
")",
"Streamer",
"{",
"return",
"StreamerFunc",
"(",
"func",
"(",
"samples",
"[",
"]",
"[",
"2",
"]",
"float64",
")",
"(",
"n",
"int",
",",
"ok",
"bool",
")",
"{",
"if",
"num",
"==",
"0",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"if",
"0",
"<",
"num",
"&&",
"num",
"<",
"len",
"(",
"samples",
")",
"{",
"samples",
"=",
"samples",
"[",
":",
"num",
"]",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"samples",
"{",
"samples",
"[",
"i",
"]",
"=",
"[",
"2",
"]",
"float64",
"{",
"}",
"\n",
"}",
"\n",
"if",
"num",
">",
"0",
"{",
"num",
"-=",
"len",
"(",
"samples",
")",
"\n",
"}",
"\n",
"return",
"len",
"(",
"samples",
")",
",",
"true",
"\n",
"}",
")",
"\n",
"}"
] | // Silence returns a Streamer which streams num samples of silence. If num is negative, silence is
// streamed forever. | [
"Silence",
"returns",
"a",
"Streamer",
"which",
"streams",
"num",
"samples",
"of",
"silence",
".",
"If",
"num",
"is",
"negative",
"silence",
"is",
"streamed",
"forever",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/streamers.go#L5-L21 |
148,433 | faiface/beep | streamers.go | Callback | func Callback(f func()) Streamer {
return StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
if f != nil {
f()
f = nil
}
return 0, false
})
} | go | func Callback(f func()) Streamer {
return StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
if f != nil {
f()
f = nil
}
return 0, false
})
} | [
"func",
"Callback",
"(",
"f",
"func",
"(",
")",
")",
"Streamer",
"{",
"return",
"StreamerFunc",
"(",
"func",
"(",
"samples",
"[",
"]",
"[",
"2",
"]",
"float64",
")",
"(",
"n",
"int",
",",
"ok",
"bool",
")",
"{",
"if",
"f",
"!=",
"nil",
"{",
"f",
"(",
")",
"\n",
"f",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"0",
",",
"false",
"\n",
"}",
")",
"\n",
"}"
] | // Callback returns a Streamer, which does not stream any samples, but instead calls f the first
// time its Stream method is called. | [
"Callback",
"returns",
"a",
"Streamer",
"which",
"does",
"not",
"stream",
"any",
"samples",
"but",
"instead",
"calls",
"f",
"the",
"first",
"time",
"its",
"Stream",
"method",
"is",
"called",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/streamers.go#L25-L33 |
148,434 | faiface/beep | streamers.go | Iterate | func Iterate(g func() Streamer) Streamer {
var (
s Streamer
first = true
)
return StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
if first {
s = g()
first = false
}
if s == nil {
return 0, false
}
for len(samples) > 0 {
if s == nil {
break
}
sn, sok := s.Stream(samples)
if !sok {
s = g()
}
samples = samples[sn:]
n += sn
}
return n, true
})
} | go | func Iterate(g func() Streamer) Streamer {
var (
s Streamer
first = true
)
return StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
if first {
s = g()
first = false
}
if s == nil {
return 0, false
}
for len(samples) > 0 {
if s == nil {
break
}
sn, sok := s.Stream(samples)
if !sok {
s = g()
}
samples = samples[sn:]
n += sn
}
return n, true
})
} | [
"func",
"Iterate",
"(",
"g",
"func",
"(",
")",
"Streamer",
")",
"Streamer",
"{",
"var",
"(",
"s",
"Streamer",
"\n",
"first",
"=",
"true",
"\n",
")",
"\n",
"return",
"StreamerFunc",
"(",
"func",
"(",
"samples",
"[",
"]",
"[",
"2",
"]",
"float64",
")",
"(",
"n",
"int",
",",
"ok",
"bool",
")",
"{",
"if",
"first",
"{",
"s",
"=",
"g",
"(",
")",
"\n",
"first",
"=",
"false",
"\n",
"}",
"\n",
"if",
"s",
"==",
"nil",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"for",
"len",
"(",
"samples",
")",
">",
"0",
"{",
"if",
"s",
"==",
"nil",
"{",
"break",
"\n",
"}",
"\n",
"sn",
",",
"sok",
":=",
"s",
".",
"Stream",
"(",
"samples",
")",
"\n",
"if",
"!",
"sok",
"{",
"s",
"=",
"g",
"(",
")",
"\n",
"}",
"\n",
"samples",
"=",
"samples",
"[",
"sn",
":",
"]",
"\n",
"n",
"+=",
"sn",
"\n",
"}",
"\n",
"return",
"n",
",",
"true",
"\n",
"}",
")",
"\n",
"}"
] | // Iterate returns a Streamer which successively streams Streamers obtains by calling the provided g
// function. The streaming stops when g returns nil.
//
// Iterate does not propagate errors from the generated Streamers. | [
"Iterate",
"returns",
"a",
"Streamer",
"which",
"successively",
"streams",
"Streamers",
"obtains",
"by",
"calling",
"the",
"provided",
"g",
"function",
".",
"The",
"streaming",
"stops",
"when",
"g",
"returns",
"nil",
".",
"Iterate",
"does",
"not",
"propagate",
"errors",
"from",
"the",
"generated",
"Streamers",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/streamers.go#L39-L65 |
148,435 | faiface/beep | flac/decode.go | Decode | func Decode(rc io.ReadCloser) (s beep.StreamSeekCloser, format beep.Format, err error) {
d := decoder{rc: rc}
defer func() { // hacky way to always close rc if an error occurred
if err != nil {
d.rc.Close()
}
}()
d.stream, err = flac.New(rc)
if err != nil {
return nil, beep.Format{}, errors.Wrap(err, "flac")
}
format = beep.Format{
SampleRate: beep.SampleRate(d.stream.Info.SampleRate),
NumChannels: int(d.stream.Info.NChannels),
Precision: int(d.stream.Info.BitsPerSample / 8),
}
return &d, format, nil
} | go | func Decode(rc io.ReadCloser) (s beep.StreamSeekCloser, format beep.Format, err error) {
d := decoder{rc: rc}
defer func() { // hacky way to always close rc if an error occurred
if err != nil {
d.rc.Close()
}
}()
d.stream, err = flac.New(rc)
if err != nil {
return nil, beep.Format{}, errors.Wrap(err, "flac")
}
format = beep.Format{
SampleRate: beep.SampleRate(d.stream.Info.SampleRate),
NumChannels: int(d.stream.Info.NChannels),
Precision: int(d.stream.Info.BitsPerSample / 8),
}
return &d, format, nil
} | [
"func",
"Decode",
"(",
"rc",
"io",
".",
"ReadCloser",
")",
"(",
"s",
"beep",
".",
"StreamSeekCloser",
",",
"format",
"beep",
".",
"Format",
",",
"err",
"error",
")",
"{",
"d",
":=",
"decoder",
"{",
"rc",
":",
"rc",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"// hacky way to always close rc if an error occurred",
"if",
"err",
"!=",
"nil",
"{",
"d",
".",
"rc",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"d",
".",
"stream",
",",
"err",
"=",
"flac",
".",
"New",
"(",
"rc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"beep",
".",
"Format",
"{",
"}",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"format",
"=",
"beep",
".",
"Format",
"{",
"SampleRate",
":",
"beep",
".",
"SampleRate",
"(",
"d",
".",
"stream",
".",
"Info",
".",
"SampleRate",
")",
",",
"NumChannels",
":",
"int",
"(",
"d",
".",
"stream",
".",
"Info",
".",
"NChannels",
")",
",",
"Precision",
":",
"int",
"(",
"d",
".",
"stream",
".",
"Info",
".",
"BitsPerSample",
"/",
"8",
")",
",",
"}",
"\n",
"return",
"&",
"d",
",",
"format",
",",
"nil",
"\n",
"}"
] | // Decode takes a ReadCloser containing audio data in FLAC format and returns a StreamSeekCloser,
// which streams that audio. The Seek method will panic if rc is not io.Seeker.
//
// Do not close the supplied ReadSeekCloser, instead, use the Close method of the returned
// StreamSeekCloser when you want to release the resources. | [
"Decode",
"takes",
"a",
"ReadCloser",
"containing",
"audio",
"data",
"in",
"FLAC",
"format",
"and",
"returns",
"a",
"StreamSeekCloser",
"which",
"streams",
"that",
"audio",
".",
"The",
"Seek",
"method",
"will",
"panic",
"if",
"rc",
"is",
"not",
"io",
".",
"Seeker",
".",
"Do",
"not",
"close",
"the",
"supplied",
"ReadSeekCloser",
"instead",
"use",
"the",
"Close",
"method",
"of",
"the",
"returned",
"StreamSeekCloser",
"when",
"you",
"want",
"to",
"release",
"the",
"resources",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/flac/decode.go#L17-L34 |
148,436 | faiface/beep | mixer.go | Add | func (m *Mixer) Add(s ...Streamer) {
m.streamers = append(m.streamers, s...)
} | go | func (m *Mixer) Add(s ...Streamer) {
m.streamers = append(m.streamers, s...)
} | [
"func",
"(",
"m",
"*",
"Mixer",
")",
"Add",
"(",
"s",
"...",
"Streamer",
")",
"{",
"m",
".",
"streamers",
"=",
"append",
"(",
"m",
".",
"streamers",
",",
"s",
"...",
")",
"\n",
"}"
] | // Add adds Streamers to the Mixer. | [
"Add",
"adds",
"Streamers",
"to",
"the",
"Mixer",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/mixer.go#L15-L17 |
148,437 | faiface/beep | interface.go | Stream | func (sf StreamerFunc) Stream(samples [][2]float64) (n int, ok bool) {
return sf(samples)
} | go | func (sf StreamerFunc) Stream(samples [][2]float64) (n int, ok bool) {
return sf(samples)
} | [
"func",
"(",
"sf",
"StreamerFunc",
")",
"Stream",
"(",
"samples",
"[",
"]",
"[",
"2",
"]",
"float64",
")",
"(",
"n",
"int",
",",
"ok",
"bool",
")",
"{",
"return",
"sf",
"(",
"samples",
")",
"\n",
"}"
] | // Stream calls the wrapped streaming function. | [
"Stream",
"calls",
"the",
"wrapped",
"streaming",
"function",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/interface.go#L99-L101 |
148,438 | faiface/beep | speaker/speaker.go | Init | func Init(sampleRate beep.SampleRate, bufferSize int) error {
mu.Lock()
defer mu.Unlock()
if player != nil {
done <- struct{}{}
player.Close()
context.Close()
}
mixer = beep.Mixer{}
numBytes := bufferSize * 4
samples = make([][2]float64, bufferSize)
buf = make([]byte, numBytes)
var err error
context, err = oto.NewContext(int(sampleRate), 2, 2, numBytes)
if err != nil {
return errors.Wrap(err, "failed to initialize speaker")
}
player = context.NewPlayer()
done = make(chan struct{})
go func() {
for {
select {
default:
update()
case <-done:
return
}
}
}()
return nil
} | go | func Init(sampleRate beep.SampleRate, bufferSize int) error {
mu.Lock()
defer mu.Unlock()
if player != nil {
done <- struct{}{}
player.Close()
context.Close()
}
mixer = beep.Mixer{}
numBytes := bufferSize * 4
samples = make([][2]float64, bufferSize)
buf = make([]byte, numBytes)
var err error
context, err = oto.NewContext(int(sampleRate), 2, 2, numBytes)
if err != nil {
return errors.Wrap(err, "failed to initialize speaker")
}
player = context.NewPlayer()
done = make(chan struct{})
go func() {
for {
select {
default:
update()
case <-done:
return
}
}
}()
return nil
} | [
"func",
"Init",
"(",
"sampleRate",
"beep",
".",
"SampleRate",
",",
"bufferSize",
"int",
")",
"error",
"{",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"player",
"!=",
"nil",
"{",
"done",
"<-",
"struct",
"{",
"}",
"{",
"}",
"\n",
"player",
".",
"Close",
"(",
")",
"\n",
"context",
".",
"Close",
"(",
")",
"\n",
"}",
"\n\n",
"mixer",
"=",
"beep",
".",
"Mixer",
"{",
"}",
"\n\n",
"numBytes",
":=",
"bufferSize",
"*",
"4",
"\n",
"samples",
"=",
"make",
"(",
"[",
"]",
"[",
"2",
"]",
"float64",
",",
"bufferSize",
")",
"\n",
"buf",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"numBytes",
")",
"\n\n",
"var",
"err",
"error",
"\n",
"context",
",",
"err",
"=",
"oto",
".",
"NewContext",
"(",
"int",
"(",
"sampleRate",
")",
",",
"2",
",",
"2",
",",
"numBytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"player",
"=",
"context",
".",
"NewPlayer",
"(",
")",
"\n\n",
"done",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"default",
":",
"update",
"(",
")",
"\n",
"case",
"<-",
"done",
":",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Init initializes audio playback through speaker. Must be called before using this package.
//
// The bufferSize argument specifies the number of samples of the speaker's buffer. Bigger
// bufferSize means lower CPU usage and more reliable playback. Lower bufferSize means better
// responsiveness and less delay. | [
"Init",
"initializes",
"audio",
"playback",
"through",
"speaker",
".",
"Must",
"be",
"called",
"before",
"using",
"this",
"package",
".",
"The",
"bufferSize",
"argument",
"specifies",
"the",
"number",
"of",
"samples",
"of",
"the",
"speaker",
"s",
"buffer",
".",
"Bigger",
"bufferSize",
"means",
"lower",
"CPU",
"usage",
"and",
"more",
"reliable",
"playback",
".",
"Lower",
"bufferSize",
"means",
"better",
"responsiveness",
"and",
"less",
"delay",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/speaker/speaker.go#L27-L64 |
148,439 | faiface/beep | speaker/speaker.go | Play | func Play(s ...beep.Streamer) {
mu.Lock()
mixer.Add(s...)
mu.Unlock()
} | go | func Play(s ...beep.Streamer) {
mu.Lock()
mixer.Add(s...)
mu.Unlock()
} | [
"func",
"Play",
"(",
"s",
"...",
"beep",
".",
"Streamer",
")",
"{",
"mu",
".",
"Lock",
"(",
")",
"\n",
"mixer",
".",
"Add",
"(",
"s",
"...",
")",
"\n",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // Play starts playing all provided Streamers through the speaker. | [
"Play",
"starts",
"playing",
"all",
"provided",
"Streamers",
"through",
"the",
"speaker",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/speaker/speaker.go#L80-L84 |
148,440 | faiface/beep | speaker/speaker.go | update | func update() {
mu.Lock()
mixer.Stream(samples)
mu.Unlock()
for i := range samples {
for c := range samples[i] {
val := samples[i][c]
if val < -1 {
val = -1
}
if val > +1 {
val = +1
}
valInt16 := int16(val * (1<<15 - 1))
low := byte(valInt16)
high := byte(valInt16 >> 8)
buf[i*4+c*2+0] = low
buf[i*4+c*2+1] = high
}
}
player.Write(buf)
} | go | func update() {
mu.Lock()
mixer.Stream(samples)
mu.Unlock()
for i := range samples {
for c := range samples[i] {
val := samples[i][c]
if val < -1 {
val = -1
}
if val > +1 {
val = +1
}
valInt16 := int16(val * (1<<15 - 1))
low := byte(valInt16)
high := byte(valInt16 >> 8)
buf[i*4+c*2+0] = low
buf[i*4+c*2+1] = high
}
}
player.Write(buf)
} | [
"func",
"update",
"(",
")",
"{",
"mu",
".",
"Lock",
"(",
")",
"\n",
"mixer",
".",
"Stream",
"(",
"samples",
")",
"\n",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"i",
":=",
"range",
"samples",
"{",
"for",
"c",
":=",
"range",
"samples",
"[",
"i",
"]",
"{",
"val",
":=",
"samples",
"[",
"i",
"]",
"[",
"c",
"]",
"\n",
"if",
"val",
"<",
"-",
"1",
"{",
"val",
"=",
"-",
"1",
"\n",
"}",
"\n",
"if",
"val",
">",
"+",
"1",
"{",
"val",
"=",
"+",
"1",
"\n",
"}",
"\n",
"valInt16",
":=",
"int16",
"(",
"val",
"*",
"(",
"1",
"<<",
"15",
"-",
"1",
")",
")",
"\n",
"low",
":=",
"byte",
"(",
"valInt16",
")",
"\n",
"high",
":=",
"byte",
"(",
"valInt16",
">>",
"8",
")",
"\n",
"buf",
"[",
"i",
"*",
"4",
"+",
"c",
"*",
"2",
"+",
"0",
"]",
"=",
"low",
"\n",
"buf",
"[",
"i",
"*",
"4",
"+",
"c",
"*",
"2",
"+",
"1",
"]",
"=",
"high",
"\n",
"}",
"\n",
"}",
"\n\n",
"player",
".",
"Write",
"(",
"buf",
")",
"\n",
"}"
] | // update pulls new data from the playing Streamers and sends it to the speaker. Blocks until the
// data is sent and started playing. | [
"update",
"pulls",
"new",
"data",
"from",
"the",
"playing",
"Streamers",
"and",
"sends",
"it",
"to",
"the",
"speaker",
".",
"Blocks",
"until",
"the",
"data",
"is",
"sent",
"and",
"started",
"playing",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/speaker/speaker.go#L95-L118 |
148,441 | faiface/beep | effects/volume.go | Stream | func (v *Volume) Stream(samples [][2]float64) (n int, ok bool) {
n, ok = v.Streamer.Stream(samples)
gain := 0.0
if !v.Silent {
gain = math.Pow(v.Base, v.Volume)
}
for i := range samples[:n] {
samples[i][0] *= gain
samples[i][1] *= gain
}
return n, ok
} | go | func (v *Volume) Stream(samples [][2]float64) (n int, ok bool) {
n, ok = v.Streamer.Stream(samples)
gain := 0.0
if !v.Silent {
gain = math.Pow(v.Base, v.Volume)
}
for i := range samples[:n] {
samples[i][0] *= gain
samples[i][1] *= gain
}
return n, ok
} | [
"func",
"(",
"v",
"*",
"Volume",
")",
"Stream",
"(",
"samples",
"[",
"]",
"[",
"2",
"]",
"float64",
")",
"(",
"n",
"int",
",",
"ok",
"bool",
")",
"{",
"n",
",",
"ok",
"=",
"v",
".",
"Streamer",
".",
"Stream",
"(",
"samples",
")",
"\n",
"gain",
":=",
"0.0",
"\n",
"if",
"!",
"v",
".",
"Silent",
"{",
"gain",
"=",
"math",
".",
"Pow",
"(",
"v",
".",
"Base",
",",
"v",
".",
"Volume",
")",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"samples",
"[",
":",
"n",
"]",
"{",
"samples",
"[",
"i",
"]",
"[",
"0",
"]",
"*=",
"gain",
"\n",
"samples",
"[",
"i",
"]",
"[",
"1",
"]",
"*=",
"gain",
"\n",
"}",
"\n",
"return",
"n",
",",
"ok",
"\n",
"}"
] | // Stream streams the wrapped Streamer with volume adjusted according to Base, Volume and Silent
// fields. | [
"Stream",
"streams",
"the",
"wrapped",
"Streamer",
"with",
"volume",
"adjusted",
"according",
"to",
"Base",
"Volume",
"and",
"Silent",
"fields",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/effects/volume.go#L30-L41 |
148,442 | faiface/beep | compositors.go | Take | func Take(num int, s Streamer) Streamer {
return &take{
s: s,
remains: num,
}
} | go | func Take(num int, s Streamer) Streamer {
return &take{
s: s,
remains: num,
}
} | [
"func",
"Take",
"(",
"num",
"int",
",",
"s",
"Streamer",
")",
"Streamer",
"{",
"return",
"&",
"take",
"{",
"s",
":",
"s",
",",
"remains",
":",
"num",
",",
"}",
"\n",
"}"
] | // Take returns a Streamer which streams at most num samples from s.
//
// The returned Streamer propagates s's errors through Err. | [
"Take",
"returns",
"a",
"Streamer",
"which",
"streams",
"at",
"most",
"num",
"samples",
"from",
"s",
".",
"The",
"returned",
"Streamer",
"propagates",
"s",
"s",
"errors",
"through",
"Err",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/compositors.go#L6-L11 |
148,443 | faiface/beep | compositors.go | Loop | func Loop(count int, s StreamSeeker) Streamer {
return &loop{
s: s,
remains: count,
}
} | go | func Loop(count int, s StreamSeeker) Streamer {
return &loop{
s: s,
remains: count,
}
} | [
"func",
"Loop",
"(",
"count",
"int",
",",
"s",
"StreamSeeker",
")",
"Streamer",
"{",
"return",
"&",
"loop",
"{",
"s",
":",
"s",
",",
"remains",
":",
"count",
",",
"}",
"\n",
"}"
] | // Loop takes a StreamSeeker and plays it count times. If count is negative, s is looped infinitely.
//
// The returned Streamer propagates s's errors. | [
"Loop",
"takes",
"a",
"StreamSeeker",
"and",
"plays",
"it",
"count",
"times",
".",
"If",
"count",
"is",
"negative",
"s",
"is",
"looped",
"infinitely",
".",
"The",
"returned",
"Streamer",
"propagates",
"s",
"s",
"errors",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/compositors.go#L38-L43 |
148,444 | faiface/beep | compositors.go | Seq | func Seq(s ...Streamer) Streamer {
i := 0
return StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
for i < len(s) && len(samples) > 0 {
sn, sok := s[i].Stream(samples)
samples = samples[sn:]
n, ok = n+sn, ok || sok
if !sok {
i++
}
}
return n, ok
})
} | go | func Seq(s ...Streamer) Streamer {
i := 0
return StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
for i < len(s) && len(samples) > 0 {
sn, sok := s[i].Stream(samples)
samples = samples[sn:]
n, ok = n+sn, ok || sok
if !sok {
i++
}
}
return n, ok
})
} | [
"func",
"Seq",
"(",
"s",
"...",
"Streamer",
")",
"Streamer",
"{",
"i",
":=",
"0",
"\n",
"return",
"StreamerFunc",
"(",
"func",
"(",
"samples",
"[",
"]",
"[",
"2",
"]",
"float64",
")",
"(",
"n",
"int",
",",
"ok",
"bool",
")",
"{",
"for",
"i",
"<",
"len",
"(",
"s",
")",
"&&",
"len",
"(",
"samples",
")",
">",
"0",
"{",
"sn",
",",
"sok",
":=",
"s",
"[",
"i",
"]",
".",
"Stream",
"(",
"samples",
")",
"\n",
"samples",
"=",
"samples",
"[",
"sn",
":",
"]",
"\n",
"n",
",",
"ok",
"=",
"n",
"+",
"sn",
",",
"ok",
"||",
"sok",
"\n",
"if",
"!",
"sok",
"{",
"i",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"n",
",",
"ok",
"\n",
"}",
")",
"\n",
"}"
] | // Seq takes zero or more Streamers and returns a Streamer which streams them one by one without pauses.
//
// Seq does not propagate errors from the Streamers. | [
"Seq",
"takes",
"zero",
"or",
"more",
"Streamers",
"and",
"returns",
"a",
"Streamer",
"which",
"streams",
"them",
"one",
"by",
"one",
"without",
"pauses",
".",
"Seq",
"does",
"not",
"propagate",
"errors",
"from",
"the",
"Streamers",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/compositors.go#L82-L95 |
148,445 | faiface/beep | compositors.go | Mix | func Mix(s ...Streamer) Streamer {
return StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
var tmp [512][2]float64
for len(samples) > 0 {
toStream := len(tmp)
if toStream > len(samples) {
toStream = len(samples)
}
// clear the samples
for i := range samples[:toStream] {
samples[i] = [2]float64{}
}
snMax := 0 // max number of streamed samples in this iteration
for _, st := range s {
// mix the stream
sn, sok := st.Stream(tmp[:toStream])
if sn > snMax {
snMax = sn
}
ok = ok || sok
for i := range tmp[:sn] {
samples[i][0] += tmp[i][0]
samples[i][1] += tmp[i][1]
}
}
n += snMax
if snMax < len(tmp) {
break
}
samples = samples[snMax:]
}
return n, ok
})
} | go | func Mix(s ...Streamer) Streamer {
return StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
var tmp [512][2]float64
for len(samples) > 0 {
toStream := len(tmp)
if toStream > len(samples) {
toStream = len(samples)
}
// clear the samples
for i := range samples[:toStream] {
samples[i] = [2]float64{}
}
snMax := 0 // max number of streamed samples in this iteration
for _, st := range s {
// mix the stream
sn, sok := st.Stream(tmp[:toStream])
if sn > snMax {
snMax = sn
}
ok = ok || sok
for i := range tmp[:sn] {
samples[i][0] += tmp[i][0]
samples[i][1] += tmp[i][1]
}
}
n += snMax
if snMax < len(tmp) {
break
}
samples = samples[snMax:]
}
return n, ok
})
} | [
"func",
"Mix",
"(",
"s",
"...",
"Streamer",
")",
"Streamer",
"{",
"return",
"StreamerFunc",
"(",
"func",
"(",
"samples",
"[",
"]",
"[",
"2",
"]",
"float64",
")",
"(",
"n",
"int",
",",
"ok",
"bool",
")",
"{",
"var",
"tmp",
"[",
"512",
"]",
"[",
"2",
"]",
"float64",
"\n\n",
"for",
"len",
"(",
"samples",
")",
">",
"0",
"{",
"toStream",
":=",
"len",
"(",
"tmp",
")",
"\n",
"if",
"toStream",
">",
"len",
"(",
"samples",
")",
"{",
"toStream",
"=",
"len",
"(",
"samples",
")",
"\n",
"}",
"\n\n",
"// clear the samples",
"for",
"i",
":=",
"range",
"samples",
"[",
":",
"toStream",
"]",
"{",
"samples",
"[",
"i",
"]",
"=",
"[",
"2",
"]",
"float64",
"{",
"}",
"\n",
"}",
"\n\n",
"snMax",
":=",
"0",
"// max number of streamed samples in this iteration",
"\n",
"for",
"_",
",",
"st",
":=",
"range",
"s",
"{",
"// mix the stream",
"sn",
",",
"sok",
":=",
"st",
".",
"Stream",
"(",
"tmp",
"[",
":",
"toStream",
"]",
")",
"\n",
"if",
"sn",
">",
"snMax",
"{",
"snMax",
"=",
"sn",
"\n",
"}",
"\n",
"ok",
"=",
"ok",
"||",
"sok",
"\n\n",
"for",
"i",
":=",
"range",
"tmp",
"[",
":",
"sn",
"]",
"{",
"samples",
"[",
"i",
"]",
"[",
"0",
"]",
"+=",
"tmp",
"[",
"i",
"]",
"[",
"0",
"]",
"\n",
"samples",
"[",
"i",
"]",
"[",
"1",
"]",
"+=",
"tmp",
"[",
"i",
"]",
"[",
"1",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"n",
"+=",
"snMax",
"\n",
"if",
"snMax",
"<",
"len",
"(",
"tmp",
")",
"{",
"break",
"\n",
"}",
"\n",
"samples",
"=",
"samples",
"[",
"snMax",
":",
"]",
"\n",
"}",
"\n\n",
"return",
"n",
",",
"ok",
"\n",
"}",
")",
"\n",
"}"
] | // Mix takes zero or more Streamers and returns a Streamer which streams them mixed together.
//
// Mix does not propagate errors from the Streamers. | [
"Mix",
"takes",
"zero",
"or",
"more",
"Streamers",
"and",
"returns",
"a",
"Streamer",
"which",
"streams",
"them",
"mixed",
"together",
".",
"Mix",
"does",
"not",
"propagate",
"errors",
"from",
"the",
"Streamers",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/compositors.go#L100-L139 |
148,446 | faiface/beep | compositors.go | Dup | func Dup(s Streamer) (t, u Streamer) {
var tBuf, uBuf [][2]float64
return &dup{&tBuf, &uBuf, s}, &dup{&uBuf, &tBuf, s}
} | go | func Dup(s Streamer) (t, u Streamer) {
var tBuf, uBuf [][2]float64
return &dup{&tBuf, &uBuf, s}, &dup{&uBuf, &tBuf, s}
} | [
"func",
"Dup",
"(",
"s",
"Streamer",
")",
"(",
"t",
",",
"u",
"Streamer",
")",
"{",
"var",
"tBuf",
",",
"uBuf",
"[",
"]",
"[",
"2",
"]",
"float64",
"\n",
"return",
"&",
"dup",
"{",
"&",
"tBuf",
",",
"&",
"uBuf",
",",
"s",
"}",
",",
"&",
"dup",
"{",
"&",
"uBuf",
",",
"&",
"tBuf",
",",
"s",
"}",
"\n",
"}"
] | // Dup returns two Streamers which both stream the same data as the original s. The two Streamers
// can't be used concurrently without synchronization. | [
"Dup",
"returns",
"two",
"Streamers",
"which",
"both",
"stream",
"the",
"same",
"data",
"as",
"the",
"original",
"s",
".",
"The",
"two",
"Streamers",
"can",
"t",
"be",
"used",
"concurrently",
"without",
"synchronization",
"."
] | e59a7440241ac37c8debc0c36d69a6a489850a1f | https://github.com/faiface/beep/blob/e59a7440241ac37c8debc0c36d69a6a489850a1f/compositors.go#L143-L146 |
148,447 | mattn/go-gtk | gdkpixbuf/gdkpixbuf.go | NewPixbufFromData | func NewPixbufFromData(pbd PixbufData) *Pixbuf {
gpixbuf := C.gdk_pixbuf_new_from_data(
C.to_gucharptr(unsafe.Pointer(&pbd.Data[0])),
C.GdkColorspace(pbd.Colorspace),
gbool(pbd.HasAlpha),
C.int(pbd.BitsPerSample),
C.int(pbd.Width),
C.int(pbd.Height),
C.int(pbd.RowStride),
nil, nil)
return &Pixbuf{
GdkPixbuf: &GdkPixbuf{gpixbuf},
GObject: glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
}
} | go | func NewPixbufFromData(pbd PixbufData) *Pixbuf {
gpixbuf := C.gdk_pixbuf_new_from_data(
C.to_gucharptr(unsafe.Pointer(&pbd.Data[0])),
C.GdkColorspace(pbd.Colorspace),
gbool(pbd.HasAlpha),
C.int(pbd.BitsPerSample),
C.int(pbd.Width),
C.int(pbd.Height),
C.int(pbd.RowStride),
nil, nil)
return &Pixbuf{
GdkPixbuf: &GdkPixbuf{gpixbuf},
GObject: glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
}
} | [
"func",
"NewPixbufFromData",
"(",
"pbd",
"PixbufData",
")",
"*",
"Pixbuf",
"{",
"gpixbuf",
":=",
"C",
".",
"gdk_pixbuf_new_from_data",
"(",
"C",
".",
"to_gucharptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"pbd",
".",
"Data",
"[",
"0",
"]",
")",
")",
",",
"C",
".",
"GdkColorspace",
"(",
"pbd",
".",
"Colorspace",
")",
",",
"gbool",
"(",
"pbd",
".",
"HasAlpha",
")",
",",
"C",
".",
"int",
"(",
"pbd",
".",
"BitsPerSample",
")",
",",
"C",
".",
"int",
"(",
"pbd",
".",
"Width",
")",
",",
"C",
".",
"int",
"(",
"pbd",
".",
"Height",
")",
",",
"C",
".",
"int",
"(",
"pbd",
".",
"RowStride",
")",
",",
"nil",
",",
"nil",
")",
"\n",
"return",
"&",
"Pixbuf",
"{",
"GdkPixbuf",
":",
"&",
"GdkPixbuf",
"{",
"gpixbuf",
"}",
",",
"GObject",
":",
"glib",
".",
"ObjectFromNative",
"(",
"unsafe",
".",
"Pointer",
"(",
"gpixbuf",
")",
")",
",",
"}",
"\n",
"}"
] | // NewPixbufFromData creates a Pixbuf from image data in a byte array | [
"NewPixbufFromData",
"creates",
"a",
"Pixbuf",
"from",
"image",
"data",
"in",
"a",
"byte",
"array"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gdkpixbuf/gdkpixbuf.go#L155-L169 |
148,448 | mattn/go-gtk | gdkpixbuf/gdkpixbuf.go | Save | func (p *Pixbuf) Save(filename, savetype string, options ...string) *glib.Error {
if len(options)%2 != 0 {
argumentPanic("Save options must be even (key and value)")
}
pfilename := C.CString(filename)
defer cfree(pfilename)
psavetype := C.CString(savetype)
defer cfree(psavetype)
klen := len(options) / 2
keys := C.makeCstrv(C.int(klen + 1))
vals := C.makeCstrv(C.int(klen + 1))
for i := 0; i < klen; i++ {
C.setCstr(keys, C.int(i), C.CString(options[2*i]))
C.setCstr(vals, C.int(i), C.CString(options[2*i+1]))
}
C.setCstr(keys, C.int(klen), nil)
C.setCstr(vals, C.int(klen), nil)
defer func() {
for i := 0; i < klen; i++ {
cfree(C.getCstr(keys, C.int(i)))
cfree(C.getCstr(vals, C.int(i)))
}
C.freeCstrv(keys)
C.freeCstrv(vals)
}()
var err *C.GError
C.gdk_pixbuf_savev(p.GPixbuf, pfilename, psavetype, keys, vals, &err)
if err != nil {
return glib.ErrorFromNative(unsafe.Pointer(err))
}
return nil
} | go | func (p *Pixbuf) Save(filename, savetype string, options ...string) *glib.Error {
if len(options)%2 != 0 {
argumentPanic("Save options must be even (key and value)")
}
pfilename := C.CString(filename)
defer cfree(pfilename)
psavetype := C.CString(savetype)
defer cfree(psavetype)
klen := len(options) / 2
keys := C.makeCstrv(C.int(klen + 1))
vals := C.makeCstrv(C.int(klen + 1))
for i := 0; i < klen; i++ {
C.setCstr(keys, C.int(i), C.CString(options[2*i]))
C.setCstr(vals, C.int(i), C.CString(options[2*i+1]))
}
C.setCstr(keys, C.int(klen), nil)
C.setCstr(vals, C.int(klen), nil)
defer func() {
for i := 0; i < klen; i++ {
cfree(C.getCstr(keys, C.int(i)))
cfree(C.getCstr(vals, C.int(i)))
}
C.freeCstrv(keys)
C.freeCstrv(vals)
}()
var err *C.GError
C.gdk_pixbuf_savev(p.GPixbuf, pfilename, psavetype, keys, vals, &err)
if err != nil {
return glib.ErrorFromNative(unsafe.Pointer(err))
}
return nil
} | [
"func",
"(",
"p",
"*",
"Pixbuf",
")",
"Save",
"(",
"filename",
",",
"savetype",
"string",
",",
"options",
"...",
"string",
")",
"*",
"glib",
".",
"Error",
"{",
"if",
"len",
"(",
"options",
")",
"%",
"2",
"!=",
"0",
"{",
"argumentPanic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"pfilename",
":=",
"C",
".",
"CString",
"(",
"filename",
")",
"\n",
"defer",
"cfree",
"(",
"pfilename",
")",
"\n",
"psavetype",
":=",
"C",
".",
"CString",
"(",
"savetype",
")",
"\n",
"defer",
"cfree",
"(",
"psavetype",
")",
"\n\n",
"klen",
":=",
"len",
"(",
"options",
")",
"/",
"2",
"\n",
"keys",
":=",
"C",
".",
"makeCstrv",
"(",
"C",
".",
"int",
"(",
"klen",
"+",
"1",
")",
")",
"\n",
"vals",
":=",
"C",
".",
"makeCstrv",
"(",
"C",
".",
"int",
"(",
"klen",
"+",
"1",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"klen",
";",
"i",
"++",
"{",
"C",
".",
"setCstr",
"(",
"keys",
",",
"C",
".",
"int",
"(",
"i",
")",
",",
"C",
".",
"CString",
"(",
"options",
"[",
"2",
"*",
"i",
"]",
")",
")",
"\n",
"C",
".",
"setCstr",
"(",
"vals",
",",
"C",
".",
"int",
"(",
"i",
")",
",",
"C",
".",
"CString",
"(",
"options",
"[",
"2",
"*",
"i",
"+",
"1",
"]",
")",
")",
"\n",
"}",
"\n",
"C",
".",
"setCstr",
"(",
"keys",
",",
"C",
".",
"int",
"(",
"klen",
")",
",",
"nil",
")",
"\n",
"C",
".",
"setCstr",
"(",
"vals",
",",
"C",
".",
"int",
"(",
"klen",
")",
",",
"nil",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"klen",
";",
"i",
"++",
"{",
"cfree",
"(",
"C",
".",
"getCstr",
"(",
"keys",
",",
"C",
".",
"int",
"(",
"i",
")",
")",
")",
"\n",
"cfree",
"(",
"C",
".",
"getCstr",
"(",
"vals",
",",
"C",
".",
"int",
"(",
"i",
")",
")",
")",
"\n",
"}",
"\n",
"C",
".",
"freeCstrv",
"(",
"keys",
")",
"\n",
"C",
".",
"freeCstrv",
"(",
"vals",
")",
"\n",
"}",
"(",
")",
"\n\n",
"var",
"err",
"*",
"C",
".",
"GError",
"\n",
"C",
".",
"gdk_pixbuf_savev",
"(",
"p",
".",
"GPixbuf",
",",
"pfilename",
",",
"psavetype",
",",
"keys",
",",
"vals",
",",
"&",
"err",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"glib",
".",
"ErrorFromNative",
"(",
"unsafe",
".",
"Pointer",
"(",
"err",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // gdk_pixbuf_get_byte_length
// gdk_pixbuf_get_option
// File saving | [
"gdk_pixbuf_get_byte_length",
"gdk_pixbuf_get_option",
"File",
"saving"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gdkpixbuf/gdkpixbuf.go#L368-L402 |
148,449 | mattn/go-gtk | glib/glib.go | toSlice | func toSlice(ar **C.gchar) []string {
result := make([]string, 0)
for i := 0; ; i++ {
str := C.GoString(C.to_charptr(*ar))
if str == "" {
break
}
result = append(result, str)
*ar = C.next_string(*ar)
}
return result
} | go | func toSlice(ar **C.gchar) []string {
result := make([]string, 0)
for i := 0; ; i++ {
str := C.GoString(C.to_charptr(*ar))
if str == "" {
break
}
result = append(result, str)
*ar = C.next_string(*ar)
}
return result
} | [
"func",
"toSlice",
"(",
"ar",
"*",
"*",
"C",
".",
"gchar",
")",
"[",
"]",
"string",
"{",
"result",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n",
"for",
"i",
":=",
"0",
";",
";",
"i",
"++",
"{",
"str",
":=",
"C",
".",
"GoString",
"(",
"C",
".",
"to_charptr",
"(",
"*",
"ar",
")",
")",
"\n",
"if",
"str",
"==",
"\"",
"\"",
"{",
"break",
"\n",
"}",
"\n",
"result",
"=",
"append",
"(",
"result",
",",
"str",
")",
"\n",
"*",
"ar",
"=",
"C",
".",
"next_string",
"(",
"*",
"ar",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // converts a C string array to a Go string slice | [
"converts",
"a",
"C",
"string",
"array",
"to",
"a",
"Go",
"string",
"slice"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/glib/glib.go#L73-L84 |
148,450 | mattn/go-gtk | gio/gio.go | NewGFileForPath | func NewGFileForPath(filename string) *GFile {
ptrFilename := C.CString(filename)
defer cfree(ptrFilename)
return &GFile{C.g_file_new_for_path(ptrFilename)}
} | go | func NewGFileForPath(filename string) *GFile {
ptrFilename := C.CString(filename)
defer cfree(ptrFilename)
return &GFile{C.g_file_new_for_path(ptrFilename)}
} | [
"func",
"NewGFileForPath",
"(",
"filename",
"string",
")",
"*",
"GFile",
"{",
"ptrFilename",
":=",
"C",
".",
"CString",
"(",
"filename",
")",
"\n",
"defer",
"cfree",
"(",
"ptrFilename",
")",
"\n\n",
"return",
"&",
"GFile",
"{",
"C",
".",
"g_file_new_for_path",
"(",
"ptrFilename",
")",
"}",
"\n",
"}"
] | // NewGFileForPath is g_file_new_for_path | [
"NewGFileForPath",
"is",
"g_file_new_for_path"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gio/gio.go#L25-L30 |
148,451 | mattn/go-gtk | gio/gio.go | NewGFileForURI | func NewGFileForURI(uriFilename string) *GFile {
ptrFilename := C.CString(uriFilename)
defer cfree(ptrFilename)
return &GFile{C.g_file_new_for_uri(ptrFilename)}
} | go | func NewGFileForURI(uriFilename string) *GFile {
ptrFilename := C.CString(uriFilename)
defer cfree(ptrFilename)
return &GFile{C.g_file_new_for_uri(ptrFilename)}
} | [
"func",
"NewGFileForURI",
"(",
"uriFilename",
"string",
")",
"*",
"GFile",
"{",
"ptrFilename",
":=",
"C",
".",
"CString",
"(",
"uriFilename",
")",
"\n",
"defer",
"cfree",
"(",
"ptrFilename",
")",
"\n\n",
"return",
"&",
"GFile",
"{",
"C",
".",
"g_file_new_for_uri",
"(",
"ptrFilename",
")",
"}",
"\n",
"}"
] | // NewGFileForURI is g_file_new_for_uri | [
"NewGFileForURI",
"is",
"g_file_new_for_uri"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gio/gio.go#L33-L38 |
148,452 | mattn/go-gtk | gio/gio.go | QueryInfo | func (f *GFile) QueryInfo(attributes string, flags GFileQueryInfoFlags) (*GFileInfo, error) {
ptr := C.CString(attributes)
defer cfree(ptr)
var gerror *C.GError
gfileinfo := C.g_file_query_info(
f.GFile,
ptr,
C.GFileQueryInfoFlags(flags),
nil, // nil is GCancellable, not yet implemented
&gerror,
)
if gerror != nil {
return nil, glib.ErrorFromNative(unsafe.Pointer(gerror))
}
return &GFileInfo{gfileinfo}, nil
} | go | func (f *GFile) QueryInfo(attributes string, flags GFileQueryInfoFlags) (*GFileInfo, error) {
ptr := C.CString(attributes)
defer cfree(ptr)
var gerror *C.GError
gfileinfo := C.g_file_query_info(
f.GFile,
ptr,
C.GFileQueryInfoFlags(flags),
nil, // nil is GCancellable, not yet implemented
&gerror,
)
if gerror != nil {
return nil, glib.ErrorFromNative(unsafe.Pointer(gerror))
}
return &GFileInfo{gfileinfo}, nil
} | [
"func",
"(",
"f",
"*",
"GFile",
")",
"QueryInfo",
"(",
"attributes",
"string",
",",
"flags",
"GFileQueryInfoFlags",
")",
"(",
"*",
"GFileInfo",
",",
"error",
")",
"{",
"ptr",
":=",
"C",
".",
"CString",
"(",
"attributes",
")",
"\n",
"defer",
"cfree",
"(",
"ptr",
")",
"\n\n",
"var",
"gerror",
"*",
"C",
".",
"GError",
"\n\n",
"gfileinfo",
":=",
"C",
".",
"g_file_query_info",
"(",
"f",
".",
"GFile",
",",
"ptr",
",",
"C",
".",
"GFileQueryInfoFlags",
"(",
"flags",
")",
",",
"nil",
",",
"// nil is GCancellable, not yet implemented",
"&",
"gerror",
",",
")",
"\n",
"if",
"gerror",
"!=",
"nil",
"{",
"return",
"nil",
",",
"glib",
".",
"ErrorFromNative",
"(",
"unsafe",
".",
"Pointer",
"(",
"gerror",
")",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"GFileInfo",
"{",
"gfileinfo",
"}",
",",
"nil",
"\n",
"}"
] | // QueryInfo is g_file_query_info | [
"QueryInfo",
"is",
"g_file_query_info"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gio/gio.go#L48-L66 |
148,453 | mattn/go-gtk | gio/gio.go | GetPath | func (f *GFile) GetPath() string {
return gostring(gstring(C.g_file_get_path(f.GFile)))
} | go | func (f *GFile) GetPath() string {
return gostring(gstring(C.g_file_get_path(f.GFile)))
} | [
"func",
"(",
"f",
"*",
"GFile",
")",
"GetPath",
"(",
")",
"string",
"{",
"return",
"gostring",
"(",
"gstring",
"(",
"C",
".",
"g_file_get_path",
"(",
"f",
".",
"GFile",
")",
")",
")",
"\n",
"}"
] | // GetPath is `g_file_get_path`, return real, absolute, canonical path. It might contain symlinks. | [
"GetPath",
"is",
"g_file_get_path",
"return",
"real",
"absolute",
"canonical",
"path",
".",
"It",
"might",
"contain",
"symlinks",
"."
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gio/gio.go#L69-L71 |
148,454 | mattn/go-gtk | gtk/gtk.go | stringArray2Native | func stringArray2Native(ss []string) **C.gchar {
css := C.make_strings(C.int(len(ss) + 1))
for i, s := range ss {
ptr := C.CString(s)
C.set_string(css, C.int(i), gstring(ptr))
}
C.set_string(css, C.int(len(ss)), nil)
return css
} | go | func stringArray2Native(ss []string) **C.gchar {
css := C.make_strings(C.int(len(ss) + 1))
for i, s := range ss {
ptr := C.CString(s)
C.set_string(css, C.int(i), gstring(ptr))
}
C.set_string(css, C.int(len(ss)), nil)
return css
} | [
"func",
"stringArray2Native",
"(",
"ss",
"[",
"]",
"string",
")",
"*",
"*",
"C",
".",
"gchar",
"{",
"css",
":=",
"C",
".",
"make_strings",
"(",
"C",
".",
"int",
"(",
"len",
"(",
"ss",
")",
"+",
"1",
")",
")",
"\n",
"for",
"i",
",",
"s",
":=",
"range",
"ss",
"{",
"ptr",
":=",
"C",
".",
"CString",
"(",
"s",
")",
"\n",
"C",
".",
"set_string",
"(",
"css",
",",
"C",
".",
"int",
"(",
"i",
")",
",",
"gstring",
"(",
"ptr",
")",
")",
"\n",
"}",
"\n",
"C",
".",
"set_string",
"(",
"css",
",",
"C",
".",
"int",
"(",
"len",
"(",
"ss",
")",
")",
",",
"nil",
")",
"\n",
"return",
"css",
"\n",
"}"
] | // use C.g_strfreev to free the result | [
"use",
"C",
".",
"g_strfreev",
"to",
"free",
"the",
"result"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L250-L258 |
148,455 | mattn/go-gtk | gtk/gtk.go | Init | func Init(args *[]string) {
if args != nil {
argc := C.int(len(*args))
argv := C.make_strings(argc)
defer C.destroy_strings(argv)
for i, arg := range *args {
cstr := C.CString(arg)
C.set_string(argv, C.int(i), (*C.gchar)(cstr))
}
C.gtk_init((*C.int)(unsafe.Pointer(&argc)),
(***C.char)(unsafe.Pointer(&argv)))
unhandled := make([]string, argc)
for i := 0; i < int(argc); i++ {
cstr := C.get_string(argv, C.int(i))
unhandled[i] = C.GoString((*C.char)(cstr))
C.free(unsafe.Pointer(cstr))
}
*args = unhandled
} else {
C.gtk_init(nil, nil)
}
} | go | func Init(args *[]string) {
if args != nil {
argc := C.int(len(*args))
argv := C.make_strings(argc)
defer C.destroy_strings(argv)
for i, arg := range *args {
cstr := C.CString(arg)
C.set_string(argv, C.int(i), (*C.gchar)(cstr))
}
C.gtk_init((*C.int)(unsafe.Pointer(&argc)),
(***C.char)(unsafe.Pointer(&argv)))
unhandled := make([]string, argc)
for i := 0; i < int(argc); i++ {
cstr := C.get_string(argv, C.int(i))
unhandled[i] = C.GoString((*C.char)(cstr))
C.free(unsafe.Pointer(cstr))
}
*args = unhandled
} else {
C.gtk_init(nil, nil)
}
} | [
"func",
"Init",
"(",
"args",
"*",
"[",
"]",
"string",
")",
"{",
"if",
"args",
"!=",
"nil",
"{",
"argc",
":=",
"C",
".",
"int",
"(",
"len",
"(",
"*",
"args",
")",
")",
"\n",
"argv",
":=",
"C",
".",
"make_strings",
"(",
"argc",
")",
"\n",
"defer",
"C",
".",
"destroy_strings",
"(",
"argv",
")",
"\n\n",
"for",
"i",
",",
"arg",
":=",
"range",
"*",
"args",
"{",
"cstr",
":=",
"C",
".",
"CString",
"(",
"arg",
")",
"\n",
"C",
".",
"set_string",
"(",
"argv",
",",
"C",
".",
"int",
"(",
"i",
")",
",",
"(",
"*",
"C",
".",
"gchar",
")",
"(",
"cstr",
")",
")",
"\n",
"}",
"\n\n",
"C",
".",
"gtk_init",
"(",
"(",
"*",
"C",
".",
"int",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"argc",
")",
")",
",",
"(",
"*",
"*",
"*",
"C",
".",
"char",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"argv",
")",
")",
")",
"\n\n",
"unhandled",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"argc",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"int",
"(",
"argc",
")",
";",
"i",
"++",
"{",
"cstr",
":=",
"C",
".",
"get_string",
"(",
"argv",
",",
"C",
".",
"int",
"(",
"i",
")",
")",
"\n",
"unhandled",
"[",
"i",
"]",
"=",
"C",
".",
"GoString",
"(",
"(",
"*",
"C",
".",
"char",
")",
"(",
"cstr",
")",
")",
"\n",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cstr",
")",
")",
"\n",
"}",
"\n",
"*",
"args",
"=",
"unhandled",
"\n",
"}",
"else",
"{",
"C",
".",
"gtk_init",
"(",
"nil",
",",
"nil",
")",
"\n",
"}",
"\n",
"}"
] | // gtk_disable_setlocale
// gtk_get_default_language
// gtk_parse_args | [
"gtk_disable_setlocale",
"gtk_get_default_language",
"gtk_parse_args"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L274-L298 |
148,456 | mattn/go-gtk | gtk/gtk.go | AcceleratorParse | func AcceleratorParse(accelerator string) (uint, gdk.ModifierType) {
ptrn := C.CString(accelerator)
defer cfree(ptrn)
var key C.guint
var mods C.GdkModifierType
C.gtk_accelerator_parse(gstring(ptrn), &key, &mods)
return uint(key), gdk.ModifierType(mods)
} | go | func AcceleratorParse(accelerator string) (uint, gdk.ModifierType) {
ptrn := C.CString(accelerator)
defer cfree(ptrn)
var key C.guint
var mods C.GdkModifierType
C.gtk_accelerator_parse(gstring(ptrn), &key, &mods)
return uint(key), gdk.ModifierType(mods)
} | [
"func",
"AcceleratorParse",
"(",
"accelerator",
"string",
")",
"(",
"uint",
",",
"gdk",
".",
"ModifierType",
")",
"{",
"ptrn",
":=",
"C",
".",
"CString",
"(",
"accelerator",
")",
"\n",
"defer",
"cfree",
"(",
"ptrn",
")",
"\n\n",
"var",
"key",
"C",
".",
"guint",
"\n",
"var",
"mods",
"C",
".",
"GdkModifierType",
"\n",
"C",
".",
"gtk_accelerator_parse",
"(",
"gstring",
"(",
"ptrn",
")",
",",
"&",
"key",
",",
"&",
"mods",
")",
"\n",
"return",
"uint",
"(",
"key",
")",
",",
"gdk",
".",
"ModifierType",
"(",
"mods",
")",
"\n",
"}"
] | // gtk_accel_group_connect
// gtk_accel_group_connect_by_path
// gtk_accel_group_disconnect
// gtk_accel_group_disconnect_key
// gtk_accel_group_query
// gtk_accel_group_activate
// gtk_accel_group_lock
// gtk_accel_group_unlock
// gtk_accel_group_from_accel_closure
// gtk_accel_groups_activate
// gtk_accel_groups_from_object
// gtk_accel_group_find
// gtk_accelerator_valid
// Parse string representing an accelerator
// and return the key code and the modifier masks. | [
"gtk_accel_group_connect",
"gtk_accel_group_connect_by_path",
"gtk_accel_group_disconnect",
"gtk_accel_group_disconnect_key",
"gtk_accel_group_query",
"gtk_accel_group_activate",
"gtk_accel_group_lock",
"gtk_accel_group_unlock",
"gtk_accel_group_from_accel_closure",
"gtk_accel_groups_activate",
"gtk_accel_groups_from_object",
"gtk_accel_group_find",
"gtk_accelerator_valid",
"Parse",
"string",
"representing",
"an",
"accelerator",
"and",
"return",
"the",
"key",
"code",
"and",
"the",
"modifier",
"masks",
"."
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L370-L378 |
148,457 | mattn/go-gtk | gtk/gtk.go | LookupByGIcon | func (it *IconTheme) LookupByGIcon(icon *gio.GIcon, width int) *IconInfo {
return &IconInfo{C.gtk_icon_theme_lookup_by_gicon(
it.GtkIconTheme,
(*C.GIcon)(unsafe.Pointer(icon.GIcon)),
gint(width),
C.GtkIconLookupFlags(IconLookupUseBuiltin),
)}
} | go | func (it *IconTheme) LookupByGIcon(icon *gio.GIcon, width int) *IconInfo {
return &IconInfo{C.gtk_icon_theme_lookup_by_gicon(
it.GtkIconTheme,
(*C.GIcon)(unsafe.Pointer(icon.GIcon)),
gint(width),
C.GtkIconLookupFlags(IconLookupUseBuiltin),
)}
} | [
"func",
"(",
"it",
"*",
"IconTheme",
")",
"LookupByGIcon",
"(",
"icon",
"*",
"gio",
".",
"GIcon",
",",
"width",
"int",
")",
"*",
"IconInfo",
"{",
"return",
"&",
"IconInfo",
"{",
"C",
".",
"gtk_icon_theme_lookup_by_gicon",
"(",
"it",
".",
"GtkIconTheme",
",",
"(",
"*",
"C",
".",
"GIcon",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"icon",
".",
"GIcon",
")",
")",
",",
"gint",
"(",
"width",
")",
",",
"C",
".",
"GtkIconLookupFlags",
"(",
"IconLookupUseBuiltin",
")",
",",
")",
"}",
"\n",
"}"
] | // gtk_icon_theme_lookup_icon
// gtk_icon_theme_choose_icon
// gtk_icon_theme_lookup_by_gicon | [
"gtk_icon_theme_lookup_icon",
"gtk_icon_theme_choose_icon",
"gtk_icon_theme_lookup_by_gicon"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L605-L613 |
148,458 | mattn/go-gtk | gtk/gtk.go | LoadIcon | func (ii *IconInfo) LoadIcon() (*gdkpixbuf.GdkPixbuf, error) {
var gerror *C.GError
pixbuf := C.gtk_icon_info_load_icon(ii.GtkIconInfo, &gerror)
if gerror != nil {
return nil, glib.ErrorFromNative(unsafe.Pointer(gerror))
}
return gdkpixbuf.NewGdkPixbuf(unsafe.Pointer(pixbuf)), nil
} | go | func (ii *IconInfo) LoadIcon() (*gdkpixbuf.GdkPixbuf, error) {
var gerror *C.GError
pixbuf := C.gtk_icon_info_load_icon(ii.GtkIconInfo, &gerror)
if gerror != nil {
return nil, glib.ErrorFromNative(unsafe.Pointer(gerror))
}
return gdkpixbuf.NewGdkPixbuf(unsafe.Pointer(pixbuf)), nil
} | [
"func",
"(",
"ii",
"*",
"IconInfo",
")",
"LoadIcon",
"(",
")",
"(",
"*",
"gdkpixbuf",
".",
"GdkPixbuf",
",",
"error",
")",
"{",
"var",
"gerror",
"*",
"C",
".",
"GError",
"\n",
"pixbuf",
":=",
"C",
".",
"gtk_icon_info_load_icon",
"(",
"ii",
".",
"GtkIconInfo",
",",
"&",
"gerror",
")",
"\n\n",
"if",
"gerror",
"!=",
"nil",
"{",
"return",
"nil",
",",
"glib",
".",
"ErrorFromNative",
"(",
"unsafe",
".",
"Pointer",
"(",
"gerror",
")",
")",
"\n",
"}",
"\n\n",
"return",
"gdkpixbuf",
".",
"NewGdkPixbuf",
"(",
"unsafe",
".",
"Pointer",
"(",
"pixbuf",
")",
")",
",",
"nil",
"\n",
"}"
] | // gtk_icon_info_copy
// gtk_icon_info_free
// gtk_icon_info_new_for_pixbuf
// gtk_icon_info_get_base_size
// gtk_icon_info_get_filename
// gtk_icon_info_get_builtin_pixbuf
// gtk_icon_info_load_icon | [
"gtk_icon_info_copy",
"gtk_icon_info_free",
"gtk_icon_info_new_for_pixbuf",
"gtk_icon_info_get_base_size",
"gtk_icon_info_get_filename",
"gtk_icon_info_get_builtin_pixbuf",
"gtk_icon_info_load_icon"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L634-L643 |
148,459 | mattn/go-gtk | gtk/gtk.go | ToGObject | func (s *Settings) ToGObject() *glib.GObject {
return &glib.GObject{unsafe.Pointer(s.GSettings)}
} | go | func (s *Settings) ToGObject() *glib.GObject {
return &glib.GObject{unsafe.Pointer(s.GSettings)}
} | [
"func",
"(",
"s",
"*",
"Settings",
")",
"ToGObject",
"(",
")",
"*",
"glib",
".",
"GObject",
"{",
"return",
"&",
"glib",
".",
"GObject",
"{",
"unsafe",
".",
"Pointer",
"(",
"s",
".",
"GSettings",
")",
"}",
"\n",
"}"
] | // gtk_settings_install_property
// gtk_settings_install_property_parser
// gtk_rc_property_parse_color
// gtk_rc_property_parse_enum
// gtk_rc_property_parse_flags
// gtk_rc_property_parse_requisition
// gtk_rc_property_parse_border
// gtk_settings_set_property_value | [
"gtk_settings_install_property",
"gtk_settings_install_property_parser",
"gtk_rc_property_parse_color",
"gtk_rc_property_parse_enum",
"gtk_rc_property_parse_flags",
"gtk_rc_property_parse_requisition",
"gtk_rc_property_parse_border",
"gtk_settings_set_property_value"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L913-L915 |
148,460 | mattn/go-gtk | gtk/gtk.go | GetHasSeparator | func (v *Dialog) GetHasSeparator() bool {
deprecated_since(2, 22, 0, "gtk_dialog_get_has_separator()")
return gobool(C.gtk_dialog_get_has_separator(DIALOG(v)))
} | go | func (v *Dialog) GetHasSeparator() bool {
deprecated_since(2, 22, 0, "gtk_dialog_get_has_separator()")
return gobool(C.gtk_dialog_get_has_separator(DIALOG(v)))
} | [
"func",
"(",
"v",
"*",
"Dialog",
")",
"GetHasSeparator",
"(",
")",
"bool",
"{",
"deprecated_since",
"(",
"2",
",",
"22",
",",
"0",
",",
"\"",
"\"",
")",
"\n",
"return",
"gobool",
"(",
"C",
".",
"gtk_dialog_get_has_separator",
"(",
"DIALOG",
"(",
"v",
")",
")",
")",
"\n",
"}"
] | // gtk_dialog_add_buttons
// gtk_dialog_add_action_widget
//Deprecated since 2.22. | [
"gtk_dialog_add_buttons",
"gtk_dialog_add_action_widget",
"Deprecated",
"since",
"2",
".",
"22",
"."
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L1257-L1260 |
148,461 | mattn/go-gtk | gtk/gtk.go | SetHasSeparator | func (v *Dialog) SetHasSeparator(f bool) {
deprecated_since(2, 22, 0, "gtk_dialog_set_has_separator()")
C.gtk_dialog_set_has_separator(DIALOG(v), gbool(f))
} | go | func (v *Dialog) SetHasSeparator(f bool) {
deprecated_since(2, 22, 0, "gtk_dialog_set_has_separator()")
C.gtk_dialog_set_has_separator(DIALOG(v), gbool(f))
} | [
"func",
"(",
"v",
"*",
"Dialog",
")",
"SetHasSeparator",
"(",
"f",
"bool",
")",
"{",
"deprecated_since",
"(",
"2",
",",
"22",
",",
"0",
",",
"\"",
"\"",
")",
"\n",
"C",
".",
"gtk_dialog_set_has_separator",
"(",
"DIALOG",
"(",
"v",
")",
",",
"gbool",
"(",
"f",
")",
")",
"\n",
"}"
] | //Deprecated since 2.22. | [
"Deprecated",
"since",
"2",
".",
"22",
"."
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L1263-L1266 |
148,462 | mattn/go-gtk | gtk/gtk.go | GetVBox | func (v *Dialog) GetVBox() *VBox {
return &VBox{Box{Container{Widget{C._gtk_dialog_get_vbox(v.GWidget)}}}}
} | go | func (v *Dialog) GetVBox() *VBox {
return &VBox{Box{Container{Widget{C._gtk_dialog_get_vbox(v.GWidget)}}}}
} | [
"func",
"(",
"v",
"*",
"Dialog",
")",
"GetVBox",
"(",
")",
"*",
"VBox",
"{",
"return",
"&",
"VBox",
"{",
"Box",
"{",
"Container",
"{",
"Widget",
"{",
"C",
".",
"_gtk_dialog_get_vbox",
"(",
"v",
".",
"GWidget",
")",
"}",
"}",
"}",
"}",
"\n",
"}"
] | // gtk_alternative_dialog_button_order
// gtk_dialog_set_alternative_button_order
// gtk_dialog_set_alternative_button_order_from_array | [
"gtk_alternative_dialog_button_order",
"gtk_dialog_set_alternative_button_order",
"gtk_dialog_set_alternative_button_order_from_array"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L1296-L1298 |
148,463 | mattn/go-gtk | gtk/gtk.go | SetDefault | func (v *Window) SetDefault(w *Widget) {
C.gtk_window_set_default(WINDOW(v), w.GWidget)
} | go | func (v *Window) SetDefault(w *Widget) {
C.gtk_window_set_default(WINDOW(v), w.GWidget)
} | [
"func",
"(",
"v",
"*",
"Window",
")",
"SetDefault",
"(",
"w",
"*",
"Widget",
")",
"{",
"C",
".",
"gtk_window_set_default",
"(",
"WINDOW",
"(",
"v",
")",
",",
"w",
".",
"GWidget",
")",
"\n",
"}"
] | // gtk_window_add_mnemonic
// gtk_window_remove_mnemonic
// gtk_window_mnemonic_activate
// gtk_window_activate_key
// gtk_window_propagate_key_event
// gtk_window_get_focus
// gtk_window_set_focus
// gtk_window_get_default_widget | [
"gtk_window_add_mnemonic",
"gtk_window_remove_mnemonic",
"gtk_window_mnemonic_activate",
"gtk_window_activate_key",
"gtk_window_propagate_key_event",
"gtk_window_get_focus",
"gtk_window_set_focus",
"gtk_window_get_default_widget"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L1502-L1504 |
148,464 | mattn/go-gtk | gtk/gtk.go | GetDefaultSize | func (v *Window) GetDefaultSize() (width int, height int) {
var cwidth, cheight C.gint
C.gtk_window_get_default_size(WINDOW(v), &cwidth, &cheight)
return int(cwidth), int(cheight)
} | go | func (v *Window) GetDefaultSize() (width int, height int) {
var cwidth, cheight C.gint
C.gtk_window_get_default_size(WINDOW(v), &cwidth, &cheight)
return int(cwidth), int(cheight)
} | [
"func",
"(",
"v",
"*",
"Window",
")",
"GetDefaultSize",
"(",
")",
"(",
"width",
"int",
",",
"height",
"int",
")",
"{",
"var",
"cwidth",
",",
"cheight",
"C",
".",
"gint",
"\n",
"C",
".",
"gtk_window_get_default_size",
"(",
"WINDOW",
"(",
"v",
")",
",",
"&",
"cwidth",
",",
"&",
"cheight",
")",
"\n",
"return",
"int",
"(",
"cwidth",
")",
",",
"int",
"(",
"cheight",
")",
"\n",
"}"
] | // gtk_window_set_focus_on_map
// gtk_window_set_startup_id
// gtk_window_set_role
// gtk_window_get_decorated
// gtk_window_get_deletable
// gtk_window_get_default_icon_list
// gtk_window_get_default_icon_name | [
"gtk_window_set_focus_on_map",
"gtk_window_set_startup_id",
"gtk_window_set_role",
"gtk_window_get_decorated",
"gtk_window_get_deletable",
"gtk_window_get_default_icon_list",
"gtk_window_get_default_icon_name"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L1588-L1592 |
148,465 | mattn/go-gtk | gtk/gtk.go | SetIcon | func (v *Window) SetIcon(icon *gdkpixbuf.Pixbuf) {
C.gtk_window_set_icon(WINDOW(v), (*C.GdkPixbuf)(unsafe.Pointer(icon.GPixbuf)))
} | go | func (v *Window) SetIcon(icon *gdkpixbuf.Pixbuf) {
C.gtk_window_set_icon(WINDOW(v), (*C.GdkPixbuf)(unsafe.Pointer(icon.GPixbuf)))
} | [
"func",
"(",
"v",
"*",
"Window",
")",
"SetIcon",
"(",
"icon",
"*",
"gdkpixbuf",
".",
"Pixbuf",
")",
"{",
"C",
".",
"gtk_window_set_icon",
"(",
"WINDOW",
"(",
"v",
")",
",",
"(",
"*",
"C",
".",
"GdkPixbuf",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"icon",
".",
"GPixbuf",
")",
")",
")",
"\n",
"}"
] | // gtk_window_set_default_icon_list
// gtk_window_set_default_icon
// gtk_window_set_default_icon_from_file
// gtk_window_set_default_icon_name | [
"gtk_window_set_default_icon_list",
"gtk_window_set_default_icon",
"gtk_window_set_default_icon_from_file",
"gtk_window_set_default_icon_name"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L1667-L1669 |
148,466 | mattn/go-gtk | gtk/gtk.go | ForwardSearch | func (v *TextIter) ForwardSearch(str string, flags TextSearchFlags, start *TextIter, end *TextIter, limit *TextIter) bool {
cstr := C.CString(str)
defer cfree(cstr)
return gobool(C.gtk_text_iter_forward_search(&v.GTextIter, gstring(cstr), C.GtkTextSearchFlags(flags),
&start.GTextIter, &end.GTextIter, &limit.GTextIter))
} | go | func (v *TextIter) ForwardSearch(str string, flags TextSearchFlags, start *TextIter, end *TextIter, limit *TextIter) bool {
cstr := C.CString(str)
defer cfree(cstr)
return gobool(C.gtk_text_iter_forward_search(&v.GTextIter, gstring(cstr), C.GtkTextSearchFlags(flags),
&start.GTextIter, &end.GTextIter, &limit.GTextIter))
} | [
"func",
"(",
"v",
"*",
"TextIter",
")",
"ForwardSearch",
"(",
"str",
"string",
",",
"flags",
"TextSearchFlags",
",",
"start",
"*",
"TextIter",
",",
"end",
"*",
"TextIter",
",",
"limit",
"*",
"TextIter",
")",
"bool",
"{",
"cstr",
":=",
"C",
".",
"CString",
"(",
"str",
")",
"\n",
"defer",
"cfree",
"(",
"cstr",
")",
"\n",
"return",
"gobool",
"(",
"C",
".",
"gtk_text_iter_forward_search",
"(",
"&",
"v",
".",
"GTextIter",
",",
"gstring",
"(",
"cstr",
")",
",",
"C",
".",
"GtkTextSearchFlags",
"(",
"flags",
")",
",",
"&",
"start",
".",
"GTextIter",
",",
"&",
"end",
".",
"GTextIter",
",",
"&",
"limit",
".",
"GTextIter",
")",
")",
"\n",
"}"
] | // gtk_text_iter_forward_line
// gtk_text_iter_backward_line
// gtk_text_iter_forward_lines
// gtk_text_iter_backward_lines
// gtk_text_iter_forward_word_ends
// gtk_text_iter_backward_word_starts
// gtk_text_iter_forward_word_end
// gtk_text_iter_backward_word_start
// gtk_text_iter_forward_cursor_position
// gtk_text_iter_backward_cursor_position
// gtk_text_iter_forward_cursor_positions
// gtk_text_iter_backward_cursor_positions
// gtk_text_iter_backward_sentence_start
// gtk_text_iter_backward_sentence_starts
// gtk_text_iter_forward_sentence_end
// gtk_text_iter_forward_sentence_ends
// gtk_text_iter_forward_visible_word_ends
// gtk_text_iter_backward_visible_word_starts
// gtk_text_iter_forward_visible_word_end
// gtk_text_iter_backward_visible_word_start
// gtk_text_iter_forward_visible_cursor_position
// gtk_text_iter_backward_visible_cursor_position
// gtk_text_iter_forward_visible_cursor_positions
// gtk_text_iter_backward_visible_cursor_positions
// gtk_text_iter_forward_visible_line
// gtk_text_iter_backward_visible_line
// gtk_text_iter_forward_visible_lines
// gtk_text_iter_backward_visible_lines
// gtk_text_iter_set_offset
// gtk_text_iter_set_line
// gtk_text_iter_set_line_offset
// gtk_text_iter_set_line_index
// gtk_text_iter_set_visible_line_index
// gtk_text_iter_set_visible_line_offset
// gtk_text_iter_forward_to_end
// gtk_text_iter_forward_to_line_end
// gtk_text_iter_forward_to_tag_toggle
// gtk_text_iter_backward_to_tag_toggle
// gtk_text_iter_forward_find_char
// gtk_text_iter_backward_find_char | [
"gtk_text_iter_forward_line",
"gtk_text_iter_backward_line",
"gtk_text_iter_forward_lines",
"gtk_text_iter_backward_lines",
"gtk_text_iter_forward_word_ends",
"gtk_text_iter_backward_word_starts",
"gtk_text_iter_forward_word_end",
"gtk_text_iter_backward_word_start",
"gtk_text_iter_forward_cursor_position",
"gtk_text_iter_backward_cursor_position",
"gtk_text_iter_forward_cursor_positions",
"gtk_text_iter_backward_cursor_positions",
"gtk_text_iter_backward_sentence_start",
"gtk_text_iter_backward_sentence_starts",
"gtk_text_iter_forward_sentence_end",
"gtk_text_iter_forward_sentence_ends",
"gtk_text_iter_forward_visible_word_ends",
"gtk_text_iter_backward_visible_word_starts",
"gtk_text_iter_forward_visible_word_end",
"gtk_text_iter_backward_visible_word_start",
"gtk_text_iter_forward_visible_cursor_position",
"gtk_text_iter_backward_visible_cursor_position",
"gtk_text_iter_forward_visible_cursor_positions",
"gtk_text_iter_backward_visible_cursor_positions",
"gtk_text_iter_forward_visible_line",
"gtk_text_iter_backward_visible_line",
"gtk_text_iter_forward_visible_lines",
"gtk_text_iter_backward_visible_lines",
"gtk_text_iter_set_offset",
"gtk_text_iter_set_line",
"gtk_text_iter_set_line_offset",
"gtk_text_iter_set_line_index",
"gtk_text_iter_set_visible_line_index",
"gtk_text_iter_set_visible_line_offset",
"gtk_text_iter_forward_to_end",
"gtk_text_iter_forward_to_line_end",
"gtk_text_iter_forward_to_tag_toggle",
"gtk_text_iter_backward_to_tag_toggle",
"gtk_text_iter_forward_find_char",
"gtk_text_iter_backward_find_char"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L3964-L3969 |
148,467 | mattn/go-gtk | gtk/gtk.go | Assign | func (v *TextIter) Assign(iter *TextIter) {
C._gtk_text_iter_assign(&v.GTextIter, &iter.GTextIter)
} | go | func (v *TextIter) Assign(iter *TextIter) {
C._gtk_text_iter_assign(&v.GTextIter, &iter.GTextIter)
} | [
"func",
"(",
"v",
"*",
"TextIter",
")",
"Assign",
"(",
"iter",
"*",
"TextIter",
")",
"{",
"C",
".",
"_gtk_text_iter_assign",
"(",
"&",
"v",
".",
"GTextIter",
",",
"&",
"iter",
".",
"GTextIter",
")",
"\n",
"}"
] | // gtk_text_iter_equal
// gtk_text_iter_compare
// gtk_text_iter_in_range
// gtk_text_iter_order | [
"gtk_text_iter_equal",
"gtk_text_iter_compare",
"gtk_text_iter_in_range",
"gtk_text_iter_order"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L3983-L3985 |
148,468 | mattn/go-gtk | gtk/gtk.go | GetSelectionBounds | func (v *TextBuffer) GetSelectionBounds(be, en *TextIter) bool {
return gobool(C.gtk_text_buffer_get_selection_bounds(v.GTextBuffer, &be.GTextIter, &en.GTextIter))
} | go | func (v *TextBuffer) GetSelectionBounds(be, en *TextIter) bool {
return gobool(C.gtk_text_buffer_get_selection_bounds(v.GTextBuffer, &be.GTextIter, &en.GTextIter))
} | [
"func",
"(",
"v",
"*",
"TextBuffer",
")",
"GetSelectionBounds",
"(",
"be",
",",
"en",
"*",
"TextIter",
")",
"bool",
"{",
"return",
"gobool",
"(",
"C",
".",
"gtk_text_buffer_get_selection_bounds",
"(",
"v",
".",
"GTextBuffer",
",",
"&",
"be",
".",
"GTextIter",
",",
"&",
"en",
".",
"GTextIter",
")",
")",
"\n",
"}"
] | // gtk_text_buffer_paste_clipboard
// gtk_text_buffer_copy_clipboard
// gtk_text_buffer_cut_clipboard | [
"gtk_text_buffer_paste_clipboard",
"gtk_text_buffer_copy_clipboard",
"gtk_text_buffer_cut_clipboard"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L4283-L4285 |
148,469 | mattn/go-gtk | gtk/gtk.go | RemoveColumn | func (v *TreeView) RemoveColumn(c *TreeViewColumn) int {
return int(C.gtk_tree_view_remove_column(TREE_VIEW(v), c.GTreeViewColumn))
} | go | func (v *TreeView) RemoveColumn(c *TreeViewColumn) int {
return int(C.gtk_tree_view_remove_column(TREE_VIEW(v), c.GTreeViewColumn))
} | [
"func",
"(",
"v",
"*",
"TreeView",
")",
"RemoveColumn",
"(",
"c",
"*",
"TreeViewColumn",
")",
"int",
"{",
"return",
"int",
"(",
"C",
".",
"gtk_tree_view_remove_column",
"(",
"TREE_VIEW",
"(",
"v",
")",
",",
"c",
".",
"GTreeViewColumn",
")",
")",
"\n",
"}"
] | // Remove column from TreeView and return number of existing columns | [
"Remove",
"column",
"from",
"TreeView",
"and",
"return",
"number",
"of",
"existing",
"columns"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L5217-L5219 |
148,470 | mattn/go-gtk | gtk/gtk.go | GetActiveText | func (v *ComboBox) GetActiveText() string {
deprecated_since(2, 24, 0, "gtk_combo_box_get_active_text()")
return gostring(C.gtk_combo_box_get_active_text(COMBO_BOX(v)))
} | go | func (v *ComboBox) GetActiveText() string {
deprecated_since(2, 24, 0, "gtk_combo_box_get_active_text()")
return gostring(C.gtk_combo_box_get_active_text(COMBO_BOX(v)))
} | [
"func",
"(",
"v",
"*",
"ComboBox",
")",
"GetActiveText",
"(",
")",
"string",
"{",
"deprecated_since",
"(",
"2",
",",
"24",
",",
"0",
",",
"\"",
"\"",
")",
"\n",
"return",
"gostring",
"(",
"C",
".",
"gtk_combo_box_get_active_text",
"(",
"COMBO_BOX",
"(",
"v",
")",
")",
")",
"\n",
"}"
] | //Deprecated since 2.24. Use GtkComboBoxText or, if combo box contains an entry,
// get text directly from GtkEntry. | [
"Deprecated",
"since",
"2",
".",
"24",
".",
"Use",
"GtkComboBoxText",
"or",
"if",
"combo",
"box",
"contains",
"an",
"entry",
"get",
"text",
"directly",
"from",
"GtkEntry",
"."
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L6156-L6159 |
148,471 | mattn/go-gtk | gtk/gtk.go | SetAddTearoffs | func (v *ComboBox) SetAddTearoffs(add_tearoffs bool) {
C.gtk_combo_box_set_add_tearoffs(COMBO_BOX(v), gbool(add_tearoffs))
} | go | func (v *ComboBox) SetAddTearoffs(add_tearoffs bool) {
C.gtk_combo_box_set_add_tearoffs(COMBO_BOX(v), gbool(add_tearoffs))
} | [
"func",
"(",
"v",
"*",
"ComboBox",
")",
"SetAddTearoffs",
"(",
"add_tearoffs",
"bool",
")",
"{",
"C",
".",
"gtk_combo_box_set_add_tearoffs",
"(",
"COMBO_BOX",
"(",
"v",
")",
",",
"gbool",
"(",
"add_tearoffs",
")",
")",
"\n",
"}"
] | // gtk_combo_box_get_popup_accessible
// gtk_combo_box_get_row_separator_func
// gtk_combo_box_set_row_separator_func | [
"gtk_combo_box_get_popup_accessible",
"gtk_combo_box_get_row_separator_func",
"gtk_combo_box_set_row_separator_func"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L6173-L6175 |
148,472 | mattn/go-gtk | gtk/gtk.go | SetGroup | func (v *RadioMenuItem) SetGroup(group *glib.SList) {
C.gtk_radio_menu_item_set_group(RADIO_MENU_ITEM(v), gslist(group))
} | go | func (v *RadioMenuItem) SetGroup(group *glib.SList) {
C.gtk_radio_menu_item_set_group(RADIO_MENU_ITEM(v), gslist(group))
} | [
"func",
"(",
"v",
"*",
"RadioMenuItem",
")",
"SetGroup",
"(",
"group",
"*",
"glib",
".",
"SList",
")",
"{",
"C",
".",
"gtk_radio_menu_item_set_group",
"(",
"RADIO_MENU_ITEM",
"(",
"v",
")",
",",
"gslist",
"(",
"group",
")",
")",
"\n",
"}"
] | // gtk_radio_menu_item_new_with_mnemonic
// gtk_radio_menu_item_new_from_widget
// gtk_radio_menu_item_new_with_label_from_widget
// gtk_radio_menu_item_new_with_mnemonic_from_widget
// gtk_radio_menu_item_group | [
"gtk_radio_menu_item_new_with_mnemonic",
"gtk_radio_menu_item_new_from_widget",
"gtk_radio_menu_item_new_with_label_from_widget",
"gtk_radio_menu_item_new_with_mnemonic_from_widget",
"gtk_radio_menu_item_group"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L6606-L6608 |
148,473 | mattn/go-gtk | gtk/gtk.go | SelectFilename | func (v *FileChooser) SelectFilename(filename string) bool {
ptr := C.CString(filename)
defer cfree(ptr)
return gobool(C.gtk_file_chooser_select_filename(v.GFileChooser, ptr))
} | go | func (v *FileChooser) SelectFilename(filename string) bool {
ptr := C.CString(filename)
defer cfree(ptr)
return gobool(C.gtk_file_chooser_select_filename(v.GFileChooser, ptr))
} | [
"func",
"(",
"v",
"*",
"FileChooser",
")",
"SelectFilename",
"(",
"filename",
"string",
")",
"bool",
"{",
"ptr",
":=",
"C",
".",
"CString",
"(",
"filename",
")",
"\n",
"defer",
"cfree",
"(",
"ptr",
")",
"\n",
"return",
"gobool",
"(",
"C",
".",
"gtk_file_chooser_select_filename",
"(",
"v",
".",
"GFileChooser",
",",
"ptr",
")",
")",
"\n",
"}"
] | // GTK doc said the return value is "Not useful". | [
"GTK",
"doc",
"said",
"the",
"return",
"value",
"is",
"Not",
"useful",
"."
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L8113-L8117 |
148,474 | mattn/go-gtk | gtk/gtk.go | Configure | func (v *Adjustment) Configure(value, lower, upper, step_increment, page_increment, page_size float64) {
panic_if_version_older(2, 14, 0, "gtk_adjustment_configure()")
C._gtk_adjustment_configure(v.GAdjustment, gdouble(value), gdouble(lower), gdouble(upper),
gdouble(step_increment), gdouble(page_increment), gdouble(page_size))
} | go | func (v *Adjustment) Configure(value, lower, upper, step_increment, page_increment, page_size float64) {
panic_if_version_older(2, 14, 0, "gtk_adjustment_configure()")
C._gtk_adjustment_configure(v.GAdjustment, gdouble(value), gdouble(lower), gdouble(upper),
gdouble(step_increment), gdouble(page_increment), gdouble(page_size))
} | [
"func",
"(",
"v",
"*",
"Adjustment",
")",
"Configure",
"(",
"value",
",",
"lower",
",",
"upper",
",",
"step_increment",
",",
"page_increment",
",",
"page_size",
"float64",
")",
"{",
"panic_if_version_older",
"(",
"2",
",",
"14",
",",
"0",
",",
"\"",
"\"",
")",
"\n",
"C",
".",
"_gtk_adjustment_configure",
"(",
"v",
".",
"GAdjustment",
",",
"gdouble",
"(",
"value",
")",
",",
"gdouble",
"(",
"lower",
")",
",",
"gdouble",
"(",
"upper",
")",
",",
"gdouble",
"(",
"step_increment",
")",
",",
"gdouble",
"(",
"page_increment",
")",
",",
"gdouble",
"(",
"page_size",
")",
")",
"\n",
"}"
] | // gtk_adjustment_clamp_page
// gtk_adjustment_changed
// gtk_adjustment_value_changed | [
"gtk_adjustment_clamp_page",
"gtk_adjustment_changed",
"gtk_adjustment_value_changed"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L9687-L9691 |
148,475 | mattn/go-gtk | gtk/gtk.go | NewArrow | func NewArrow(at ArrowType, st ShadowType) *Arrow {
return &Arrow{Widget{C.gtk_arrow_new(C.GtkArrowType(at), C.GtkShadowType(st))}}
} | go | func NewArrow(at ArrowType, st ShadowType) *Arrow {
return &Arrow{Widget{C.gtk_arrow_new(C.GtkArrowType(at), C.GtkShadowType(st))}}
} | [
"func",
"NewArrow",
"(",
"at",
"ArrowType",
",",
"st",
"ShadowType",
")",
"*",
"Arrow",
"{",
"return",
"&",
"Arrow",
"{",
"Widget",
"{",
"C",
".",
"gtk_arrow_new",
"(",
"C",
".",
"GtkArrowType",
"(",
"at",
")",
",",
"C",
".",
"GtkShadowType",
"(",
"st",
")",
")",
"}",
"}",
"\n",
"}"
] | // Draw arrowhead facing in given direction with a shadow.
// Like gtk.Label it does not emit signals. | [
"Draw",
"arrowhead",
"facing",
"in",
"given",
"direction",
"with",
"a",
"shadow",
".",
"Like",
"gtk",
".",
"Label",
"it",
"does",
"not",
"emit",
"signals",
"."
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L9767-L9769 |
148,476 | mattn/go-gtk | gtk/gtk.go | Set | func (a *Arrow) Set(at ArrowType, st ShadowType) {
C.gtk_arrow_set(ARROW(a), C.GtkArrowType(at), C.GtkShadowType(st))
} | go | func (a *Arrow) Set(at ArrowType, st ShadowType) {
C.gtk_arrow_set(ARROW(a), C.GtkArrowType(at), C.GtkShadowType(st))
} | [
"func",
"(",
"a",
"*",
"Arrow",
")",
"Set",
"(",
"at",
"ArrowType",
",",
"st",
"ShadowType",
")",
"{",
"C",
".",
"gtk_arrow_set",
"(",
"ARROW",
"(",
"a",
")",
",",
"C",
".",
"GtkArrowType",
"(",
"at",
")",
",",
"C",
".",
"GtkShadowType",
"(",
"st",
")",
")",
"\n",
"}"
] | // Change the arrows direction and shadow. | [
"Change",
"the",
"arrows",
"direction",
"and",
"shadow",
"."
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L9772-L9774 |
148,477 | mattn/go-gtk | gtk/gtk.go | EventBoxFromObject | func EventBoxFromObject(object *glib.GObject) *EventBox {
return &EventBox{Bin{Container{Widget{C.toGWidget(object.Object)}}}}
} | go | func EventBoxFromObject(object *glib.GObject) *EventBox {
return &EventBox{Bin{Container{Widget{C.toGWidget(object.Object)}}}}
} | [
"func",
"EventBoxFromObject",
"(",
"object",
"*",
"glib",
".",
"GObject",
")",
"*",
"EventBox",
"{",
"return",
"&",
"EventBox",
"{",
"Bin",
"{",
"Container",
"{",
"Widget",
"{",
"C",
".",
"toGWidget",
"(",
"object",
".",
"Object",
")",
"}",
"}",
"}",
"}",
"\n",
"}"
] | //add by xtlx2000 | [
"add",
"by",
"xtlx2000"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L9827-L9829 |
148,478 | mattn/go-gtk | gtk/gtk.go | ChildSet | func (v *Container) ChildSet(w IWidget, propName string, value interface{}) {
ptr := C.CString(propName)
defer cfree(ptr)
switch value.(type) {
case bool:
C._gtk_container_child_set_bool(CONTAINER(v), ToNative(w), gstring(ptr), gbool(value.(bool)))
case int:
C._gtk_container_child_set_int(CONTAINER(v), ToNative(w), gstring(ptr), gint(value.(int)))
}
} | go | func (v *Container) ChildSet(w IWidget, propName string, value interface{}) {
ptr := C.CString(propName)
defer cfree(ptr)
switch value.(type) {
case bool:
C._gtk_container_child_set_bool(CONTAINER(v), ToNative(w), gstring(ptr), gbool(value.(bool)))
case int:
C._gtk_container_child_set_int(CONTAINER(v), ToNative(w), gstring(ptr), gint(value.(int)))
}
} | [
"func",
"(",
"v",
"*",
"Container",
")",
"ChildSet",
"(",
"w",
"IWidget",
",",
"propName",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"ptr",
":=",
"C",
".",
"CString",
"(",
"propName",
")",
"\n",
"defer",
"cfree",
"(",
"ptr",
")",
"\n\n",
"switch",
"value",
".",
"(",
"type",
")",
"{",
"case",
"bool",
":",
"C",
".",
"_gtk_container_child_set_bool",
"(",
"CONTAINER",
"(",
"v",
")",
",",
"ToNative",
"(",
"w",
")",
",",
"gstring",
"(",
"ptr",
")",
",",
"gbool",
"(",
"value",
".",
"(",
"bool",
")",
")",
")",
"\n",
"case",
"int",
":",
"C",
".",
"_gtk_container_child_set_int",
"(",
"CONTAINER",
"(",
"v",
")",
",",
"ToNative",
"(",
"w",
")",
",",
"gstring",
"(",
"ptr",
")",
",",
"gint",
"(",
"value",
".",
"(",
"int",
")",
")",
")",
"\n",
"}",
"\n",
"}"
] | // gtk_container_resize_children
// gtk_container_child_type
// gtk_container_child_get | [
"gtk_container_resize_children",
"gtk_container_child_type",
"gtk_container_child_get"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L10211-L10222 |
148,479 | mattn/go-gtk | gtk/gtk.go | AddAccelerator | func (v *Widget) AddAccelerator(signal string, group *AccelGroup, key uint, mods gdk.ModifierType, flags AccelFlags) {
csignal := C.CString(signal)
defer cfree(csignal)
C.gtk_widget_add_accelerator(v.GWidget, gstring(csignal), group.GAccelGroup, guint(key),
C.GdkModifierType(mods), C.GtkAccelFlags(flags))
} | go | func (v *Widget) AddAccelerator(signal string, group *AccelGroup, key uint, mods gdk.ModifierType, flags AccelFlags) {
csignal := C.CString(signal)
defer cfree(csignal)
C.gtk_widget_add_accelerator(v.GWidget, gstring(csignal), group.GAccelGroup, guint(key),
C.GdkModifierType(mods), C.GtkAccelFlags(flags))
} | [
"func",
"(",
"v",
"*",
"Widget",
")",
"AddAccelerator",
"(",
"signal",
"string",
",",
"group",
"*",
"AccelGroup",
",",
"key",
"uint",
",",
"mods",
"gdk",
".",
"ModifierType",
",",
"flags",
"AccelFlags",
")",
"{",
"csignal",
":=",
"C",
".",
"CString",
"(",
"signal",
")",
"\n",
"defer",
"cfree",
"(",
"csignal",
")",
"\n",
"C",
".",
"gtk_widget_add_accelerator",
"(",
"v",
".",
"GWidget",
",",
"gstring",
"(",
"csignal",
")",
",",
"group",
".",
"GAccelGroup",
",",
"guint",
"(",
"key",
")",
",",
"C",
".",
"GdkModifierType",
"(",
"mods",
")",
",",
"C",
".",
"GtkAccelFlags",
"(",
"flags",
")",
")",
"\n",
"}"
] | // gtk_widget_size_request
// gtk_widget_get_child_requisition
// gtk_widget_size_allocate | [
"gtk_widget_size_request",
"gtk_widget_get_child_requisition",
"gtk_widget_size_allocate"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L10718-L10723 |
148,480 | mattn/go-gtk | gtk/gtk.go | CanActivateAccel | func (v *Widget) CanActivateAccel(signal_id uint) bool {
return gobool(C.gtk_widget_can_activate_accel(v.GWidget, guint(signal_id)))
} | go | func (v *Widget) CanActivateAccel(signal_id uint) bool {
return gobool(C.gtk_widget_can_activate_accel(v.GWidget, guint(signal_id)))
} | [
"func",
"(",
"v",
"*",
"Widget",
")",
"CanActivateAccel",
"(",
"signal_id",
"uint",
")",
"bool",
"{",
"return",
"gobool",
"(",
"C",
".",
"gtk_widget_can_activate_accel",
"(",
"v",
".",
"GWidget",
",",
"guint",
"(",
"signal_id",
")",
")",
")",
"\n",
"}"
] | // gtk_widget_remove_accelerator
// gtk_widget_set_accel_path
// gtk_widget_list_accel_closures | [
"gtk_widget_remove_accelerator",
"gtk_widget_set_accel_path",
"gtk_widget_list_accel_closures"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L10729-L10731 |
148,481 | mattn/go-gtk | gtk/gtk.go | GetPangoContext | func (v *Widget) GetPangoContext() *pango.Context {
return pango.ContextFromUnsafe(unsafe.Pointer(C.gtk_widget_get_pango_context((*C.GtkWidget)(v.GWidget))))
} | go | func (v *Widget) GetPangoContext() *pango.Context {
return pango.ContextFromUnsafe(unsafe.Pointer(C.gtk_widget_get_pango_context((*C.GtkWidget)(v.GWidget))))
} | [
"func",
"(",
"v",
"*",
"Widget",
")",
"GetPangoContext",
"(",
")",
"*",
"pango",
".",
"Context",
"{",
"return",
"pango",
".",
"ContextFromUnsafe",
"(",
"unsafe",
".",
"Pointer",
"(",
"C",
".",
"gtk_widget_get_pango_context",
"(",
"(",
"*",
"C",
".",
"GtkWidget",
")",
"(",
"v",
".",
"GWidget",
")",
")",
")",
")",
"\n",
"}"
] | // gtk_widget_reset_rc_styles
// gtk_widget_push_colormap
// gtk_widget_pop_colormap
// gtk_widget_set_default_colormap
// gtk_widget_get_default_style
// gtk_widget_get_default_colormap
// gtk_widget_get_default_visual
// gtk_widget_set_direction
// gtk_widget_get_direction
// gtk_widget_set_default_direction
// gtk_widget_get_default_direction
// gtk_widget_shape_combine_mask
// gtk_widget_input_shape_combine_mask
// gtk_widget_path
// gtk_widget_class_path
// gtk_widget_get_composite_name
// gtk_widget_modify_style
// gtk_widget_get_modifier_style
// gtk_widget_modify_text
// gtk_widget_modify_base
// gtk_widget_modify_cursor
// gtk_widget_create_pango_context
// gtk_widget_get_pango_context | [
"gtk_widget_reset_rc_styles",
"gtk_widget_push_colormap",
"gtk_widget_pop_colormap",
"gtk_widget_set_default_colormap",
"gtk_widget_get_default_style",
"gtk_widget_get_default_colormap",
"gtk_widget_get_default_visual",
"gtk_widget_set_direction",
"gtk_widget_get_direction",
"gtk_widget_set_default_direction",
"gtk_widget_get_default_direction",
"gtk_widget_shape_combine_mask",
"gtk_widget_input_shape_combine_mask",
"gtk_widget_path",
"gtk_widget_class_path",
"gtk_widget_get_composite_name",
"gtk_widget_modify_style",
"gtk_widget_get_modifier_style",
"gtk_widget_modify_text",
"gtk_widget_modify_base",
"gtk_widget_modify_cursor",
"gtk_widget_create_pango_context",
"gtk_widget_get_pango_context"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L10856-L10858 |
148,482 | mattn/go-gtk | gtk/gtk.go | GetSizeRequest | func (v *Widget) GetSizeRequest() (width int, height int) {
var w, h C.gint
C.gtk_widget_get_size_request(v.GWidget, &w, &h)
return int(w), int(h)
} | go | func (v *Widget) GetSizeRequest() (width int, height int) {
var w, h C.gint
C.gtk_widget_get_size_request(v.GWidget, &w, &h)
return int(w), int(h)
} | [
"func",
"(",
"v",
"*",
"Widget",
")",
"GetSizeRequest",
"(",
")",
"(",
"width",
"int",
",",
"height",
"int",
")",
"{",
"var",
"w",
",",
"h",
"C",
".",
"gint",
"\n",
"C",
".",
"gtk_widget_get_size_request",
"(",
"v",
".",
"GWidget",
",",
"&",
"w",
",",
"&",
"h",
")",
"\n",
"return",
"int",
"(",
"w",
")",
",",
"int",
"(",
"h",
")",
"\n",
"}"
] | // gtk_widget_get_clipboard
// gtk_widget_get_display
// gtk_widget_get_root_window
// gtk_widget_get_screen
// gtk_widget_has_screen | [
"gtk_widget_get_clipboard",
"gtk_widget_get_display",
"gtk_widget_get_root_window",
"gtk_widget_get_screen",
"gtk_widget_has_screen"
] | 4deadb416788be678fb9cac22ea76dba83c946b0 | https://github.com/mattn/go-gtk/blob/4deadb416788be678fb9cac22ea76dba83c946b0/gtk/gtk.go#L10938-L10942 |
148,483 | tjfoc/gmsm | sm2/pkcs7.go | UnmarshalSignedAttribute | func (p7 *PKCS7) UnmarshalSignedAttribute(attributeType asn1.ObjectIdentifier, out interface{}) error {
sd, ok := p7.raw.(signedData)
if !ok {
return errors.New("pkcs7: payload is not signedData content")
}
if len(sd.SignerInfos) < 1 {
return errors.New("pkcs7: payload has no signers")
}
attributes := sd.SignerInfos[0].AuthenticatedAttributes
return unmarshalAttribute(attributes, attributeType, out)
} | go | func (p7 *PKCS7) UnmarshalSignedAttribute(attributeType asn1.ObjectIdentifier, out interface{}) error {
sd, ok := p7.raw.(signedData)
if !ok {
return errors.New("pkcs7: payload is not signedData content")
}
if len(sd.SignerInfos) < 1 {
return errors.New("pkcs7: payload has no signers")
}
attributes := sd.SignerInfos[0].AuthenticatedAttributes
return unmarshalAttribute(attributes, attributeType, out)
} | [
"func",
"(",
"p7",
"*",
"PKCS7",
")",
"UnmarshalSignedAttribute",
"(",
"attributeType",
"asn1",
".",
"ObjectIdentifier",
",",
"out",
"interface",
"{",
"}",
")",
"error",
"{",
"sd",
",",
"ok",
":=",
"p7",
".",
"raw",
".",
"(",
"signedData",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"sd",
".",
"SignerInfos",
")",
"<",
"1",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"attributes",
":=",
"sd",
".",
"SignerInfos",
"[",
"0",
"]",
".",
"AuthenticatedAttributes",
"\n",
"return",
"unmarshalAttribute",
"(",
"attributes",
",",
"attributeType",
",",
"out",
")",
"\n",
"}"
] | // UnmarshalSignedAttribute decodes a single attribute from the signer info | [
"UnmarshalSignedAttribute",
"decodes",
"a",
"single",
"attribute",
"from",
"the",
"signer",
"info"
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm2/pkcs7.go#L518-L528 |
148,484 | tjfoc/gmsm | sm2/pkcs7.go | NewSignedData | func NewSignedData(data []byte) (*SignedData, error) {
content, err := asn1.Marshal(data)
if err != nil {
return nil, err
}
ci := contentInfo{
ContentType: oidData,
Content: asn1.RawValue{Class: 2, Tag: 0, Bytes: content, IsCompound: true},
}
digAlg := pkix.AlgorithmIdentifier{
Algorithm: oidDigestAlgorithmSHA1,
}
h := crypto.SHA1.New()
h.Write(data)
md := h.Sum(nil)
sd := signedData{
ContentInfo: ci,
Version: 1,
DigestAlgorithmIdentifiers: []pkix.AlgorithmIdentifier{digAlg},
}
return &SignedData{sd: sd, messageDigest: md}, nil
} | go | func NewSignedData(data []byte) (*SignedData, error) {
content, err := asn1.Marshal(data)
if err != nil {
return nil, err
}
ci := contentInfo{
ContentType: oidData,
Content: asn1.RawValue{Class: 2, Tag: 0, Bytes: content, IsCompound: true},
}
digAlg := pkix.AlgorithmIdentifier{
Algorithm: oidDigestAlgorithmSHA1,
}
h := crypto.SHA1.New()
h.Write(data)
md := h.Sum(nil)
sd := signedData{
ContentInfo: ci,
Version: 1,
DigestAlgorithmIdentifiers: []pkix.AlgorithmIdentifier{digAlg},
}
return &SignedData{sd: sd, messageDigest: md}, nil
} | [
"func",
"NewSignedData",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"SignedData",
",",
"error",
")",
"{",
"content",
",",
"err",
":=",
"asn1",
".",
"Marshal",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ci",
":=",
"contentInfo",
"{",
"ContentType",
":",
"oidData",
",",
"Content",
":",
"asn1",
".",
"RawValue",
"{",
"Class",
":",
"2",
",",
"Tag",
":",
"0",
",",
"Bytes",
":",
"content",
",",
"IsCompound",
":",
"true",
"}",
",",
"}",
"\n",
"digAlg",
":=",
"pkix",
".",
"AlgorithmIdentifier",
"{",
"Algorithm",
":",
"oidDigestAlgorithmSHA1",
",",
"}",
"\n",
"h",
":=",
"crypto",
".",
"SHA1",
".",
"New",
"(",
")",
"\n",
"h",
".",
"Write",
"(",
"data",
")",
"\n",
"md",
":=",
"h",
".",
"Sum",
"(",
"nil",
")",
"\n",
"sd",
":=",
"signedData",
"{",
"ContentInfo",
":",
"ci",
",",
"Version",
":",
"1",
",",
"DigestAlgorithmIdentifiers",
":",
"[",
"]",
"pkix",
".",
"AlgorithmIdentifier",
"{",
"digAlg",
"}",
",",
"}",
"\n",
"return",
"&",
"SignedData",
"{",
"sd",
":",
"sd",
",",
"messageDigest",
":",
"md",
"}",
",",
"nil",
"\n",
"}"
] | // NewSignedData initializes a SignedData with content | [
"NewSignedData",
"initializes",
"a",
"SignedData",
"with",
"content"
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm2/pkcs7.go#L550-L571 |
148,485 | tjfoc/gmsm | sm2/pkcs7.go | Add | func (attrs *attributes) Add(attrType asn1.ObjectIdentifier, value interface{}) {
attrs.types = append(attrs.types, attrType)
attrs.values = append(attrs.values, value)
} | go | func (attrs *attributes) Add(attrType asn1.ObjectIdentifier, value interface{}) {
attrs.types = append(attrs.types, attrType)
attrs.values = append(attrs.values, value)
} | [
"func",
"(",
"attrs",
"*",
"attributes",
")",
"Add",
"(",
"attrType",
"asn1",
".",
"ObjectIdentifier",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"attrs",
".",
"types",
"=",
"append",
"(",
"attrs",
".",
"types",
",",
"attrType",
")",
"\n",
"attrs",
".",
"values",
"=",
"append",
"(",
"attrs",
".",
"values",
",",
"value",
")",
"\n",
"}"
] | // Add adds the attribute, maintaining insertion order | [
"Add",
"adds",
"the",
"attribute",
"maintaining",
"insertion",
"order"
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm2/pkcs7.go#L579-L582 |
148,486 | tjfoc/gmsm | sm2/pkcs7.go | Finish | func (sd *SignedData) Finish() ([]byte, error) {
sd.sd.Certificates = marshalCertificates(sd.certs)
inner, err := asn1.Marshal(sd.sd)
if err != nil {
return nil, err
}
outer := contentInfo{
ContentType: oidSignedData,
Content: asn1.RawValue{Class: 2, Tag: 0, Bytes: inner, IsCompound: true},
}
return asn1.Marshal(outer)
} | go | func (sd *SignedData) Finish() ([]byte, error) {
sd.sd.Certificates = marshalCertificates(sd.certs)
inner, err := asn1.Marshal(sd.sd)
if err != nil {
return nil, err
}
outer := contentInfo{
ContentType: oidSignedData,
Content: asn1.RawValue{Class: 2, Tag: 0, Bytes: inner, IsCompound: true},
}
return asn1.Marshal(outer)
} | [
"func",
"(",
"sd",
"*",
"SignedData",
")",
"Finish",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"sd",
".",
"sd",
".",
"Certificates",
"=",
"marshalCertificates",
"(",
"sd",
".",
"certs",
")",
"\n",
"inner",
",",
"err",
":=",
"asn1",
".",
"Marshal",
"(",
"sd",
".",
"sd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"outer",
":=",
"contentInfo",
"{",
"ContentType",
":",
"oidSignedData",
",",
"Content",
":",
"asn1",
".",
"RawValue",
"{",
"Class",
":",
"2",
",",
"Tag",
":",
"0",
",",
"Bytes",
":",
"inner",
",",
"IsCompound",
":",
"true",
"}",
",",
"}",
"\n",
"return",
"asn1",
".",
"Marshal",
"(",
"outer",
")",
"\n",
"}"
] | // Finish marshals the content and its signers | [
"Finish",
"marshals",
"the",
"content",
"and",
"its",
"signers"
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm2/pkcs7.go#L686-L697 |
148,487 | tjfoc/gmsm | sm2/pkcs7.go | signAttributes | func signAttributes(attrs []attribute, pkey crypto.PrivateKey, hash crypto.Hash) ([]byte, error) {
attrBytes, err := marshalAttributes(attrs)
if err != nil {
return nil, err
}
h := hash.New()
h.Write(attrBytes)
hashed := h.Sum(nil)
switch priv := pkey.(type) {
case *rsa.PrivateKey:
return rsa.SignPKCS1v15(rand.Reader, priv, crypto.SHA1, hashed)
}
return nil, ErrPKCS7UnsupportedAlgorithm
} | go | func signAttributes(attrs []attribute, pkey crypto.PrivateKey, hash crypto.Hash) ([]byte, error) {
attrBytes, err := marshalAttributes(attrs)
if err != nil {
return nil, err
}
h := hash.New()
h.Write(attrBytes)
hashed := h.Sum(nil)
switch priv := pkey.(type) {
case *rsa.PrivateKey:
return rsa.SignPKCS1v15(rand.Reader, priv, crypto.SHA1, hashed)
}
return nil, ErrPKCS7UnsupportedAlgorithm
} | [
"func",
"signAttributes",
"(",
"attrs",
"[",
"]",
"attribute",
",",
"pkey",
"crypto",
".",
"PrivateKey",
",",
"hash",
"crypto",
".",
"Hash",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"attrBytes",
",",
"err",
":=",
"marshalAttributes",
"(",
"attrs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"h",
":=",
"hash",
".",
"New",
"(",
")",
"\n",
"h",
".",
"Write",
"(",
"attrBytes",
")",
"\n",
"hashed",
":=",
"h",
".",
"Sum",
"(",
"nil",
")",
"\n",
"switch",
"priv",
":=",
"pkey",
".",
"(",
"type",
")",
"{",
"case",
"*",
"rsa",
".",
"PrivateKey",
":",
"return",
"rsa",
".",
"SignPKCS1v15",
"(",
"rand",
".",
"Reader",
",",
"priv",
",",
"crypto",
".",
"SHA1",
",",
"hashed",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"ErrPKCS7UnsupportedAlgorithm",
"\n",
"}"
] | // signs the DER encoded form of the attributes with the private key | [
"signs",
"the",
"DER",
"encoded",
"form",
"of",
"the",
"attributes",
"with",
"the",
"private",
"key"
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm2/pkcs7.go#L710-L723 |
148,488 | tjfoc/gmsm | sm2/pkcs7.go | marshalCertificates | func marshalCertificates(certs []*Certificate) rawCertificates {
var buf bytes.Buffer
for _, cert := range certs {
buf.Write(cert.Raw)
}
rawCerts, _ := marshalCertificateBytes(buf.Bytes())
return rawCerts
} | go | func marshalCertificates(certs []*Certificate) rawCertificates {
var buf bytes.Buffer
for _, cert := range certs {
buf.Write(cert.Raw)
}
rawCerts, _ := marshalCertificateBytes(buf.Bytes())
return rawCerts
} | [
"func",
"marshalCertificates",
"(",
"certs",
"[",
"]",
"*",
"Certificate",
")",
"rawCertificates",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"for",
"_",
",",
"cert",
":=",
"range",
"certs",
"{",
"buf",
".",
"Write",
"(",
"cert",
".",
"Raw",
")",
"\n",
"}",
"\n",
"rawCerts",
",",
"_",
":=",
"marshalCertificateBytes",
"(",
"buf",
".",
"Bytes",
"(",
")",
")",
"\n",
"return",
"rawCerts",
"\n",
"}"
] | // concats and wraps the certificates in the RawValue structure | [
"concats",
"and",
"wraps",
"the",
"certificates",
"in",
"the",
"RawValue",
"structure"
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm2/pkcs7.go#L726-L733 |
148,489 | tjfoc/gmsm | sm2/pkcs7.go | DegenerateCertificate | func DegenerateCertificate(cert []byte) ([]byte, error) {
rawCert, err := marshalCertificateBytes(cert)
if err != nil {
return nil, err
}
emptyContent := contentInfo{ContentType: oidData}
sd := signedData{
Version: 1,
ContentInfo: emptyContent,
Certificates: rawCert,
CRLs: []pkix.CertificateList{},
}
content, err := asn1.Marshal(sd)
if err != nil {
return nil, err
}
signedContent := contentInfo{
ContentType: oidSignedData,
Content: asn1.RawValue{Class: 2, Tag: 0, Bytes: content, IsCompound: true},
}
return asn1.Marshal(signedContent)
} | go | func DegenerateCertificate(cert []byte) ([]byte, error) {
rawCert, err := marshalCertificateBytes(cert)
if err != nil {
return nil, err
}
emptyContent := contentInfo{ContentType: oidData}
sd := signedData{
Version: 1,
ContentInfo: emptyContent,
Certificates: rawCert,
CRLs: []pkix.CertificateList{},
}
content, err := asn1.Marshal(sd)
if err != nil {
return nil, err
}
signedContent := contentInfo{
ContentType: oidSignedData,
Content: asn1.RawValue{Class: 2, Tag: 0, Bytes: content, IsCompound: true},
}
return asn1.Marshal(signedContent)
} | [
"func",
"DegenerateCertificate",
"(",
"cert",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"rawCert",
",",
"err",
":=",
"marshalCertificateBytes",
"(",
"cert",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"emptyContent",
":=",
"contentInfo",
"{",
"ContentType",
":",
"oidData",
"}",
"\n",
"sd",
":=",
"signedData",
"{",
"Version",
":",
"1",
",",
"ContentInfo",
":",
"emptyContent",
",",
"Certificates",
":",
"rawCert",
",",
"CRLs",
":",
"[",
"]",
"pkix",
".",
"CertificateList",
"{",
"}",
",",
"}",
"\n",
"content",
",",
"err",
":=",
"asn1",
".",
"Marshal",
"(",
"sd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"signedContent",
":=",
"contentInfo",
"{",
"ContentType",
":",
"oidSignedData",
",",
"Content",
":",
"asn1",
".",
"RawValue",
"{",
"Class",
":",
"2",
",",
"Tag",
":",
"0",
",",
"Bytes",
":",
"content",
",",
"IsCompound",
":",
"true",
"}",
",",
"}",
"\n",
"return",
"asn1",
".",
"Marshal",
"(",
"signedContent",
")",
"\n",
"}"
] | // DegenerateCertificate creates a signed data structure containing only the
// provided certificate or certificate chain. | [
"DegenerateCertificate",
"creates",
"a",
"signed",
"data",
"structure",
"containing",
"only",
"the",
"provided",
"certificate",
"or",
"certificate",
"chain",
"."
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm2/pkcs7.go#L749-L770 |
148,490 | tjfoc/gmsm | sm2/pkcs1.go | MarshalPKCS1PrivateKey | func MarshalPKCS1PrivateKey(key *rsa.PrivateKey) []byte {
key.Precompute()
version := 0
if len(key.Primes) > 2 {
version = 1
}
priv := pkcs1PrivateKey{
Version: version,
N: key.N,
E: key.PublicKey.E,
D: key.D,
P: key.Primes[0],
Q: key.Primes[1],
Dp: key.Precomputed.Dp,
Dq: key.Precomputed.Dq,
Qinv: key.Precomputed.Qinv,
}
priv.AdditionalPrimes = make([]pkcs1AdditionalRSAPrime, len(key.Precomputed.CRTValues))
for i, values := range key.Precomputed.CRTValues {
priv.AdditionalPrimes[i].Prime = key.Primes[2+i]
priv.AdditionalPrimes[i].Exp = values.Exp
priv.AdditionalPrimes[i].Coeff = values.Coeff
}
b, _ := asn1.Marshal(priv)
return b
} | go | func MarshalPKCS1PrivateKey(key *rsa.PrivateKey) []byte {
key.Precompute()
version := 0
if len(key.Primes) > 2 {
version = 1
}
priv := pkcs1PrivateKey{
Version: version,
N: key.N,
E: key.PublicKey.E,
D: key.D,
P: key.Primes[0],
Q: key.Primes[1],
Dp: key.Precomputed.Dp,
Dq: key.Precomputed.Dq,
Qinv: key.Precomputed.Qinv,
}
priv.AdditionalPrimes = make([]pkcs1AdditionalRSAPrime, len(key.Precomputed.CRTValues))
for i, values := range key.Precomputed.CRTValues {
priv.AdditionalPrimes[i].Prime = key.Primes[2+i]
priv.AdditionalPrimes[i].Exp = values.Exp
priv.AdditionalPrimes[i].Coeff = values.Coeff
}
b, _ := asn1.Marshal(priv)
return b
} | [
"func",
"MarshalPKCS1PrivateKey",
"(",
"key",
"*",
"rsa",
".",
"PrivateKey",
")",
"[",
"]",
"byte",
"{",
"key",
".",
"Precompute",
"(",
")",
"\n\n",
"version",
":=",
"0",
"\n",
"if",
"len",
"(",
"key",
".",
"Primes",
")",
">",
"2",
"{",
"version",
"=",
"1",
"\n",
"}",
"\n\n",
"priv",
":=",
"pkcs1PrivateKey",
"{",
"Version",
":",
"version",
",",
"N",
":",
"key",
".",
"N",
",",
"E",
":",
"key",
".",
"PublicKey",
".",
"E",
",",
"D",
":",
"key",
".",
"D",
",",
"P",
":",
"key",
".",
"Primes",
"[",
"0",
"]",
",",
"Q",
":",
"key",
".",
"Primes",
"[",
"1",
"]",
",",
"Dp",
":",
"key",
".",
"Precomputed",
".",
"Dp",
",",
"Dq",
":",
"key",
".",
"Precomputed",
".",
"Dq",
",",
"Qinv",
":",
"key",
".",
"Precomputed",
".",
"Qinv",
",",
"}",
"\n\n",
"priv",
".",
"AdditionalPrimes",
"=",
"make",
"(",
"[",
"]",
"pkcs1AdditionalRSAPrime",
",",
"len",
"(",
"key",
".",
"Precomputed",
".",
"CRTValues",
")",
")",
"\n",
"for",
"i",
",",
"values",
":=",
"range",
"key",
".",
"Precomputed",
".",
"CRTValues",
"{",
"priv",
".",
"AdditionalPrimes",
"[",
"i",
"]",
".",
"Prime",
"=",
"key",
".",
"Primes",
"[",
"2",
"+",
"i",
"]",
"\n",
"priv",
".",
"AdditionalPrimes",
"[",
"i",
"]",
".",
"Exp",
"=",
"values",
".",
"Exp",
"\n",
"priv",
".",
"AdditionalPrimes",
"[",
"i",
"]",
".",
"Coeff",
"=",
"values",
".",
"Coeff",
"\n",
"}",
"\n\n",
"b",
",",
"_",
":=",
"asn1",
".",
"Marshal",
"(",
"priv",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // MarshalPKCS1PrivateKey converts a private key to ASN.1 DER encoded form. | [
"MarshalPKCS1PrivateKey",
"converts",
"a",
"private",
"key",
"to",
"ASN",
".",
"1",
"DER",
"encoded",
"form",
"."
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm2/pkcs1.go#L97-L126 |
148,491 | tjfoc/gmsm | sm2/p256.go | IsOnCurve | func (curve sm2P256Curve) IsOnCurve(X, Y *big.Int) bool {
var a, x, y, y2, x3 sm2P256FieldElement
sm2P256FromBig(&x, X)
sm2P256FromBig(&y, Y)
sm2P256Square(&x3, &x) // x3 = x ^ 2
sm2P256Mul(&x3, &x3, &x) // x3 = x ^ 2 * x
sm2P256Mul(&a, &curve.a, &x) // a = a * x
sm2P256Add(&x3, &x3, &a)
sm2P256Add(&x3, &x3, &curve.b)
sm2P256Square(&y2, &y) // y2 = y ^ 2
return sm2P256ToBig(&x3).Cmp(sm2P256ToBig(&y2)) == 0
} | go | func (curve sm2P256Curve) IsOnCurve(X, Y *big.Int) bool {
var a, x, y, y2, x3 sm2P256FieldElement
sm2P256FromBig(&x, X)
sm2P256FromBig(&y, Y)
sm2P256Square(&x3, &x) // x3 = x ^ 2
sm2P256Mul(&x3, &x3, &x) // x3 = x ^ 2 * x
sm2P256Mul(&a, &curve.a, &x) // a = a * x
sm2P256Add(&x3, &x3, &a)
sm2P256Add(&x3, &x3, &curve.b)
sm2P256Square(&y2, &y) // y2 = y ^ 2
return sm2P256ToBig(&x3).Cmp(sm2P256ToBig(&y2)) == 0
} | [
"func",
"(",
"curve",
"sm2P256Curve",
")",
"IsOnCurve",
"(",
"X",
",",
"Y",
"*",
"big",
".",
"Int",
")",
"bool",
"{",
"var",
"a",
",",
"x",
",",
"y",
",",
"y2",
",",
"x3",
"sm2P256FieldElement",
"\n\n",
"sm2P256FromBig",
"(",
"&",
"x",
",",
"X",
")",
"\n",
"sm2P256FromBig",
"(",
"&",
"y",
",",
"Y",
")",
"\n\n",
"sm2P256Square",
"(",
"&",
"x3",
",",
"&",
"x",
")",
"// x3 = x ^ 2",
"\n",
"sm2P256Mul",
"(",
"&",
"x3",
",",
"&",
"x3",
",",
"&",
"x",
")",
"// x3 = x ^ 2 * x",
"\n",
"sm2P256Mul",
"(",
"&",
"a",
",",
"&",
"curve",
".",
"a",
",",
"&",
"x",
")",
"// a = a * x",
"\n",
"sm2P256Add",
"(",
"&",
"x3",
",",
"&",
"x3",
",",
"&",
"a",
")",
"\n",
"sm2P256Add",
"(",
"&",
"x3",
",",
"&",
"x3",
",",
"&",
"curve",
".",
"b",
")",
"\n\n",
"sm2P256Square",
"(",
"&",
"y2",
",",
"&",
"y",
")",
"// y2 = y ^ 2",
"\n",
"return",
"sm2P256ToBig",
"(",
"&",
"x3",
")",
".",
"Cmp",
"(",
"sm2P256ToBig",
"(",
"&",
"y2",
")",
")",
"==",
"0",
"\n",
"}"
] | // y^2 = x^3 + ax + b | [
"y^2",
"=",
"x^3",
"+",
"ax",
"+",
"b"
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm2/p256.go#L93-L107 |
148,492 | tjfoc/gmsm | sm2/p256.go | sm2P256GetBit | func sm2P256GetBit(scalar *[32]uint8, bit uint) uint32 {
return uint32(((scalar[bit>>3]) >> (bit & 7)) & 1)
} | go | func sm2P256GetBit(scalar *[32]uint8, bit uint) uint32 {
return uint32(((scalar[bit>>3]) >> (bit & 7)) & 1)
} | [
"func",
"sm2P256GetBit",
"(",
"scalar",
"*",
"[",
"32",
"]",
"uint8",
",",
"bit",
"uint",
")",
"uint32",
"{",
"return",
"uint32",
"(",
"(",
"(",
"scalar",
"[",
"bit",
">>",
"3",
"]",
")",
">>",
"(",
"bit",
"&",
"7",
")",
")",
"&",
"1",
")",
"\n",
"}"
] | // sm2P256GetBit returns the bit'th bit of scalar. | [
"sm2P256GetBit",
"returns",
"the",
"bit",
"th",
"bit",
"of",
"scalar",
"."
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm2/p256.go#L343-L345 |
148,493 | tjfoc/gmsm | sm2/p256.go | sm2P256Add | func sm2P256Add(c, a, b *sm2P256FieldElement) {
carry := uint32(0)
for i := 0; ; i++ {
c[i] = a[i] + b[i]
c[i] += carry
carry = c[i] >> 29
c[i] &= bottom29Bits
i++
if i == 9 {
break
}
c[i] = a[i] + b[i]
c[i] += carry
carry = c[i] >> 28
c[i] &= bottom28Bits
}
sm2P256ReduceCarry(c, carry)
} | go | func sm2P256Add(c, a, b *sm2P256FieldElement) {
carry := uint32(0)
for i := 0; ; i++ {
c[i] = a[i] + b[i]
c[i] += carry
carry = c[i] >> 29
c[i] &= bottom29Bits
i++
if i == 9 {
break
}
c[i] = a[i] + b[i]
c[i] += carry
carry = c[i] >> 28
c[i] &= bottom28Bits
}
sm2P256ReduceCarry(c, carry)
} | [
"func",
"sm2P256Add",
"(",
"c",
",",
"a",
",",
"b",
"*",
"sm2P256FieldElement",
")",
"{",
"carry",
":=",
"uint32",
"(",
"0",
")",
"\n",
"for",
"i",
":=",
"0",
";",
";",
"i",
"++",
"{",
"c",
"[",
"i",
"]",
"=",
"a",
"[",
"i",
"]",
"+",
"b",
"[",
"i",
"]",
"\n",
"c",
"[",
"i",
"]",
"+=",
"carry",
"\n",
"carry",
"=",
"c",
"[",
"i",
"]",
">>",
"29",
"\n",
"c",
"[",
"i",
"]",
"&=",
"bottom29Bits",
"\n",
"i",
"++",
"\n",
"if",
"i",
"==",
"9",
"{",
"break",
"\n",
"}",
"\n",
"c",
"[",
"i",
"]",
"=",
"a",
"[",
"i",
"]",
"+",
"b",
"[",
"i",
"]",
"\n",
"c",
"[",
"i",
"]",
"+=",
"carry",
"\n",
"carry",
"=",
"c",
"[",
"i",
"]",
">>",
"28",
"\n",
"c",
"[",
"i",
"]",
"&=",
"bottom28Bits",
"\n",
"}",
"\n",
"sm2P256ReduceCarry",
"(",
"c",
",",
"carry",
")",
"\n",
"}"
] | // c = a + b | [
"c",
"=",
"a",
"+",
"b"
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm2/p256.go#L602-L619 |
148,494 | tjfoc/gmsm | sm2/p256.go | sm2P256Sub | func sm2P256Sub(c, a, b *sm2P256FieldElement) {
var carry uint32
for i := 0; ; i++ {
c[i] = a[i] - b[i]
c[i] += sm2P256Zero31[i]
c[i] += carry
carry = c[i] >> 29
c[i] &= bottom29Bits
i++
if i == 9 {
break
}
c[i] = a[i] - b[i]
c[i] += sm2P256Zero31[i]
c[i] += carry
carry = c[i] >> 28
c[i] &= bottom28Bits
}
sm2P256ReduceCarry(c, carry)
} | go | func sm2P256Sub(c, a, b *sm2P256FieldElement) {
var carry uint32
for i := 0; ; i++ {
c[i] = a[i] - b[i]
c[i] += sm2P256Zero31[i]
c[i] += carry
carry = c[i] >> 29
c[i] &= bottom29Bits
i++
if i == 9 {
break
}
c[i] = a[i] - b[i]
c[i] += sm2P256Zero31[i]
c[i] += carry
carry = c[i] >> 28
c[i] &= bottom28Bits
}
sm2P256ReduceCarry(c, carry)
} | [
"func",
"sm2P256Sub",
"(",
"c",
",",
"a",
",",
"b",
"*",
"sm2P256FieldElement",
")",
"{",
"var",
"carry",
"uint32",
"\n\n",
"for",
"i",
":=",
"0",
";",
";",
"i",
"++",
"{",
"c",
"[",
"i",
"]",
"=",
"a",
"[",
"i",
"]",
"-",
"b",
"[",
"i",
"]",
"\n",
"c",
"[",
"i",
"]",
"+=",
"sm2P256Zero31",
"[",
"i",
"]",
"\n",
"c",
"[",
"i",
"]",
"+=",
"carry",
"\n",
"carry",
"=",
"c",
"[",
"i",
"]",
">>",
"29",
"\n",
"c",
"[",
"i",
"]",
"&=",
"bottom29Bits",
"\n",
"i",
"++",
"\n",
"if",
"i",
"==",
"9",
"{",
"break",
"\n",
"}",
"\n",
"c",
"[",
"i",
"]",
"=",
"a",
"[",
"i",
"]",
"-",
"b",
"[",
"i",
"]",
"\n",
"c",
"[",
"i",
"]",
"+=",
"sm2P256Zero31",
"[",
"i",
"]",
"\n",
"c",
"[",
"i",
"]",
"+=",
"carry",
"\n",
"carry",
"=",
"c",
"[",
"i",
"]",
">>",
"28",
"\n",
"c",
"[",
"i",
"]",
"&=",
"bottom28Bits",
"\n",
"}",
"\n",
"sm2P256ReduceCarry",
"(",
"c",
",",
"carry",
")",
"\n",
"}"
] | // c = a - b | [
"c",
"=",
"a",
"-",
"b"
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm2/p256.go#L622-L642 |
148,495 | tjfoc/gmsm | sm2/p256.go | sm2P256ReduceCarry | func sm2P256ReduceCarry(a *sm2P256FieldElement, carry uint32) {
a[0] += sm2P256Carry[carry*9+0]
a[2] += sm2P256Carry[carry*9+2]
a[3] += sm2P256Carry[carry*9+3]
a[7] += sm2P256Carry[carry*9+7]
} | go | func sm2P256ReduceCarry(a *sm2P256FieldElement, carry uint32) {
a[0] += sm2P256Carry[carry*9+0]
a[2] += sm2P256Carry[carry*9+2]
a[3] += sm2P256Carry[carry*9+3]
a[7] += sm2P256Carry[carry*9+7]
} | [
"func",
"sm2P256ReduceCarry",
"(",
"a",
"*",
"sm2P256FieldElement",
",",
"carry",
"uint32",
")",
"{",
"a",
"[",
"0",
"]",
"+=",
"sm2P256Carry",
"[",
"carry",
"*",
"9",
"+",
"0",
"]",
"\n",
"a",
"[",
"2",
"]",
"+=",
"sm2P256Carry",
"[",
"carry",
"*",
"9",
"+",
"2",
"]",
"\n",
"a",
"[",
"3",
"]",
"+=",
"sm2P256Carry",
"[",
"carry",
"*",
"9",
"+",
"3",
"]",
"\n",
"a",
"[",
"7",
"]",
"+=",
"sm2P256Carry",
"[",
"carry",
"*",
"9",
"+",
"7",
"]",
"\n",
"}"
] | // carry < 2 ^ 3 | [
"carry",
"<",
"2",
"^",
"3"
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm2/p256.go#L807-L812 |
148,496 | tjfoc/gmsm | sm3/sm3.go | Sum | func (sm3 *SM3) Sum(in []byte) []byte {
sm3.Write(in)
msg := sm3.pad()
// Finialize
sm3.update(msg, len(msg)/sm3.BlockSize())
// save hash to in
needed := sm3.Size()
if cap(in)-len(in) < needed {
newIn := make([]byte, len(in), len(in)+needed)
copy(newIn, in)
in = newIn
}
out := in[len(in) : len(in)+needed]
for i := 0; i < 8; i++ {
binary.BigEndian.PutUint32(out[i*4:], sm3.digest[i])
}
return out
} | go | func (sm3 *SM3) Sum(in []byte) []byte {
sm3.Write(in)
msg := sm3.pad()
// Finialize
sm3.update(msg, len(msg)/sm3.BlockSize())
// save hash to in
needed := sm3.Size()
if cap(in)-len(in) < needed {
newIn := make([]byte, len(in), len(in)+needed)
copy(newIn, in)
in = newIn
}
out := in[len(in) : len(in)+needed]
for i := 0; i < 8; i++ {
binary.BigEndian.PutUint32(out[i*4:], sm3.digest[i])
}
return out
} | [
"func",
"(",
"sm3",
"*",
"SM3",
")",
"Sum",
"(",
"in",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"sm3",
".",
"Write",
"(",
"in",
")",
"\n",
"msg",
":=",
"sm3",
".",
"pad",
"(",
")",
"\n\n",
"// Finialize",
"sm3",
".",
"update",
"(",
"msg",
",",
"len",
"(",
"msg",
")",
"/",
"sm3",
".",
"BlockSize",
"(",
")",
")",
"\n\n",
"// save hash to in",
"needed",
":=",
"sm3",
".",
"Size",
"(",
")",
"\n",
"if",
"cap",
"(",
"in",
")",
"-",
"len",
"(",
"in",
")",
"<",
"needed",
"{",
"newIn",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"in",
")",
",",
"len",
"(",
"in",
")",
"+",
"needed",
")",
"\n",
"copy",
"(",
"newIn",
",",
"in",
")",
"\n",
"in",
"=",
"newIn",
"\n",
"}",
"\n",
"out",
":=",
"in",
"[",
"len",
"(",
"in",
")",
":",
"len",
"(",
"in",
")",
"+",
"needed",
"]",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"8",
";",
"i",
"++",
"{",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"out",
"[",
"i",
"*",
"4",
":",
"]",
",",
"sm3",
".",
"digest",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"return",
"out",
"\n\n",
"}"
] | // Sum, required by the hash.Hash interface.
// Sum appends the current hash to b and returns the resulting slice.
// It does not change the underlying hash state. | [
"Sum",
"required",
"by",
"the",
"hash",
".",
"Hash",
"interface",
".",
"Sum",
"appends",
"the",
"current",
"hash",
"to",
"b",
"and",
"returns",
"the",
"resulting",
"slice",
".",
"It",
"does",
"not",
"change",
"the",
"underlying",
"hash",
"state",
"."
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm3/sm3.go#L178-L199 |
148,497 | tjfoc/gmsm | sm4/sm4.go | NewCipher | func NewCipher(key []byte) (cipher.Block, error) {
if len(key) != BlockSize {
return nil, KeySizeError(len(key))
}
c := new(Sm4Cipher)
c.subkeys = generateSubKeys(key)
c.block1 = make([]uint32, 4)
c.block2 = make([]byte, 16)
return c, nil
} | go | func NewCipher(key []byte) (cipher.Block, error) {
if len(key) != BlockSize {
return nil, KeySizeError(len(key))
}
c := new(Sm4Cipher)
c.subkeys = generateSubKeys(key)
c.block1 = make([]uint32, 4)
c.block2 = make([]byte, 16)
return c, nil
} | [
"func",
"NewCipher",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"cipher",
".",
"Block",
",",
"error",
")",
"{",
"if",
"len",
"(",
"key",
")",
"!=",
"BlockSize",
"{",
"return",
"nil",
",",
"KeySizeError",
"(",
"len",
"(",
"key",
")",
")",
"\n",
"}",
"\n",
"c",
":=",
"new",
"(",
"Sm4Cipher",
")",
"\n",
"c",
".",
"subkeys",
"=",
"generateSubKeys",
"(",
"key",
")",
"\n",
"c",
".",
"block1",
"=",
"make",
"(",
"[",
"]",
"uint32",
",",
"4",
")",
"\n",
"c",
".",
"block2",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"16",
")",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // NewCipher creates and returns a new cipher.Block. | [
"NewCipher",
"creates",
"and",
"returns",
"a",
"new",
"cipher",
".",
"Block",
"."
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm4/sm4.go#L321-L330 |
148,498 | tjfoc/gmsm | sm2/cert_pool.go | NewCertPool | func NewCertPool() *CertPool {
return &CertPool{
bySubjectKeyId: make(map[string][]int),
byName: make(map[string][]int),
}
} | go | func NewCertPool() *CertPool {
return &CertPool{
bySubjectKeyId: make(map[string][]int),
byName: make(map[string][]int),
}
} | [
"func",
"NewCertPool",
"(",
")",
"*",
"CertPool",
"{",
"return",
"&",
"CertPool",
"{",
"bySubjectKeyId",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"int",
")",
",",
"byName",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"int",
")",
",",
"}",
"\n",
"}"
] | // NewCertPool returns a new, empty CertPool. | [
"NewCertPool",
"returns",
"a",
"new",
"empty",
"CertPool",
"."
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm2/cert_pool.go#L44-L49 |
148,499 | tjfoc/gmsm | sm2/cert_pool.go | findVerifiedParents | func (s *CertPool) findVerifiedParents(cert *Certificate) (parents []int, errCert *Certificate, err error) {
if s == nil {
return
}
var candidates []int
if len(cert.AuthorityKeyId) > 0 {
candidates = s.bySubjectKeyId[string(cert.AuthorityKeyId)]
}
if len(candidates) == 0 {
candidates = s.byName[string(cert.RawIssuer)]
}
for _, c := range candidates {
if err = cert.CheckSignatureFrom(s.certs[c]); err == nil {
parents = append(parents, c)
} else {
errCert = s.certs[c]
}
}
return
} | go | func (s *CertPool) findVerifiedParents(cert *Certificate) (parents []int, errCert *Certificate, err error) {
if s == nil {
return
}
var candidates []int
if len(cert.AuthorityKeyId) > 0 {
candidates = s.bySubjectKeyId[string(cert.AuthorityKeyId)]
}
if len(candidates) == 0 {
candidates = s.byName[string(cert.RawIssuer)]
}
for _, c := range candidates {
if err = cert.CheckSignatureFrom(s.certs[c]); err == nil {
parents = append(parents, c)
} else {
errCert = s.certs[c]
}
}
return
} | [
"func",
"(",
"s",
"*",
"CertPool",
")",
"findVerifiedParents",
"(",
"cert",
"*",
"Certificate",
")",
"(",
"parents",
"[",
"]",
"int",
",",
"errCert",
"*",
"Certificate",
",",
"err",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"var",
"candidates",
"[",
"]",
"int",
"\n\n",
"if",
"len",
"(",
"cert",
".",
"AuthorityKeyId",
")",
">",
"0",
"{",
"candidates",
"=",
"s",
".",
"bySubjectKeyId",
"[",
"string",
"(",
"cert",
".",
"AuthorityKeyId",
")",
"]",
"\n",
"}",
"\n",
"if",
"len",
"(",
"candidates",
")",
"==",
"0",
"{",
"candidates",
"=",
"s",
".",
"byName",
"[",
"string",
"(",
"cert",
".",
"RawIssuer",
")",
"]",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"c",
":=",
"range",
"candidates",
"{",
"if",
"err",
"=",
"cert",
".",
"CheckSignatureFrom",
"(",
"s",
".",
"certs",
"[",
"c",
"]",
")",
";",
"err",
"==",
"nil",
"{",
"parents",
"=",
"append",
"(",
"parents",
",",
"c",
")",
"\n",
"}",
"else",
"{",
"errCert",
"=",
"s",
".",
"certs",
"[",
"c",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // findVerifiedParents attempts to find certificates in s which have signed the
// given certificate. If any candidates were rejected then errCert will be set
// to one of them, arbitrarily, and err will contain the reason that it was
// rejected. | [
"findVerifiedParents",
"attempts",
"to",
"find",
"certificates",
"in",
"s",
"which",
"have",
"signed",
"the",
"given",
"certificate",
".",
"If",
"any",
"candidates",
"were",
"rejected",
"then",
"errCert",
"will",
"be",
"set",
"to",
"one",
"of",
"them",
"arbitrarily",
"and",
"err",
"will",
"contain",
"the",
"reason",
"that",
"it",
"was",
"rejected",
"."
] | 18fd8096dc8a3dcd43e9eccbdb4ef598900ae252 | https://github.com/tjfoc/gmsm/blob/18fd8096dc8a3dcd43e9eccbdb4ef598900ae252/sm2/cert_pool.go#L131-L153 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.