repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
stellar/go-stellar-base
xdr/xdr_generated.go
MustIpv6
func (u PeerAddressIp) MustIpv6() [16]byte { val, ok := u.GetIpv6() if !ok { panic("arm Ipv6 is not set") } return val }
go
func (u PeerAddressIp) MustIpv6() [16]byte { val, ok := u.GetIpv6() if !ok { panic("arm Ipv6 is not set") } return val }
[ "func", "(", "u", "PeerAddressIp", ")", "MustIpv6", "(", ")", "[", "16", "]", "byte", "{", "val", ",", "ok", ":=", "u", ".", "GetIpv6", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm Ipv6 is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustIpv6 retrieves the Ipv6 value from the union, // panicing if the value is not set.
[ "MustIpv6", "retrieves", "the", "Ipv6", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6154-L6162
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetIpv6
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
func (u PeerAddressIp) GetIpv6() (result [16]byte, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Ipv6" { result = *u.Ipv6 ok = true } return }
[ "func", "(", "u", "PeerAddressIp", ")", "GetIpv6", "(", ")", "(", "result", "[", "16", "]", "byte", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"Ipv6\"", "{", "result", "=", "*", "u", ".", "Ipv6", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetIpv6 retrieves the Ipv6 value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetIpv6", "retrieves", "the", "Ipv6", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6166-L6175
test
stellar/go-stellar-base
xdr/xdr_generated.go
ValidEnum
func (e MessageType) ValidEnum(v int32) bool { _, ok := messageTypeMap[v] return ok }
go
func (e MessageType) ValidEnum(v int32) bool { _, ok := messageTypeMap[v] return ok }
[ "func", "(", "e", "MessageType", ")", "ValidEnum", "(", "v", "int32", ")", "bool", "{", "_", ",", "ok", ":=", "messageTypeMap", "[", "v", "]", "\n", "return", "ok", "\n", "}" ]
// ValidEnum validates a proposed value for this enum. Implements // the Enum interface for MessageType
[ "ValidEnum", "validates", "a", "proposed", "value", "for", "this", "enum", ".", "Implements", "the", "Enum", "interface", "for", "MessageType" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6261-L6264
test
stellar/go-stellar-base
xdr/xdr_generated.go
ArmForSwitch
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
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 }
[ "func", "(", "u", "StellarMessage", ")", "ArmForSwitch", "(", "sw", "int32", ")", "(", "string", ",", "bool", ")", "{", "switch", "MessageType", "(", "sw", ")", "{", "case", "MessageTypeErrorMsg", ":", "return", "\"Error\"", ",", "true", "\n", "case", "MessageTypeHello", ":", "return", "\"Hello\"", ",", "true", "\n", "case", "MessageTypeAuth", ":", "return", "\"Auth\"", ",", "true", "\n", "case", "MessageTypeDontHave", ":", "return", "\"DontHave\"", ",", "true", "\n", "case", "MessageTypeGetPeers", ":", "return", "\"\"", ",", "true", "\n", "case", "MessageTypePeers", ":", "return", "\"Peers\"", ",", "true", "\n", "case", "MessageTypeGetTxSet", ":", "return", "\"TxSetHash\"", ",", "true", "\n", "case", "MessageTypeTxSet", ":", "return", "\"TxSet\"", ",", "true", "\n", "case", "MessageTypeTransaction", ":", "return", "\"Transaction\"", ",", "true", "\n", "case", "MessageTypeGetScpQuorumset", ":", "return", "\"QSetHash\"", ",", "true", "\n", "case", "MessageTypeScpQuorumset", ":", "return", "\"QSet\"", ",", "true", "\n", "case", "MessageTypeScpMessage", ":", "return", "\"Envelope\"", ",", "true", "\n", "case", "MessageTypeGetScpState", ":", "return", "\"GetScpLedgerSeq\"", ",", "true", "\n", "}", "\n", "return", "\"-\"", ",", "false", "\n", "}" ]
// ArmForSwitch returns which field name should be used for storing // the value for an instance of StellarMessage
[ "ArmForSwitch", "returns", "which", "field", "name", "should", "be", "used", "for", "storing", "the", "value", "for", "an", "instance", "of", "StellarMessage" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6345-L6375
test
stellar/go-stellar-base
xdr/xdr_generated.go
NewStellarMessage
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
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 }
[ "func", "NewStellarMessage", "(", "aType", "MessageType", ",", "value", "interface", "{", "}", ")", "(", "result", "StellarMessage", ",", "err", "error", ")", "{", "result", ".", "Type", "=", "aType", "\n", "switch", "MessageType", "(", "aType", ")", "{", "case", "MessageTypeErrorMsg", ":", "tv", ",", "ok", ":=", "value", ".", "(", "Error", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be Error\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "Error", "=", "&", "tv", "\n", "case", "MessageTypeHello", ":", "tv", ",", "ok", ":=", "value", ".", "(", "Hello", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be Hello\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "Hello", "=", "&", "tv", "\n", "case", "MessageTypeAuth", ":", "tv", ",", "ok", ":=", "value", ".", "(", "Auth", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be Auth\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "Auth", "=", "&", "tv", "\n", "case", "MessageTypeDontHave", ":", "tv", ",", "ok", ":=", "value", ".", "(", "DontHave", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be DontHave\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "DontHave", "=", "&", "tv", "\n", "case", "MessageTypeGetPeers", ":", "case", "MessageTypePeers", ":", "tv", ",", "ok", ":=", "value", ".", "(", "[", "]", "PeerAddress", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be []PeerAddress\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "Peers", "=", "&", "tv", "\n", "case", "MessageTypeGetTxSet", ":", "tv", ",", "ok", ":=", "value", ".", "(", "Uint256", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be Uint256\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "TxSetHash", "=", "&", "tv", "\n", "case", "MessageTypeTxSet", ":", "tv", ",", "ok", ":=", "value", ".", "(", "TransactionSet", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be TransactionSet\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "TxSet", "=", "&", "tv", "\n", "case", "MessageTypeTransaction", ":", "tv", ",", "ok", ":=", "value", ".", "(", "TransactionEnvelope", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be TransactionEnvelope\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "Transaction", "=", "&", "tv", "\n", "case", "MessageTypeGetScpQuorumset", ":", "tv", ",", "ok", ":=", "value", ".", "(", "Uint256", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be Uint256\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "QSetHash", "=", "&", "tv", "\n", "case", "MessageTypeScpQuorumset", ":", "tv", ",", "ok", ":=", "value", ".", "(", "ScpQuorumSet", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be ScpQuorumSet\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "QSet", "=", "&", "tv", "\n", "case", "MessageTypeScpMessage", ":", "tv", ",", "ok", ":=", "value", ".", "(", "ScpEnvelope", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be ScpEnvelope\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "Envelope", "=", "&", "tv", "\n", "case", "MessageTypeGetScpState", ":", "tv", ",", "ok", ":=", "value", ".", "(", "Uint32", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be Uint32\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "GetScpLedgerSeq", "=", "&", "tv", "\n", "}", "\n", "return", "\n", "}" ]
// NewStellarMessage creates a new StellarMessage.
[ "NewStellarMessage", "creates", "a", "new", "StellarMessage", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6378-L6469
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustError
func (u StellarMessage) MustError() Error { val, ok := u.GetError() if !ok { panic("arm Error is not set") } return val }
go
func (u StellarMessage) MustError() Error { val, ok := u.GetError() if !ok { panic("arm Error is not set") } return val }
[ "func", "(", "u", "StellarMessage", ")", "MustError", "(", ")", "Error", "{", "val", ",", "ok", ":=", "u", ".", "GetError", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm Error is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustError retrieves the Error value from the union, // panicing if the value is not set.
[ "MustError", "retrieves", "the", "Error", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6473-L6481
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetError
func (u StellarMessage) GetError() (result Error, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Error" { result = *u.Error ok = true } return }
go
func (u StellarMessage) GetError() (result Error, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Error" { result = *u.Error ok = true } return }
[ "func", "(", "u", "StellarMessage", ")", "GetError", "(", ")", "(", "result", "Error", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"Error\"", "{", "result", "=", "*", "u", ".", "Error", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetError retrieves the Error value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetError", "retrieves", "the", "Error", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6485-L6494
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustHello
func (u StellarMessage) MustHello() Hello { val, ok := u.GetHello() if !ok { panic("arm Hello is not set") } return val }
go
func (u StellarMessage) MustHello() Hello { val, ok := u.GetHello() if !ok { panic("arm Hello is not set") } return val }
[ "func", "(", "u", "StellarMessage", ")", "MustHello", "(", ")", "Hello", "{", "val", ",", "ok", ":=", "u", ".", "GetHello", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm Hello is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustHello retrieves the Hello value from the union, // panicing if the value is not set.
[ "MustHello", "retrieves", "the", "Hello", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6498-L6506
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetHello
func (u StellarMessage) GetHello() (result Hello, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Hello" { result = *u.Hello ok = true } return }
go
func (u StellarMessage) GetHello() (result Hello, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Hello" { result = *u.Hello ok = true } return }
[ "func", "(", "u", "StellarMessage", ")", "GetHello", "(", ")", "(", "result", "Hello", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"Hello\"", "{", "result", "=", "*", "u", ".", "Hello", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetHello retrieves the Hello value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetHello", "retrieves", "the", "Hello", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6510-L6519
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustAuth
func (u StellarMessage) MustAuth() Auth { val, ok := u.GetAuth() if !ok { panic("arm Auth is not set") } return val }
go
func (u StellarMessage) MustAuth() Auth { val, ok := u.GetAuth() if !ok { panic("arm Auth is not set") } return val }
[ "func", "(", "u", "StellarMessage", ")", "MustAuth", "(", ")", "Auth", "{", "val", ",", "ok", ":=", "u", ".", "GetAuth", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm Auth is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustAuth retrieves the Auth value from the union, // panicing if the value is not set.
[ "MustAuth", "retrieves", "the", "Auth", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6523-L6531
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetAuth
func (u StellarMessage) GetAuth() (result Auth, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Auth" { result = *u.Auth ok = true } return }
go
func (u StellarMessage) GetAuth() (result Auth, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Auth" { result = *u.Auth ok = true } return }
[ "func", "(", "u", "StellarMessage", ")", "GetAuth", "(", ")", "(", "result", "Auth", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"Auth\"", "{", "result", "=", "*", "u", ".", "Auth", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetAuth retrieves the Auth value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetAuth", "retrieves", "the", "Auth", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6535-L6544
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustDontHave
func (u StellarMessage) MustDontHave() DontHave { val, ok := u.GetDontHave() if !ok { panic("arm DontHave is not set") } return val }
go
func (u StellarMessage) MustDontHave() DontHave { val, ok := u.GetDontHave() if !ok { panic("arm DontHave is not set") } return val }
[ "func", "(", "u", "StellarMessage", ")", "MustDontHave", "(", ")", "DontHave", "{", "val", ",", "ok", ":=", "u", ".", "GetDontHave", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm DontHave is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustDontHave retrieves the DontHave value from the union, // panicing if the value is not set.
[ "MustDontHave", "retrieves", "the", "DontHave", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6548-L6556
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetDontHave
func (u StellarMessage) GetDontHave() (result DontHave, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "DontHave" { result = *u.DontHave ok = true } return }
go
func (u StellarMessage) GetDontHave() (result DontHave, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "DontHave" { result = *u.DontHave ok = true } return }
[ "func", "(", "u", "StellarMessage", ")", "GetDontHave", "(", ")", "(", "result", "DontHave", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"DontHave\"", "{", "result", "=", "*", "u", ".", "DontHave", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetDontHave retrieves the DontHave value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetDontHave", "retrieves", "the", "DontHave", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6560-L6569
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustPeers
func (u StellarMessage) MustPeers() []PeerAddress { val, ok := u.GetPeers() if !ok { panic("arm Peers is not set") } return val }
go
func (u StellarMessage) MustPeers() []PeerAddress { val, ok := u.GetPeers() if !ok { panic("arm Peers is not set") } return val }
[ "func", "(", "u", "StellarMessage", ")", "MustPeers", "(", ")", "[", "]", "PeerAddress", "{", "val", ",", "ok", ":=", "u", ".", "GetPeers", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm Peers is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustPeers retrieves the Peers value from the union, // panicing if the value is not set.
[ "MustPeers", "retrieves", "the", "Peers", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6573-L6581
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetPeers
func (u StellarMessage) GetPeers() (result []PeerAddress, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Peers" { result = *u.Peers ok = true } return }
go
func (u StellarMessage) GetPeers() (result []PeerAddress, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Peers" { result = *u.Peers ok = true } return }
[ "func", "(", "u", "StellarMessage", ")", "GetPeers", "(", ")", "(", "result", "[", "]", "PeerAddress", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"Peers\"", "{", "result", "=", "*", "u", ".", "Peers", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetPeers retrieves the Peers value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetPeers", "retrieves", "the", "Peers", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6585-L6594
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustTxSetHash
func (u StellarMessage) MustTxSetHash() Uint256 { val, ok := u.GetTxSetHash() if !ok { panic("arm TxSetHash is not set") } return val }
go
func (u StellarMessage) MustTxSetHash() Uint256 { val, ok := u.GetTxSetHash() if !ok { panic("arm TxSetHash is not set") } return val }
[ "func", "(", "u", "StellarMessage", ")", "MustTxSetHash", "(", ")", "Uint256", "{", "val", ",", "ok", ":=", "u", ".", "GetTxSetHash", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm TxSetHash is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustTxSetHash retrieves the TxSetHash value from the union, // panicing if the value is not set.
[ "MustTxSetHash", "retrieves", "the", "TxSetHash", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6598-L6606
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetTxSetHash
func (u StellarMessage) GetTxSetHash() (result Uint256, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "TxSetHash" { result = *u.TxSetHash ok = true } return }
go
func (u StellarMessage) GetTxSetHash() (result Uint256, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "TxSetHash" { result = *u.TxSetHash ok = true } return }
[ "func", "(", "u", "StellarMessage", ")", "GetTxSetHash", "(", ")", "(", "result", "Uint256", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"TxSetHash\"", "{", "result", "=", "*", "u", ".", "TxSetHash", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetTxSetHash retrieves the TxSetHash value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetTxSetHash", "retrieves", "the", "TxSetHash", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6610-L6619
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustTxSet
func (u StellarMessage) MustTxSet() TransactionSet { val, ok := u.GetTxSet() if !ok { panic("arm TxSet is not set") } return val }
go
func (u StellarMessage) MustTxSet() TransactionSet { val, ok := u.GetTxSet() if !ok { panic("arm TxSet is not set") } return val }
[ "func", "(", "u", "StellarMessage", ")", "MustTxSet", "(", ")", "TransactionSet", "{", "val", ",", "ok", ":=", "u", ".", "GetTxSet", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm TxSet is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustTxSet retrieves the TxSet value from the union, // panicing if the value is not set.
[ "MustTxSet", "retrieves", "the", "TxSet", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6623-L6631
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetTxSet
func (u StellarMessage) GetTxSet() (result TransactionSet, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "TxSet" { result = *u.TxSet ok = true } return }
go
func (u StellarMessage) GetTxSet() (result TransactionSet, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "TxSet" { result = *u.TxSet ok = true } return }
[ "func", "(", "u", "StellarMessage", ")", "GetTxSet", "(", ")", "(", "result", "TransactionSet", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"TxSet\"", "{", "result", "=", "*", "u", ".", "TxSet", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetTxSet retrieves the TxSet value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetTxSet", "retrieves", "the", "TxSet", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6635-L6644
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustTransaction
func (u StellarMessage) MustTransaction() TransactionEnvelope { val, ok := u.GetTransaction() if !ok { panic("arm Transaction is not set") } return val }
go
func (u StellarMessage) MustTransaction() TransactionEnvelope { val, ok := u.GetTransaction() if !ok { panic("arm Transaction is not set") } return val }
[ "func", "(", "u", "StellarMessage", ")", "MustTransaction", "(", ")", "TransactionEnvelope", "{", "val", ",", "ok", ":=", "u", ".", "GetTransaction", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm Transaction is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustTransaction retrieves the Transaction value from the union, // panicing if the value is not set.
[ "MustTransaction", "retrieves", "the", "Transaction", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6648-L6656
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetTransaction
func (u StellarMessage) GetTransaction() (result TransactionEnvelope, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Transaction" { result = *u.Transaction ok = true } return }
go
func (u StellarMessage) GetTransaction() (result TransactionEnvelope, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Transaction" { result = *u.Transaction ok = true } return }
[ "func", "(", "u", "StellarMessage", ")", "GetTransaction", "(", ")", "(", "result", "TransactionEnvelope", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"Transaction\"", "{", "result", "=", "*", "u", ".", "Transaction", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetTransaction retrieves the Transaction value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetTransaction", "retrieves", "the", "Transaction", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6660-L6669
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustQSetHash
func (u StellarMessage) MustQSetHash() Uint256 { val, ok := u.GetQSetHash() if !ok { panic("arm QSetHash is not set") } return val }
go
func (u StellarMessage) MustQSetHash() Uint256 { val, ok := u.GetQSetHash() if !ok { panic("arm QSetHash is not set") } return val }
[ "func", "(", "u", "StellarMessage", ")", "MustQSetHash", "(", ")", "Uint256", "{", "val", ",", "ok", ":=", "u", ".", "GetQSetHash", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm QSetHash is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustQSetHash retrieves the QSetHash value from the union, // panicing if the value is not set.
[ "MustQSetHash", "retrieves", "the", "QSetHash", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6673-L6681
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetQSetHash
func (u StellarMessage) GetQSetHash() (result Uint256, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "QSetHash" { result = *u.QSetHash ok = true } return }
go
func (u StellarMessage) GetQSetHash() (result Uint256, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "QSetHash" { result = *u.QSetHash ok = true } return }
[ "func", "(", "u", "StellarMessage", ")", "GetQSetHash", "(", ")", "(", "result", "Uint256", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"QSetHash\"", "{", "result", "=", "*", "u", ".", "QSetHash", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetQSetHash retrieves the QSetHash value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetQSetHash", "retrieves", "the", "QSetHash", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6685-L6694
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustQSet
func (u StellarMessage) MustQSet() ScpQuorumSet { val, ok := u.GetQSet() if !ok { panic("arm QSet is not set") } return val }
go
func (u StellarMessage) MustQSet() ScpQuorumSet { val, ok := u.GetQSet() if !ok { panic("arm QSet is not set") } return val }
[ "func", "(", "u", "StellarMessage", ")", "MustQSet", "(", ")", "ScpQuorumSet", "{", "val", ",", "ok", ":=", "u", ".", "GetQSet", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm QSet is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustQSet retrieves the QSet value from the union, // panicing if the value is not set.
[ "MustQSet", "retrieves", "the", "QSet", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6698-L6706
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetQSet
func (u StellarMessage) GetQSet() (result ScpQuorumSet, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "QSet" { result = *u.QSet ok = true } return }
go
func (u StellarMessage) GetQSet() (result ScpQuorumSet, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "QSet" { result = *u.QSet ok = true } return }
[ "func", "(", "u", "StellarMessage", ")", "GetQSet", "(", ")", "(", "result", "ScpQuorumSet", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"QSet\"", "{", "result", "=", "*", "u", ".", "QSet", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetQSet retrieves the QSet value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetQSet", "retrieves", "the", "QSet", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6710-L6719
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustEnvelope
func (u StellarMessage) MustEnvelope() ScpEnvelope { val, ok := u.GetEnvelope() if !ok { panic("arm Envelope is not set") } return val }
go
func (u StellarMessage) MustEnvelope() ScpEnvelope { val, ok := u.GetEnvelope() if !ok { panic("arm Envelope is not set") } return val }
[ "func", "(", "u", "StellarMessage", ")", "MustEnvelope", "(", ")", "ScpEnvelope", "{", "val", ",", "ok", ":=", "u", ".", "GetEnvelope", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm Envelope is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustEnvelope retrieves the Envelope value from the union, // panicing if the value is not set.
[ "MustEnvelope", "retrieves", "the", "Envelope", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6723-L6731
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetEnvelope
func (u StellarMessage) GetEnvelope() (result ScpEnvelope, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Envelope" { result = *u.Envelope ok = true } return }
go
func (u StellarMessage) GetEnvelope() (result ScpEnvelope, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Envelope" { result = *u.Envelope ok = true } return }
[ "func", "(", "u", "StellarMessage", ")", "GetEnvelope", "(", ")", "(", "result", "ScpEnvelope", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"Envelope\"", "{", "result", "=", "*", "u", ".", "Envelope", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetEnvelope retrieves the Envelope value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetEnvelope", "retrieves", "the", "Envelope", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6735-L6744
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustGetScpLedgerSeq
func (u StellarMessage) MustGetScpLedgerSeq() Uint32 { val, ok := u.GetGetScpLedgerSeq() if !ok { panic("arm GetScpLedgerSeq is not set") } return val }
go
func (u StellarMessage) MustGetScpLedgerSeq() Uint32 { val, ok := u.GetGetScpLedgerSeq() if !ok { panic("arm GetScpLedgerSeq is not set") } return val }
[ "func", "(", "u", "StellarMessage", ")", "MustGetScpLedgerSeq", "(", ")", "Uint32", "{", "val", ",", "ok", ":=", "u", ".", "GetGetScpLedgerSeq", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm GetScpLedgerSeq is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustGetScpLedgerSeq retrieves the GetScpLedgerSeq value from the union, // panicing if the value is not set.
[ "MustGetScpLedgerSeq", "retrieves", "the", "GetScpLedgerSeq", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6748-L6756
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetGetScpLedgerSeq
func (u StellarMessage) GetGetScpLedgerSeq() (result Uint32, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "GetScpLedgerSeq" { result = *u.GetScpLedgerSeq ok = true } return }
go
func (u StellarMessage) GetGetScpLedgerSeq() (result Uint32, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "GetScpLedgerSeq" { result = *u.GetScpLedgerSeq ok = true } return }
[ "func", "(", "u", "StellarMessage", ")", "GetGetScpLedgerSeq", "(", ")", "(", "result", "Uint32", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"GetScpLedgerSeq\"", "{", "result", "=", "*", "u", ".", "GetScpLedgerSeq", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetGetScpLedgerSeq retrieves the GetScpLedgerSeq value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetGetScpLedgerSeq", "retrieves", "the", "GetScpLedgerSeq", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6760-L6769
test
stellar/go-stellar-base
xdr/xdr_generated.go
ArmForSwitch
func (u AuthenticatedMessage) ArmForSwitch(sw int32) (string, bool) { switch Uint32(sw) { case 0: return "V0", true } return "-", false }
go
func (u AuthenticatedMessage) ArmForSwitch(sw int32) (string, bool) { switch Uint32(sw) { case 0: return "V0", true } return "-", false }
[ "func", "(", "u", "AuthenticatedMessage", ")", "ArmForSwitch", "(", "sw", "int32", ")", "(", "string", ",", "bool", ")", "{", "switch", "Uint32", "(", "sw", ")", "{", "case", "0", ":", "return", "\"V0\"", ",", "true", "\n", "}", "\n", "return", "\"-\"", ",", "false", "\n", "}" ]
// ArmForSwitch returns which field name should be used for storing // the value for an instance of AuthenticatedMessage
[ "ArmForSwitch", "returns", "which", "field", "name", "should", "be", "used", "for", "storing", "the", "value", "for", "an", "instance", "of", "AuthenticatedMessage" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6812-L6818
test
stellar/go-stellar-base
xdr/xdr_generated.go
NewAuthenticatedMessage
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
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 }
[ "func", "NewAuthenticatedMessage", "(", "v", "Uint32", ",", "value", "interface", "{", "}", ")", "(", "result", "AuthenticatedMessage", ",", "err", "error", ")", "{", "result", ".", "V", "=", "v", "\n", "switch", "Uint32", "(", "v", ")", "{", "case", "0", ":", "tv", ",", "ok", ":=", "value", ".", "(", "AuthenticatedMessageV0", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be AuthenticatedMessageV0\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "V0", "=", "&", "tv", "\n", "}", "\n", "return", "\n", "}" ]
// NewAuthenticatedMessage creates a new AuthenticatedMessage.
[ "NewAuthenticatedMessage", "creates", "a", "new", "AuthenticatedMessage", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6821-L6833
test
stellar/go-stellar-base
xdr/xdr_generated.go
ValidEnum
func (e ScpStatementType) ValidEnum(v int32) bool { _, ok := scpStatementTypeMap[v] return ok }
go
func (e ScpStatementType) ValidEnum(v int32) bool { _, ok := scpStatementTypeMap[v] return ok }
[ "func", "(", "e", "ScpStatementType", ")", "ValidEnum", "(", "v", "int32", ")", "bool", "{", "_", ",", "ok", ":=", "scpStatementTypeMap", "[", "v", "]", "\n", "return", "ok", "\n", "}" ]
// ValidEnum validates a proposed value for this enum. Implements // the Enum interface for ScpStatementType
[ "ValidEnum", "validates", "a", "proposed", "value", "for", "this", "enum", ".", "Implements", "the", "Enum", "interface", "for", "ScpStatementType" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L6907-L6910
test
stellar/go-stellar-base
xdr/xdr_generated.go
ArmForSwitch
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
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 }
[ "func", "(", "u", "ScpStatementPledges", ")", "ArmForSwitch", "(", "sw", "int32", ")", "(", "string", ",", "bool", ")", "{", "switch", "ScpStatementType", "(", "sw", ")", "{", "case", "ScpStatementTypeScpStPrepare", ":", "return", "\"Prepare\"", ",", "true", "\n", "case", "ScpStatementTypeScpStConfirm", ":", "return", "\"Confirm\"", ",", "true", "\n", "case", "ScpStatementTypeScpStExternalize", ":", "return", "\"Externalize\"", ",", "true", "\n", "case", "ScpStatementTypeScpStNominate", ":", "return", "\"Nominate\"", ",", "true", "\n", "}", "\n", "return", "\"-\"", ",", "false", "\n", "}" ]
// ArmForSwitch returns which field name should be used for storing // the value for an instance of ScpStatementPledges
[ "ArmForSwitch", "returns", "which", "field", "name", "should", "be", "used", "for", "storing", "the", "value", "for", "an", "instance", "of", "ScpStatementPledges" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L7038-L7050
test
stellar/go-stellar-base
xdr/xdr_generated.go
NewScpStatementPledges
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
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 }
[ "func", "NewScpStatementPledges", "(", "aType", "ScpStatementType", ",", "value", "interface", "{", "}", ")", "(", "result", "ScpStatementPledges", ",", "err", "error", ")", "{", "result", ".", "Type", "=", "aType", "\n", "switch", "ScpStatementType", "(", "aType", ")", "{", "case", "ScpStatementTypeScpStPrepare", ":", "tv", ",", "ok", ":=", "value", ".", "(", "ScpStatementPrepare", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be ScpStatementPrepare\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "Prepare", "=", "&", "tv", "\n", "case", "ScpStatementTypeScpStConfirm", ":", "tv", ",", "ok", ":=", "value", ".", "(", "ScpStatementConfirm", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be ScpStatementConfirm\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "Confirm", "=", "&", "tv", "\n", "case", "ScpStatementTypeScpStExternalize", ":", "tv", ",", "ok", ":=", "value", ".", "(", "ScpStatementExternalize", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be ScpStatementExternalize\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "Externalize", "=", "&", "tv", "\n", "case", "ScpStatementTypeScpStNominate", ":", "tv", ",", "ok", ":=", "value", ".", "(", "ScpNomination", ")", "\n", "if", "!", "ok", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"invalid value, must be ScpNomination\"", ")", "\n", "return", "\n", "}", "\n", "result", ".", "Nominate", "=", "&", "tv", "\n", "}", "\n", "return", "\n", "}" ]
// NewScpStatementPledges creates a new ScpStatementPledges.
[ "NewScpStatementPledges", "creates", "a", "new", "ScpStatementPledges", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L7053-L7086
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustPrepare
func (u ScpStatementPledges) MustPrepare() ScpStatementPrepare { val, ok := u.GetPrepare() if !ok { panic("arm Prepare is not set") } return val }
go
func (u ScpStatementPledges) MustPrepare() ScpStatementPrepare { val, ok := u.GetPrepare() if !ok { panic("arm Prepare is not set") } return val }
[ "func", "(", "u", "ScpStatementPledges", ")", "MustPrepare", "(", ")", "ScpStatementPrepare", "{", "val", ",", "ok", ":=", "u", ".", "GetPrepare", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm Prepare is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustPrepare retrieves the Prepare value from the union, // panicing if the value is not set.
[ "MustPrepare", "retrieves", "the", "Prepare", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L7090-L7098
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetPrepare
func (u ScpStatementPledges) GetPrepare() (result ScpStatementPrepare, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Prepare" { result = *u.Prepare ok = true } return }
go
func (u ScpStatementPledges) GetPrepare() (result ScpStatementPrepare, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Prepare" { result = *u.Prepare ok = true } return }
[ "func", "(", "u", "ScpStatementPledges", ")", "GetPrepare", "(", ")", "(", "result", "ScpStatementPrepare", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"Prepare\"", "{", "result", "=", "*", "u", ".", "Prepare", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetPrepare retrieves the Prepare value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetPrepare", "retrieves", "the", "Prepare", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L7102-L7111
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustConfirm
func (u ScpStatementPledges) MustConfirm() ScpStatementConfirm { val, ok := u.GetConfirm() if !ok { panic("arm Confirm is not set") } return val }
go
func (u ScpStatementPledges) MustConfirm() ScpStatementConfirm { val, ok := u.GetConfirm() if !ok { panic("arm Confirm is not set") } return val }
[ "func", "(", "u", "ScpStatementPledges", ")", "MustConfirm", "(", ")", "ScpStatementConfirm", "{", "val", ",", "ok", ":=", "u", ".", "GetConfirm", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm Confirm is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustConfirm retrieves the Confirm value from the union, // panicing if the value is not set.
[ "MustConfirm", "retrieves", "the", "Confirm", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L7115-L7123
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetConfirm
func (u ScpStatementPledges) GetConfirm() (result ScpStatementConfirm, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Confirm" { result = *u.Confirm ok = true } return }
go
func (u ScpStatementPledges) GetConfirm() (result ScpStatementConfirm, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Confirm" { result = *u.Confirm ok = true } return }
[ "func", "(", "u", "ScpStatementPledges", ")", "GetConfirm", "(", ")", "(", "result", "ScpStatementConfirm", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"Confirm\"", "{", "result", "=", "*", "u", ".", "Confirm", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetConfirm retrieves the Confirm value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetConfirm", "retrieves", "the", "Confirm", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L7127-L7136
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustExternalize
func (u ScpStatementPledges) MustExternalize() ScpStatementExternalize { val, ok := u.GetExternalize() if !ok { panic("arm Externalize is not set") } return val }
go
func (u ScpStatementPledges) MustExternalize() ScpStatementExternalize { val, ok := u.GetExternalize() if !ok { panic("arm Externalize is not set") } return val }
[ "func", "(", "u", "ScpStatementPledges", ")", "MustExternalize", "(", ")", "ScpStatementExternalize", "{", "val", ",", "ok", ":=", "u", ".", "GetExternalize", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm Externalize is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustExternalize retrieves the Externalize value from the union, // panicing if the value is not set.
[ "MustExternalize", "retrieves", "the", "Externalize", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L7140-L7148
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetExternalize
func (u ScpStatementPledges) GetExternalize() (result ScpStatementExternalize, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Externalize" { result = *u.Externalize ok = true } return }
go
func (u ScpStatementPledges) GetExternalize() (result ScpStatementExternalize, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Externalize" { result = *u.Externalize ok = true } return }
[ "func", "(", "u", "ScpStatementPledges", ")", "GetExternalize", "(", ")", "(", "result", "ScpStatementExternalize", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"Externalize\"", "{", "result", "=", "*", "u", ".", "Externalize", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetExternalize retrieves the Externalize value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetExternalize", "retrieves", "the", "Externalize", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L7152-L7161
test
stellar/go-stellar-base
xdr/xdr_generated.go
MustNominate
func (u ScpStatementPledges) MustNominate() ScpNomination { val, ok := u.GetNominate() if !ok { panic("arm Nominate is not set") } return val }
go
func (u ScpStatementPledges) MustNominate() ScpNomination { val, ok := u.GetNominate() if !ok { panic("arm Nominate is not set") } return val }
[ "func", "(", "u", "ScpStatementPledges", ")", "MustNominate", "(", ")", "ScpNomination", "{", "val", ",", "ok", ":=", "u", ".", "GetNominate", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"arm Nominate is not set\"", ")", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustNominate retrieves the Nominate value from the union, // panicing if the value is not set.
[ "MustNominate", "retrieves", "the", "Nominate", "value", "from", "the", "union", "panicing", "if", "the", "value", "is", "not", "set", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L7165-L7173
test
stellar/go-stellar-base
xdr/xdr_generated.go
GetNominate
func (u ScpStatementPledges) GetNominate() (result ScpNomination, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Nominate" { result = *u.Nominate ok = true } return }
go
func (u ScpStatementPledges) GetNominate() (result ScpNomination, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) if armName == "Nominate" { result = *u.Nominate ok = true } return }
[ "func", "(", "u", "ScpStatementPledges", ")", "GetNominate", "(", ")", "(", "result", "ScpNomination", ",", "ok", "bool", ")", "{", "armName", ",", "_", ":=", "u", ".", "ArmForSwitch", "(", "int32", "(", "u", ".", "Type", ")", ")", "\n", "if", "armName", "==", "\"Nominate\"", "{", "result", "=", "*", "u", ".", "Nominate", "\n", "ok", "=", "true", "\n", "}", "\n", "return", "\n", "}" ]
// GetNominate retrieves the Nominate value from the union, // returning ok if the union's switch indicated the value is valid.
[ "GetNominate", "retrieves", "the", "Nominate", "value", "from", "the", "union", "returning", "ok", "if", "the", "union", "s", "switch", "indicated", "the", "value", "is", "valid", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/xdr_generated.go#L7177-L7186
test
stellar/go-stellar-base
xdr/main.go
SafeUnmarshalBase64
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
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 }
[ "func", "SafeUnmarshalBase64", "(", "data", "string", ",", "dest", "interface", "{", "}", ")", "error", "{", "count", ":=", "&", "countWriter", "{", "}", "\n", "l", ":=", "len", "(", "data", ")", "\n", "b64", ":=", "io", ".", "TeeReader", "(", "strings", ".", "NewReader", "(", "data", ")", ",", "count", ")", "\n", "raw", ":=", "base64", ".", "NewDecoder", "(", "base64", ".", "StdEncoding", ",", "b64", ")", "\n", "_", ",", "err", ":=", "Unmarshal", "(", "raw", ",", "dest", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "count", ".", "Count", "!=", "l", "{", "return", "fmt", ".", "Errorf", "(", "\"input not fully consumed. expected to read: %d, actual: %d\"", ",", "l", ",", "count", ".", "Count", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// SafeUnmarshalBase64 first decodes the provided reader from base64 before decoding the xdr // into the provided destination. Also ensures that the reader is fully consumed.
[ "SafeUnmarshalBase64", "first", "decodes", "the", "provided", "reader", "from", "base64", "before", "decoding", "the", "xdr", "into", "the", "provided", "destination", ".", "Also", "ensures", "that", "the", "reader", "is", "fully", "consumed", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/main.go#L23-L40
test
stellar/go-stellar-base
xdr/main.go
SafeUnmarshal
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
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 }
[ "func", "SafeUnmarshal", "(", "data", "[", "]", "byte", ",", "dest", "interface", "{", "}", ")", "error", "{", "r", ":=", "bytes", ".", "NewReader", "(", "data", ")", "\n", "n", ",", "err", ":=", "Unmarshal", "(", "r", ",", "dest", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "n", "!=", "len", "(", "data", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"input not fully consumed. expected to read: %d, actual: %d\"", ",", "len", "(", "data", ")", ",", "n", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// SafeUnmarshal decodes the provided reader into the destination and verifies // that provided bytes are all consumed by the unmarshalling process.
[ "SafeUnmarshal", "decodes", "the", "provided", "reader", "into", "the", "destination", "and", "verifies", "that", "provided", "bytes", "are", "all", "consumed", "by", "the", "unmarshalling", "process", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/main.go#L44-L57
test
stellar/go-stellar-base
xdr/path_payment_result.go
SendAmount
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
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 }
[ "func", "(", "pr", "*", "PathPaymentResult", ")", "SendAmount", "(", ")", "Int64", "{", "s", ",", "ok", ":=", "pr", ".", "GetSuccess", "(", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "if", "len", "(", "s", ".", "Offers", ")", "==", "0", "{", "return", "s", ".", "Last", ".", "Amount", "\n", "}", "\n", "sa", ":=", "s", ".", "Offers", "[", "0", "]", ".", "AssetBought", "\n", "var", "ret", "Int64", "\n", "for", "_", ",", "o", ":=", "range", "s", ".", "Offers", "{", "if", "o", ".", "AssetBought", ".", "String", "(", ")", "!=", "sa", ".", "String", "(", ")", "{", "break", "\n", "}", "\n", "ret", "+=", "o", ".", "AmountBought", "\n", "}", "\n", "return", "ret", "\n", "}" ]
// SendAmount returns the amount spent, denominated in the source asset, in the // course of this path payment
[ "SendAmount", "returns", "the", "amount", "spent", "denominated", "in", "the", "source", "asset", "in", "the", "course", "of", "this", "path", "payment" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/path_payment_result.go#L5-L26
test
stellar/go-stellar-base
horizon/main.go
LoadAccount
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
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 }
[ "func", "(", "c", "*", "Client", ")", "LoadAccount", "(", "accountID", "string", ")", "(", "account", "Account", ",", "err", "error", ")", "{", "c", ".", "initHTTPClient", "(", ")", "\n", "resp", ",", "err", ":=", "c", ".", "Client", ".", "Get", "(", "c", ".", "URL", "+", "\"/accounts/\"", "+", "accountID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "err", "=", "decodeResponse", "(", "resp", ",", "&", "account", ")", "\n", "return", "\n", "}" ]
// LoadAccount loads the account state from horizon. err can be either error // object or horizon.Error object.
[ "LoadAccount", "loads", "the", "account", "state", "from", "horizon", ".", "err", "can", "be", "either", "error", "object", "or", "horizon", ".", "Error", "object", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/horizon/main.go#L48-L57
test
stellar/go-stellar-base
horizon/main.go
SequenceForAccount
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
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 }
[ "func", "(", "c", "*", "Client", ")", "SequenceForAccount", "(", "accountID", "string", ",", ")", "(", "xdr", ".", "SequenceNumber", ",", "error", ")", "{", "a", ",", "err", ":=", "c", ".", "LoadAccount", "(", "accountID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "seq", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "a", ".", "Sequence", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "xdr", ".", "SequenceNumber", "(", "seq", ")", ",", "nil", "\n", "}" ]
// SequenceForAccount implements build.SequenceProvider
[ "SequenceForAccount", "implements", "build", ".", "SequenceProvider" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/horizon/main.go#L60-L75
test
stellar/go-stellar-base
horizon/main.go
SubmitTransaction
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
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 }
[ "func", "(", "c", "*", "Client", ")", "SubmitTransaction", "(", "transactionEnvelopeXdr", "string", ")", "(", "response", "TransactionSuccess", ",", "err", "error", ")", "{", "v", ":=", "url", ".", "Values", "{", "}", "\n", "v", ".", "Set", "(", "\"tx\"", ",", "transactionEnvelopeXdr", ")", "\n", "c", ".", "initHTTPClient", "(", ")", "\n", "resp", ",", "err", ":=", "c", ".", "Client", ".", "PostForm", "(", "c", ".", "URL", "+", "\"/transactions\"", ",", "v", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "err", "=", "decodeResponse", "(", "resp", ",", "&", "response", ")", "\n", "return", "\n", "}" ]
// SubmitTransaction submits a transaction to the network. err can be either error object or horizon.Error object.
[ "SubmitTransaction", "submits", "a", "transaction", "to", "the", "network", ".", "err", "can", "be", "either", "error", "object", "or", "horizon", ".", "Error", "object", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/horizon/main.go#L78-L90
test
stellar/go-stellar-base
xdr/ledger_key.go
Equals
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
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)) } }
[ "func", "(", "key", "*", "LedgerKey", ")", "Equals", "(", "other", "LedgerKey", ")", "bool", "{", "if", "key", ".", "Type", "!=", "other", ".", "Type", "{", "return", "false", "\n", "}", "\n", "switch", "key", ".", "Type", "{", "case", "LedgerEntryTypeAccount", ":", "l", ":=", "key", ".", "MustAccount", "(", ")", "\n", "r", ":=", "other", ".", "MustAccount", "(", ")", "\n", "return", "l", ".", "AccountId", ".", "Equals", "(", "r", ".", "AccountId", ")", "\n", "case", "LedgerEntryTypeData", ":", "l", ":=", "key", ".", "MustData", "(", ")", "\n", "r", ":=", "other", ".", "MustData", "(", ")", "\n", "return", "l", ".", "AccountId", ".", "Equals", "(", "r", ".", "AccountId", ")", "&&", "l", ".", "DataName", "==", "r", ".", "DataName", "\n", "case", "LedgerEntryTypeOffer", ":", "l", ":=", "key", ".", "MustOffer", "(", ")", "\n", "r", ":=", "other", ".", "MustOffer", "(", ")", "\n", "return", "l", ".", "SellerId", ".", "Equals", "(", "r", ".", "SellerId", ")", "&&", "l", ".", "OfferId", "==", "r", ".", "OfferId", "\n", "case", "LedgerEntryTypeTrustline", ":", "l", ":=", "key", ".", "MustTrustLine", "(", ")", "\n", "r", ":=", "other", ".", "MustTrustLine", "(", ")", "\n", "return", "l", ".", "AccountId", ".", "Equals", "(", "r", ".", "AccountId", ")", "&&", "l", ".", "Asset", ".", "Equals", "(", "r", ".", "Asset", ")", "\n", "default", ":", "panic", "(", "fmt", ".", "Errorf", "(", "\"Unknown ledger key type: %v\"", ",", "key", ".", "Type", ")", ")", "\n", "}", "\n", "}" ]
// Equals returns true if `other` is equivalent to `key`
[ "Equals", "returns", "true", "if", "other", "is", "equivalent", "to", "key" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/ledger_key.go#L11-L36
test
stellar/go-stellar-base
xdr/ledger_key.go
SetAccount
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
func (key *LedgerKey) SetAccount(account AccountId) error { data := LedgerKeyAccount{account} nkey, err := NewLedgerKey(LedgerEntryTypeAccount, data) if err != nil { return err } *key = nkey return nil }
[ "func", "(", "key", "*", "LedgerKey", ")", "SetAccount", "(", "account", "AccountId", ")", "error", "{", "data", ":=", "LedgerKeyAccount", "{", "account", "}", "\n", "nkey", ",", "err", ":=", "NewLedgerKey", "(", "LedgerEntryTypeAccount", ",", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "*", "key", "=", "nkey", "\n", "return", "nil", "\n", "}" ]
// SetAccount mutates `key` such that it represents the identity of `account`
[ "SetAccount", "mutates", "key", "such", "that", "it", "represents", "the", "identity", "of", "account" ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/ledger_key.go#L39-L48
test
stellar/go-stellar-base
xdr/ledger_key.go
SetData
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
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 }
[ "func", "(", "key", "*", "LedgerKey", ")", "SetData", "(", "account", "AccountId", ",", "name", "string", ")", "error", "{", "data", ":=", "LedgerKeyData", "{", "account", ",", "String64", "(", "name", ")", "}", "\n", "nkey", ",", "err", ":=", "NewLedgerKey", "(", "LedgerEntryTypeData", ",", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "*", "key", "=", "nkey", "\n", "return", "nil", "\n", "}" ]
// SetData mutates `key` such that it represents the identity of the // data entry owned by `account` and for `name`.
[ "SetData", "mutates", "key", "such", "that", "it", "represents", "the", "identity", "of", "the", "data", "entry", "owned", "by", "account", "and", "for", "name", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/ledger_key.go#L52-L61
test
stellar/go-stellar-base
xdr/ledger_key.go
SetOffer
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
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 }
[ "func", "(", "key", "*", "LedgerKey", ")", "SetOffer", "(", "account", "AccountId", ",", "id", "uint64", ")", "error", "{", "data", ":=", "LedgerKeyOffer", "{", "account", ",", "Uint64", "(", "id", ")", "}", "\n", "nkey", ",", "err", ":=", "NewLedgerKey", "(", "LedgerEntryTypeOffer", ",", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "*", "key", "=", "nkey", "\n", "return", "nil", "\n", "}" ]
// SetOffer mutates `key` such that it represents the identity of the // data entry owned by `account` and for offer `id`.
[ "SetOffer", "mutates", "key", "such", "that", "it", "represents", "the", "identity", "of", "the", "data", "entry", "owned", "by", "account", "and", "for", "offer", "id", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/ledger_key.go#L65-L74
test
stellar/go-stellar-base
xdr/ledger_key.go
SetTrustline
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
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 }
[ "func", "(", "key", "*", "LedgerKey", ")", "SetTrustline", "(", "account", "AccountId", ",", "line", "Asset", ")", "error", "{", "data", ":=", "LedgerKeyTrustLine", "{", "account", ",", "line", "}", "\n", "nkey", ",", "err", ":=", "NewLedgerKey", "(", "LedgerEntryTypeTrustline", ",", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "*", "key", "=", "nkey", "\n", "return", "nil", "\n", "}" ]
// SetTrustline mutates `key` such that it represents the identity of the // trustline owned by `account` and for `asset`.
[ "SetTrustline", "mutates", "key", "such", "that", "it", "represents", "the", "identity", "of", "the", "trustline", "owned", "by", "account", "and", "for", "asset", "." ]
79c570612c0b461db178aa8949d9f13cafc2a7c9
https://github.com/stellar/go-stellar-base/blob/79c570612c0b461db178aa8949d9f13cafc2a7c9/xdr/ledger_key.go#L78-L87
test
alecthomas/mph
chd_builder.go
Add
func (b *CHDBuilder) Add(key []byte, value []byte) { b.keys = append(b.keys, key) b.values = append(b.values, value) }
go
func (b *CHDBuilder) Add(key []byte, value []byte) { b.keys = append(b.keys, key) b.values = append(b.values, value) }
[ "func", "(", "b", "*", "CHDBuilder", ")", "Add", "(", "key", "[", "]", "byte", ",", "value", "[", "]", "byte", ")", "{", "b", ".", "keys", "=", "append", "(", "b", ".", "keys", ",", "key", ")", "\n", "b", ".", "values", "=", "append", "(", "b", ".", "values", ",", "value", ")", "\n", "}" ]
// Add a key and value to the hash table.
[ "Add", "a", "key", "and", "value", "to", "the", "hash", "table", "." ]
cf7b0cd2d9579868ec2a49493fd62b2e28bcb336
https://github.com/alecthomas/mph/blob/cf7b0cd2d9579868ec2a49493fd62b2e28bcb336/chd_builder.go#L51-L54
test
alecthomas/mph
chd_builder.go
tryHash
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
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 }
[ "func", "tryHash", "(", "hasher", "*", "chdHasher", ",", "seen", "map", "[", "uint64", "]", "bool", ",", "keys", "[", "]", "[", "]", "byte", ",", "values", "[", "]", "[", "]", "byte", ",", "indices", "[", "]", "uint16", ",", "bucket", "*", "bucket", ",", "ri", "uint16", ",", "r", "uint64", ")", "bool", "{", "duplicate", ":=", "make", "(", "map", "[", "uint64", "]", "bool", ")", "\n", "hashes", ":=", "make", "(", "[", "]", "uint64", ",", "len", "(", "bucket", ".", "keys", ")", ")", "\n", "for", "i", ",", "k", ":=", "range", "bucket", ".", "keys", "{", "h", ":=", "hasher", ".", "Table", "(", "r", ",", "k", ")", "\n", "hashes", "[", "i", "]", "=", "h", "\n", "if", "seen", "[", "h", "]", "{", "return", "false", "\n", "}", "\n", "if", "duplicate", "[", "h", "]", "{", "return", "false", "\n", "}", "\n", "duplicate", "[", "h", "]", "=", "true", "\n", "}", "\n", "for", "_", ",", "h", ":=", "range", "hashes", "{", "seen", "[", "h", "]", "=", "true", "\n", "}", "\n", "indices", "[", "bucket", ".", "index", "]", "=", "ri", "\n", "for", "i", ",", "h", ":=", "range", "hashes", "{", "keys", "[", "h", "]", "=", "bucket", ".", "keys", "[", "i", "]", "\n", "values", "[", "h", "]", "=", "bucket", ".", "values", "[", "i", "]", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Try to find a hash function that does not cause collisions with table, when // applied to the keys in the bucket.
[ "Try", "to", "find", "a", "hash", "function", "that", "does", "not", "cause", "collisions", "with", "table", "when", "applied", "to", "the", "keys", "in", "the", "bucket", "." ]
cf7b0cd2d9579868ec2a49493fd62b2e28bcb336
https://github.com/alecthomas/mph/blob/cf7b0cd2d9579868ec2a49493fd62b2e28bcb336/chd_builder.go#L58-L89
test
alecthomas/mph
chd_builder.go
HashIndexFromKey
func (h *chdHasher) HashIndexFromKey(b []byte) uint64 { return (hasher(b) ^ h.r[0]) % h.buckets }
go
func (h *chdHasher) HashIndexFromKey(b []byte) uint64 { return (hasher(b) ^ h.r[0]) % h.buckets }
[ "func", "(", "h", "*", "chdHasher", ")", "HashIndexFromKey", "(", "b", "[", "]", "byte", ")", "uint64", "{", "return", "(", "hasher", "(", "b", ")", "^", "h", ".", "r", "[", "0", "]", ")", "%", "h", ".", "buckets", "\n", "}" ]
// Hash index from key.
[ "Hash", "index", "from", "key", "." ]
cf7b0cd2d9579868ec2a49493fd62b2e28bcb336
https://github.com/alecthomas/mph/blob/cf7b0cd2d9579868ec2a49493fd62b2e28bcb336/chd_builder.go#L187-L189
test
alecthomas/mph
slicereader_fast.go
ReadInt
func (b *sliceReader) ReadInt() uint64 { return uint64(binary.LittleEndian.Uint32(b.Read(4))) }
go
func (b *sliceReader) ReadInt() uint64 { return uint64(binary.LittleEndian.Uint32(b.Read(4))) }
[ "func", "(", "b", "*", "sliceReader", ")", "ReadInt", "(", ")", "uint64", "{", "return", "uint64", "(", "binary", ".", "LittleEndian", ".", "Uint32", "(", "b", ".", "Read", "(", "4", ")", ")", ")", "\n", "}" ]
// Despite returning a uint64, this actually reads a uint32. All table indices // and lengths are stored as uint32 values.
[ "Despite", "returning", "a", "uint64", "this", "actually", "reads", "a", "uint32", ".", "All", "table", "indices", "and", "lengths", "are", "stored", "as", "uint32", "values", "." ]
cf7b0cd2d9579868ec2a49493fd62b2e28bcb336
https://github.com/alecthomas/mph/blob/cf7b0cd2d9579868ec2a49493fd62b2e28bcb336/slicereader_fast.go#L37-L39
test
alecthomas/mph
chd.go
Read
func Read(r io.Reader) (*CHD, error) { b, err := ioutil.ReadAll(r) if err != nil { return nil, err } return Mmap(b) }
go
func Read(r io.Reader) (*CHD, error) { b, err := ioutil.ReadAll(r) if err != nil { return nil, err } return Mmap(b) }
[ "func", "Read", "(", "r", "io", ".", "Reader", ")", "(", "*", "CHD", ",", "error", ")", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "Mmap", "(", "b", ")", "\n", "}" ]
// Read a serialized CHD.
[ "Read", "a", "serialized", "CHD", "." ]
cf7b0cd2d9579868ec2a49493fd62b2e28bcb336
https://github.com/alecthomas/mph/blob/cf7b0cd2d9579868ec2a49493fd62b2e28bcb336/chd.go#L61-L67
test
alecthomas/mph
chd.go
Get
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
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 }
[ "func", "(", "c", "*", "CHD", ")", "Get", "(", "key", "[", "]", "byte", ")", "[", "]", "byte", "{", "r0", ":=", "c", ".", "r", "[", "0", "]", "\n", "h", ":=", "hasher", "(", "key", ")", "^", "r0", "\n", "i", ":=", "h", "%", "uint64", "(", "len", "(", "c", ".", "indices", ")", ")", "\n", "ri", ":=", "c", ".", "indices", "[", "i", "]", "\n", "if", "ri", ">=", "uint16", "(", "len", "(", "c", ".", "r", ")", ")", "{", "return", "nil", "\n", "}", "\n", "r", ":=", "c", ".", "r", "[", "ri", "]", "\n", "ti", ":=", "(", "h", "^", "r", ")", "%", "uint64", "(", "len", "(", "c", ".", "keys", ")", ")", "\n", "k", ":=", "c", ".", "keys", "[", "ti", "]", "\n", "if", "bytes", ".", "Compare", "(", "k", ",", "key", ")", "!=", "0", "{", "return", "nil", "\n", "}", "\n", "v", ":=", "c", ".", "values", "[", "ti", "]", "\n", "return", "v", "\n", "}" ]
// Get an entry from the hash table.
[ "Get", "an", "entry", "from", "the", "hash", "table", "." ]
cf7b0cd2d9579868ec2a49493fd62b2e28bcb336
https://github.com/alecthomas/mph/blob/cf7b0cd2d9579868ec2a49493fd62b2e28bcb336/chd.go#L99-L117
test
alecthomas/mph
chd.go
Iterate
func (c *CHD) Iterate() *Iterator { if len(c.keys) == 0 { return nil } return &Iterator{c: c} }
go
func (c *CHD) Iterate() *Iterator { if len(c.keys) == 0 { return nil } return &Iterator{c: c} }
[ "func", "(", "c", "*", "CHD", ")", "Iterate", "(", ")", "*", "Iterator", "{", "if", "len", "(", "c", ".", "keys", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "return", "&", "Iterator", "{", "c", ":", "c", "}", "\n", "}" ]
// Iterate over entries in the hash table.
[ "Iterate", "over", "entries", "in", "the", "hash", "table", "." ]
cf7b0cd2d9579868ec2a49493fd62b2e28bcb336
https://github.com/alecthomas/mph/blob/cf7b0cd2d9579868ec2a49493fd62b2e28bcb336/chd.go#L124-L129
test
alecthomas/mph
chd.go
Write
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
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 }
[ "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", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "data", ":=", "[", "]", "interface", "{", "}", "{", "uint32", "(", "len", "(", "c", ".", "r", ")", ")", ",", "c", ".", "r", ",", "uint32", "(", "len", "(", "c", ".", "indices", ")", ")", ",", "c", ".", "indices", ",", "uint32", "(", "len", "(", "c", ".", "keys", ")", ")", ",", "}", "\n", "if", "err", ":=", "write", "(", "data", "...", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "i", ":=", "range", "c", ".", "keys", "{", "k", ",", "v", ":=", "c", ".", "keys", "[", "i", "]", ",", "c", ".", "values", "[", "i", "]", "\n", "if", "err", ":=", "write", "(", "uint32", "(", "len", "(", "k", ")", ")", ",", "uint32", "(", "len", "(", "v", ")", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "_", ",", "err", ":=", "w", ".", "Write", "(", "k", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "_", ",", "err", ":=", "w", ".", "Write", "(", "v", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Serialize the CHD. The serialized form is conducive to mmapped access. See // the Mmap function for details.
[ "Serialize", "the", "CHD", ".", "The", "serialized", "form", "is", "conducive", "to", "mmapped", "access", ".", "See", "the", "Mmap", "function", "for", "details", "." ]
cf7b0cd2d9579868ec2a49493fd62b2e28bcb336
https://github.com/alecthomas/mph/blob/cf7b0cd2d9579868ec2a49493fd62b2e28bcb336/chd.go#L133-L166
test
omniscale/go-mapnik
mapnik.go
RegisterDatasources
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
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 }
[ "func", "RegisterDatasources", "(", "path", "string", ")", "error", "{", "cs", ":=", "C", ".", "CString", "(", "path", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cs", ")", ")", "\n", "if", "C", ".", "mapnik_register_datasources", "(", "cs", ")", "==", "0", "{", "e", ":=", "C", ".", "GoString", "(", "C", ".", "mapnik_register_last_error", "(", ")", ")", "\n", "if", "e", "!=", "\"\"", "{", "return", "errors", ".", "New", "(", "\"registering datasources: \"", "+", "e", ")", "\n", "}", "\n", "return", "errors", ".", "New", "(", "\"error while registering datasources\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RegisterDatasources adds path to the Mapnik plugin search path.
[ "RegisterDatasources", "adds", "path", "to", "the", "Mapnik", "plugin", "search", "path", "." ]
710dfcc5e486e5760d0a5c46be909d91968e1ffb
https://github.com/omniscale/go-mapnik/blob/710dfcc5e486e5760d0a5c46be909d91968e1ffb/mapnik.go#L40-L51
test
omniscale/go-mapnik
mapnik.go
RegisterFonts
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
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 }
[ "func", "RegisterFonts", "(", "path", "string", ")", "error", "{", "cs", ":=", "C", ".", "CString", "(", "path", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cs", ")", ")", "\n", "if", "C", ".", "mapnik_register_fonts", "(", "cs", ")", "==", "0", "{", "e", ":=", "C", ".", "GoString", "(", "C", ".", "mapnik_register_last_error", "(", ")", ")", "\n", "if", "e", "!=", "\"\"", "{", "return", "errors", ".", "New", "(", "\"registering fonts: \"", "+", "e", ")", "\n", "}", "\n", "return", "errors", ".", "New", "(", "\"error while registering fonts\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RegisterDatasources adds path to the Mapnik fonts search path.
[ "RegisterDatasources", "adds", "path", "to", "the", "Mapnik", "fonts", "search", "path", "." ]
710dfcc5e486e5760d0a5c46be909d91968e1ffb
https://github.com/omniscale/go-mapnik/blob/710dfcc5e486e5760d0a5c46be909d91968e1ffb/mapnik.go#L54-L65
test
omniscale/go-mapnik
mapnik.go
New
func New() *Map { return &Map{ m: C.mapnik_map(C.uint(800), C.uint(600)), width: 800, height: 600, } }
go
func New() *Map { return &Map{ m: C.mapnik_map(C.uint(800), C.uint(600)), width: 800, height: 600, } }
[ "func", "New", "(", ")", "*", "Map", "{", "return", "&", "Map", "{", "m", ":", "C", ".", "mapnik_map", "(", "C", ".", "uint", "(", "800", ")", ",", "C", ".", "uint", "(", "600", ")", ")", ",", "width", ":", "800", ",", "height", ":", "600", ",", "}", "\n", "}" ]
// New initializes a new Map.
[ "New", "initializes", "a", "new", "Map", "." ]
710dfcc5e486e5760d0a5c46be909d91968e1ffb
https://github.com/omniscale/go-mapnik/blob/710dfcc5e486e5760d0a5c46be909d91968e1ffb/mapnik.go#L99-L105
test
omniscale/go-mapnik
mapnik.go
NewSized
func NewSized(width, height int) *Map { return &Map{ m: C.mapnik_map(C.uint(width), C.uint(height)), width: width, height: height, } }
go
func NewSized(width, height int) *Map { return &Map{ m: C.mapnik_map(C.uint(width), C.uint(height)), width: width, height: height, } }
[ "func", "NewSized", "(", "width", ",", "height", "int", ")", "*", "Map", "{", "return", "&", "Map", "{", "m", ":", "C", ".", "mapnik_map", "(", "C", ".", "uint", "(", "width", ")", ",", "C", ".", "uint", "(", "height", ")", ")", ",", "width", ":", "width", ",", "height", ":", "height", ",", "}", "\n", "}" ]
// NewSized initializes a new Map with the given size.
[ "NewSized", "initializes", "a", "new", "Map", "with", "the", "given", "size", "." ]
710dfcc5e486e5760d0a5c46be909d91968e1ffb
https://github.com/omniscale/go-mapnik/blob/710dfcc5e486e5760d0a5c46be909d91968e1ffb/mapnik.go#L108-L114
test
omniscale/go-mapnik
mapnik.go
Load
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
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 }
[ "func", "(", "m", "*", "Map", ")", "Load", "(", "stylesheet", "string", ")", "error", "{", "cs", ":=", "C", ".", "CString", "(", "stylesheet", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cs", ")", ")", "\n", "if", "C", ".", "mapnik_map_load", "(", "m", ".", "m", ",", "cs", ")", "!=", "0", "{", "return", "m", ".", "lastError", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Load reads in a Mapnik map XML.
[ "Load", "reads", "in", "a", "Mapnik", "map", "XML", "." ]
710dfcc5e486e5760d0a5c46be909d91968e1ffb
https://github.com/omniscale/go-mapnik/blob/710dfcc5e486e5760d0a5c46be909d91968e1ffb/mapnik.go#L121-L128
test
omniscale/go-mapnik
mapnik.go
Resize
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
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 }
[ "func", "(", "m", "*", "Map", ")", "Resize", "(", "width", ",", "height", "int", ")", "{", "C", ".", "mapnik_map_resize", "(", "m", ".", "m", ",", "C", ".", "uint", "(", "width", ")", ",", "C", ".", "uint", "(", "height", ")", ")", "\n", "m", ".", "width", "=", "width", "\n", "m", ".", "height", "=", "height", "\n", "}" ]
// Resize changes the map size in pixel. // Sizes larger than 16k pixels are ignored by Mapnik. Use NewSized // to initialize larger maps.
[ "Resize", "changes", "the", "map", "size", "in", "pixel", ".", "Sizes", "larger", "than", "16k", "pixels", "are", "ignored", "by", "Mapnik", ".", "Use", "NewSized", "to", "initialize", "larger", "maps", "." ]
710dfcc5e486e5760d0a5c46be909d91968e1ffb
https://github.com/omniscale/go-mapnik/blob/710dfcc5e486e5760d0a5c46be909d91968e1ffb/mapnik.go#L133-L137
test
omniscale/go-mapnik
mapnik.go
Free
func (m *Map) Free() { C.mapnik_map_free(m.m) m.m = nil }
go
func (m *Map) Free() { C.mapnik_map_free(m.m) m.m = nil }
[ "func", "(", "m", "*", "Map", ")", "Free", "(", ")", "{", "C", ".", "mapnik_map_free", "(", "m", ".", "m", ")", "\n", "m", ".", "m", "=", "nil", "\n", "}" ]
// Free deallocates the map.
[ "Free", "deallocates", "the", "map", "." ]
710dfcc5e486e5760d0a5c46be909d91968e1ffb
https://github.com/omniscale/go-mapnik/blob/710dfcc5e486e5760d0a5c46be909d91968e1ffb/mapnik.go#L140-L143
test
omniscale/go-mapnik
mapnik.go
SRS
func (m *Map) SRS() string { return C.GoString(C.mapnik_map_get_srs(m.m)) }
go
func (m *Map) SRS() string { return C.GoString(C.mapnik_map_get_srs(m.m)) }
[ "func", "(", "m", "*", "Map", ")", "SRS", "(", ")", "string", "{", "return", "C", ".", "GoString", "(", "C", ".", "mapnik_map_get_srs", "(", "m", ".", "m", ")", ")", "\n", "}" ]
// SRS returns the projection of the map.
[ "SRS", "returns", "the", "projection", "of", "the", "map", "." ]
710dfcc5e486e5760d0a5c46be909d91968e1ffb
https://github.com/omniscale/go-mapnik/blob/710dfcc5e486e5760d0a5c46be909d91968e1ffb/mapnik.go#L146-L148
test
omniscale/go-mapnik
mapnik.go
ZoomAll
func (m *Map) ZoomAll() error { if C.mapnik_map_zoom_all(m.m) != 0 { return m.lastError() } return nil }
go
func (m *Map) ZoomAll() error { if C.mapnik_map_zoom_all(m.m) != 0 { return m.lastError() } return nil }
[ "func", "(", "m", "*", "Map", ")", "ZoomAll", "(", ")", "error", "{", "if", "C", ".", "mapnik_map_zoom_all", "(", "m", ".", "m", ")", "!=", "0", "{", "return", "m", ".", "lastError", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ZoomAll zooms to the maximum extent.
[ "ZoomAll", "zooms", "to", "the", "maximum", "extent", "." ]
710dfcc5e486e5760d0a5c46be909d91968e1ffb
https://github.com/omniscale/go-mapnik/blob/710dfcc5e486e5760d0a5c46be909d91968e1ffb/mapnik.go#L163-L168
test
omniscale/go-mapnik
mapnik.go
ZoomTo
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
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) }
[ "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", ")", ")", "\n", "defer", "C", ".", "mapnik_bbox_free", "(", "bbox", ")", "\n", "C", ".", "mapnik_map_zoom_to_box", "(", "m", ".", "m", ",", "bbox", ")", "\n", "}" ]
// ZoomTo zooms to the given bounding box.
[ "ZoomTo", "zooms", "to", "the", "given", "bounding", "box", "." ]
710dfcc5e486e5760d0a5c46be909d91968e1ffb
https://github.com/omniscale/go-mapnik/blob/710dfcc5e486e5760d0a5c46be909d91968e1ffb/mapnik.go#L171-L175
test
omniscale/go-mapnik
mapnik.go
Render
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
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 }
[ "func", "(", "m", "*", "Map", ")", "Render", "(", "opts", "RenderOpts", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "scaleFactor", ":=", "opts", ".", "ScaleFactor", "\n", "if", "scaleFactor", "==", "0.0", "{", "scaleFactor", "=", "1.0", "\n", "}", "\n", "i", ":=", "C", ".", "mapnik_map_render_to_image", "(", "m", ".", "m", ",", "C", ".", "double", "(", "opts", ".", "Scale", ")", ",", "C", ".", "double", "(", "scaleFactor", ")", ")", "\n", "if", "i", "==", "nil", "{", "return", "nil", ",", "m", ".", "lastError", "(", ")", "\n", "}", "\n", "defer", "C", ".", "mapnik_image_free", "(", "i", ")", "\n", "if", "opts", ".", "Format", "==", "\"raw\"", "{", "size", ":=", "0", "\n", "raw", ":=", "C", ".", "mapnik_image_to_raw", "(", "i", ",", "(", "*", "C", ".", "size_t", ")", "(", "unsafe", ".", "Pointer", "(", "&", "size", ")", ")", ")", "\n", "return", "C", ".", "GoBytes", "(", "unsafe", ".", "Pointer", "(", "raw", ")", ",", "C", ".", "int", "(", "size", ")", ")", ",", "nil", "\n", "}", "\n", "var", "format", "*", "C", ".", "char", "\n", "if", "opts", ".", "Format", "!=", "\"\"", "{", "format", "=", "C", ".", "CString", "(", "opts", ".", "Format", ")", "\n", "}", "else", "{", "format", "=", "C", ".", "CString", "(", "\"png256\"", ")", "\n", "}", "\n", "b", ":=", "C", ".", "mapnik_image_to_blob", "(", "i", ",", "format", ")", "\n", "if", "b", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"mapnik: \"", "+", "C", ".", "GoString", "(", "C", ".", "mapnik_image_last_error", "(", "i", ")", ")", ")", "\n", "}", "\n", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "format", ")", ")", "\n", "defer", "C", ".", "mapnik_image_blob_free", "(", "b", ")", "\n", "return", "C", ".", "GoBytes", "(", "unsafe", ".", "Pointer", "(", "b", ".", "ptr", ")", ",", "C", ".", "int", "(", "b", ".", "len", ")", ")", ",", "nil", "\n", "}" ]
// Render returns the map as an encoded image.
[ "Render", "returns", "the", "map", "as", "an", "encoded", "image", "." ]
710dfcc5e486e5760d0a5c46be909d91968e1ffb
https://github.com/omniscale/go-mapnik/blob/710dfcc5e486e5760d0a5c46be909d91968e1ffb/mapnik.go#L301-L329
test
omniscale/go-mapnik
mapnik.go
RenderImage
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
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 }
[ "func", "(", "m", "*", "Map", ")", "RenderImage", "(", "opts", "RenderOpts", ")", "(", "*", "image", ".", "NRGBA", ",", "error", ")", "{", "scaleFactor", ":=", "opts", ".", "ScaleFactor", "\n", "if", "scaleFactor", "==", "0.0", "{", "scaleFactor", "=", "1.0", "\n", "}", "\n", "i", ":=", "C", ".", "mapnik_map_render_to_image", "(", "m", ".", "m", ",", "C", ".", "double", "(", "opts", ".", "Scale", ")", ",", "C", ".", "double", "(", "scaleFactor", ")", ")", "\n", "if", "i", "==", "nil", "{", "return", "nil", ",", "m", ".", "lastError", "(", ")", "\n", "}", "\n", "defer", "C", ".", "mapnik_image_free", "(", "i", ")", "\n", "size", ":=", "0", "\n", "raw", ":=", "C", ".", "mapnik_image_to_raw", "(", "i", ",", "(", "*", "C", ".", "size_t", ")", "(", "unsafe", ".", "Pointer", "(", "&", "size", ")", ")", ")", "\n", "b", ":=", "C", ".", "GoBytes", "(", "unsafe", ".", "Pointer", "(", "raw", ")", ",", "C", ".", "int", "(", "size", ")", ")", "\n", "img", ":=", "&", "image", ".", "NRGBA", "{", "Pix", ":", "b", ",", "Stride", ":", "int", "(", "m", ".", "width", "*", "4", ")", ",", "Rect", ":", "image", ".", "Rect", "(", "0", ",", "0", ",", "int", "(", "m", ".", "width", ")", ",", "int", "(", "m", ".", "height", ")", ")", ",", "}", "\n", "return", "img", ",", "nil", "\n", "}" ]
// RenderImage returns the map as an unencoded image.Image.
[ "RenderImage", "returns", "the", "map", "as", "an", "unencoded", "image", ".", "Image", "." ]
710dfcc5e486e5760d0a5c46be909d91968e1ffb
https://github.com/omniscale/go-mapnik/blob/710dfcc5e486e5760d0a5c46be909d91968e1ffb/mapnik.go#L332-L351
test
omniscale/go-mapnik
mapnik.go
RenderToFile
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
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 }
[ "func", "(", "m", "*", "Map", ")", "RenderToFile", "(", "opts", "RenderOpts", ",", "path", "string", ")", "error", "{", "scaleFactor", ":=", "opts", ".", "ScaleFactor", "\n", "if", "scaleFactor", "==", "0.0", "{", "scaleFactor", "=", "1.0", "\n", "}", "\n", "cs", ":=", "C", ".", "CString", "(", "path", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cs", ")", ")", "\n", "var", "format", "*", "C", ".", "char", "\n", "if", "opts", ".", "Format", "!=", "\"\"", "{", "format", "=", "C", ".", "CString", "(", "opts", ".", "Format", ")", "\n", "}", "else", "{", "format", "=", "C", ".", "CString", "(", "\"png256\"", ")", "\n", "}", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "format", ")", ")", "\n", "if", "C", ".", "mapnik_map_render_to_file", "(", "m", ".", "m", ",", "cs", ",", "C", ".", "double", "(", "opts", ".", "Scale", ")", ",", "C", ".", "double", "(", "scaleFactor", ")", ",", "format", ")", "!=", "0", "{", "return", "m", ".", "lastError", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RenderToFile writes the map as an encoded image to the file system.
[ "RenderToFile", "writes", "the", "map", "as", "an", "encoded", "image", "to", "the", "file", "system", "." ]
710dfcc5e486e5760d0a5c46be909d91968e1ffb
https://github.com/omniscale/go-mapnik/blob/710dfcc5e486e5760d0a5c46be909d91968e1ffb/mapnik.go#L354-L372
test
omniscale/go-mapnik
mapnik.go
SetBufferSize
func (m *Map) SetBufferSize(s int) { C.mapnik_map_set_buffer_size(m.m, C.int(s)) }
go
func (m *Map) SetBufferSize(s int) { C.mapnik_map_set_buffer_size(m.m, C.int(s)) }
[ "func", "(", "m", "*", "Map", ")", "SetBufferSize", "(", "s", "int", ")", "{", "C", ".", "mapnik_map_set_buffer_size", "(", "m", ".", "m", ",", "C", ".", "int", "(", "s", ")", ")", "\n", "}" ]
// SetBufferSize sets the pixel buffer at the map image edges where Mapnik should not render any labels.
[ "SetBufferSize", "sets", "the", "pixel", "buffer", "at", "the", "map", "image", "edges", "where", "Mapnik", "should", "not", "render", "any", "labels", "." ]
710dfcc5e486e5760d0a5c46be909d91968e1ffb
https://github.com/omniscale/go-mapnik/blob/710dfcc5e486e5760d0a5c46be909d91968e1ffb/mapnik.go#L375-L377
test
bcurren/go-ssdp
ssdp.go
Search
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
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) }
[ "func", "Search", "(", "st", "string", ",", "mx", "time", ".", "Duration", ")", "(", "[", "]", "SearchResponse", ",", "error", ")", "{", "conn", ",", "err", ":=", "listenForSearchResponses", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "conn", ".", "Close", "(", ")", "\n", "searchBytes", ",", "broadcastAddr", ":=", "buildSearchRequest", "(", "st", ",", "mx", ")", "\n", "_", ",", "err", "=", "conn", ".", "WriteTo", "(", "searchBytes", ",", "broadcastAddr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "readSearchResponses", "(", "conn", ",", "mx", ")", "\n", "}" ]
// Search the network for SSDP devices using the given search string and duration // to discover new devices. This function will return an array of SearchReponses // discovered.
[ "Search", "the", "network", "for", "SSDP", "devices", "using", "the", "given", "search", "string", "and", "duration", "to", "discover", "new", "devices", ".", "This", "function", "will", "return", "an", "array", "of", "SearchReponses", "discovered", "." ]
ae8e7a0ef8a8f119ef439791570ee2a094d1d094
https://github.com/bcurren/go-ssdp/blob/ae8e7a0ef8a8f119ef439791570ee2a094d1d094/ssdp.go#L47-L62
test
ctripcorp/ghost
pool/blockingPool.go
Get
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
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 } }
[ "func", "(", "p", "*", "blockingPool", ")", "Get", "(", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "conns", ":=", "p", ".", "conns", "\n", "if", "conns", "==", "nil", "{", "return", "nil", ",", "ErrClosed", "\n", "}", "\n", "select", "{", "case", "conn", ":=", "<-", "conns", ":", "if", "time", ".", "Since", "(", "conn", ".", "start", ")", ">", "p", ".", "livetime", "{", "if", "conn", ".", "Conn", "!=", "nil", "{", "conn", ".", "Conn", ".", "Close", "(", ")", "\n", "conn", ".", "Conn", "=", "nil", "\n", "}", "\n", "}", "\n", "if", "conn", ".", "Conn", "==", "nil", "{", "var", "err", "error", "\n", "conn", ".", "Conn", ",", "err", "=", "p", ".", "factory", "(", ")", "\n", "if", "err", "!=", "nil", "{", "conn", ".", "start", "=", "time", ".", "Now", "(", ")", "\n", "p", ".", "put", "(", "conn", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "conn", ".", "unusable", "=", "false", "\n", "return", "conn", ",", "nil", "\n", "case", "<-", "time", ".", "After", "(", "time", ".", "Second", "*", "p", ".", "timeout", ")", ":", "return", "nil", ",", "ErrTimeout", "\n", "}", "\n", "}" ]
//Get blocks for an available connection.
[ "Get", "blocks", "for", "an", "available", "connection", "." ]
9dce30d85194129b9c0ba6702c612f3b5c41d02f
https://github.com/ctripcorp/ghost/blob/9dce30d85194129b9c0ba6702c612f3b5c41d02f/pool/blockingPool.go#L55-L84
test
ctripcorp/ghost
pool/blockingPool.go
put
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
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 }
[ "func", "(", "p", "*", "blockingPool", ")", "put", "(", "conn", "*", "WrappedConn", ")", "error", "{", "conns", ":=", "p", ".", "conns", "\n", "if", "conns", "==", "nil", "{", "if", "conn", ".", "Conn", "!=", "nil", "{", "conn", ".", "Conn", ".", "Close", "(", ")", "\n", "conn", ".", "Conn", "=", "nil", "\n", "}", "\n", "return", "ErrClosed", "\n", "}", "\n", "if", "conn", ".", "unusable", "{", "if", "conn", ".", "Conn", "!=", "nil", "{", "conn", ".", "Conn", ".", "Close", "(", ")", "\n", "conn", ".", "Conn", "=", "nil", "\n", "}", "\n", "}", "\n", "conns", "<-", "conn", "\n", "return", "nil", "\n", "}" ]
//put puts the connection back to the pool. If the pool is closed, put simply close //any connections received and return immediately. A nil net.Conn is illegal and will be rejected.
[ "put", "puts", "the", "connection", "back", "to", "the", "pool", ".", "If", "the", "pool", "is", "closed", "put", "simply", "close", "any", "connections", "received", "and", "return", "immediately", ".", "A", "nil", "net", ".", "Conn", "is", "illegal", "and", "will", "be", "rejected", "." ]
9dce30d85194129b9c0ba6702c612f3b5c41d02f
https://github.com/ctripcorp/ghost/blob/9dce30d85194129b9c0ba6702c612f3b5c41d02f/pool/blockingPool.go#L88-L112
test
go-audio/transforms
stereo.go
MonoToStereoF32
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
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 }
[ "func", "MonoToStereoF32", "(", "buf", "*", "audio", ".", "Float32Buffer", ")", "error", "{", "if", "buf", "==", "nil", "||", "buf", ".", "Format", "==", "nil", "||", "buf", ".", "Format", ".", "NumChannels", "!=", "1", "{", "return", "audio", ".", "ErrInvalidBuffer", "\n", "}", "\n", "stereoData", ":=", "make", "(", "[", "]", "float32", ",", "len", "(", "buf", ".", "Data", ")", "*", "2", ")", "\n", "var", "j", "int", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "buf", ".", "Data", ")", ";", "i", "++", "{", "stereoData", "[", "j", "]", "=", "buf", ".", "Data", "[", "i", "]", "\n", "j", "++", "\n", "stereoData", "[", "j", "]", "=", "buf", ".", "Data", "[", "i", "]", "\n", "j", "++", "\n", "}", "\n", "buf", ".", "Data", "=", "stereoData", "\n", "buf", ".", "Format", ".", "NumChannels", "=", "2", "\n", "return", "nil", "\n", "}" ]
// MonoToStereoF32 converts a mono stream into a stereo one // by copying the mono signal to both channels in an interleaved // signal.
[ "MonoToStereoF32", "converts", "a", "mono", "stream", "into", "a", "stereo", "one", "by", "copying", "the", "mono", "signal", "to", "both", "channels", "in", "an", "interleaved", "signal", "." ]
51830ccc35a5ce4be9d09b1d1f3f82dad376c240
https://github.com/go-audio/transforms/blob/51830ccc35a5ce4be9d09b1d1f3f82dad376c240/stereo.go#L8-L23
test
go-audio/transforms
bit_crush.go
BitCrush
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
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) } }
[ "func", "BitCrush", "(", "buf", "*", "audio", ".", "FloatBuffer", ",", "factor", "float64", ")", "{", "stepSize", ":=", "crusherStepSize", "*", "factor", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "buf", ".", "Data", ")", ";", "i", "++", "{", "frac", ",", "exp", ":=", "math", ".", "Frexp", "(", "buf", ".", "Data", "[", "i", "]", ")", "\n", "frac", "=", "signum", "(", "frac", ")", "*", "math", ".", "Floor", "(", "math", ".", "Abs", "(", "frac", ")", "/", "stepSize", "+", "0.5", ")", "*", "stepSize", "\n", "buf", ".", "Data", "[", "i", "]", "=", "math", ".", "Ldexp", "(", "frac", ",", "exp", ")", "\n", "}", "\n", "}" ]
// BitCrush reduces the resolution of the sample to the target bit depth // Note that bit crusher effects are usually made of this feature + a decimator
[ "BitCrush", "reduces", "the", "resolution", "of", "the", "sample", "to", "the", "target", "bit", "depth", "Note", "that", "bit", "crusher", "effects", "are", "usually", "made", "of", "this", "feature", "+", "a", "decimator" ]
51830ccc35a5ce4be9d09b1d1f3f82dad376c240
https://github.com/go-audio/transforms/blob/51830ccc35a5ce4be9d09b1d1f3f82dad376c240/bit_crush.go#L17-L24
test
go-audio/transforms
normalize.go
NormalizeMax
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
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 } } }
[ "func", "NormalizeMax", "(", "buf", "*", "audio", ".", "FloatBuffer", ")", "{", "if", "buf", "==", "nil", "{", "return", "\n", "}", "\n", "max", ":=", "0.0", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "buf", ".", "Data", ")", ";", "i", "++", "{", "if", "math", ".", "Abs", "(", "buf", ".", "Data", "[", "i", "]", ")", ">", "max", "{", "max", "=", "math", ".", "Abs", "(", "buf", ".", "Data", "[", "i", "]", ")", "\n", "}", "\n", "}", "\n", "if", "max", "!=", "0.0", "{", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "buf", ".", "Data", ")", ";", "i", "++", "{", "buf", ".", "Data", "[", "i", "]", "/=", "max", "\n", "}", "\n", "}", "\n", "}" ]
// NormalizeMax sets the max value to 1 and normalize the rest of the data.
[ "NormalizeMax", "sets", "the", "max", "value", "to", "1", "and", "normalize", "the", "rest", "of", "the", "data", "." ]
51830ccc35a5ce4be9d09b1d1f3f82dad376c240
https://github.com/go-audio/transforms/blob/51830ccc35a5ce4be9d09b1d1f3f82dad376c240/normalize.go#L10-L27
test
go-audio/transforms
gain.go
Gain
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
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 }
[ "func", "Gain", "(", "buf", "*", "audio", ".", "FloatBuffer", ",", "multiplier", "float64", ")", "error", "{", "if", "buf", "==", "nil", "{", "return", "audio", ".", "ErrInvalidBuffer", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "buf", ".", "Data", ")", ";", "i", "++", "{", "buf", ".", "Data", "[", "i", "]", "*=", "multiplier", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Gain applies the multiplier to the passed buffer. // A multipler of 1 would increase the amplitude of the signal by 100% // while a multiplier of 0 would not do anything. // Note that this is a very very naive implementation and we will more // than add a more useful DB gain transform.
[ "Gain", "applies", "the", "multiplier", "to", "the", "passed", "buffer", ".", "A", "multipler", "of", "1", "would", "increase", "the", "amplitude", "of", "the", "signal", "by", "100%", "while", "a", "multiplier", "of", "0", "would", "not", "do", "anything", ".", "Note", "that", "this", "is", "a", "very", "very", "naive", "implementation", "and", "we", "will", "more", "than", "add", "a", "more", "useful", "DB", "gain", "transform", "." ]
51830ccc35a5ce4be9d09b1d1f3f82dad376c240
https://github.com/go-audio/transforms/blob/51830ccc35a5ce4be9d09b1d1f3f82dad376c240/gain.go#L10-L20
test
go-audio/transforms
mono.go
MonoDownmix
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
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 }
[ "func", "MonoDownmix", "(", "buf", "*", "audio", ".", "FloatBuffer", ")", "error", "{", "if", "buf", "==", "nil", "||", "buf", ".", "Format", "==", "nil", "{", "return", "audio", ".", "ErrInvalidBuffer", "\n", "}", "\n", "nChans", ":=", "buf", ".", "Format", ".", "NumChannels", "\n", "if", "nChans", "<", "2", "{", "return", "nil", "\n", "}", "\n", "nChansF", ":=", "float64", "(", "nChans", ")", "\n", "frameCount", ":=", "buf", ".", "NumFrames", "(", ")", "\n", "newData", ":=", "make", "(", "[", "]", "float64", ",", "frameCount", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "frameCount", ";", "i", "++", "{", "newData", "[", "i", "]", "=", "0", "\n", "for", "j", ":=", "0", ";", "j", "<", "nChans", ";", "j", "++", "{", "newData", "[", "i", "]", "+=", "buf", ".", "Data", "[", "i", "*", "nChans", "+", "j", "]", "\n", "}", "\n", "newData", "[", "i", "]", "/=", "nChansF", "\n", "}", "\n", "buf", ".", "Data", "=", "newData", "\n", "buf", ".", "Format", ".", "NumChannels", "=", "1", "\n", "return", "nil", "\n", "}" ]
// MonoDownmix converts the buffer to a mono buffer // by downmixing the channels together.
[ "MonoDownmix", "converts", "the", "buffer", "to", "a", "mono", "buffer", "by", "downmixing", "the", "channels", "together", "." ]
51830ccc35a5ce4be9d09b1d1f3f82dad376c240
https://github.com/go-audio/transforms/blob/51830ccc35a5ce4be9d09b1d1f3f82dad376c240/mono.go#L7-L30
test
go-audio/transforms
quantize.go
Quantize
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
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 } }
[ "func", "Quantize", "(", "buf", "*", "audio", ".", "FloatBuffer", ",", "bitDepth", "int", ")", "{", "if", "buf", "==", "nil", "{", "return", "\n", "}", "\n", "max", ":=", "math", ".", "Pow", "(", "2", ",", "float64", "(", "bitDepth", ")", ")", "-", "1", "\n", "bufLen", ":=", "len", "(", "buf", ".", "Data", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "bufLen", ";", "i", "++", "{", "buf", ".", "Data", "[", "i", "]", "=", "round", "(", "(", "buf", ".", "Data", "[", "i", "]", "+", "1", ")", "*", "max", ")", "/", "max", "-", "1.0", "\n", "}", "\n", "}" ]
// Quantize quantizes the audio signal to match the target bitDepth
[ "Quantize", "quantizes", "the", "audio", "signal", "to", "match", "the", "target", "bitDepth" ]
51830ccc35a5ce4be9d09b1d1f3f82dad376c240
https://github.com/go-audio/transforms/blob/51830ccc35a5ce4be9d09b1d1f3f82dad376c240/quantize.go#L10-L20
test
go-audio/transforms
pcm_scale.go
PCMScale
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
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 }
[ "func", "PCMScale", "(", "buf", "*", "audio", ".", "FloatBuffer", ",", "bitDepth", "int", ")", "error", "{", "if", "buf", "==", "nil", "||", "buf", ".", "Format", "==", "nil", "{", "return", "audio", ".", "ErrInvalidBuffer", "\n", "}", "\n", "factor", ":=", "math", ".", "Pow", "(", "2", ",", "8", "*", "float64", "(", "bitDepth", "/", "8", ")", "-", "1", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "buf", ".", "Data", ")", ";", "i", "++", "{", "buf", ".", "Data", "[", "i", "]", "*=", "factor", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// PCMScale converts a buffer with audio content from -1 to 1 into // the PCM scale based on the passed bitdepth. // Note that while the PCM data is scaled, the PCM format is not changed.
[ "PCMScale", "converts", "a", "buffer", "with", "audio", "content", "from", "-", "1", "to", "1", "into", "the", "PCM", "scale", "based", "on", "the", "passed", "bitdepth", ".", "Note", "that", "while", "the", "PCM", "data", "is", "scaled", "the", "PCM", "format", "is", "not", "changed", "." ]
51830ccc35a5ce4be9d09b1d1f3f82dad376c240
https://github.com/go-audio/transforms/blob/51830ccc35a5ce4be9d09b1d1f3f82dad376c240/pcm_scale.go#L12-L22
test
go-audio/transforms
stereo_pan.go
StereoPan
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
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 }
[ "func", "StereoPan", "(", "buf", "*", "audio", ".", "FloatBuffer", ",", "pan", "float64", ")", "error", "{", "if", "buf", "==", "nil", "||", "buf", ".", "Format", "==", "nil", "||", "buf", ".", "Format", ".", "NumChannels", "!=", "2", "{", "return", "audio", ".", "ErrInvalidBuffer", "\n", "}", "\n", "if", "pan", "<", "0", "||", "pan", ">", "1", "{", "return", "errors", ".", "New", "(", "\"invalid pan value, should be betwen 0 and 1\"", ")", "\n", "}", "\n", "if", "pan", "==", "0.5", "{", "return", "nil", "\n", "}", "\n", "if", "pan", "<", "0.5", "{", "for", "i", ":=", "0", ";", "i", "+", "2", "<=", "len", "(", "buf", ".", "Data", ")", ";", "i", "+=", "2", "{", "buf", ".", "Data", "[", "i", "+", "1", "]", "*=", "(", "pan", "*", "2", ")", "\n", "}", "\n", "}", "else", "{", "for", "i", ":=", "0", ";", "i", "+", "2", "<=", "len", "(", "buf", ".", "Data", ")", ";", "i", "+=", "2", "{", "buf", ".", "Data", "[", "i", "]", "*=", "(", "(", "1", "-", "pan", ")", "*", "2", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// StereoPan changes the balance of the input buffer by "panning" // more to the left or the right. The pan value must be between // 0 and 1 where 0 is full first channel, 0.5 center and 1 full second channel. // Note that the signal from 1 channel is not sent to the other, this transform // only reduces the balance of one of the 2 channels.
[ "StereoPan", "changes", "the", "balance", "of", "the", "input", "buffer", "by", "panning", "more", "to", "the", "left", "or", "the", "right", ".", "The", "pan", "value", "must", "be", "between", "0", "and", "1", "where", "0", "is", "full", "first", "channel", "0", ".", "5", "center", "and", "1", "full", "second", "channel", ".", "Note", "that", "the", "signal", "from", "1", "channel", "is", "not", "sent", "to", "the", "other", "this", "transform", "only", "reduces", "the", "balance", "of", "one", "of", "the", "2", "channels", "." ]
51830ccc35a5ce4be9d09b1d1f3f82dad376c240
https://github.com/go-audio/transforms/blob/51830ccc35a5ce4be9d09b1d1f3f82dad376c240/stereo_pan.go#L14-L36
test
abronan/leadership
follower.go
Leader
func (f *Follower) Leader() string { f.lock.Lock() defer f.lock.Unlock() return f.leader }
go
func (f *Follower) Leader() string { f.lock.Lock() defer f.lock.Unlock() return f.leader }
[ "func", "(", "f", "*", "Follower", ")", "Leader", "(", ")", "string", "{", "f", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "lock", ".", "Unlock", "(", ")", "\n", "return", "f", ".", "leader", "\n", "}" ]
// Leader returns the current leader.
[ "Leader", "returns", "the", "current", "leader", "." ]
76df1b7fa3841b453d70d7183e8c02a87538c0ee
https://github.com/abronan/leadership/blob/76df1b7fa3841b453d70d7183e8c02a87538c0ee/follower.go#L33-L37
test
abronan/leadership
candidate.go
IsLeader
func (c *Candidate) IsLeader() bool { c.lock.Lock() defer c.lock.Unlock() return c.leader }
go
func (c *Candidate) IsLeader() bool { c.lock.Lock() defer c.lock.Unlock() return c.leader }
[ "func", "(", "c", "*", "Candidate", ")", "IsLeader", "(", ")", "bool", "{", "c", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "lock", ".", "Unlock", "(", ")", "\n", "return", "c", ".", "leader", "\n", "}" ]
// IsLeader returns true if the candidate is currently a leader.
[ "IsLeader", "returns", "true", "if", "the", "candidate", "is", "currently", "a", "leader", "." ]
76df1b7fa3841b453d70d7183e8c02a87538c0ee
https://github.com/abronan/leadership/blob/76df1b7fa3841b453d70d7183e8c02a87538c0ee/candidate.go#L45-L49
test
DamienFontaine/lunarc
security/response.go
NewResponse
func NewResponse(clientID, redirectURI, userID, exp, code string) Response { return Response{ClientID: clientID, RedirectURI: redirectURI, UserID: userID, Exp: exp, Code: code} }
go
func NewResponse(clientID, redirectURI, userID, exp, code string) Response { return Response{ClientID: clientID, RedirectURI: redirectURI, UserID: userID, Exp: exp, Code: code} }
[ "func", "NewResponse", "(", "clientID", ",", "redirectURI", ",", "userID", ",", "exp", ",", "code", "string", ")", "Response", "{", "return", "Response", "{", "ClientID", ":", "clientID", ",", "RedirectURI", ":", "redirectURI", ",", "UserID", ":", "userID", ",", "Exp", ":", "exp", ",", "Code", ":", "code", "}", "\n", "}" ]
//NewResponse returns a new OAuth2Response
[ "NewResponse", "returns", "a", "new", "OAuth2Response" ]
2e7332a51f554794a549a313430eaa7dec8d13cc
https://github.com/DamienFontaine/lunarc/blob/2e7332a51f554794a549a313430eaa7dec8d13cc/security/response.go#L29-L31
test
solher/snakepit
request_id.go
GetRequestID
func GetRequestID(ctx context.Context) (string, error) { if ctx == nil { return "", errors.New("nil context") } reqID, ok := ctx.Value(contextRequestID).(string) if !ok { return "", errors.New("unexpected type") } if len(reqID) == 0 { return "", errors.New("empty value in context") } return reqID, nil }
go
func GetRequestID(ctx context.Context) (string, error) { if ctx == nil { return "", errors.New("nil context") } reqID, ok := ctx.Value(contextRequestID).(string) if !ok { return "", errors.New("unexpected type") } if len(reqID) == 0 { return "", errors.New("empty value in context") } return reqID, nil }
[ "func", "GetRequestID", "(", "ctx", "context", ".", "Context", ")", "(", "string", ",", "error", ")", "{", "if", "ctx", "==", "nil", "{", "return", "\"\"", ",", "errors", ".", "New", "(", "\"nil context\"", ")", "\n", "}", "\n", "reqID", ",", "ok", ":=", "ctx", ".", "Value", "(", "contextRequestID", ")", ".", "(", "string", ")", "\n", "if", "!", "ok", "{", "return", "\"\"", ",", "errors", ".", "New", "(", "\"unexpected type\"", ")", "\n", "}", "\n", "if", "len", "(", "reqID", ")", "==", "0", "{", "return", "\"\"", ",", "errors", ".", "New", "(", "\"empty value in context\"", ")", "\n", "}", "\n", "return", "reqID", ",", "nil", "\n", "}" ]
// GetRequestID returns a request ID from the given context if one is present. // Returns the empty string if a request ID cannot be found.
[ "GetRequestID", "returns", "a", "request", "ID", "from", "the", "given", "context", "if", "one", "is", "present", ".", "Returns", "the", "empty", "string", "if", "a", "request", "ID", "cannot", "be", "found", "." ]
bc2b6bc4ed85156fe5f715b058a30048c62f7ad5
https://github.com/solher/snakepit/blob/bc2b6bc4ed85156fe5f715b058a30048c62f7ad5/request_id.go#L26-L41
test
jpillora/requestlog
writer.go
Log
func (m *monitorableWriter) Log() { duration := time.Now().Sub(m.t0) if m.Code == 0 { m.Code = 200 } if m.opts.Filter != nil && !m.opts.Filter(m.r, m.Code, duration, m.Size) { return //skip } cc := m.colorCode() size := "" if m.Size > 0 { size = sizestr.ToString(m.Size) } buff := bytes.Buffer{} m.opts.formatTmpl.Execute(&buff, &struct { *Colors Timestamp, Method, Path, CodeColor string Code int Duration, Size, IP string }{ m.opts.Colors, m.t0.Format(m.opts.TimeFormat), m.method, m.path, cc, m.Code, fmtDuration(duration), size, m.ip, }) //fmt is threadsafe :) fmt.Fprint(m.opts.Writer, buff.String()) }
go
func (m *monitorableWriter) Log() { duration := time.Now().Sub(m.t0) if m.Code == 0 { m.Code = 200 } if m.opts.Filter != nil && !m.opts.Filter(m.r, m.Code, duration, m.Size) { return //skip } cc := m.colorCode() size := "" if m.Size > 0 { size = sizestr.ToString(m.Size) } buff := bytes.Buffer{} m.opts.formatTmpl.Execute(&buff, &struct { *Colors Timestamp, Method, Path, CodeColor string Code int Duration, Size, IP string }{ m.opts.Colors, m.t0.Format(m.opts.TimeFormat), m.method, m.path, cc, m.Code, fmtDuration(duration), size, m.ip, }) //fmt is threadsafe :) fmt.Fprint(m.opts.Writer, buff.String()) }
[ "func", "(", "m", "*", "monitorableWriter", ")", "Log", "(", ")", "{", "duration", ":=", "time", ".", "Now", "(", ")", ".", "Sub", "(", "m", ".", "t0", ")", "\n", "if", "m", ".", "Code", "==", "0", "{", "m", ".", "Code", "=", "200", "\n", "}", "\n", "if", "m", ".", "opts", ".", "Filter", "!=", "nil", "&&", "!", "m", ".", "opts", ".", "Filter", "(", "m", ".", "r", ",", "m", ".", "Code", ",", "duration", ",", "m", ".", "Size", ")", "{", "return", "\n", "}", "\n", "cc", ":=", "m", ".", "colorCode", "(", ")", "\n", "size", ":=", "\"\"", "\n", "if", "m", ".", "Size", ">", "0", "{", "size", "=", "sizestr", ".", "ToString", "(", "m", ".", "Size", ")", "\n", "}", "\n", "buff", ":=", "bytes", ".", "Buffer", "{", "}", "\n", "m", ".", "opts", ".", "formatTmpl", ".", "Execute", "(", "&", "buff", ",", "&", "struct", "{", "*", "Colors", "\n", "Timestamp", ",", "Method", ",", "Path", ",", "CodeColor", "string", "\n", "Code", "int", "\n", "Duration", ",", "Size", ",", "IP", "string", "\n", "}", "{", "m", ".", "opts", ".", "Colors", ",", "m", ".", "t0", ".", "Format", "(", "m", ".", "opts", ".", "TimeFormat", ")", ",", "m", ".", "method", ",", "m", ".", "path", ",", "cc", ",", "m", ".", "Code", ",", "fmtDuration", "(", "duration", ")", ",", "size", ",", "m", ".", "ip", ",", "}", ")", "\n", "fmt", ".", "Fprint", "(", "m", ".", "opts", ".", "Writer", ",", "buff", ".", "String", "(", ")", ")", "\n", "}" ]
//replace ResponseWriter with a monitorable one, return logger
[ "replace", "ResponseWriter", "with", "a", "monitorable", "one", "return", "logger" ]
df8817be5f8288874e4cbe58d441a01222a28a2f
https://github.com/jpillora/requestlog/blob/df8817be5f8288874e4cbe58d441a01222a28a2f/writer.go#L81-L108
test
DamienFontaine/lunarc
smtp/util.go
SendMailSSL
func SendMailSSL(addr string, a smtp.Auth, from string, to []string, msg []byte) error { conn, err := tls.Dial("tcp", addr, &tls.Config{InsecureSkipVerify: true}) //TODO: Not secure if err != nil { log.Println("Error Dialing", err) return err } h, _, _ := net.SplitHostPort(addr) c, err := smtp.NewClient(conn, h) if err != nil { log.Println("Error SMTP connection", err) return err } defer c.Close() if a != nil { if ok, _ := c.Extension("AUTH"); ok { if err = c.Auth(a); err != nil { log.Printf("Authentication error: %v", err) return err } } } if err = c.Mail(from); err != nil { log.Printf("From error: %v", err) return err } for _, addr := range to { if err = c.Rcpt(addr); err != nil { log.Printf("Recipient error: %v", err) return err } } w, err := c.Data() if err != nil { return err } w.Write(msg) w.Close() return c.Quit() }
go
func SendMailSSL(addr string, a smtp.Auth, from string, to []string, msg []byte) error { conn, err := tls.Dial("tcp", addr, &tls.Config{InsecureSkipVerify: true}) //TODO: Not secure if err != nil { log.Println("Error Dialing", err) return err } h, _, _ := net.SplitHostPort(addr) c, err := smtp.NewClient(conn, h) if err != nil { log.Println("Error SMTP connection", err) return err } defer c.Close() if a != nil { if ok, _ := c.Extension("AUTH"); ok { if err = c.Auth(a); err != nil { log.Printf("Authentication error: %v", err) return err } } } if err = c.Mail(from); err != nil { log.Printf("From error: %v", err) return err } for _, addr := range to { if err = c.Rcpt(addr); err != nil { log.Printf("Recipient error: %v", err) return err } } w, err := c.Data() if err != nil { return err } w.Write(msg) w.Close() return c.Quit() }
[ "func", "SendMailSSL", "(", "addr", "string", ",", "a", "smtp", ".", "Auth", ",", "from", "string", ",", "to", "[", "]", "string", ",", "msg", "[", "]", "byte", ")", "error", "{", "conn", ",", "err", ":=", "tls", ".", "Dial", "(", "\"tcp\"", ",", "addr", ",", "&", "tls", ".", "Config", "{", "InsecureSkipVerify", ":", "true", "}", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Println", "(", "\"Error Dialing\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "h", ",", "_", ",", "_", ":=", "net", ".", "SplitHostPort", "(", "addr", ")", "\n", "c", ",", "err", ":=", "smtp", ".", "NewClient", "(", "conn", ",", "h", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Println", "(", "\"Error SMTP connection\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "defer", "c", ".", "Close", "(", ")", "\n", "if", "a", "!=", "nil", "{", "if", "ok", ",", "_", ":=", "c", ".", "Extension", "(", "\"AUTH\"", ")", ";", "ok", "{", "if", "err", "=", "c", ".", "Auth", "(", "a", ")", ";", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"Authentication error: %v\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "err", "=", "c", ".", "Mail", "(", "from", ")", ";", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"From error: %v\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "for", "_", ",", "addr", ":=", "range", "to", "{", "if", "err", "=", "c", ".", "Rcpt", "(", "addr", ")", ";", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"Recipient error: %v\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "w", ",", "err", ":=", "c", ".", "Data", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "w", ".", "Write", "(", "msg", ")", "\n", "w", ".", "Close", "(", ")", "\n", "return", "c", ".", "Quit", "(", ")", "\n", "}" ]
// SendMailSSL envoie un email par SSL
[ "SendMailSSL", "envoie", "un", "email", "par", "SSL" ]
2e7332a51f554794a549a313430eaa7dec8d13cc
https://github.com/DamienFontaine/lunarc/blob/2e7332a51f554794a549a313430eaa7dec8d13cc/smtp/util.go#L26-L70
test
DamienFontaine/lunarc
smtp/mail.go
Send
func (m *MailService) Send(message string, subject string, from string, to string) (err error) { t := []string{to} msg := []byte("From: " + from + "\r\n" + "To: " + to + "\r\n" + "Subject: " + subject + "\r\n" + "\r\n" + message + "\r\n") err = m.SMTP.SendMail(from, t, msg) return }
go
func (m *MailService) Send(message string, subject string, from string, to string) (err error) { t := []string{to} msg := []byte("From: " + from + "\r\n" + "To: " + to + "\r\n" + "Subject: " + subject + "\r\n" + "\r\n" + message + "\r\n") err = m.SMTP.SendMail(from, t, msg) return }
[ "func", "(", "m", "*", "MailService", ")", "Send", "(", "message", "string", ",", "subject", "string", ",", "from", "string", ",", "to", "string", ")", "(", "err", "error", ")", "{", "t", ":=", "[", "]", "string", "{", "to", "}", "\n", "msg", ":=", "[", "]", "byte", "(", "\"From: \"", "+", "from", "+", "\"\\r\\n\"", "+", "\\r", "+", "\\n", "+", "\"To: \"", "+", "to", "+", "\"\\r\\n\"", "+", "\\r", "+", "\\n", "+", "\"Subject: \"", "+", "subject", ")", "\n", "\"\\r\\n\"", "\n", "\\r", "\n", "}" ]
//Send envoie un email
[ "Send", "envoie", "un", "email" ]
2e7332a51f554794a549a313430eaa7dec8d13cc
https://github.com/DamienFontaine/lunarc/blob/2e7332a51f554794a549a313430eaa7dec8d13cc/smtp/mail.go#L34-L45
test
malice-plugins/go-plugin-utils
waitforit/waitforit.go
WaitForIt
func WaitForIt(fullConn, host string, port, timeout int) error { // fullConn := flag.String("full-connection", "", "full connection") // host := flag.String("host", "", "host to connect") // port := flag.Int("port", 80, "port to connect") // timeout := flag.Int("timeout", 10, "time to wait until port become available") // printVersion := flag.Bool("v", false, "show the current version") // debug = flag.Bool("debug", false, "enable debug") // flag.Parse() // if *printVersion { // fmt.Println("waitforit version " + VERSION) // return // } conn := buildConn(host, port, fullConn) if conn == nil { return errors.New("Invalid connection") } log.Debug("Waiting " + strconv.Itoa(timeout) + " seconds") if err := pingTCP(conn, timeout); err != nil { return err } if conn.Scheme != "http" && conn.Scheme != "https" { return nil } if err := pingHTTP(conn, timeout); err != nil { return err } return nil }
go
func WaitForIt(fullConn, host string, port, timeout int) error { // fullConn := flag.String("full-connection", "", "full connection") // host := flag.String("host", "", "host to connect") // port := flag.Int("port", 80, "port to connect") // timeout := flag.Int("timeout", 10, "time to wait until port become available") // printVersion := flag.Bool("v", false, "show the current version") // debug = flag.Bool("debug", false, "enable debug") // flag.Parse() // if *printVersion { // fmt.Println("waitforit version " + VERSION) // return // } conn := buildConn(host, port, fullConn) if conn == nil { return errors.New("Invalid connection") } log.Debug("Waiting " + strconv.Itoa(timeout) + " seconds") if err := pingTCP(conn, timeout); err != nil { return err } if conn.Scheme != "http" && conn.Scheme != "https" { return nil } if err := pingHTTP(conn, timeout); err != nil { return err } return nil }
[ "func", "WaitForIt", "(", "fullConn", ",", "host", "string", ",", "port", ",", "timeout", "int", ")", "error", "{", "conn", ":=", "buildConn", "(", "host", ",", "port", ",", "fullConn", ")", "\n", "if", "conn", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"Invalid connection\"", ")", "\n", "}", "\n", "log", ".", "Debug", "(", "\"Waiting \"", "+", "strconv", ".", "Itoa", "(", "timeout", ")", "+", "\" seconds\"", ")", "\n", "if", "err", ":=", "pingTCP", "(", "conn", ",", "timeout", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "conn", ".", "Scheme", "!=", "\"http\"", "&&", "conn", ".", "Scheme", "!=", "\"https\"", "{", "return", "nil", "\n", "}", "\n", "if", "err", ":=", "pingHTTP", "(", "conn", ",", "timeout", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// WaitForIt waits for a service or URL to become online
[ "WaitForIt", "waits", "for", "a", "service", "or", "URL", "to", "become", "online" ]
9ee76663c3b0a531b8c529f03f12a5a84ff9b61b
https://github.com/malice-plugins/go-plugin-utils/blob/9ee76663c3b0a531b8c529f03f12a5a84ff9b61b/waitforit/waitforit.go#L122-L156
test
DamienFontaine/lunarc
config/utils.go
Get
func Get(source interface{}, environment string, configEnv Environment) (conf interface{}, err error) { if filename, ok := source.(string); ok { source, err = ioutil.ReadFile(filename) if err != nil { log.Printf("Fatal: %v", err) return } } err = yaml.Unmarshal(source.([]byte), configEnv) if err != nil { log.Printf("Fatal: bad config : %v", err) return } conf = configEnv.GetEnvironment(environment) if conf == nil { err = errors.New("No configuration") return } return }
go
func Get(source interface{}, environment string, configEnv Environment) (conf interface{}, err error) { if filename, ok := source.(string); ok { source, err = ioutil.ReadFile(filename) if err != nil { log.Printf("Fatal: %v", err) return } } err = yaml.Unmarshal(source.([]byte), configEnv) if err != nil { log.Printf("Fatal: bad config : %v", err) return } conf = configEnv.GetEnvironment(environment) if conf == nil { err = errors.New("No configuration") return } return }
[ "func", "Get", "(", "source", "interface", "{", "}", ",", "environment", "string", ",", "configEnv", "Environment", ")", "(", "conf", "interface", "{", "}", ",", "err", "error", ")", "{", "if", "filename", ",", "ok", ":=", "source", ".", "(", "string", ")", ";", "ok", "{", "source", ",", "err", "=", "ioutil", ".", "ReadFile", "(", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"Fatal: %v\"", ",", "err", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "err", "=", "yaml", ".", "Unmarshal", "(", "source", ".", "(", "[", "]", "byte", ")", ",", "configEnv", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"Fatal: bad config : %v\"", ",", "err", ")", "\n", "return", "\n", "}", "\n", "conf", "=", "configEnv", ".", "GetEnvironment", "(", "environment", ")", "\n", "if", "conf", "==", "nil", "{", "err", "=", "errors", ".", "New", "(", "\"No configuration\"", ")", "\n", "return", "\n", "}", "\n", "return", "\n", "}" ]
// Get a config
[ "Get", "a", "config" ]
2e7332a51f554794a549a313430eaa7dec8d13cc
https://github.com/DamienFontaine/lunarc/blob/2e7332a51f554794a549a313430eaa7dec8d13cc/config/utils.go#L27-L48
test
solher/snakepit
root/root.go
initConfig
func initConfig() { if cfgFile != "" { // enable ability to specify config file via flag Viper.SetConfigFile(cfgFile) } Viper.SetConfigName("config") // name of config file (without extension) Viper.AddConfigPath("$HOME") // adding home directory as first search path Viper.AddConfigPath("./") // adding local directory as second search path Viper.AutomaticEnv() // read in environment variables that match // If a config file is found, read it in. if err := Viper.ReadInConfig(); err == nil { fmt.Println("Using config file:", Viper.ConfigFileUsed()) } }
go
func initConfig() { if cfgFile != "" { // enable ability to specify config file via flag Viper.SetConfigFile(cfgFile) } Viper.SetConfigName("config") // name of config file (without extension) Viper.AddConfigPath("$HOME") // adding home directory as first search path Viper.AddConfigPath("./") // adding local directory as second search path Viper.AutomaticEnv() // read in environment variables that match // If a config file is found, read it in. if err := Viper.ReadInConfig(); err == nil { fmt.Println("Using config file:", Viper.ConfigFileUsed()) } }
[ "func", "initConfig", "(", ")", "{", "if", "cfgFile", "!=", "\"\"", "{", "Viper", ".", "SetConfigFile", "(", "cfgFile", ")", "\n", "}", "\n", "Viper", ".", "SetConfigName", "(", "\"config\"", ")", "\n", "Viper", ".", "AddConfigPath", "(", "\"$HOME\"", ")", "\n", "Viper", ".", "AddConfigPath", "(", "\"./\"", ")", "\n", "Viper", ".", "AutomaticEnv", "(", ")", "\n", "if", "err", ":=", "Viper", ".", "ReadInConfig", "(", ")", ";", "err", "==", "nil", "{", "fmt", ".", "Println", "(", "\"Using config file:\"", ",", "Viper", ".", "ConfigFileUsed", "(", ")", ")", "\n", "}", "\n", "}" ]
// Read in config file and ENV variables if set.
[ "Read", "in", "config", "file", "and", "ENV", "variables", "if", "set", "." ]
bc2b6bc4ed85156fe5f715b058a30048c62f7ad5
https://github.com/solher/snakepit/blob/bc2b6bc4ed85156fe5f715b058a30048c62f7ad5/root/root.go#L37-L51
test
malice-plugins/go-plugin-utils
database/rethinkdb/rethinkdb.go
WritePluginResultsToDatabase
func WritePluginResultsToDatabase(results map[string]interface{}) { // connect to RethinkDB session, err := r.Connect(r.ConnectOpts{ Address: fmt.Sprintf("%s:28015", utils.Getopt("MALICE_RETHINKDB", "rethink")), Timeout: 5 * time.Second, Database: "malice", }) if err != nil { log.Debug(err) return } defer session.Close() res, err := r.Table("samples").Get(results["ID"]).Run(session) utils.Assert(err) defer res.Close() if res.IsNil() { // upsert into RethinkDB resp, err := r.Table("samples").Insert(results, r.InsertOpts{Conflict: "replace"}).RunWrite(session) utils.Assert(err) log.Debug(resp) } else { resp, err := r.Table("samples").Get(results["ID"]).Update(map[string]interface{}{ "plugins": map[string]interface{}{ category: map[string]interface{}{ name: results["Data"], }, }, }).RunWrite(session) utils.Assert(err) log.Debug(resp) } }
go
func WritePluginResultsToDatabase(results map[string]interface{}) { // connect to RethinkDB session, err := r.Connect(r.ConnectOpts{ Address: fmt.Sprintf("%s:28015", utils.Getopt("MALICE_RETHINKDB", "rethink")), Timeout: 5 * time.Second, Database: "malice", }) if err != nil { log.Debug(err) return } defer session.Close() res, err := r.Table("samples").Get(results["ID"]).Run(session) utils.Assert(err) defer res.Close() if res.IsNil() { // upsert into RethinkDB resp, err := r.Table("samples").Insert(results, r.InsertOpts{Conflict: "replace"}).RunWrite(session) utils.Assert(err) log.Debug(resp) } else { resp, err := r.Table("samples").Get(results["ID"]).Update(map[string]interface{}{ "plugins": map[string]interface{}{ category: map[string]interface{}{ name: results["Data"], }, }, }).RunWrite(session) utils.Assert(err) log.Debug(resp) } }
[ "func", "WritePluginResultsToDatabase", "(", "results", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "session", ",", "err", ":=", "r", ".", "Connect", "(", "r", ".", "ConnectOpts", "{", "Address", ":", "fmt", ".", "Sprintf", "(", "\"%s:28015\"", ",", "utils", ".", "Getopt", "(", "\"MALICE_RETHINKDB\"", ",", "\"rethink\"", ")", ")", ",", "Timeout", ":", "5", "*", "time", ".", "Second", ",", "Database", ":", "\"malice\"", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debug", "(", "err", ")", "\n", "return", "\n", "}", "\n", "defer", "session", ".", "Close", "(", ")", "\n", "res", ",", "err", ":=", "r", ".", "Table", "(", "\"samples\"", ")", ".", "Get", "(", "results", "[", "\"ID\"", "]", ")", ".", "Run", "(", "session", ")", "\n", "utils", ".", "Assert", "(", "err", ")", "\n", "defer", "res", ".", "Close", "(", ")", "\n", "if", "res", ".", "IsNil", "(", ")", "{", "resp", ",", "err", ":=", "r", ".", "Table", "(", "\"samples\"", ")", ".", "Insert", "(", "results", ",", "r", ".", "InsertOpts", "{", "Conflict", ":", "\"replace\"", "}", ")", ".", "RunWrite", "(", "session", ")", "\n", "utils", ".", "Assert", "(", "err", ")", "\n", "log", ".", "Debug", "(", "resp", ")", "\n", "}", "else", "{", "resp", ",", "err", ":=", "r", ".", "Table", "(", "\"samples\"", ")", ".", "Get", "(", "results", "[", "\"ID\"", "]", ")", ".", "Update", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"plugins\"", ":", "map", "[", "string", "]", "interface", "{", "}", "{", "category", ":", "map", "[", "string", "]", "interface", "{", "}", "{", "name", ":", "results", "[", "\"Data\"", "]", ",", "}", ",", "}", ",", "}", ")", ".", "RunWrite", "(", "session", ")", "\n", "utils", ".", "Assert", "(", "err", ")", "\n", "log", ".", "Debug", "(", "resp", ")", "\n", "}", "\n", "}" ]
// WritePluginResultsToDatabase upserts plugin results into Database
[ "WritePluginResultsToDatabase", "upserts", "plugin", "results", "into", "Database" ]
9ee76663c3b0a531b8c529f03f12a5a84ff9b61b
https://github.com/malice-plugins/go-plugin-utils/blob/9ee76663c3b0a531b8c529f03f12a5a84ff9b61b/database/rethinkdb/rethinkdb.go#L23-L58
test
DamienFontaine/lunarc
security/controller.go
NewAuthController
func NewAuthController(um UserManager, cnf web.Config) *AuthController { authController := AuthController{UserManager: um, cnf: cnf} return &authController }
go
func NewAuthController(um UserManager, cnf web.Config) *AuthController { authController := AuthController{UserManager: um, cnf: cnf} return &authController }
[ "func", "NewAuthController", "(", "um", "UserManager", ",", "cnf", "web", ".", "Config", ")", "*", "AuthController", "{", "authController", ":=", "AuthController", "{", "UserManager", ":", "um", ",", "cnf", ":", "cnf", "}", "\n", "return", "&", "authController", "\n", "}" ]
//NewAuthController constructs new AuthController
[ "NewAuthController", "constructs", "new", "AuthController" ]
2e7332a51f554794a549a313430eaa7dec8d13cc
https://github.com/DamienFontaine/lunarc/blob/2e7332a51f554794a549a313430eaa7dec8d13cc/security/controller.go#L39-L42
test
DamienFontaine/lunarc
security/controller.go
Authenticate
func (c *AuthController) Authenticate(w http.ResponseWriter, r *http.Request) { decoder := json.NewDecoder(r.Body) var user User var data map[string]string err := decoder.Decode(&user) if err != nil { http.Error(w, fmt.Sprintf("%v", err), 400) return } user, _ = c.UserManager.Get(user.Username, user.Password) if user.Username != "" { token := jwt.New(jwt.GetSigningMethod("HS256")) claims := token.Claims.(jwt.MapClaims) claims["username"] = user.Username claims["email"] = user.Email claims["exp"] = time.Now().Add(time.Minute * 10).Unix() tokenString, _ := token.SignedString([]byte(c.cnf.Jwt.Key)) data = map[string]string{ "id_token": tokenString, } } js, _ := json.Marshal(data) w.Write(js) }
go
func (c *AuthController) Authenticate(w http.ResponseWriter, r *http.Request) { decoder := json.NewDecoder(r.Body) var user User var data map[string]string err := decoder.Decode(&user) if err != nil { http.Error(w, fmt.Sprintf("%v", err), 400) return } user, _ = c.UserManager.Get(user.Username, user.Password) if user.Username != "" { token := jwt.New(jwt.GetSigningMethod("HS256")) claims := token.Claims.(jwt.MapClaims) claims["username"] = user.Username claims["email"] = user.Email claims["exp"] = time.Now().Add(time.Minute * 10).Unix() tokenString, _ := token.SignedString([]byte(c.cnf.Jwt.Key)) data = map[string]string{ "id_token": tokenString, } } js, _ := json.Marshal(data) w.Write(js) }
[ "func", "(", "c", "*", "AuthController", ")", "Authenticate", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "decoder", ":=", "json", ".", "NewDecoder", "(", "r", ".", "Body", ")", "\n", "var", "user", "User", "\n", "var", "data", "map", "[", "string", "]", "string", "\n", "err", ":=", "decoder", ".", "Decode", "(", "&", "user", ")", "\n", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "fmt", ".", "Sprintf", "(", "\"%v\"", ",", "err", ")", ",", "400", ")", "\n", "return", "\n", "}", "\n", "user", ",", "_", "=", "c", ".", "UserManager", ".", "Get", "(", "user", ".", "Username", ",", "user", ".", "Password", ")", "\n", "if", "user", ".", "Username", "!=", "\"\"", "{", "token", ":=", "jwt", ".", "New", "(", "jwt", ".", "GetSigningMethod", "(", "\"HS256\"", ")", ")", "\n", "claims", ":=", "token", ".", "Claims", ".", "(", "jwt", ".", "MapClaims", ")", "\n", "claims", "[", "\"username\"", "]", "=", "user", ".", "Username", "\n", "claims", "[", "\"email\"", "]", "=", "user", ".", "Email", "\n", "claims", "[", "\"exp\"", "]", "=", "time", ".", "Now", "(", ")", ".", "Add", "(", "time", ".", "Minute", "*", "10", ")", ".", "Unix", "(", ")", "\n", "tokenString", ",", "_", ":=", "token", ".", "SignedString", "(", "[", "]", "byte", "(", "c", ".", "cnf", ".", "Jwt", ".", "Key", ")", ")", "\n", "data", "=", "map", "[", "string", "]", "string", "{", "\"id_token\"", ":", "tokenString", ",", "}", "\n", "}", "\n", "js", ",", "_", ":=", "json", ".", "Marshal", "(", "data", ")", "\n", "w", ".", "Write", "(", "js", ")", "\n", "}" ]
//Authenticate controls authorizations
[ "Authenticate", "controls", "authorizations" ]
2e7332a51f554794a549a313430eaa7dec8d13cc
https://github.com/DamienFontaine/lunarc/blob/2e7332a51f554794a549a313430eaa7dec8d13cc/security/controller.go#L45-L69
test
DamienFontaine/lunarc
security/controller.go
NewOAuth2Controller
func NewOAuth2Controller(am ApplicationManager, cnf web.Config) *OAuth2Controller { oAuth2Controller := OAuth2Controller{cnf: cnf, ApplicationManager: am} return &oAuth2Controller }
go
func NewOAuth2Controller(am ApplicationManager, cnf web.Config) *OAuth2Controller { oAuth2Controller := OAuth2Controller{cnf: cnf, ApplicationManager: am} return &oAuth2Controller }
[ "func", "NewOAuth2Controller", "(", "am", "ApplicationManager", ",", "cnf", "web", ".", "Config", ")", "*", "OAuth2Controller", "{", "oAuth2Controller", ":=", "OAuth2Controller", "{", "cnf", ":", "cnf", ",", "ApplicationManager", ":", "am", "}", "\n", "return", "&", "oAuth2Controller", "\n", "}" ]
//NewOAuth2Controller constructs new AuthController
[ "NewOAuth2Controller", "constructs", "new", "AuthController" ]
2e7332a51f554794a549a313430eaa7dec8d13cc
https://github.com/DamienFontaine/lunarc/blob/2e7332a51f554794a549a313430eaa7dec8d13cc/security/controller.go#L78-L81
test