_id
stringlengths
2
7
title
stringlengths
1
118
partition
stringclasses
3 values
text
stringlengths
52
85.5k
language
stringclasses
1 value
meta_information
dict
q182200
MustRemoved
test
func (u LedgerEntryChange) MustRemoved() LedgerKey { val, ok := u.GetRemoved() if !ok { panic("arm Removed is not set") } return val }
go
{ "resource": "" }
q182201
GetRemoved
test
func (u LedgerEntryChange) GetRemoved() (result LedgerKey, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Removed" { result = *u.Removed ok = true } return }
go
{ "resource": "" }
q182202
MustState
test
func (u LedgerEntryChange) MustState() LedgerEntry { val, ok := u.GetState() if !ok { panic("arm State is not set") } return val }
go
{ "resource": "" }
q182203
GetState
test
func (u LedgerEntryChange) GetState() (result LedgerEntry, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "State" { result = *u.State ok = true } return }
go
{ "resource": "" }
q182204
NewTransactionMeta
test
func NewTransactionMeta(v int32, value interface{}) (result TransactionMeta, err error) { result.V = v switch int32(v) { case 0: tv, ok := value.([]OperationMeta) if !ok { err = fmt.Errorf("invalid value, must be []OperationMeta") return } result.Operations = &tv } return }
go
{ "resource": "" }
q182205
MustOperations
test
func (u TransactionMeta) MustOperations() []OperationMeta { val, ok := u.GetOperations() if !ok { panic("arm Operations is not set") } return val }
go
{ "resource": "" }
q182206
GetOperations
test
func (u TransactionMeta) GetOperations() (result []OperationMeta, ok bool) { armName, _ := u.ArmForSwitch(int32(u.V)) if armName == "Operations" { result = *u.Operations ok = true } return }
go
{ "resource": "" }
q182207
ValidEnum
test
func (e ErrorCode) ValidEnum(v int32) bool { _, ok := errorCodeMap[v] return ok }
go
{ "resource": "" }
q182208
ValidEnum
test
func (e IpAddrType) ValidEnum(v int32) bool { _, ok := ipAddrTypeMap[v] return ok }
go
{ "resource": "" }
q182209
ArmForSwitch
test
func (u PeerAddressIp) ArmForSwitch(sw int32) (string, bool) { switch IpAddrType(sw) { case IpAddrTypeIPv4: return "Ipv4", true case IpAddrTypeIPv6: return "Ipv6", true } return "-", false }
go
{ "resource": "" }
q182210
NewPeerAddressIp
test
func NewPeerAddressIp(aType IpAddrType, value interface{}) (result PeerAddressIp, err error) { result.Type = aType switch IpAddrType(aType) { case IpAddrTypeIPv4: tv, ok := value.([4]byte) if !ok { err = fmt.Errorf("invalid value, must be [4]byte") return } result.Ipv4 = &tv case IpAddrTypeIPv6: tv, ok := value.([16]byte) if !ok { err = fmt.Errorf("invalid value, must be [16]byte") return } result.Ipv6 = &tv } return }
go
{ "resource": "" }
q182211
MustIpv4
test
func (u PeerAddressIp) MustIpv4() [4]byte { val, ok := u.GetIpv4() if !ok { panic("arm Ipv4 is not set") } return val }
go
{ "resource": "" }
q182212
GetIpv4
test
func (u PeerAddressIp) GetIpv4() (result [4]byte, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Ipv4" { result = *u.Ipv4 ok = true } return }
go
{ "resource": "" }
q182213
MustIpv6
test
func (u PeerAddressIp) MustIpv6() [16]byte { val, ok := u.GetIpv6() if !ok { panic("arm Ipv6 is not set") } return val }
go
{ "resource": "" }
q182214
GetIpv6
test
func (u PeerAddressIp) GetIpv6() (result [16]byte, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Ipv6" { result = *u.Ipv6 ok = true } return }
go
{ "resource": "" }
q182215
ValidEnum
test
func (e MessageType) ValidEnum(v int32) bool { _, ok := messageTypeMap[v] return ok }
go
{ "resource": "" }
q182216
ArmForSwitch
test
func (u StellarMessage) ArmForSwitch(sw int32) (string, bool) { switch MessageType(sw) { case MessageTypeErrorMsg: return "Error", true case MessageTypeHello: return "Hello", true case MessageTypeAuth: return "Auth", true case MessageTypeDontHave: return "DontHave", true case MessageTypeGetPeers: return "", true case MessageTypePeers: return "Peers", true case MessageTypeGetTxSet: return "TxSetHash", true case MessageTypeTxSet: return "TxSet", true case MessageTypeTransaction: return "Transaction", true case MessageTypeGetScpQuorumset: return "QSetHash", true case MessageTypeScpQuorumset: return "QSet", true case MessageTypeScpMessage: return "Envelope", true case MessageTypeGetScpState: return "GetScpLedgerSeq", true } return "-", false }
go
{ "resource": "" }
q182217
NewStellarMessage
test
func NewStellarMessage(aType MessageType, value interface{}) (result StellarMessage, err error) { result.Type = aType switch MessageType(aType) { case MessageTypeErrorMsg: tv, ok := value.(Error) if !ok { err = fmt.Errorf("invalid value, must be Error") return } result.Error = &tv case MessageTypeHello: tv, ok := value.(Hello) if !ok { err = fmt.Errorf("invalid value, must be Hello") return } result.Hello = &tv case MessageTypeAuth: tv, ok := value.(Auth) if !ok { err = fmt.Errorf("invalid value, must be Auth") return } result.Auth = &tv case MessageTypeDontHave: tv, ok := value.(DontHave) if !ok { err = fmt.Errorf("invalid value, must be DontHave") return } result.DontHave = &tv case MessageTypeGetPeers: // void case MessageTypePeers: tv, ok := value.([]PeerAddress) if !ok { err = fmt.Errorf("invalid value, must be []PeerAddress") return } result.Peers = &tv case MessageTypeGetTxSet: tv, ok := value.(Uint256) if !ok { err = fmt.Errorf("invalid value, must be Uint256") return } result.TxSetHash = &tv case MessageTypeTxSet: tv, ok := value.(TransactionSet) if !ok { err = fmt.Errorf("invalid value, must be TransactionSet") return } result.TxSet = &tv case MessageTypeTransaction: tv, ok := value.(TransactionEnvelope) if !ok { err = fmt.Errorf("invalid value, must be TransactionEnvelope") return } result.Transaction = &tv case MessageTypeGetScpQuorumset: tv, ok := value.(Uint256) if !ok { err = fmt.Errorf("invalid value, must be Uint256") return } result.QSetHash = &tv case MessageTypeScpQuorumset: tv, ok := value.(ScpQuorumSet) if !ok { err = fmt.Errorf("invalid value, must be ScpQuorumSet") return } result.QSet = &tv case MessageTypeScpMessage: tv, ok := value.(ScpEnvelope) if !ok { err = fmt.Errorf("invalid value, must be ScpEnvelope") return } result.Envelope = &tv case MessageTypeGetScpState: tv, ok := value.(Uint32) if !ok { err = fmt.Errorf("invalid value, must be Uint32") return } result.GetScpLedgerSeq = &tv } return }
go
{ "resource": "" }
q182218
MustError
test
func (u StellarMessage) MustError() Error { val, ok := u.GetError() if !ok { panic("arm Error is not set") } return val }
go
{ "resource": "" }
q182219
GetError
test
func (u StellarMessage) GetError() (result Error, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Error" { result = *u.Error ok = true } return }
go
{ "resource": "" }
q182220
MustHello
test
func (u StellarMessage) MustHello() Hello { val, ok := u.GetHello() if !ok { panic("arm Hello is not set") } return val }
go
{ "resource": "" }
q182221
GetHello
test
func (u StellarMessage) GetHello() (result Hello, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Hello" { result = *u.Hello ok = true } return }
go
{ "resource": "" }
q182222
MustAuth
test
func (u StellarMessage) MustAuth() Auth { val, ok := u.GetAuth() if !ok { panic("arm Auth is not set") } return val }
go
{ "resource": "" }
q182223
GetAuth
test
func (u StellarMessage) GetAuth() (result Auth, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Auth" { result = *u.Auth ok = true } return }
go
{ "resource": "" }
q182224
MustDontHave
test
func (u StellarMessage) MustDontHave() DontHave { val, ok := u.GetDontHave() if !ok { panic("arm DontHave is not set") } return val }
go
{ "resource": "" }
q182225
GetDontHave
test
func (u StellarMessage) GetDontHave() (result DontHave, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "DontHave" { result = *u.DontHave ok = true } return }
go
{ "resource": "" }
q182226
MustPeers
test
func (u StellarMessage) MustPeers() []PeerAddress { val, ok := u.GetPeers() if !ok { panic("arm Peers is not set") } return val }
go
{ "resource": "" }
q182227
GetPeers
test
func (u StellarMessage) GetPeers() (result []PeerAddress, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Peers" { result = *u.Peers ok = true } return }
go
{ "resource": "" }
q182228
MustTxSetHash
test
func (u StellarMessage) MustTxSetHash() Uint256 { val, ok := u.GetTxSetHash() if !ok { panic("arm TxSetHash is not set") } return val }
go
{ "resource": "" }
q182229
GetTxSetHash
test
func (u StellarMessage) GetTxSetHash() (result Uint256, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "TxSetHash" { result = *u.TxSetHash ok = true } return }
go
{ "resource": "" }
q182230
MustTxSet
test
func (u StellarMessage) MustTxSet() TransactionSet { val, ok := u.GetTxSet() if !ok { panic("arm TxSet is not set") } return val }
go
{ "resource": "" }
q182231
GetTxSet
test
func (u StellarMessage) GetTxSet() (result TransactionSet, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "TxSet" { result = *u.TxSet ok = true } return }
go
{ "resource": "" }
q182232
MustTransaction
test
func (u StellarMessage) MustTransaction() TransactionEnvelope { val, ok := u.GetTransaction() if !ok { panic("arm Transaction is not set") } return val }
go
{ "resource": "" }
q182233
GetTransaction
test
func (u StellarMessage) GetTransaction() (result TransactionEnvelope, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Transaction" { result = *u.Transaction ok = true } return }
go
{ "resource": "" }
q182234
MustQSetHash
test
func (u StellarMessage) MustQSetHash() Uint256 { val, ok := u.GetQSetHash() if !ok { panic("arm QSetHash is not set") } return val }
go
{ "resource": "" }
q182235
GetQSetHash
test
func (u StellarMessage) GetQSetHash() (result Uint256, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "QSetHash" { result = *u.QSetHash ok = true } return }
go
{ "resource": "" }
q182236
MustQSet
test
func (u StellarMessage) MustQSet() ScpQuorumSet { val, ok := u.GetQSet() if !ok { panic("arm QSet is not set") } return val }
go
{ "resource": "" }
q182237
GetQSet
test
func (u StellarMessage) GetQSet() (result ScpQuorumSet, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "QSet" { result = *u.QSet ok = true } return }
go
{ "resource": "" }
q182238
MustEnvelope
test
func (u StellarMessage) MustEnvelope() ScpEnvelope { val, ok := u.GetEnvelope() if !ok { panic("arm Envelope is not set") } return val }
go
{ "resource": "" }
q182239
GetEnvelope
test
func (u StellarMessage) GetEnvelope() (result ScpEnvelope, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Envelope" { result = *u.Envelope ok = true } return }
go
{ "resource": "" }
q182240
MustGetScpLedgerSeq
test
func (u StellarMessage) MustGetScpLedgerSeq() Uint32 { val, ok := u.GetGetScpLedgerSeq() if !ok { panic("arm GetScpLedgerSeq is not set") } return val }
go
{ "resource": "" }
q182241
GetGetScpLedgerSeq
test
func (u StellarMessage) GetGetScpLedgerSeq() (result Uint32, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "GetScpLedgerSeq" { result = *u.GetScpLedgerSeq ok = true } return }
go
{ "resource": "" }
q182242
ArmForSwitch
test
func (u AuthenticatedMessage) ArmForSwitch(sw int32) (string, bool) { switch Uint32(sw) { case 0: return "V0", true } return "-", false }
go
{ "resource": "" }
q182243
NewAuthenticatedMessage
test
func NewAuthenticatedMessage(v Uint32, value interface{}) (result AuthenticatedMessage, err error) { result.V = v switch Uint32(v) { case 0: tv, ok := value.(AuthenticatedMessageV0) if !ok { err = fmt.Errorf("invalid value, must be AuthenticatedMessageV0") return } result.V0 = &tv } return }
go
{ "resource": "" }
q182244
ValidEnum
test
func (e ScpStatementType) ValidEnum(v int32) bool { _, ok := scpStatementTypeMap[v] return ok }
go
{ "resource": "" }
q182245
ArmForSwitch
test
func (u ScpStatementPledges) ArmForSwitch(sw int32) (string, bool) { switch ScpStatementType(sw) { case ScpStatementTypeScpStPrepare: return "Prepare", true case ScpStatementTypeScpStConfirm: return "Confirm", true case ScpStatementTypeScpStExternalize: return "Externalize", true case ScpStatementTypeScpStNominate: return "Nominate", true } return "-", false }
go
{ "resource": "" }
q182246
NewScpStatementPledges
test
func NewScpStatementPledges(aType ScpStatementType, value interface{}) (result ScpStatementPledges, err error) { result.Type = aType switch ScpStatementType(aType) { case ScpStatementTypeScpStPrepare: tv, ok := value.(ScpStatementPrepare) if !ok { err = fmt.Errorf("invalid value, must be ScpStatementPrepare") return } result.Prepare = &tv case ScpStatementTypeScpStConfirm: tv, ok := value.(ScpStatementConfirm) if !ok { err = fmt.Errorf("invalid value, must be ScpStatementConfirm") return } result.Confirm = &tv case ScpStatementTypeScpStExternalize: tv, ok := value.(ScpStatementExternalize) if !ok { err = fmt.Errorf("invalid value, must be ScpStatementExternalize") return } result.Externalize = &tv case ScpStatementTypeScpStNominate: tv, ok := value.(ScpNomination) if !ok { err = fmt.Errorf("invalid value, must be ScpNomination") return } result.Nominate = &tv } return }
go
{ "resource": "" }
q182247
MustPrepare
test
func (u ScpStatementPledges) MustPrepare() ScpStatementPrepare { val, ok := u.GetPrepare() if !ok { panic("arm Prepare is not set") } return val }
go
{ "resource": "" }
q182248
GetPrepare
test
func (u ScpStatementPledges) GetPrepare() (result ScpStatementPrepare, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Prepare" { result = *u.Prepare ok = true } return }
go
{ "resource": "" }
q182249
MustConfirm
test
func (u ScpStatementPledges) MustConfirm() ScpStatementConfirm { val, ok := u.GetConfirm() if !ok { panic("arm Confirm is not set") } return val }
go
{ "resource": "" }
q182250
GetConfirm
test
func (u ScpStatementPledges) GetConfirm() (result ScpStatementConfirm, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Confirm" { result = *u.Confirm ok = true } return }
go
{ "resource": "" }
q182251
MustExternalize
test
func (u ScpStatementPledges) MustExternalize() ScpStatementExternalize { val, ok := u.GetExternalize() if !ok { panic("arm Externalize is not set") } return val }
go
{ "resource": "" }
q182252
GetExternalize
test
func (u ScpStatementPledges) GetExternalize() (result ScpStatementExternalize, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Externalize" { result = *u.Externalize ok = true } return }
go
{ "resource": "" }
q182253
MustNominate
test
func (u ScpStatementPledges) MustNominate() ScpNomination { val, ok := u.GetNominate() if !ok { panic("arm Nominate is not set") } return val }
go
{ "resource": "" }
q182254
GetNominate
test
func (u ScpStatementPledges) GetNominate() (result ScpNomination, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Nominate" { result = *u.Nominate ok = true } return }
go
{ "resource": "" }
q182255
SafeUnmarshalBase64
test
func SafeUnmarshalBase64(data string, dest interface{}) error { count := &countWriter{} l := len(data) b64 := io.TeeReader(strings.NewReader(data), count) raw := base64.NewDecoder(base64.StdEncoding, b64) _, err := Unmarshal(raw, dest) if err != nil { return err } if count.Count != l { return fmt.Errorf("input not fully consumed. expected to read: %d, actual: %d", l, count.Count) } return nil }
go
{ "resource": "" }
q182256
SafeUnmarshal
test
func SafeUnmarshal(data []byte, dest interface{}) error { r := bytes.NewReader(data) n, err := Unmarshal(r, dest) if err != nil { return err } if n != len(data) { return fmt.Errorf("input not fully consumed. expected to read: %d, actual: %d", len(data), n) } return nil }
go
{ "resource": "" }
q182257
SendAmount
test
func (pr *PathPaymentResult) SendAmount() Int64 { s, ok := pr.GetSuccess() if !ok { return 0 } if len(s.Offers) == 0 { return s.Last.Amount } sa := s.Offers[0].AssetBought var ret Int64 for _, o := range s.Offers { if o.AssetBought.String() != sa.String() { break } ret += o.AmountBought } return ret }
go
{ "resource": "" }
q182258
LoadAccount
test
func (c *Client) LoadAccount(accountID string) (account Account, err error) { c.initHTTPClient() resp, err := c.Client.Get(c.URL + "/accounts/" + accountID) if err != nil { return } err = decodeResponse(resp, &account) return }
go
{ "resource": "" }
q182259
SequenceForAccount
test
func (c *Client) SequenceForAccount( accountID string, ) (xdr.SequenceNumber, error) { a, err := c.LoadAccount(accountID) if err != nil { return 0, err } seq, err := strconv.ParseUint(a.Sequence, 10, 64) if err != nil { return 0, err } return xdr.SequenceNumber(seq), nil }
go
{ "resource": "" }
q182260
SubmitTransaction
test
func (c *Client) SubmitTransaction(transactionEnvelopeXdr string) (response TransactionSuccess, err error) { v := url.Values{} v.Set("tx", transactionEnvelopeXdr) c.initHTTPClient() resp, err := c.Client.PostForm(c.URL+"/transactions", v) if err != nil { return } err = decodeResponse(resp, &response) return }
go
{ "resource": "" }
q182261
Equals
test
func (key *LedgerKey) Equals(other LedgerKey) bool { if key.Type != other.Type { return false } switch key.Type { case LedgerEntryTypeAccount: l := key.MustAccount() r := other.MustAccount() return l.AccountId.Equals(r.AccountId) case LedgerEntryTypeData: l := key.MustData() r := other.MustData() return l.AccountId.Equals(r.AccountId) && l.DataName == r.DataName case LedgerEntryTypeOffer: l := key.MustOffer() r := other.MustOffer() return l.SellerId.Equals(r.SellerId) && l.OfferId == r.OfferId case LedgerEntryTypeTrustline: l := key.MustTrustLine() r := other.MustTrustLine() return l.AccountId.Equals(r.AccountId) && l.Asset.Equals(r.Asset) default: panic(fmt.Errorf("Unknown ledger key type: %v", key.Type)) } }
go
{ "resource": "" }
q182262
SetAccount
test
func (key *LedgerKey) SetAccount(account AccountId) error { data := LedgerKeyAccount{account} nkey, err := NewLedgerKey(LedgerEntryTypeAccount, data) if err != nil { return err } *key = nkey return nil }
go
{ "resource": "" }
q182263
SetData
test
func (key *LedgerKey) SetData(account AccountId, name string) error { data := LedgerKeyData{account, String64(name)} nkey, err := NewLedgerKey(LedgerEntryTypeData, data) if err != nil { return err } *key = nkey return nil }
go
{ "resource": "" }
q182264
SetOffer
test
func (key *LedgerKey) SetOffer(account AccountId, id uint64) error { data := LedgerKeyOffer{account, Uint64(id)} nkey, err := NewLedgerKey(LedgerEntryTypeOffer, data) if err != nil { return err } *key = nkey return nil }
go
{ "resource": "" }
q182265
SetTrustline
test
func (key *LedgerKey) SetTrustline(account AccountId, line Asset) error { data := LedgerKeyTrustLine{account, line} nkey, err := NewLedgerKey(LedgerEntryTypeTrustline, data) if err != nil { return err } *key = nkey return nil }
go
{ "resource": "" }
q182266
Add
test
func (b *CHDBuilder) Add(key []byte, value []byte) { b.keys = append(b.keys, key) b.values = append(b.values, value) }
go
{ "resource": "" }
q182267
tryHash
test
func tryHash(hasher *chdHasher, seen map[uint64]bool, keys [][]byte, values [][]byte, indices []uint16, bucket *bucket, ri uint16, r uint64) bool { // Track duplicates within this bucket. duplicate := make(map[uint64]bool) // Make hashes for each entry in the bucket. hashes := make([]uint64, len(bucket.keys)) for i, k := range bucket.keys { h := hasher.Table(r, k) hashes[i] = h if seen[h] { return false } if duplicate[h] { return false } duplicate[h] = true } // Update seen hashes for _, h := range hashes { seen[h] = true } // Add the hash index. indices[bucket.index] = ri // Update the the hash table. for i, h := range hashes { keys[h] = bucket.keys[i] values[h] = bucket.values[i] } return true }
go
{ "resource": "" }
q182268
HashIndexFromKey
test
func (h *chdHasher) HashIndexFromKey(b []byte) uint64 { return (hasher(b) ^ h.r[0]) % h.buckets }
go
{ "resource": "" }
q182269
ReadInt
test
func (b *sliceReader) ReadInt() uint64 { return uint64(binary.LittleEndian.Uint32(b.Read(4))) }
go
{ "resource": "" }
q182270
Read
test
func Read(r io.Reader) (*CHD, error) { b, err := ioutil.ReadAll(r) if err != nil { return nil, err } return Mmap(b) }
go
{ "resource": "" }
q182271
Get
test
func (c *CHD) Get(key []byte) []byte { r0 := c.r[0] h := hasher(key) ^ r0 i := h % uint64(len(c.indices)) ri := c.indices[i] // This can occur if there were unassigned slots in the hash table. if ri >= uint16(len(c.r)) { return nil } r := c.r[ri] ti := (h ^ r) % uint64(len(c.keys)) // fmt.Printf("r[0]=%d, h=%d, i=%d, ri=%d, r=%d, ti=%d\n", c.r[0], h, i, ri, r, ti) k := c.keys[ti] if bytes.Compare(k, key) != 0 { return nil } v := c.values[ti] return v }
go
{ "resource": "" }
q182272
Iterate
test
func (c *CHD) Iterate() *Iterator { if len(c.keys) == 0 { return nil } return &Iterator{c: c} }
go
{ "resource": "" }
q182273
Write
test
func (c *CHD) Write(w io.Writer) error { write := func(nd ...interface{}) error { for _, d := range nd { if err := binary.Write(w, binary.LittleEndian, d); err != nil { return err } } return nil } data := []interface{}{ uint32(len(c.r)), c.r, uint32(len(c.indices)), c.indices, uint32(len(c.keys)), } if err := write(data...); err != nil { return err } for i := range c.keys { k, v := c.keys[i], c.values[i] if err := write(uint32(len(k)), uint32(len(v))); err != nil { return err } if _, err := w.Write(k); err != nil { return err } if _, err := w.Write(v); err != nil { return err } } return nil }
go
{ "resource": "" }
q182274
RegisterDatasources
test
func RegisterDatasources(path string) error { cs := C.CString(path) defer C.free(unsafe.Pointer(cs)) if C.mapnik_register_datasources(cs) == 0 { e := C.GoString(C.mapnik_register_last_error()) if e != "" { return errors.New("registering datasources: " + e) } return errors.New("error while registering datasources") } return nil }
go
{ "resource": "" }
q182275
RegisterFonts
test
func RegisterFonts(path string) error { cs := C.CString(path) defer C.free(unsafe.Pointer(cs)) if C.mapnik_register_fonts(cs) == 0 { e := C.GoString(C.mapnik_register_last_error()) if e != "" { return errors.New("registering fonts: " + e) } return errors.New("error while registering fonts") } return nil }
go
{ "resource": "" }
q182276
New
test
func New() *Map { return &Map{ m: C.mapnik_map(C.uint(800), C.uint(600)), width: 800, height: 600, } }
go
{ "resource": "" }
q182277
NewSized
test
func NewSized(width, height int) *Map { return &Map{ m: C.mapnik_map(C.uint(width), C.uint(height)), width: width, height: height, } }
go
{ "resource": "" }
q182278
Load
test
func (m *Map) Load(stylesheet string) error { cs := C.CString(stylesheet) defer C.free(unsafe.Pointer(cs)) if C.mapnik_map_load(m.m, cs) != 0 { return m.lastError() } return nil }
go
{ "resource": "" }
q182279
Resize
test
func (m *Map) Resize(width, height int) { C.mapnik_map_resize(m.m, C.uint(width), C.uint(height)) m.width = width m.height = height }
go
{ "resource": "" }
q182280
Free
test
func (m *Map) Free() { C.mapnik_map_free(m.m) m.m = nil }
go
{ "resource": "" }
q182281
SRS
test
func (m *Map) SRS() string { return C.GoString(C.mapnik_map_get_srs(m.m)) }
go
{ "resource": "" }
q182282
ZoomAll
test
func (m *Map) ZoomAll() error { if C.mapnik_map_zoom_all(m.m) != 0 { return m.lastError() } return nil }
go
{ "resource": "" }
q182283
ZoomTo
test
func (m *Map) ZoomTo(minx, miny, maxx, maxy float64) { bbox := C.mapnik_bbox(C.double(minx), C.double(miny), C.double(maxx), C.double(maxy)) defer C.mapnik_bbox_free(bbox) C.mapnik_map_zoom_to_box(m.m, bbox) }
go
{ "resource": "" }
q182284
Render
test
func (m *Map) Render(opts RenderOpts) ([]byte, error) { scaleFactor := opts.ScaleFactor if scaleFactor == 0.0 { scaleFactor = 1.0 } i := C.mapnik_map_render_to_image(m.m, C.double(opts.Scale), C.double(scaleFactor)) if i == nil { return nil, m.lastError() } defer C.mapnik_image_free(i) if opts.Format == "raw" { size := 0 raw := C.mapnik_image_to_raw(i, (*C.size_t)(unsafe.Pointer(&size))) return C.GoBytes(unsafe.Pointer(raw), C.int(size)), nil } var format *C.char if opts.Format != "" { format = C.CString(opts.Format) } else { format = C.CString("png256") } b := C.mapnik_image_to_blob(i, format) if b == nil { return nil, errors.New("mapnik: " + C.GoString(C.mapnik_image_last_error(i))) } C.free(unsafe.Pointer(format)) defer C.mapnik_image_blob_free(b) return C.GoBytes(unsafe.Pointer(b.ptr), C.int(b.len)), nil }
go
{ "resource": "" }
q182285
RenderImage
test
func (m *Map) RenderImage(opts RenderOpts) (*image.NRGBA, error) { scaleFactor := opts.ScaleFactor if scaleFactor == 0.0 { scaleFactor = 1.0 } i := C.mapnik_map_render_to_image(m.m, C.double(opts.Scale), C.double(scaleFactor)) if i == nil { return nil, m.lastError() } defer C.mapnik_image_free(i) size := 0 raw := C.mapnik_image_to_raw(i, (*C.size_t)(unsafe.Pointer(&size))) b := C.GoBytes(unsafe.Pointer(raw), C.int(size)) img := &image.NRGBA{ Pix: b, Stride: int(m.width * 4), Rect: image.Rect(0, 0, int(m.width), int(m.height)), } return img, nil }
go
{ "resource": "" }
q182286
RenderToFile
test
func (m *Map) RenderToFile(opts RenderOpts, path string) error { scaleFactor := opts.ScaleFactor if scaleFactor == 0.0 { scaleFactor = 1.0 } cs := C.CString(path) defer C.free(unsafe.Pointer(cs)) var format *C.char if opts.Format != "" { format = C.CString(opts.Format) } else { format = C.CString("png256") } defer C.free(unsafe.Pointer(format)) if C.mapnik_map_render_to_file(m.m, cs, C.double(opts.Scale), C.double(scaleFactor), format) != 0 { return m.lastError() } return nil }
go
{ "resource": "" }
q182287
SetBufferSize
test
func (m *Map) SetBufferSize(s int) { C.mapnik_map_set_buffer_size(m.m, C.int(s)) }
go
{ "resource": "" }
q182288
Search
test
func Search(st string, mx time.Duration) ([]SearchResponse, error) { conn, err := listenForSearchResponses() if err != nil { return nil, err } defer conn.Close() searchBytes, broadcastAddr := buildSearchRequest(st, mx) // Write search bytes on the wire so all devices can respond _, err = conn.WriteTo(searchBytes, broadcastAddr) if err != nil { return nil, err } return readSearchResponses(conn, mx) }
go
{ "resource": "" }
q182289
Get
test
func (p *blockingPool) Get() (net.Conn, error) { //in case that pool is closed or pool.conns is set to nil conns := p.conns if conns == nil { return nil, ErrClosed } select { case conn := <-conns: if time.Since(conn.start) > p.livetime { if conn.Conn != nil { conn.Conn.Close() conn.Conn = nil } } if conn.Conn == nil { var err error conn.Conn, err = p.factory() if err != nil { conn.start = time.Now() p.put(conn) return nil, err } } conn.unusable = false return conn, nil case <-time.After(time.Second*p.timeout): return nil, ErrTimeout } }
go
{ "resource": "" }
q182290
put
test
func (p *blockingPool) put(conn *WrappedConn) error { //in case that pool is closed and pool.conns is set to nil conns := p.conns if conns == nil { //conn.Conn is possibly nil coz factory() may fail, in which case conn is immediately //put back to the pool if conn.Conn != nil { conn.Conn.Close() conn.Conn = nil } return ErrClosed } //if conn is marked unusable, underlying net.Conn is set to nil if conn.unusable { if conn.Conn != nil { conn.Conn.Close() conn.Conn = nil } } //It is impossible to block as number of connections is never more than length of channel conns <-conn return nil }
go
{ "resource": "" }
q182291
MonoToStereoF32
test
func MonoToStereoF32(buf *audio.Float32Buffer) error { if buf == nil || buf.Format == nil || buf.Format.NumChannels != 1 { return audio.ErrInvalidBuffer } stereoData := make([]float32, len(buf.Data)*2) var j int for i := 0; i < len(buf.Data); i++ { stereoData[j] = buf.Data[i] j++ stereoData[j] = buf.Data[i] j++ } buf.Data = stereoData buf.Format.NumChannels = 2 return nil }
go
{ "resource": "" }
q182292
BitCrush
test
func BitCrush(buf *audio.FloatBuffer, factor float64) { stepSize := crusherStepSize * factor for i := 0; i < len(buf.Data); i++ { frac, exp := math.Frexp(buf.Data[i]) frac = signum(frac) * math.Floor(math.Abs(frac)/stepSize+0.5) * stepSize buf.Data[i] = math.Ldexp(frac, exp) } }
go
{ "resource": "" }
q182293
NormalizeMax
test
func NormalizeMax(buf *audio.FloatBuffer) { if buf == nil { return } max := 0.0 for i := 0; i < len(buf.Data); i++ { if math.Abs(buf.Data[i]) > max { max = math.Abs(buf.Data[i]) } } if max != 0.0 { for i := 0; i < len(buf.Data); i++ { buf.Data[i] /= max } } }
go
{ "resource": "" }
q182294
Gain
test
func Gain(buf *audio.FloatBuffer, multiplier float64) error { if buf == nil { return audio.ErrInvalidBuffer } for i := 0; i < len(buf.Data); i++ { buf.Data[i] *= multiplier } return nil }
go
{ "resource": "" }
q182295
MonoDownmix
test
func MonoDownmix(buf *audio.FloatBuffer) error { if buf == nil || buf.Format == nil { return audio.ErrInvalidBuffer } nChans := buf.Format.NumChannels if nChans < 2 { return nil } nChansF := float64(nChans) frameCount := buf.NumFrames() newData := make([]float64, frameCount) for i := 0; i < frameCount; i++ { newData[i] = 0 for j := 0; j < nChans; j++ { newData[i] += buf.Data[i*nChans+j] } newData[i] /= nChansF } buf.Data = newData buf.Format.NumChannels = 1 return nil }
go
{ "resource": "" }
q182296
Quantize
test
func Quantize(buf *audio.FloatBuffer, bitDepth int) { if buf == nil { return } max := math.Pow(2, float64(bitDepth)) - 1 bufLen := len(buf.Data) for i := 0; i < bufLen; i++ { buf.Data[i] = round((buf.Data[i]+1)*max)/max - 1.0 } }
go
{ "resource": "" }
q182297
PCMScale
test
func PCMScale(buf *audio.FloatBuffer, bitDepth int) error { if buf == nil || buf.Format == nil { return audio.ErrInvalidBuffer } factor := math.Pow(2, 8*float64(bitDepth/8)-1) for i := 0; i < len(buf.Data); i++ { buf.Data[i] *= factor } return nil }
go
{ "resource": "" }
q182298
StereoPan
test
func StereoPan(buf *audio.FloatBuffer, pan float64) error { if buf == nil || buf.Format == nil || buf.Format.NumChannels != 2 { return audio.ErrInvalidBuffer } if pan < 0 || pan > 1 { return errors.New("invalid pan value, should be betwen 0 and 1") } if pan == 0.5 { return nil } if pan < 0.5 { for i := 0; i+2 <= len(buf.Data); i += 2 { buf.Data[i+1] *= (pan * 2) } } else { for i := 0; i+2 <= len(buf.Data); i += 2 { buf.Data[i] *= ((1 - pan) * 2) } } return nil }
go
{ "resource": "" }
q182299
Leader
test
func (f *Follower) Leader() string { f.lock.Lock() defer f.lock.Unlock() return f.leader }
go
{ "resource": "" }