id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
5,800 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_QuestStatus | func (c *Callbacks) OnCDOTAUserMsg_QuestStatus(fn func(*dota.CDOTAUserMsg_QuestStatus) error) {
c.onCDOTAUserMsg_QuestStatus = append(c.onCDOTAUserMsg_QuestStatus, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_QuestStatus(fn func(*dota.CDOTAUserMsg_QuestStatus) error) {
c.onCDOTAUserMsg_QuestStatus = append(c.onCDOTAUserMsg_QuestStatus, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_QuestStatus",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_QuestStatus",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_QuestStatus",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_QuestStatus",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_QuestStatus registers a callback for EDotaUserMessages_DOTA_UM_QuestStatus | [
"OnCDOTAUserMsg_QuestStatus",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_QuestStatus"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1216-L1218 |
5,801 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_SuggestHeroPick | func (c *Callbacks) OnCDOTAUserMsg_SuggestHeroPick(fn func(*dota.CDOTAUserMsg_SuggestHeroPick) error) {
c.onCDOTAUserMsg_SuggestHeroPick = append(c.onCDOTAUserMsg_SuggestHeroPick, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_SuggestHeroPick(fn func(*dota.CDOTAUserMsg_SuggestHeroPick) error) {
c.onCDOTAUserMsg_SuggestHeroPick = append(c.onCDOTAUserMsg_SuggestHeroPick, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_SuggestHeroPick",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_SuggestHeroPick",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_SuggestHeroPick",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_SuggestHeroPick",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_SuggestHeroPick registers a callback for EDotaUserMessages_DOTA_UM_SuggestHeroPick | [
"OnCDOTAUserMsg_SuggestHeroPick",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_SuggestHeroPick"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1221-L1223 |
5,802 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_SuggestHeroRole | func (c *Callbacks) OnCDOTAUserMsg_SuggestHeroRole(fn func(*dota.CDOTAUserMsg_SuggestHeroRole) error) {
c.onCDOTAUserMsg_SuggestHeroRole = append(c.onCDOTAUserMsg_SuggestHeroRole, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_SuggestHeroRole(fn func(*dota.CDOTAUserMsg_SuggestHeroRole) error) {
c.onCDOTAUserMsg_SuggestHeroRole = append(c.onCDOTAUserMsg_SuggestHeroRole, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_SuggestHeroRole",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_SuggestHeroRole",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_SuggestHeroRole",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_SuggestHeroRole",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_SuggestHeroRole registers a callback for EDotaUserMessages_DOTA_UM_SuggestHeroRole | [
"OnCDOTAUserMsg_SuggestHeroRole",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_SuggestHeroRole"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1226-L1228 |
5,803 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_KillcamDamageTaken | func (c *Callbacks) OnCDOTAUserMsg_KillcamDamageTaken(fn func(*dota.CDOTAUserMsg_KillcamDamageTaken) error) {
c.onCDOTAUserMsg_KillcamDamageTaken = append(c.onCDOTAUserMsg_KillcamDamageTaken, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_KillcamDamageTaken(fn func(*dota.CDOTAUserMsg_KillcamDamageTaken) error) {
c.onCDOTAUserMsg_KillcamDamageTaken = append(c.onCDOTAUserMsg_KillcamDamageTaken, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_KillcamDamageTaken",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_KillcamDamageTaken",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_KillcamDamageTaken",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_KillcamDamageTaken",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_KillcamDamageTaken registers a callback for EDotaUserMessages_DOTA_UM_KillcamDamageTaken | [
"OnCDOTAUserMsg_KillcamDamageTaken",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_KillcamDamageTaken"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1231-L1233 |
5,804 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_SelectPenaltyGold | func (c *Callbacks) OnCDOTAUserMsg_SelectPenaltyGold(fn func(*dota.CDOTAUserMsg_SelectPenaltyGold) error) {
c.onCDOTAUserMsg_SelectPenaltyGold = append(c.onCDOTAUserMsg_SelectPenaltyGold, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_SelectPenaltyGold(fn func(*dota.CDOTAUserMsg_SelectPenaltyGold) error) {
c.onCDOTAUserMsg_SelectPenaltyGold = append(c.onCDOTAUserMsg_SelectPenaltyGold, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_SelectPenaltyGold",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_SelectPenaltyGold",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_SelectPenaltyGold",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_SelectPenaltyGold",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_SelectPenaltyGold registers a callback for EDotaUserMessages_DOTA_UM_SelectPenaltyGold | [
"OnCDOTAUserMsg_SelectPenaltyGold",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_SelectPenaltyGold"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1236-L1238 |
5,805 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_RollDiceResult | func (c *Callbacks) OnCDOTAUserMsg_RollDiceResult(fn func(*dota.CDOTAUserMsg_RollDiceResult) error) {
c.onCDOTAUserMsg_RollDiceResult = append(c.onCDOTAUserMsg_RollDiceResult, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_RollDiceResult(fn func(*dota.CDOTAUserMsg_RollDiceResult) error) {
c.onCDOTAUserMsg_RollDiceResult = append(c.onCDOTAUserMsg_RollDiceResult, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_RollDiceResult",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_RollDiceResult",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_RollDiceResult",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_RollDiceResult",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_RollDiceResult registers a callback for EDotaUserMessages_DOTA_UM_RollDiceResult | [
"OnCDOTAUserMsg_RollDiceResult",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_RollDiceResult"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1241-L1243 |
5,806 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_FlipCoinResult | func (c *Callbacks) OnCDOTAUserMsg_FlipCoinResult(fn func(*dota.CDOTAUserMsg_FlipCoinResult) error) {
c.onCDOTAUserMsg_FlipCoinResult = append(c.onCDOTAUserMsg_FlipCoinResult, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_FlipCoinResult(fn func(*dota.CDOTAUserMsg_FlipCoinResult) error) {
c.onCDOTAUserMsg_FlipCoinResult = append(c.onCDOTAUserMsg_FlipCoinResult, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_FlipCoinResult",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_FlipCoinResult",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_FlipCoinResult",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_FlipCoinResult",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_FlipCoinResult registers a callback for EDotaUserMessages_DOTA_UM_FlipCoinResult | [
"OnCDOTAUserMsg_FlipCoinResult",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_FlipCoinResult"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1246-L1248 |
5,807 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_SendRoshanSpectatorPhase | func (c *Callbacks) OnCDOTAUserMsg_SendRoshanSpectatorPhase(fn func(*dota.CDOTAUserMsg_SendRoshanSpectatorPhase) error) {
c.onCDOTAUserMsg_SendRoshanSpectatorPhase = append(c.onCDOTAUserMsg_SendRoshanSpectatorPhase, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_SendRoshanSpectatorPhase(fn func(*dota.CDOTAUserMsg_SendRoshanSpectatorPhase) error) {
c.onCDOTAUserMsg_SendRoshanSpectatorPhase = append(c.onCDOTAUserMsg_SendRoshanSpectatorPhase, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_SendRoshanSpectatorPhase",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_SendRoshanSpectatorPhase",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_SendRoshanSpectatorPhase",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_SendRoshanSpectatorPhase",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_SendRoshanSpectatorPhase registers a callback for EDotaUserMessages_DOTA_UM_SendRoshanSpectatorPhase | [
"OnCDOTAUserMsg_SendRoshanSpectatorPhase",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_SendRoshanSpectatorPhase"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1251-L1253 |
5,808 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_ChatWheelCooldown | func (c *Callbacks) OnCDOTAUserMsg_ChatWheelCooldown(fn func(*dota.CDOTAUserMsg_ChatWheelCooldown) error) {
c.onCDOTAUserMsg_ChatWheelCooldown = append(c.onCDOTAUserMsg_ChatWheelCooldown, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_ChatWheelCooldown(fn func(*dota.CDOTAUserMsg_ChatWheelCooldown) error) {
c.onCDOTAUserMsg_ChatWheelCooldown = append(c.onCDOTAUserMsg_ChatWheelCooldown, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_ChatWheelCooldown",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_ChatWheelCooldown",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_ChatWheelCooldown",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_ChatWheelCooldown",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_ChatWheelCooldown registers a callback for EDotaUserMessages_DOTA_UM_ChatWheelCooldown | [
"OnCDOTAUserMsg_ChatWheelCooldown",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_ChatWheelCooldown"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1256-L1258 |
5,809 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_DismissAllStatPopups | func (c *Callbacks) OnCDOTAUserMsg_DismissAllStatPopups(fn func(*dota.CDOTAUserMsg_DismissAllStatPopups) error) {
c.onCDOTAUserMsg_DismissAllStatPopups = append(c.onCDOTAUserMsg_DismissAllStatPopups, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_DismissAllStatPopups(fn func(*dota.CDOTAUserMsg_DismissAllStatPopups) error) {
c.onCDOTAUserMsg_DismissAllStatPopups = append(c.onCDOTAUserMsg_DismissAllStatPopups, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_DismissAllStatPopups",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_DismissAllStatPopups",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_DismissAllStatPopups",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_DismissAllStatPopups",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_DismissAllStatPopups registers a callback for EDotaUserMessages_DOTA_UM_DismissAllStatPopups | [
"OnCDOTAUserMsg_DismissAllStatPopups",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_DismissAllStatPopups"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1261-L1263 |
5,810 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_TE_DestroyProjectile | func (c *Callbacks) OnCDOTAUserMsg_TE_DestroyProjectile(fn func(*dota.CDOTAUserMsg_TE_DestroyProjectile) error) {
c.onCDOTAUserMsg_TE_DestroyProjectile = append(c.onCDOTAUserMsg_TE_DestroyProjectile, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_TE_DestroyProjectile(fn func(*dota.CDOTAUserMsg_TE_DestroyProjectile) error) {
c.onCDOTAUserMsg_TE_DestroyProjectile = append(c.onCDOTAUserMsg_TE_DestroyProjectile, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_TE_DestroyProjectile",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_TE_DestroyProjectile",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_TE_DestroyProjectile",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_TE_DestroyProjectile",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_TE_DestroyProjectile registers a callback for EDotaUserMessages_DOTA_UM_TE_DestroyProjectile | [
"OnCDOTAUserMsg_TE_DestroyProjectile",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_TE_DestroyProjectile"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1266-L1268 |
5,811 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_HeroRelicProgress | func (c *Callbacks) OnCDOTAUserMsg_HeroRelicProgress(fn func(*dota.CDOTAUserMsg_HeroRelicProgress) error) {
c.onCDOTAUserMsg_HeroRelicProgress = append(c.onCDOTAUserMsg_HeroRelicProgress, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_HeroRelicProgress(fn func(*dota.CDOTAUserMsg_HeroRelicProgress) error) {
c.onCDOTAUserMsg_HeroRelicProgress = append(c.onCDOTAUserMsg_HeroRelicProgress, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_HeroRelicProgress",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_HeroRelicProgress",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_HeroRelicProgress",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_HeroRelicProgress",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_HeroRelicProgress registers a callback for EDotaUserMessages_DOTA_UM_HeroRelicProgress | [
"OnCDOTAUserMsg_HeroRelicProgress",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_HeroRelicProgress"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1271-L1273 |
5,812 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_AbilityDraftRequestAbility | func (c *Callbacks) OnCDOTAUserMsg_AbilityDraftRequestAbility(fn func(*dota.CDOTAUserMsg_AbilityDraftRequestAbility) error) {
c.onCDOTAUserMsg_AbilityDraftRequestAbility = append(c.onCDOTAUserMsg_AbilityDraftRequestAbility, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_AbilityDraftRequestAbility(fn func(*dota.CDOTAUserMsg_AbilityDraftRequestAbility) error) {
c.onCDOTAUserMsg_AbilityDraftRequestAbility = append(c.onCDOTAUserMsg_AbilityDraftRequestAbility, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_AbilityDraftRequestAbility",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_AbilityDraftRequestAbility",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_AbilityDraftRequestAbility",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_AbilityDraftRequestAbility",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_AbilityDraftRequestAbility registers a callback for EDotaUserMessages_DOTA_UM_AbilityDraftRequestAbility | [
"OnCDOTAUserMsg_AbilityDraftRequestAbility",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_AbilityDraftRequestAbility"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1276-L1278 |
5,813 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_ItemSold | func (c *Callbacks) OnCDOTAUserMsg_ItemSold(fn func(*dota.CDOTAUserMsg_ItemSold) error) {
c.onCDOTAUserMsg_ItemSold = append(c.onCDOTAUserMsg_ItemSold, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_ItemSold(fn func(*dota.CDOTAUserMsg_ItemSold) error) {
c.onCDOTAUserMsg_ItemSold = append(c.onCDOTAUserMsg_ItemSold, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_ItemSold",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_ItemSold",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_ItemSold",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_ItemSold",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_ItemSold registers a callback for EDotaUserMessages_DOTA_UM_ItemSold | [
"OnCDOTAUserMsg_ItemSold",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_ItemSold"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1281-L1283 |
5,814 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_DamageReport | func (c *Callbacks) OnCDOTAUserMsg_DamageReport(fn func(*dota.CDOTAUserMsg_DamageReport) error) {
c.onCDOTAUserMsg_DamageReport = append(c.onCDOTAUserMsg_DamageReport, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_DamageReport(fn func(*dota.CDOTAUserMsg_DamageReport) error) {
c.onCDOTAUserMsg_DamageReport = append(c.onCDOTAUserMsg_DamageReport, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_DamageReport",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_DamageReport",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_DamageReport",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_DamageReport",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_DamageReport registers a callback for EDotaUserMessages_DOTA_UM_DamageReport | [
"OnCDOTAUserMsg_DamageReport",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_DamageReport"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1286-L1288 |
5,815 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_SalutePlayer | func (c *Callbacks) OnCDOTAUserMsg_SalutePlayer(fn func(*dota.CDOTAUserMsg_SalutePlayer) error) {
c.onCDOTAUserMsg_SalutePlayer = append(c.onCDOTAUserMsg_SalutePlayer, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_SalutePlayer(fn func(*dota.CDOTAUserMsg_SalutePlayer) error) {
c.onCDOTAUserMsg_SalutePlayer = append(c.onCDOTAUserMsg_SalutePlayer, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_SalutePlayer",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_SalutePlayer",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_SalutePlayer",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_SalutePlayer",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_SalutePlayer registers a callback for EDotaUserMessages_DOTA_UM_SalutePlayer | [
"OnCDOTAUserMsg_SalutePlayer",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_SalutePlayer"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1291-L1293 |
5,816 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_TipAlert | func (c *Callbacks) OnCDOTAUserMsg_TipAlert(fn func(*dota.CDOTAUserMsg_TipAlert) error) {
c.onCDOTAUserMsg_TipAlert = append(c.onCDOTAUserMsg_TipAlert, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_TipAlert(fn func(*dota.CDOTAUserMsg_TipAlert) error) {
c.onCDOTAUserMsg_TipAlert = append(c.onCDOTAUserMsg_TipAlert, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_TipAlert",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_TipAlert",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_TipAlert",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_TipAlert",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_TipAlert registers a callback for EDotaUserMessages_DOTA_UM_TipAlert | [
"OnCDOTAUserMsg_TipAlert",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_TipAlert"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1296-L1298 |
5,817 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_ReplaceQueryUnit | func (c *Callbacks) OnCDOTAUserMsg_ReplaceQueryUnit(fn func(*dota.CDOTAUserMsg_ReplaceQueryUnit) error) {
c.onCDOTAUserMsg_ReplaceQueryUnit = append(c.onCDOTAUserMsg_ReplaceQueryUnit, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_ReplaceQueryUnit(fn func(*dota.CDOTAUserMsg_ReplaceQueryUnit) error) {
c.onCDOTAUserMsg_ReplaceQueryUnit = append(c.onCDOTAUserMsg_ReplaceQueryUnit, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_ReplaceQueryUnit",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_ReplaceQueryUnit",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_ReplaceQueryUnit",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_ReplaceQueryUnit",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_ReplaceQueryUnit registers a callback for EDotaUserMessages_DOTA_UM_ReplaceQueryUnit | [
"OnCDOTAUserMsg_ReplaceQueryUnit",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_ReplaceQueryUnit"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1301-L1303 |
5,818 | dotabuff/manta | callbacks.go | OnCDOTAUserMsg_EmptyTeleportAlert | func (c *Callbacks) OnCDOTAUserMsg_EmptyTeleportAlert(fn func(*dota.CDOTAUserMsg_EmptyTeleportAlert) error) {
c.onCDOTAUserMsg_EmptyTeleportAlert = append(c.onCDOTAUserMsg_EmptyTeleportAlert, fn)
} | go | func (c *Callbacks) OnCDOTAUserMsg_EmptyTeleportAlert(fn func(*dota.CDOTAUserMsg_EmptyTeleportAlert) error) {
c.onCDOTAUserMsg_EmptyTeleportAlert = append(c.onCDOTAUserMsg_EmptyTeleportAlert, fn)
} | [
"func",
"(",
"c",
"*",
"Callbacks",
")",
"OnCDOTAUserMsg_EmptyTeleportAlert",
"(",
"fn",
"func",
"(",
"*",
"dota",
".",
"CDOTAUserMsg_EmptyTeleportAlert",
")",
"error",
")",
"{",
"c",
".",
"onCDOTAUserMsg_EmptyTeleportAlert",
"=",
"append",
"(",
"c",
".",
"onCDOTAUserMsg_EmptyTeleportAlert",
",",
"fn",
")",
"\n",
"}"
] | // OnCDOTAUserMsg_EmptyTeleportAlert registers a callback for EDotaUserMessages_DOTA_UM_EmptyTeleportAlert | [
"OnCDOTAUserMsg_EmptyTeleportAlert",
"registers",
"a",
"callback",
"for",
"EDotaUserMessages_DOTA_UM_EmptyTeleportAlert"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/callbacks.go#L1306-L1308 |
5,819 | dotabuff/manta | reader.go | nextByte | func (r *reader) nextByte() byte {
r.pos += 1
if r.pos > r.size {
_panicf("nextByte: insufficient buffer (%d of %d)", r.pos, r.size)
}
return r.buf[r.pos-1]
} | go | func (r *reader) nextByte() byte {
r.pos += 1
if r.pos > r.size {
_panicf("nextByte: insufficient buffer (%d of %d)", r.pos, r.size)
}
return r.buf[r.pos-1]
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"nextByte",
"(",
")",
"byte",
"{",
"r",
".",
"pos",
"+=",
"1",
"\n",
"if",
"r",
".",
"pos",
">",
"r",
".",
"size",
"{",
"_panicf",
"(",
"\"",
"\"",
",",
"r",
".",
"pos",
",",
"r",
".",
"size",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"buf",
"[",
"r",
".",
"pos",
"-",
"1",
"]",
"\n",
"}"
] | // nextByte reads the next byte from the buffer | [
"nextByte",
"reads",
"the",
"next",
"byte",
"from",
"the",
"buffer"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L41-L47 |
5,820 | dotabuff/manta | reader.go | readBits | func (r *reader) readBits(n uint32) uint32 {
for n > r.bitCount {
r.bitVal |= uint64(r.nextByte()) << r.bitCount
r.bitCount += 8
}
x := (r.bitVal & ((1 << n) - 1))
r.bitVal >>= n
r.bitCount -= n
return uint32(x)
} | go | func (r *reader) readBits(n uint32) uint32 {
for n > r.bitCount {
r.bitVal |= uint64(r.nextByte()) << r.bitCount
r.bitCount += 8
}
x := (r.bitVal & ((1 << n) - 1))
r.bitVal >>= n
r.bitCount -= n
return uint32(x)
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"readBits",
"(",
"n",
"uint32",
")",
"uint32",
"{",
"for",
"n",
">",
"r",
".",
"bitCount",
"{",
"r",
".",
"bitVal",
"|=",
"uint64",
"(",
"r",
".",
"nextByte",
"(",
")",
")",
"<<",
"r",
".",
"bitCount",
"\n",
"r",
".",
"bitCount",
"+=",
"8",
"\n",
"}",
"\n\n",
"x",
":=",
"(",
"r",
".",
"bitVal",
"&",
"(",
"(",
"1",
"<<",
"n",
")",
"-",
"1",
")",
")",
"\n",
"r",
".",
"bitVal",
">>=",
"n",
"\n",
"r",
".",
"bitCount",
"-=",
"n",
"\n\n",
"return",
"uint32",
"(",
"x",
")",
"\n",
"}"
] | // readBits returns the uint32 value for the given number of sequential bits | [
"readBits",
"returns",
"the",
"uint32",
"value",
"for",
"the",
"given",
"number",
"of",
"sequential",
"bits"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L50-L61 |
5,821 | dotabuff/manta | reader.go | readByte | func (r *reader) readByte() byte {
// Fast path if we're byte aligned
if r.bitCount == 0 {
return r.nextByte()
}
return byte(r.readBits(8))
} | go | func (r *reader) readByte() byte {
// Fast path if we're byte aligned
if r.bitCount == 0 {
return r.nextByte()
}
return byte(r.readBits(8))
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"readByte",
"(",
")",
"byte",
"{",
"// Fast path if we're byte aligned",
"if",
"r",
".",
"bitCount",
"==",
"0",
"{",
"return",
"r",
".",
"nextByte",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"byte",
"(",
"r",
".",
"readBits",
"(",
"8",
")",
")",
"\n",
"}"
] | // readByte reads a single byte | [
"readByte",
"reads",
"a",
"single",
"byte"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L64-L71 |
5,822 | dotabuff/manta | reader.go | readBytes | func (r *reader) readBytes(n uint32) []byte {
// Fast path if we're byte aligned
if r.bitCount == 0 {
r.pos += n
if r.pos > r.size {
_panicf("readBytes: insufficient buffer (%d of %d)", r.pos, r.size)
}
return r.buf[r.pos-n : r.pos]
}
buf := make([]byte, n)
for i := uint32(0); i < n; i++ {
buf[i] = byte(r.readBits(8))
}
return buf
} | go | func (r *reader) readBytes(n uint32) []byte {
// Fast path if we're byte aligned
if r.bitCount == 0 {
r.pos += n
if r.pos > r.size {
_panicf("readBytes: insufficient buffer (%d of %d)", r.pos, r.size)
}
return r.buf[r.pos-n : r.pos]
}
buf := make([]byte, n)
for i := uint32(0); i < n; i++ {
buf[i] = byte(r.readBits(8))
}
return buf
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"readBytes",
"(",
"n",
"uint32",
")",
"[",
"]",
"byte",
"{",
"// Fast path if we're byte aligned",
"if",
"r",
".",
"bitCount",
"==",
"0",
"{",
"r",
".",
"pos",
"+=",
"n",
"\n",
"if",
"r",
".",
"pos",
">",
"r",
".",
"size",
"{",
"_panicf",
"(",
"\"",
"\"",
",",
"r",
".",
"pos",
",",
"r",
".",
"size",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"buf",
"[",
"r",
".",
"pos",
"-",
"n",
":",
"r",
".",
"pos",
"]",
"\n",
"}",
"\n\n",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
")",
"\n",
"for",
"i",
":=",
"uint32",
"(",
"0",
")",
";",
"i",
"<",
"n",
";",
"i",
"++",
"{",
"buf",
"[",
"i",
"]",
"=",
"byte",
"(",
"r",
".",
"readBits",
"(",
"8",
")",
")",
"\n",
"}",
"\n",
"return",
"buf",
"\n",
"}"
] | // readBytes reads the given number of bytes | [
"readBytes",
"reads",
"the",
"given",
"number",
"of",
"bytes"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L74-L89 |
5,823 | dotabuff/manta | reader.go | readVarUint32 | func (r *reader) readVarUint32() uint32 {
var x, s uint32
for {
b := uint32(r.readByte())
x |= (b & 0x7F) << s
s += 7
if ((b & 0x80) == 0) || (s == 35) {
break
}
}
return x
} | go | func (r *reader) readVarUint32() uint32 {
var x, s uint32
for {
b := uint32(r.readByte())
x |= (b & 0x7F) << s
s += 7
if ((b & 0x80) == 0) || (s == 35) {
break
}
}
return x
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"readVarUint32",
"(",
")",
"uint32",
"{",
"var",
"x",
",",
"s",
"uint32",
"\n",
"for",
"{",
"b",
":=",
"uint32",
"(",
"r",
".",
"readByte",
"(",
")",
")",
"\n",
"x",
"|=",
"(",
"b",
"&",
"0x7F",
")",
"<<",
"s",
"\n",
"s",
"+=",
"7",
"\n",
"if",
"(",
"(",
"b",
"&",
"0x80",
")",
"==",
"0",
")",
"||",
"(",
"s",
"==",
"35",
")",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"x",
"\n",
"}"
] | // readVarUint64 reads an unsigned 32-bit varint | [
"readVarUint64",
"reads",
"an",
"unsigned",
"32",
"-",
"bit",
"varint"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L102-L114 |
5,824 | dotabuff/manta | reader.go | readVarInt32 | func (r *reader) readVarInt32() int32 {
ux := r.readVarUint32()
x := int32(ux >> 1)
if ux&1 != 0 {
x = ^x
}
return x
} | go | func (r *reader) readVarInt32() int32 {
ux := r.readVarUint32()
x := int32(ux >> 1)
if ux&1 != 0 {
x = ^x
}
return x
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"readVarInt32",
"(",
")",
"int32",
"{",
"ux",
":=",
"r",
".",
"readVarUint32",
"(",
")",
"\n",
"x",
":=",
"int32",
"(",
"ux",
">>",
"1",
")",
"\n",
"if",
"ux",
"&",
"1",
"!=",
"0",
"{",
"x",
"=",
"^",
"x",
"\n",
"}",
"\n",
"return",
"x",
"\n",
"}"
] | // readVarInt64 reads a signed 32-bit varint | [
"readVarInt64",
"reads",
"a",
"signed",
"32",
"-",
"bit",
"varint"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L117-L124 |
5,825 | dotabuff/manta | reader.go | readVarUint64 | func (r *reader) readVarUint64() uint64 {
var x, s uint64
for i := 0; ; i++ {
b := r.readByte()
if b < 0x80 {
if i > 9 || i == 9 && b > 1 {
_panicf("read overflow: varint overflows uint64")
}
return x | uint64(b)<<s
}
x |= uint64(b&0x7f) << s
s += 7
}
} | go | func (r *reader) readVarUint64() uint64 {
var x, s uint64
for i := 0; ; i++ {
b := r.readByte()
if b < 0x80 {
if i > 9 || i == 9 && b > 1 {
_panicf("read overflow: varint overflows uint64")
}
return x | uint64(b)<<s
}
x |= uint64(b&0x7f) << s
s += 7
}
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"readVarUint64",
"(",
")",
"uint64",
"{",
"var",
"x",
",",
"s",
"uint64",
"\n",
"for",
"i",
":=",
"0",
";",
";",
"i",
"++",
"{",
"b",
":=",
"r",
".",
"readByte",
"(",
")",
"\n",
"if",
"b",
"<",
"0x80",
"{",
"if",
"i",
">",
"9",
"||",
"i",
"==",
"9",
"&&",
"b",
">",
"1",
"{",
"_panicf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"x",
"|",
"uint64",
"(",
"b",
")",
"<<",
"s",
"\n",
"}",
"\n",
"x",
"|=",
"uint64",
"(",
"b",
"&",
"0x7f",
")",
"<<",
"s",
"\n",
"s",
"+=",
"7",
"\n",
"}",
"\n",
"}"
] | // readVarUint64 reads an unsigned 64-bit varint | [
"readVarUint64",
"reads",
"an",
"unsigned",
"64",
"-",
"bit",
"varint"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L127-L140 |
5,826 | dotabuff/manta | reader.go | readVarInt64 | func (r *reader) readVarInt64() int64 {
ux := r.readVarUint64()
x := int64(ux >> 1)
if ux&1 != 0 {
x = ^x
}
return x
} | go | func (r *reader) readVarInt64() int64 {
ux := r.readVarUint64()
x := int64(ux >> 1)
if ux&1 != 0 {
x = ^x
}
return x
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"readVarInt64",
"(",
")",
"int64",
"{",
"ux",
":=",
"r",
".",
"readVarUint64",
"(",
")",
"\n",
"x",
":=",
"int64",
"(",
"ux",
">>",
"1",
")",
"\n",
"if",
"ux",
"&",
"1",
"!=",
"0",
"{",
"x",
"=",
"^",
"x",
"\n",
"}",
"\n",
"return",
"x",
"\n",
"}"
] | // readVarInt64 reads a signed 64-bit varint | [
"readVarInt64",
"reads",
"a",
"signed",
"64",
"-",
"bit",
"varint"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L143-L150 |
5,827 | dotabuff/manta | reader.go | readUBitVar | func (r *reader) readUBitVar() uint32 {
ret := r.readBits(6)
switch ret & 0x30 {
case 16:
ret = (ret & 15) | (r.readBits(4) << 4)
break
case 32:
ret = (ret & 15) | (r.readBits(8) << 4)
break
case 48:
ret = (ret & 15) | (r.readBits(28) << 4)
break
}
return ret
} | go | func (r *reader) readUBitVar() uint32 {
ret := r.readBits(6)
switch ret & 0x30 {
case 16:
ret = (ret & 15) | (r.readBits(4) << 4)
break
case 32:
ret = (ret & 15) | (r.readBits(8) << 4)
break
case 48:
ret = (ret & 15) | (r.readBits(28) << 4)
break
}
return ret
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"readUBitVar",
"(",
")",
"uint32",
"{",
"ret",
":=",
"r",
".",
"readBits",
"(",
"6",
")",
"\n\n",
"switch",
"ret",
"&",
"0x30",
"{",
"case",
"16",
":",
"ret",
"=",
"(",
"ret",
"&",
"15",
")",
"|",
"(",
"r",
".",
"readBits",
"(",
"4",
")",
"<<",
"4",
")",
"\n",
"break",
"\n",
"case",
"32",
":",
"ret",
"=",
"(",
"ret",
"&",
"15",
")",
"|",
"(",
"r",
".",
"readBits",
"(",
"8",
")",
"<<",
"4",
")",
"\n",
"break",
"\n",
"case",
"48",
":",
"ret",
"=",
"(",
"ret",
"&",
"15",
")",
"|",
"(",
"r",
".",
"readBits",
"(",
"28",
")",
"<<",
"4",
")",
"\n",
"break",
"\n",
"}",
"\n\n",
"return",
"ret",
"\n",
"}"
] | // readUBitVar reads a variable length uint32 with encoding in last to bits of 6 bit group | [
"readUBitVar",
"reads",
"a",
"variable",
"length",
"uint32",
"with",
"encoding",
"in",
"last",
"to",
"bits",
"of",
"6",
"bit",
"group"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L163-L179 |
5,828 | dotabuff/manta | reader.go | readUBitVarFP | func (r *reader) readUBitVarFP() uint32 {
if r.readBoolean() {
return r.readBits(2)
}
if r.readBoolean() {
return r.readBits(4)
}
if r.readBoolean() {
return r.readBits(10)
}
if r.readBoolean() {
return r.readBits(17)
}
return r.readBits(31)
} | go | func (r *reader) readUBitVarFP() uint32 {
if r.readBoolean() {
return r.readBits(2)
}
if r.readBoolean() {
return r.readBits(4)
}
if r.readBoolean() {
return r.readBits(10)
}
if r.readBoolean() {
return r.readBits(17)
}
return r.readBits(31)
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"readUBitVarFP",
"(",
")",
"uint32",
"{",
"if",
"r",
".",
"readBoolean",
"(",
")",
"{",
"return",
"r",
".",
"readBits",
"(",
"2",
")",
"\n",
"}",
"\n",
"if",
"r",
".",
"readBoolean",
"(",
")",
"{",
"return",
"r",
".",
"readBits",
"(",
"4",
")",
"\n",
"}",
"\n",
"if",
"r",
".",
"readBoolean",
"(",
")",
"{",
"return",
"r",
".",
"readBits",
"(",
"10",
")",
"\n",
"}",
"\n",
"if",
"r",
".",
"readBoolean",
"(",
")",
"{",
"return",
"r",
".",
"readBits",
"(",
"17",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"readBits",
"(",
"31",
")",
"\n",
"}"
] | // readUBitVarFP reads a variable length uint32 encoded using fieldpath encoding | [
"readUBitVarFP",
"reads",
"a",
"variable",
"length",
"uint32",
"encoded",
"using",
"fieldpath",
"encoding"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L182-L196 |
5,829 | dotabuff/manta | reader.go | readStringN | func (r *reader) readStringN(n uint32) string {
return string(r.readBytes(n))
} | go | func (r *reader) readStringN(n uint32) string {
return string(r.readBytes(n))
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"readStringN",
"(",
"n",
"uint32",
")",
"string",
"{",
"return",
"string",
"(",
"r",
".",
"readBytes",
"(",
"n",
")",
")",
"\n",
"}"
] | // readStringN reads a string of a given length | [
"readStringN",
"reads",
"a",
"string",
"of",
"a",
"given",
"length"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L203-L205 |
5,830 | dotabuff/manta | reader.go | readString | func (r *reader) readString() string {
buf := make([]byte, 0)
for {
b := r.readByte()
if b == 0 {
break
}
buf = append(buf, b)
}
return string(buf)
} | go | func (r *reader) readString() string {
buf := make([]byte, 0)
for {
b := r.readByte()
if b == 0 {
break
}
buf = append(buf, b)
}
return string(buf)
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"readString",
"(",
")",
"string",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
")",
"\n",
"for",
"{",
"b",
":=",
"r",
".",
"readByte",
"(",
")",
"\n",
"if",
"b",
"==",
"0",
"{",
"break",
"\n",
"}",
"\n",
"buf",
"=",
"append",
"(",
"buf",
",",
"b",
")",
"\n",
"}",
"\n\n",
"return",
"string",
"(",
"buf",
")",
"\n",
"}"
] | // readString reads a null terminated string | [
"readString",
"reads",
"a",
"null",
"terminated",
"string"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L208-L219 |
5,831 | dotabuff/manta | reader.go | readCoord | func (r *reader) readCoord() float32 {
value := float32(0.0)
intval := r.readBits(1)
fractval := r.readBits(1)
signbit := false
if intval != 0 || fractval != 0 {
signbit = r.readBoolean()
if intval != 0 {
intval = r.readBits(14) + 1
}
if fractval != 0 {
fractval = r.readBits(5)
}
value = float32(intval) + float32(fractval)*(1.0/(1<<5))
// Fixup the sign if negative.
if signbit {
value = -value
}
}
return value
} | go | func (r *reader) readCoord() float32 {
value := float32(0.0)
intval := r.readBits(1)
fractval := r.readBits(1)
signbit := false
if intval != 0 || fractval != 0 {
signbit = r.readBoolean()
if intval != 0 {
intval = r.readBits(14) + 1
}
if fractval != 0 {
fractval = r.readBits(5)
}
value = float32(intval) + float32(fractval)*(1.0/(1<<5))
// Fixup the sign if negative.
if signbit {
value = -value
}
}
return value
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"readCoord",
"(",
")",
"float32",
"{",
"value",
":=",
"float32",
"(",
"0.0",
")",
"\n\n",
"intval",
":=",
"r",
".",
"readBits",
"(",
"1",
")",
"\n",
"fractval",
":=",
"r",
".",
"readBits",
"(",
"1",
")",
"\n",
"signbit",
":=",
"false",
"\n\n",
"if",
"intval",
"!=",
"0",
"||",
"fractval",
"!=",
"0",
"{",
"signbit",
"=",
"r",
".",
"readBoolean",
"(",
")",
"\n\n",
"if",
"intval",
"!=",
"0",
"{",
"intval",
"=",
"r",
".",
"readBits",
"(",
"14",
")",
"+",
"1",
"\n",
"}",
"\n\n",
"if",
"fractval",
"!=",
"0",
"{",
"fractval",
"=",
"r",
".",
"readBits",
"(",
"5",
")",
"\n",
"}",
"\n\n",
"value",
"=",
"float32",
"(",
"intval",
")",
"+",
"float32",
"(",
"fractval",
")",
"*",
"(",
"1.0",
"/",
"(",
"1",
"<<",
"5",
")",
")",
"\n\n",
"// Fixup the sign if negative.",
"if",
"signbit",
"{",
"value",
"=",
"-",
"value",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"value",
"\n",
"}"
] | // readCoord reads a coord as a float32 | [
"readCoord",
"reads",
"a",
"coord",
"as",
"a",
"float32"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L222-L249 |
5,832 | dotabuff/manta | reader.go | readAngle | func (r *reader) readAngle(n uint32) float32 {
return float32(r.readBits(n)) * 360.0 / float32(int(1<<n))
} | go | func (r *reader) readAngle(n uint32) float32 {
return float32(r.readBits(n)) * 360.0 / float32(int(1<<n))
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"readAngle",
"(",
"n",
"uint32",
")",
"float32",
"{",
"return",
"float32",
"(",
"r",
".",
"readBits",
"(",
"n",
")",
")",
"*",
"360.0",
"/",
"float32",
"(",
"int",
"(",
"1",
"<<",
"n",
")",
")",
"\n",
"}"
] | // readAngle reads a bit angle of the given size | [
"readAngle",
"reads",
"a",
"bit",
"angle",
"of",
"the",
"given",
"size"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L252-L254 |
5,833 | dotabuff/manta | reader.go | readNormal | func (r *reader) readNormal() float32 {
isNeg := r.readBoolean()
len := r.readBits(11)
ret := float32(len) * float32(1.0/(float32(1<<11)-1.0))
if isNeg {
return -ret
} else {
return ret
}
} | go | func (r *reader) readNormal() float32 {
isNeg := r.readBoolean()
len := r.readBits(11)
ret := float32(len) * float32(1.0/(float32(1<<11)-1.0))
if isNeg {
return -ret
} else {
return ret
}
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"readNormal",
"(",
")",
"float32",
"{",
"isNeg",
":=",
"r",
".",
"readBoolean",
"(",
")",
"\n",
"len",
":=",
"r",
".",
"readBits",
"(",
"11",
")",
"\n",
"ret",
":=",
"float32",
"(",
"len",
")",
"*",
"float32",
"(",
"1.0",
"/",
"(",
"float32",
"(",
"1",
"<<",
"11",
")",
"-",
"1.0",
")",
")",
"\n\n",
"if",
"isNeg",
"{",
"return",
"-",
"ret",
"\n",
"}",
"else",
"{",
"return",
"ret",
"\n",
"}",
"\n",
"}"
] | // readNormal reads a normalized float vector | [
"readNormal",
"reads",
"a",
"normalized",
"float",
"vector"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L257-L267 |
5,834 | dotabuff/manta | reader.go | read3BitNormal | func (r *reader) read3BitNormal() []float32 {
ret := []float32{0.0, 0.0, 0.0}
hasX := r.readBoolean()
haxY := r.readBoolean()
if hasX {
ret[0] = r.readNormal()
}
if haxY {
ret[1] = r.readNormal()
}
negZ := r.readBoolean()
prodsum := ret[0]*ret[0] + ret[1]*ret[1]
if prodsum < 1.0 {
ret[2] = float32(math.Sqrt(float64(1.0 - prodsum)))
} else {
ret[2] = 0.0
}
if negZ {
ret[2] = -ret[2]
}
return ret
} | go | func (r *reader) read3BitNormal() []float32 {
ret := []float32{0.0, 0.0, 0.0}
hasX := r.readBoolean()
haxY := r.readBoolean()
if hasX {
ret[0] = r.readNormal()
}
if haxY {
ret[1] = r.readNormal()
}
negZ := r.readBoolean()
prodsum := ret[0]*ret[0] + ret[1]*ret[1]
if prodsum < 1.0 {
ret[2] = float32(math.Sqrt(float64(1.0 - prodsum)))
} else {
ret[2] = 0.0
}
if negZ {
ret[2] = -ret[2]
}
return ret
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"read3BitNormal",
"(",
")",
"[",
"]",
"float32",
"{",
"ret",
":=",
"[",
"]",
"float32",
"{",
"0.0",
",",
"0.0",
",",
"0.0",
"}",
"\n\n",
"hasX",
":=",
"r",
".",
"readBoolean",
"(",
")",
"\n",
"haxY",
":=",
"r",
".",
"readBoolean",
"(",
")",
"\n\n",
"if",
"hasX",
"{",
"ret",
"[",
"0",
"]",
"=",
"r",
".",
"readNormal",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"haxY",
"{",
"ret",
"[",
"1",
"]",
"=",
"r",
".",
"readNormal",
"(",
")",
"\n",
"}",
"\n\n",
"negZ",
":=",
"r",
".",
"readBoolean",
"(",
")",
"\n",
"prodsum",
":=",
"ret",
"[",
"0",
"]",
"*",
"ret",
"[",
"0",
"]",
"+",
"ret",
"[",
"1",
"]",
"*",
"ret",
"[",
"1",
"]",
"\n\n",
"if",
"prodsum",
"<",
"1.0",
"{",
"ret",
"[",
"2",
"]",
"=",
"float32",
"(",
"math",
".",
"Sqrt",
"(",
"float64",
"(",
"1.0",
"-",
"prodsum",
")",
")",
")",
"\n",
"}",
"else",
"{",
"ret",
"[",
"2",
"]",
"=",
"0.0",
"\n",
"}",
"\n\n",
"if",
"negZ",
"{",
"ret",
"[",
"2",
"]",
"=",
"-",
"ret",
"[",
"2",
"]",
"\n",
"}",
"\n\n",
"return",
"ret",
"\n",
"}"
] | // read3BitNormal reads a normalized float vector | [
"read3BitNormal",
"reads",
"a",
"normalized",
"float",
"vector"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L270-L298 |
5,835 | dotabuff/manta | reader.go | readBitsAsBytes | func (r *reader) readBitsAsBytes(n uint32) []byte {
tmp := make([]byte, 0)
for n >= 8 {
tmp = append(tmp, r.readByte())
n -= 8
}
if n > 0 {
tmp = append(tmp, byte(r.readBits(n)))
}
return tmp
} | go | func (r *reader) readBitsAsBytes(n uint32) []byte {
tmp := make([]byte, 0)
for n >= 8 {
tmp = append(tmp, r.readByte())
n -= 8
}
if n > 0 {
tmp = append(tmp, byte(r.readBits(n)))
}
return tmp
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"readBitsAsBytes",
"(",
"n",
"uint32",
")",
"[",
"]",
"byte",
"{",
"tmp",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
")",
"\n",
"for",
"n",
">=",
"8",
"{",
"tmp",
"=",
"append",
"(",
"tmp",
",",
"r",
".",
"readByte",
"(",
")",
")",
"\n",
"n",
"-=",
"8",
"\n",
"}",
"\n",
"if",
"n",
">",
"0",
"{",
"tmp",
"=",
"append",
"(",
"tmp",
",",
"byte",
"(",
"r",
".",
"readBits",
"(",
"n",
")",
")",
")",
"\n",
"}",
"\n",
"return",
"tmp",
"\n",
"}"
] | // readBitsAsBytes reads the given number of bits in groups of bytes | [
"readBitsAsBytes",
"reads",
"the",
"given",
"number",
"of",
"bits",
"in",
"groups",
"of",
"bytes"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/reader.go#L301-L311 |
5,836 | dotabuff/manta | gen/callbacks.go | makeContext | func makeContext() ctx {
c := ctx{
DemoTypes: []ctxType{},
PacketTypes: []ctxType{},
}
demoIds := []int{}
demoMap := map[int]ctxType{}
packetIds := []int{}
packetMap := map[int]ctxType{}
for _, t := range messageTypes {
for vs, n := range t.enumValues {
// Find an enum type for the enum value
if ts, ok := t.enumToType(vs); ok {
// Find a struct type for the enum type
if messageTypeNames[ts] {
cs, ok := t.enumToCallback(vs)
if !ok {
cs = ts
}
if t.isPacket {
packetIds = append(packetIds, n)
packetMap[n] = ctxType{
Id: n,
Callback: cs,
EnumName: vs,
TypeName: ts,
}
} else {
demoIds = append(demoIds, n)
demoMap[n] = ctxType{
Id: n,
Callback: cs,
EnumName: vs,
TypeName: ts,
}
}
} else {
fmt.Printf("warning: no matching type %s for enum: type %s %s = %d\n", ts, vs, t.enumName, n)
}
} else {
fmt.Printf("notice: skipped manually excluded enum: type %s %s = %d\n", vs, t.enumName, n)
}
}
}
sort.Ints(demoIds)
sort.Ints(packetIds)
for _, id := range demoIds {
c.DemoTypes = append(c.DemoTypes, demoMap[id])
}
for _, id := range packetIds {
c.PacketTypes = append(c.PacketTypes, packetMap[id])
}
return c
} | go | func makeContext() ctx {
c := ctx{
DemoTypes: []ctxType{},
PacketTypes: []ctxType{},
}
demoIds := []int{}
demoMap := map[int]ctxType{}
packetIds := []int{}
packetMap := map[int]ctxType{}
for _, t := range messageTypes {
for vs, n := range t.enumValues {
// Find an enum type for the enum value
if ts, ok := t.enumToType(vs); ok {
// Find a struct type for the enum type
if messageTypeNames[ts] {
cs, ok := t.enumToCallback(vs)
if !ok {
cs = ts
}
if t.isPacket {
packetIds = append(packetIds, n)
packetMap[n] = ctxType{
Id: n,
Callback: cs,
EnumName: vs,
TypeName: ts,
}
} else {
demoIds = append(demoIds, n)
demoMap[n] = ctxType{
Id: n,
Callback: cs,
EnumName: vs,
TypeName: ts,
}
}
} else {
fmt.Printf("warning: no matching type %s for enum: type %s %s = %d\n", ts, vs, t.enumName, n)
}
} else {
fmt.Printf("notice: skipped manually excluded enum: type %s %s = %d\n", vs, t.enumName, n)
}
}
}
sort.Ints(demoIds)
sort.Ints(packetIds)
for _, id := range demoIds {
c.DemoTypes = append(c.DemoTypes, demoMap[id])
}
for _, id := range packetIds {
c.PacketTypes = append(c.PacketTypes, packetMap[id])
}
return c
} | [
"func",
"makeContext",
"(",
")",
"ctx",
"{",
"c",
":=",
"ctx",
"{",
"DemoTypes",
":",
"[",
"]",
"ctxType",
"{",
"}",
",",
"PacketTypes",
":",
"[",
"]",
"ctxType",
"{",
"}",
",",
"}",
"\n\n",
"demoIds",
":=",
"[",
"]",
"int",
"{",
"}",
"\n",
"demoMap",
":=",
"map",
"[",
"int",
"]",
"ctxType",
"{",
"}",
"\n",
"packetIds",
":=",
"[",
"]",
"int",
"{",
"}",
"\n",
"packetMap",
":=",
"map",
"[",
"int",
"]",
"ctxType",
"{",
"}",
"\n\n",
"for",
"_",
",",
"t",
":=",
"range",
"messageTypes",
"{",
"for",
"vs",
",",
"n",
":=",
"range",
"t",
".",
"enumValues",
"{",
"// Find an enum type for the enum value",
"if",
"ts",
",",
"ok",
":=",
"t",
".",
"enumToType",
"(",
"vs",
")",
";",
"ok",
"{",
"// Find a struct type for the enum type",
"if",
"messageTypeNames",
"[",
"ts",
"]",
"{",
"cs",
",",
"ok",
":=",
"t",
".",
"enumToCallback",
"(",
"vs",
")",
"\n",
"if",
"!",
"ok",
"{",
"cs",
"=",
"ts",
"\n",
"}",
"\n",
"if",
"t",
".",
"isPacket",
"{",
"packetIds",
"=",
"append",
"(",
"packetIds",
",",
"n",
")",
"\n",
"packetMap",
"[",
"n",
"]",
"=",
"ctxType",
"{",
"Id",
":",
"n",
",",
"Callback",
":",
"cs",
",",
"EnumName",
":",
"vs",
",",
"TypeName",
":",
"ts",
",",
"}",
"\n",
"}",
"else",
"{",
"demoIds",
"=",
"append",
"(",
"demoIds",
",",
"n",
")",
"\n",
"demoMap",
"[",
"n",
"]",
"=",
"ctxType",
"{",
"Id",
":",
"n",
",",
"Callback",
":",
"cs",
",",
"EnumName",
":",
"vs",
",",
"TypeName",
":",
"ts",
",",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"ts",
",",
"vs",
",",
"t",
".",
"enumName",
",",
"n",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"vs",
",",
"t",
".",
"enumName",
",",
"n",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"sort",
".",
"Ints",
"(",
"demoIds",
")",
"\n",
"sort",
".",
"Ints",
"(",
"packetIds",
")",
"\n\n",
"for",
"_",
",",
"id",
":=",
"range",
"demoIds",
"{",
"c",
".",
"DemoTypes",
"=",
"append",
"(",
"c",
".",
"DemoTypes",
",",
"demoMap",
"[",
"id",
"]",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"packetIds",
"{",
"c",
".",
"PacketTypes",
"=",
"append",
"(",
"c",
".",
"PacketTypes",
",",
"packetMap",
"[",
"id",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"c",
"\n",
"}"
] | // makeContext transforms messageTypes information into template context | [
"makeContext",
"transforms",
"messageTypes",
"information",
"into",
"template",
"context"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/gen/callbacks.go#L250-L308 |
5,837 | dotabuff/manta | gen/callbacks.go | discoverTypes | func discoverTypes(protoPath string) {
fileset := token.NewFileSet()
packageMap, err := parser.ParseDir(fileset, protoPath, nil, 0)
if err != nil {
panic(err)
}
// Iterate over packages
for _, p := range packageMap {
// Iterate over files
for _, f := range p.Files {
// Iterate over declarations
for _, d := range f.Decls {
switch t := d.(type) {
case *ast.GenDecl:
// Iterate over specifications
for _, s := range t.Specs {
// Handle type and value specs
switch t := s.(type) {
case *ast.TypeSpec:
// Type specs contain types such as CDemoPacket. Extract the type
// name and mark it as found in the corresponding message type.
typeName := t.Name.String()
//if _, ok := findMessageByTypeName(typeName); ok {
messageTypeNames[typeName] = true
//}
case *ast.ValueSpec:
// Value specs contain enum values such as EDemoCommands_DEM_Packet.
// Extract the enum name (ex. EDemoCommands), value name
// (ex. EDemoCommands_DEM_Packet) and real value (ex. 7) and
// store them with the matching enum type.
valueName := nameOfValue(t)
if enumName := typeOfValue(t); enumName != "" {
if mt, ok := findMessageByEnumName(enumName); ok {
mt.enumValues[valueName] = valueOfValue(t)
}
}
}
}
}
}
}
}
} | go | func discoverTypes(protoPath string) {
fileset := token.NewFileSet()
packageMap, err := parser.ParseDir(fileset, protoPath, nil, 0)
if err != nil {
panic(err)
}
// Iterate over packages
for _, p := range packageMap {
// Iterate over files
for _, f := range p.Files {
// Iterate over declarations
for _, d := range f.Decls {
switch t := d.(type) {
case *ast.GenDecl:
// Iterate over specifications
for _, s := range t.Specs {
// Handle type and value specs
switch t := s.(type) {
case *ast.TypeSpec:
// Type specs contain types such as CDemoPacket. Extract the type
// name and mark it as found in the corresponding message type.
typeName := t.Name.String()
//if _, ok := findMessageByTypeName(typeName); ok {
messageTypeNames[typeName] = true
//}
case *ast.ValueSpec:
// Value specs contain enum values such as EDemoCommands_DEM_Packet.
// Extract the enum name (ex. EDemoCommands), value name
// (ex. EDemoCommands_DEM_Packet) and real value (ex. 7) and
// store them with the matching enum type.
valueName := nameOfValue(t)
if enumName := typeOfValue(t); enumName != "" {
if mt, ok := findMessageByEnumName(enumName); ok {
mt.enumValues[valueName] = valueOfValue(t)
}
}
}
}
}
}
}
}
} | [
"func",
"discoverTypes",
"(",
"protoPath",
"string",
")",
"{",
"fileset",
":=",
"token",
".",
"NewFileSet",
"(",
")",
"\n",
"packageMap",
",",
"err",
":=",
"parser",
".",
"ParseDir",
"(",
"fileset",
",",
"protoPath",
",",
"nil",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// Iterate over packages",
"for",
"_",
",",
"p",
":=",
"range",
"packageMap",
"{",
"// Iterate over files",
"for",
"_",
",",
"f",
":=",
"range",
"p",
".",
"Files",
"{",
"// Iterate over declarations",
"for",
"_",
",",
"d",
":=",
"range",
"f",
".",
"Decls",
"{",
"switch",
"t",
":=",
"d",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ast",
".",
"GenDecl",
":",
"// Iterate over specifications",
"for",
"_",
",",
"s",
":=",
"range",
"t",
".",
"Specs",
"{",
"// Handle type and value specs",
"switch",
"t",
":=",
"s",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ast",
".",
"TypeSpec",
":",
"// Type specs contain types such as CDemoPacket. Extract the type",
"// name and mark it as found in the corresponding message type.",
"typeName",
":=",
"t",
".",
"Name",
".",
"String",
"(",
")",
"\n",
"//if _, ok := findMessageByTypeName(typeName); ok {",
"messageTypeNames",
"[",
"typeName",
"]",
"=",
"true",
"\n",
"//}",
"case",
"*",
"ast",
".",
"ValueSpec",
":",
"// Value specs contain enum values such as EDemoCommands_DEM_Packet.",
"// Extract the enum name (ex. EDemoCommands), value name",
"// (ex. EDemoCommands_DEM_Packet) and real value (ex. 7) and",
"// store them with the matching enum type.",
"valueName",
":=",
"nameOfValue",
"(",
"t",
")",
"\n",
"if",
"enumName",
":=",
"typeOfValue",
"(",
"t",
")",
";",
"enumName",
"!=",
"\"",
"\"",
"{",
"if",
"mt",
",",
"ok",
":=",
"findMessageByEnumName",
"(",
"enumName",
")",
";",
"ok",
"{",
"mt",
".",
"enumValues",
"[",
"valueName",
"]",
"=",
"valueOfValue",
"(",
"t",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // discoverTypes walks the go files in the dota directory and populates the data
// in messageTypes and messageTypeNames. | [
"discoverTypes",
"walks",
"the",
"go",
"files",
"in",
"the",
"dota",
"directory",
"and",
"populates",
"the",
"data",
"in",
"messageTypes",
"and",
"messageTypeNames",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/gen/callbacks.go#L312-L356 |
5,838 | dotabuff/manta | gen/callbacks.go | nameOfValue | func nameOfValue(t *ast.ValueSpec) string {
if len(t.Names) != 1 {
fmt.Println("unexpected names", t.Names)
panic("unexpected names")
}
return t.Names[0].Name
} | go | func nameOfValue(t *ast.ValueSpec) string {
if len(t.Names) != 1 {
fmt.Println("unexpected names", t.Names)
panic("unexpected names")
}
return t.Names[0].Name
} | [
"func",
"nameOfValue",
"(",
"t",
"*",
"ast",
".",
"ValueSpec",
")",
"string",
"{",
"if",
"len",
"(",
"t",
".",
"Names",
")",
"!=",
"1",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"t",
".",
"Names",
")",
"\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"t",
".",
"Names",
"[",
"0",
"]",
".",
"Name",
"\n",
"}"
] | // nameOfValue extracts the name of an enum value, ex. EDemoCommands_DEM_Packet | [
"nameOfValue",
"extracts",
"the",
"name",
"of",
"an",
"enum",
"value",
"ex",
".",
"EDemoCommands_DEM_Packet"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/gen/callbacks.go#L359-L365 |
5,839 | dotabuff/manta | gen/callbacks.go | typeOfValue | func typeOfValue(t *ast.ValueSpec) string {
switch t := t.Type.(type) {
case *ast.Ident:
return t.String()
}
return ""
} | go | func typeOfValue(t *ast.ValueSpec) string {
switch t := t.Type.(type) {
case *ast.Ident:
return t.String()
}
return ""
} | [
"func",
"typeOfValue",
"(",
"t",
"*",
"ast",
".",
"ValueSpec",
")",
"string",
"{",
"switch",
"t",
":=",
"t",
".",
"Type",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ast",
".",
"Ident",
":",
"return",
"t",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // typeOfValue extracts the type of an enum value, ex. EDemoCommands | [
"typeOfValue",
"extracts",
"the",
"type",
"of",
"an",
"enum",
"value",
"ex",
".",
"EDemoCommands"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/gen/callbacks.go#L368-L374 |
5,840 | dotabuff/manta | gen/callbacks.go | valueOfValue | func valueOfValue(t *ast.ValueSpec) int {
if len(t.Values) != 1 {
fmt.Println("unexpected values", t.Values)
panic("unexpected values")
}
switch t := t.Values[0].(type) {
case *ast.BasicLit:
n, _ := strconv.Atoi(t.Value)
return n
case *ast.UnaryExpr:
x := t.X.(*ast.BasicLit)
n, _ := strconv.Atoi(x.Value)
return n
default:
fmt.Println("unexpected type", t)
panic("unexpected type")
}
panic("fell through")
return 0
} | go | func valueOfValue(t *ast.ValueSpec) int {
if len(t.Values) != 1 {
fmt.Println("unexpected values", t.Values)
panic("unexpected values")
}
switch t := t.Values[0].(type) {
case *ast.BasicLit:
n, _ := strconv.Atoi(t.Value)
return n
case *ast.UnaryExpr:
x := t.X.(*ast.BasicLit)
n, _ := strconv.Atoi(x.Value)
return n
default:
fmt.Println("unexpected type", t)
panic("unexpected type")
}
panic("fell through")
return 0
} | [
"func",
"valueOfValue",
"(",
"t",
"*",
"ast",
".",
"ValueSpec",
")",
"int",
"{",
"if",
"len",
"(",
"t",
".",
"Values",
")",
"!=",
"1",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"t",
".",
"Values",
")",
"\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"switch",
"t",
":=",
"t",
".",
"Values",
"[",
"0",
"]",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ast",
".",
"BasicLit",
":",
"n",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"t",
".",
"Value",
")",
"\n",
"return",
"n",
"\n\n",
"case",
"*",
"ast",
".",
"UnaryExpr",
":",
"x",
":=",
"t",
".",
"X",
".",
"(",
"*",
"ast",
".",
"BasicLit",
")",
"\n",
"n",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"x",
".",
"Value",
")",
"\n",
"return",
"n",
"\n\n",
"default",
":",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"t",
")",
"\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"return",
"0",
"\n",
"}"
] | // valueOfValue extracts the value of an enum value, ex. 7 | [
"valueOfValue",
"extracts",
"the",
"value",
"of",
"an",
"enum",
"value",
"ex",
".",
"7"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/gen/callbacks.go#L377-L400 |
5,841 | dotabuff/manta | game_event.go | GetString | func (e *GameEvent) GetString(name string) (string, error) {
// Get the key from the message
k, err := e.getEventKey(name)
if err != nil {
return "", err
}
// Make sure it's a string.
if k.GetType() != gameEventTypeString {
return "", _errorf("field %s: expected string, got %s", name, gameEventTypeNames[k.GetType()])
}
return k.GetValString(), nil
} | go | func (e *GameEvent) GetString(name string) (string, error) {
// Get the key from the message
k, err := e.getEventKey(name)
if err != nil {
return "", err
}
// Make sure it's a string.
if k.GetType() != gameEventTypeString {
return "", _errorf("field %s: expected string, got %s", name, gameEventTypeNames[k.GetType()])
}
return k.GetValString(), nil
} | [
"func",
"(",
"e",
"*",
"GameEvent",
")",
"GetString",
"(",
"name",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Get the key from the message",
"k",
",",
"err",
":=",
"e",
".",
"getEventKey",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"// Make sure it's a string.",
"if",
"k",
".",
"GetType",
"(",
")",
"!=",
"gameEventTypeString",
"{",
"return",
"\"",
"\"",
",",
"_errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"gameEventTypeNames",
"[",
"k",
".",
"GetType",
"(",
")",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"k",
".",
"GetValString",
"(",
")",
",",
"nil",
"\n",
"}"
] | // Gets the string value of a named field. | [
"Gets",
"the",
"string",
"value",
"of",
"a",
"named",
"field",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/game_event.go#L75-L88 |
5,842 | dotabuff/manta | game_event.go | GetFloat32 | func (e *GameEvent) GetFloat32(name string) (float32, error) {
// Get the key from the message
k, err := e.getEventKey(name)
if err != nil {
return 0.0, err
}
// Make sure it's a bool.
if k.GetType() != gameEventTypeFloat {
return 0.0, _errorf("field %s: expected float, got %s", name, gameEventTypeNames[k.GetType()])
}
return k.GetValFloat(), nil
} | go | func (e *GameEvent) GetFloat32(name string) (float32, error) {
// Get the key from the message
k, err := e.getEventKey(name)
if err != nil {
return 0.0, err
}
// Make sure it's a bool.
if k.GetType() != gameEventTypeFloat {
return 0.0, _errorf("field %s: expected float, got %s", name, gameEventTypeNames[k.GetType()])
}
return k.GetValFloat(), nil
} | [
"func",
"(",
"e",
"*",
"GameEvent",
")",
"GetFloat32",
"(",
"name",
"string",
")",
"(",
"float32",
",",
"error",
")",
"{",
"// Get the key from the message",
"k",
",",
"err",
":=",
"e",
".",
"getEventKey",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0.0",
",",
"err",
"\n",
"}",
"\n\n",
"// Make sure it's a bool.",
"if",
"k",
".",
"GetType",
"(",
")",
"!=",
"gameEventTypeFloat",
"{",
"return",
"0.0",
",",
"_errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"gameEventTypeNames",
"[",
"k",
".",
"GetType",
"(",
")",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"k",
".",
"GetValFloat",
"(",
")",
",",
"nil",
"\n",
"}"
] | // Gets the float value of a named field. | [
"Gets",
"the",
"float",
"value",
"of",
"a",
"named",
"field",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/game_event.go#L91-L104 |
5,843 | dotabuff/manta | game_event.go | GetInt32 | func (e *GameEvent) GetInt32(name string) (int32, error) {
// Get the key from the message
k, err := e.getEventKey(name)
if err != nil {
return 0, err
}
// Return based on the type.
switch k.GetType() {
case gameEventTypeLong:
return k.GetValLong(), nil
case gameEventTypeShort:
return k.GetValShort(), nil
case gameEventTypeByte:
return k.GetValByte(), nil
}
return 0, _errorf("field %s: expected int, got %s", name, gameEventTypeNames[k.GetType()])
} | go | func (e *GameEvent) GetInt32(name string) (int32, error) {
// Get the key from the message
k, err := e.getEventKey(name)
if err != nil {
return 0, err
}
// Return based on the type.
switch k.GetType() {
case gameEventTypeLong:
return k.GetValLong(), nil
case gameEventTypeShort:
return k.GetValShort(), nil
case gameEventTypeByte:
return k.GetValByte(), nil
}
return 0, _errorf("field %s: expected int, got %s", name, gameEventTypeNames[k.GetType()])
} | [
"func",
"(",
"e",
"*",
"GameEvent",
")",
"GetInt32",
"(",
"name",
"string",
")",
"(",
"int32",
",",
"error",
")",
"{",
"// Get the key from the message",
"k",
",",
"err",
":=",
"e",
".",
"getEventKey",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"// Return based on the type.",
"switch",
"k",
".",
"GetType",
"(",
")",
"{",
"case",
"gameEventTypeLong",
":",
"return",
"k",
".",
"GetValLong",
"(",
")",
",",
"nil",
"\n",
"case",
"gameEventTypeShort",
":",
"return",
"k",
".",
"GetValShort",
"(",
")",
",",
"nil",
"\n",
"case",
"gameEventTypeByte",
":",
"return",
"k",
".",
"GetValByte",
"(",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"0",
",",
"_errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"gameEventTypeNames",
"[",
"k",
".",
"GetType",
"(",
")",
"]",
")",
"\n",
"}"
] | // Gets the integer value of a named field. | [
"Gets",
"the",
"integer",
"value",
"of",
"a",
"named",
"field",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/game_event.go#L107-L125 |
5,844 | dotabuff/manta | game_event.go | GetBool | func (e *GameEvent) GetBool(name string) (bool, error) {
// Get the key from the message
k, err := e.getEventKey(name)
if err != nil {
return false, err
}
// Make sure it's a bool.
if k.GetType() != gameEventTypeBool {
return false, _errorf("field %s: expected bool, got %s", name, gameEventTypeNames[k.GetType()])
}
return k.GetValBool(), nil
} | go | func (e *GameEvent) GetBool(name string) (bool, error) {
// Get the key from the message
k, err := e.getEventKey(name)
if err != nil {
return false, err
}
// Make sure it's a bool.
if k.GetType() != gameEventTypeBool {
return false, _errorf("field %s: expected bool, got %s", name, gameEventTypeNames[k.GetType()])
}
return k.GetValBool(), nil
} | [
"func",
"(",
"e",
"*",
"GameEvent",
")",
"GetBool",
"(",
"name",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"// Get the key from the message",
"k",
",",
"err",
":=",
"e",
".",
"getEventKey",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"// Make sure it's a bool.",
"if",
"k",
".",
"GetType",
"(",
")",
"!=",
"gameEventTypeBool",
"{",
"return",
"false",
",",
"_errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"gameEventTypeNames",
"[",
"k",
".",
"GetType",
"(",
")",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"k",
".",
"GetValBool",
"(",
")",
",",
"nil",
"\n",
"}"
] | // Gets the bool value of a named field. | [
"Gets",
"the",
"bool",
"value",
"of",
"a",
"named",
"field",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/game_event.go#L128-L141 |
5,845 | dotabuff/manta | game_event.go | GetUint64 | func (e *GameEvent) GetUint64(name string) (uint64, error) {
// Get the key from the message
k, err := e.getEventKey(name)
if err != nil {
return 0, err
}
// Make sure it's a uint64.
if k.GetType() != gameEventTypeUint64 {
return 0, _errorf("field %s: expected uint64, got %s", name, gameEventTypeNames[k.GetType()])
}
return k.GetValUint64(), nil
} | go | func (e *GameEvent) GetUint64(name string) (uint64, error) {
// Get the key from the message
k, err := e.getEventKey(name)
if err != nil {
return 0, err
}
// Make sure it's a uint64.
if k.GetType() != gameEventTypeUint64 {
return 0, _errorf("field %s: expected uint64, got %s", name, gameEventTypeNames[k.GetType()])
}
return k.GetValUint64(), nil
} | [
"func",
"(",
"e",
"*",
"GameEvent",
")",
"GetUint64",
"(",
"name",
"string",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"// Get the key from the message",
"k",
",",
"err",
":=",
"e",
".",
"getEventKey",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"// Make sure it's a uint64.",
"if",
"k",
".",
"GetType",
"(",
")",
"!=",
"gameEventTypeUint64",
"{",
"return",
"0",
",",
"_errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"gameEventTypeNames",
"[",
"k",
".",
"GetType",
"(",
")",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"k",
".",
"GetValUint64",
"(",
")",
",",
"nil",
"\n",
"}"
] | // Gets the uint64 value of a named field. | [
"Gets",
"the",
"uint64",
"value",
"of",
"a",
"named",
"field",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/game_event.go#L144-L157 |
5,846 | dotabuff/manta | game_event.go | getEventKey | func (e *GameEvent) getEventKey(name string) (*dota.CMsgSource1LegacyGameEventKeyT, error) {
f, ok := e.t.fields[name]
if !ok {
return nil, _errorf("field %s: missing", name)
}
if f.i > len(e.m.GetKeys()) {
return nil, _errorf("field %s: %d out of range", name, f.i)
}
return e.m.GetKeys()[f.i], nil
} | go | func (e *GameEvent) getEventKey(name string) (*dota.CMsgSource1LegacyGameEventKeyT, error) {
f, ok := e.t.fields[name]
if !ok {
return nil, _errorf("field %s: missing", name)
}
if f.i > len(e.m.GetKeys()) {
return nil, _errorf("field %s: %d out of range", name, f.i)
}
return e.m.GetKeys()[f.i], nil
} | [
"func",
"(",
"e",
"*",
"GameEvent",
")",
"getEventKey",
"(",
"name",
"string",
")",
"(",
"*",
"dota",
".",
"CMsgSource1LegacyGameEventKeyT",
",",
"error",
")",
"{",
"f",
",",
"ok",
":=",
"e",
".",
"t",
".",
"fields",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"_errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"if",
"f",
".",
"i",
">",
"len",
"(",
"e",
".",
"m",
".",
"GetKeys",
"(",
")",
")",
"{",
"return",
"nil",
",",
"_errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"f",
".",
"i",
")",
"\n",
"}",
"\n\n",
"return",
"e",
".",
"m",
".",
"GetKeys",
"(",
")",
"[",
"f",
".",
"i",
"]",
",",
"nil",
"\n",
"}"
] | // Finds the key in the game event which corresponds to a given name. | [
"Finds",
"the",
"key",
"in",
"the",
"game",
"event",
"which",
"corresponds",
"to",
"a",
"given",
"name",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/game_event.go#L160-L171 |
5,847 | dotabuff/manta | game_event.go | onCMsgSource1LegacyGameEvent | func (p *Parser) onCMsgSource1LegacyGameEvent(m *dota.CMsgSource1LegacyGameEvent) error {
// Look up the handler name by event id.
name, ok := p.gameEventNames[m.GetEventid()]
if !ok {
return _errorf("unknown event id: %d", m.GetEventid())
}
// Get the handlers for the event name. Return early if none.
handlers := p.gameEventHandlers[name]
if handlers == nil {
return nil
}
// Get the type for the event.
t, ok := p.gameEventTypes[name]
if !ok {
return _errorf("unknown event type: %s", name)
}
// Create a GameEvent, offer to all handlers.
e := &GameEvent{t: t, m: m}
for _, h := range handlers {
if err := h(e); err != nil {
return err
}
}
return nil
} | go | func (p *Parser) onCMsgSource1LegacyGameEvent(m *dota.CMsgSource1LegacyGameEvent) error {
// Look up the handler name by event id.
name, ok := p.gameEventNames[m.GetEventid()]
if !ok {
return _errorf("unknown event id: %d", m.GetEventid())
}
// Get the handlers for the event name. Return early if none.
handlers := p.gameEventHandlers[name]
if handlers == nil {
return nil
}
// Get the type for the event.
t, ok := p.gameEventTypes[name]
if !ok {
return _errorf("unknown event type: %s", name)
}
// Create a GameEvent, offer to all handlers.
e := &GameEvent{t: t, m: m}
for _, h := range handlers {
if err := h(e); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"onCMsgSource1LegacyGameEvent",
"(",
"m",
"*",
"dota",
".",
"CMsgSource1LegacyGameEvent",
")",
"error",
"{",
"// Look up the handler name by event id.",
"name",
",",
"ok",
":=",
"p",
".",
"gameEventNames",
"[",
"m",
".",
"GetEventid",
"(",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"_errorf",
"(",
"\"",
"\"",
",",
"m",
".",
"GetEventid",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// Get the handlers for the event name. Return early if none.",
"handlers",
":=",
"p",
".",
"gameEventHandlers",
"[",
"name",
"]",
"\n",
"if",
"handlers",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Get the type for the event.",
"t",
",",
"ok",
":=",
"p",
".",
"gameEventTypes",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"_errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"// Create a GameEvent, offer to all handlers.",
"e",
":=",
"&",
"GameEvent",
"{",
"t",
":",
"t",
",",
"m",
":",
"m",
"}",
"\n",
"for",
"_",
",",
"h",
":=",
"range",
"handlers",
"{",
"if",
"err",
":=",
"h",
"(",
"e",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Internal handler for callback OnCMsgSource1LegacyGameEvent.
// Looks up the name and type of an event and offers it to registered handlers. | [
"Internal",
"handler",
"for",
"callback",
"OnCMsgSource1LegacyGameEvent",
".",
"Looks",
"up",
"the",
"name",
"and",
"type",
"of",
"an",
"event",
"and",
"offers",
"it",
"to",
"registered",
"handlers",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/game_event.go#L217-L245 |
5,848 | dotabuff/manta | game_event.go | OnGameEvent | func (p *Parser) OnGameEvent(name string, fn GameEventHandler) {
p.gameEventHandlers[name] = append(p.gameEventHandlers[name], fn)
} | go | func (p *Parser) OnGameEvent(name string, fn GameEventHandler) {
p.gameEventHandlers[name] = append(p.gameEventHandlers[name], fn)
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"OnGameEvent",
"(",
"name",
"string",
",",
"fn",
"GameEventHandler",
")",
"{",
"p",
".",
"gameEventHandlers",
"[",
"name",
"]",
"=",
"append",
"(",
"p",
".",
"gameEventHandlers",
"[",
"name",
"]",
",",
"fn",
")",
"\n",
"}"
] | // OnGameEvent registers an GameEventHandler that will be called when a
// named GameEvent occurs. | [
"OnGameEvent",
"registers",
"an",
"GameEventHandler",
"that",
"will",
"be",
"called",
"when",
"a",
"named",
"GameEvent",
"occurs",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/game_event.go#L249-L251 |
5,849 | dotabuff/manta | string_table.go | GetTableByName | func (ts *stringTables) GetTableByName(name string) (*stringTable, bool) {
i, ok := ts.NameIndex[name]
if !ok {
return nil, false
}
t, ok := ts.Tables[i]
return t, ok
} | go | func (ts *stringTables) GetTableByName(name string) (*stringTable, bool) {
i, ok := ts.NameIndex[name]
if !ok {
return nil, false
}
t, ok := ts.Tables[i]
return t, ok
} | [
"func",
"(",
"ts",
"*",
"stringTables",
")",
"GetTableByName",
"(",
"name",
"string",
")",
"(",
"*",
"stringTable",
",",
"bool",
")",
"{",
"i",
",",
"ok",
":=",
"ts",
".",
"NameIndex",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"t",
",",
"ok",
":=",
"ts",
".",
"Tables",
"[",
"i",
"]",
"\n",
"return",
"t",
",",
"ok",
"\n",
"}"
] | // Retrieves a string table by its name. Check the bool. | [
"Retrieves",
"a",
"string",
"table",
"by",
"its",
"name",
".",
"Check",
"the",
"bool",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/string_table.go#L21-L28 |
5,850 | dotabuff/manta | string_table.go | newStringTables | func newStringTables() *stringTables {
return &stringTables{
Tables: make(map[int32]*stringTable),
NameIndex: make(map[string]int32),
nextIndex: 0,
}
} | go | func newStringTables() *stringTables {
return &stringTables{
Tables: make(map[int32]*stringTable),
NameIndex: make(map[string]int32),
nextIndex: 0,
}
} | [
"func",
"newStringTables",
"(",
")",
"*",
"stringTables",
"{",
"return",
"&",
"stringTables",
"{",
"Tables",
":",
"make",
"(",
"map",
"[",
"int32",
"]",
"*",
"stringTable",
")",
",",
"NameIndex",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"int32",
")",
",",
"nextIndex",
":",
"0",
",",
"}",
"\n",
"}"
] | // Creates a new empty StringTables. | [
"Creates",
"a",
"new",
"empty",
"StringTables",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/string_table.go#L31-L37 |
5,851 | dotabuff/manta | string_table.go | onCSVCMsg_UpdateStringTable | func (p *Parser) onCSVCMsg_UpdateStringTable(m *dota.CSVCMsg_UpdateStringTable) error {
// TODO: integrate
t, ok := p.stringTables.Tables[m.GetTableId()]
if !ok {
_panicf("missing string table %d", m.GetTableId())
}
if v(5) {
_debugf("tick=%d name=%s changedEntries=%d size=%d", p.Tick, t.name, m.GetNumChangedEntries(), len(m.GetStringData()))
}
// Parse the updates out of the string table data
items := parseStringTable(m.GetStringData(), m.GetNumChangedEntries(), t.name, t.userDataFixedSize, t.userDataSize, t.flags)
// Apply the updates to the parser state
for _, item := range items {
index := item.Index
if _, ok := t.Items[index]; ok {
if item.Key != "" && item.Key != t.Items[index].Key {
t.Items[index].Key = item.Key
}
if len(item.Value) > 0 {
t.Items[index].Value = item.Value
}
} else {
t.Items[index] = item
}
}
// Apply the updates to baseline state
if t.name == "instancebaseline" {
p.updateInstanceBaseline()
}
return nil
} | go | func (p *Parser) onCSVCMsg_UpdateStringTable(m *dota.CSVCMsg_UpdateStringTable) error {
// TODO: integrate
t, ok := p.stringTables.Tables[m.GetTableId()]
if !ok {
_panicf("missing string table %d", m.GetTableId())
}
if v(5) {
_debugf("tick=%d name=%s changedEntries=%d size=%d", p.Tick, t.name, m.GetNumChangedEntries(), len(m.GetStringData()))
}
// Parse the updates out of the string table data
items := parseStringTable(m.GetStringData(), m.GetNumChangedEntries(), t.name, t.userDataFixedSize, t.userDataSize, t.flags)
// Apply the updates to the parser state
for _, item := range items {
index := item.Index
if _, ok := t.Items[index]; ok {
if item.Key != "" && item.Key != t.Items[index].Key {
t.Items[index].Key = item.Key
}
if len(item.Value) > 0 {
t.Items[index].Value = item.Value
}
} else {
t.Items[index] = item
}
}
// Apply the updates to baseline state
if t.name == "instancebaseline" {
p.updateInstanceBaseline()
}
return nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"onCSVCMsg_UpdateStringTable",
"(",
"m",
"*",
"dota",
".",
"CSVCMsg_UpdateStringTable",
")",
"error",
"{",
"// TODO: integrate",
"t",
",",
"ok",
":=",
"p",
".",
"stringTables",
".",
"Tables",
"[",
"m",
".",
"GetTableId",
"(",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"_panicf",
"(",
"\"",
"\"",
",",
"m",
".",
"GetTableId",
"(",
")",
")",
"\n",
"}",
"\n\n",
"if",
"v",
"(",
"5",
")",
"{",
"_debugf",
"(",
"\"",
"\"",
",",
"p",
".",
"Tick",
",",
"t",
".",
"name",
",",
"m",
".",
"GetNumChangedEntries",
"(",
")",
",",
"len",
"(",
"m",
".",
"GetStringData",
"(",
")",
")",
")",
"\n",
"}",
"\n\n",
"// Parse the updates out of the string table data",
"items",
":=",
"parseStringTable",
"(",
"m",
".",
"GetStringData",
"(",
")",
",",
"m",
".",
"GetNumChangedEntries",
"(",
")",
",",
"t",
".",
"name",
",",
"t",
".",
"userDataFixedSize",
",",
"t",
".",
"userDataSize",
",",
"t",
".",
"flags",
")",
"\n\n",
"// Apply the updates to the parser state",
"for",
"_",
",",
"item",
":=",
"range",
"items",
"{",
"index",
":=",
"item",
".",
"Index",
"\n",
"if",
"_",
",",
"ok",
":=",
"t",
".",
"Items",
"[",
"index",
"]",
";",
"ok",
"{",
"if",
"item",
".",
"Key",
"!=",
"\"",
"\"",
"&&",
"item",
".",
"Key",
"!=",
"t",
".",
"Items",
"[",
"index",
"]",
".",
"Key",
"{",
"t",
".",
"Items",
"[",
"index",
"]",
".",
"Key",
"=",
"item",
".",
"Key",
"\n",
"}",
"\n",
"if",
"len",
"(",
"item",
".",
"Value",
")",
">",
"0",
"{",
"t",
".",
"Items",
"[",
"index",
"]",
".",
"Value",
"=",
"item",
".",
"Value",
"\n",
"}",
"\n",
"}",
"else",
"{",
"t",
".",
"Items",
"[",
"index",
"]",
"=",
"item",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Apply the updates to baseline state",
"if",
"t",
".",
"name",
"==",
"\"",
"\"",
"{",
"p",
".",
"updateInstanceBaseline",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Internal callback for CSVCMsg_UpdateStringTable. | [
"Internal",
"callback",
"for",
"CSVCMsg_UpdateStringTable",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/string_table.go#L126-L161 |
5,852 | dotabuff/manta | string_table.go | parseStringTable | func parseStringTable(buf []byte, numUpdates int32, name string, userDataFixed bool, userDataSize int32, flags int32) (items []*stringTableItem) {
defer func() {
if err := recover(); err != nil {
_debugf("warning: unable to parse string table %s: %s", name, err)
return
}
}()
items = make([]*stringTableItem, 0)
// Create a reader for the buffer
r := newReader(buf)
// Start with an index of -1.
// If the first item is at index 0 it will use a incr operation.
index := int32(-1)
// Maintain a list of key history
keys := make([]string, 0, stringtableKeyHistorySize)
// Some tables have no data
if len(buf) == 0 {
return items
}
// Loop through entries in the data structure
//
// Each entry is a tuple consisting of {index, key, value}
//
// Index can either be incremented from the previous position or
// overwritten with a given entry.
//
// Key may be omitted (will be represented here as "")
//
// Value may be omitted
for i := 0; i < int(numUpdates); i++ {
key := ""
value := []byte{}
// Read a boolean to determine whether the operation is an increment or
// has a fixed index position. A fixed index position of zero should be
// the last data in the buffer, and indicates that all data has been read.
incr := r.readBoolean()
if incr {
index++
} else {
index = int32(r.readVarUint32()) + 1
}
// Some values have keys, some don't.
hasKey := r.readBoolean()
if hasKey {
// Some entries use reference a position in the key history for
// part of the key. If referencing the history, read the position
// and size from the buffer, then use those to build the string
// combined with an extra string read (null terminated).
// Alternatively, just read the string.
useHistory := r.readBoolean()
if useHistory {
pos := r.readBits(5)
size := r.readBits(5)
if int(pos) >= len(keys) {
key += r.readString()
} else {
s := keys[pos]
if int(size) > len(s) {
key += s + r.readString()
} else {
key += s[0:size] + r.readString()
}
}
} else {
key = r.readString()
}
if len(keys) >= stringtableKeyHistorySize {
copy(keys[0:], keys[1:])
keys[len(keys)-1] = ""
keys = keys[:len(keys)-1]
}
keys = append(keys, key)
}
// Some entries have a value.
hasValue := r.readBoolean()
if hasValue {
bitSize := uint32(0)
if userDataFixed {
bitSize = uint32(userDataSize)
} else {
if (flags & 0x1) != 0 {
r.readBoolean()
}
bitSize = r.readBits(17) * 8
}
value = r.readBitsAsBytes(bitSize)
}
items = append(items, &stringTableItem{index, key, value})
}
return items
} | go | func parseStringTable(buf []byte, numUpdates int32, name string, userDataFixed bool, userDataSize int32, flags int32) (items []*stringTableItem) {
defer func() {
if err := recover(); err != nil {
_debugf("warning: unable to parse string table %s: %s", name, err)
return
}
}()
items = make([]*stringTableItem, 0)
// Create a reader for the buffer
r := newReader(buf)
// Start with an index of -1.
// If the first item is at index 0 it will use a incr operation.
index := int32(-1)
// Maintain a list of key history
keys := make([]string, 0, stringtableKeyHistorySize)
// Some tables have no data
if len(buf) == 0 {
return items
}
// Loop through entries in the data structure
//
// Each entry is a tuple consisting of {index, key, value}
//
// Index can either be incremented from the previous position or
// overwritten with a given entry.
//
// Key may be omitted (will be represented here as "")
//
// Value may be omitted
for i := 0; i < int(numUpdates); i++ {
key := ""
value := []byte{}
// Read a boolean to determine whether the operation is an increment or
// has a fixed index position. A fixed index position of zero should be
// the last data in the buffer, and indicates that all data has been read.
incr := r.readBoolean()
if incr {
index++
} else {
index = int32(r.readVarUint32()) + 1
}
// Some values have keys, some don't.
hasKey := r.readBoolean()
if hasKey {
// Some entries use reference a position in the key history for
// part of the key. If referencing the history, read the position
// and size from the buffer, then use those to build the string
// combined with an extra string read (null terminated).
// Alternatively, just read the string.
useHistory := r.readBoolean()
if useHistory {
pos := r.readBits(5)
size := r.readBits(5)
if int(pos) >= len(keys) {
key += r.readString()
} else {
s := keys[pos]
if int(size) > len(s) {
key += s + r.readString()
} else {
key += s[0:size] + r.readString()
}
}
} else {
key = r.readString()
}
if len(keys) >= stringtableKeyHistorySize {
copy(keys[0:], keys[1:])
keys[len(keys)-1] = ""
keys = keys[:len(keys)-1]
}
keys = append(keys, key)
}
// Some entries have a value.
hasValue := r.readBoolean()
if hasValue {
bitSize := uint32(0)
if userDataFixed {
bitSize = uint32(userDataSize)
} else {
if (flags & 0x1) != 0 {
r.readBoolean()
}
bitSize = r.readBits(17) * 8
}
value = r.readBitsAsBytes(bitSize)
}
items = append(items, &stringTableItem{index, key, value})
}
return items
} | [
"func",
"parseStringTable",
"(",
"buf",
"[",
"]",
"byte",
",",
"numUpdates",
"int32",
",",
"name",
"string",
",",
"userDataFixed",
"bool",
",",
"userDataSize",
"int32",
",",
"flags",
"int32",
")",
"(",
"items",
"[",
"]",
"*",
"stringTableItem",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
":=",
"recover",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"_debugf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"items",
"=",
"make",
"(",
"[",
"]",
"*",
"stringTableItem",
",",
"0",
")",
"\n\n",
"// Create a reader for the buffer",
"r",
":=",
"newReader",
"(",
"buf",
")",
"\n\n",
"// Start with an index of -1.",
"// If the first item is at index 0 it will use a incr operation.",
"index",
":=",
"int32",
"(",
"-",
"1",
")",
"\n\n",
"// Maintain a list of key history",
"keys",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"stringtableKeyHistorySize",
")",
"\n\n",
"// Some tables have no data",
"if",
"len",
"(",
"buf",
")",
"==",
"0",
"{",
"return",
"items",
"\n",
"}",
"\n\n",
"// Loop through entries in the data structure",
"//",
"// Each entry is a tuple consisting of {index, key, value}",
"//",
"// Index can either be incremented from the previous position or",
"// overwritten with a given entry.",
"//",
"// Key may be omitted (will be represented here as \"\")",
"//",
"// Value may be omitted",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"int",
"(",
"numUpdates",
")",
";",
"i",
"++",
"{",
"key",
":=",
"\"",
"\"",
"\n",
"value",
":=",
"[",
"]",
"byte",
"{",
"}",
"\n\n",
"// Read a boolean to determine whether the operation is an increment or",
"// has a fixed index position. A fixed index position of zero should be",
"// the last data in the buffer, and indicates that all data has been read.",
"incr",
":=",
"r",
".",
"readBoolean",
"(",
")",
"\n",
"if",
"incr",
"{",
"index",
"++",
"\n",
"}",
"else",
"{",
"index",
"=",
"int32",
"(",
"r",
".",
"readVarUint32",
"(",
")",
")",
"+",
"1",
"\n",
"}",
"\n\n",
"// Some values have keys, some don't.",
"hasKey",
":=",
"r",
".",
"readBoolean",
"(",
")",
"\n",
"if",
"hasKey",
"{",
"// Some entries use reference a position in the key history for",
"// part of the key. If referencing the history, read the position",
"// and size from the buffer, then use those to build the string",
"// combined with an extra string read (null terminated).",
"// Alternatively, just read the string.",
"useHistory",
":=",
"r",
".",
"readBoolean",
"(",
")",
"\n",
"if",
"useHistory",
"{",
"pos",
":=",
"r",
".",
"readBits",
"(",
"5",
")",
"\n",
"size",
":=",
"r",
".",
"readBits",
"(",
"5",
")",
"\n\n",
"if",
"int",
"(",
"pos",
")",
">=",
"len",
"(",
"keys",
")",
"{",
"key",
"+=",
"r",
".",
"readString",
"(",
")",
"\n",
"}",
"else",
"{",
"s",
":=",
"keys",
"[",
"pos",
"]",
"\n",
"if",
"int",
"(",
"size",
")",
">",
"len",
"(",
"s",
")",
"{",
"key",
"+=",
"s",
"+",
"r",
".",
"readString",
"(",
")",
"\n",
"}",
"else",
"{",
"key",
"+=",
"s",
"[",
"0",
":",
"size",
"]",
"+",
"r",
".",
"readString",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"key",
"=",
"r",
".",
"readString",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"keys",
")",
">=",
"stringtableKeyHistorySize",
"{",
"copy",
"(",
"keys",
"[",
"0",
":",
"]",
",",
"keys",
"[",
"1",
":",
"]",
")",
"\n",
"keys",
"[",
"len",
"(",
"keys",
")",
"-",
"1",
"]",
"=",
"\"",
"\"",
"\n",
"keys",
"=",
"keys",
"[",
":",
"len",
"(",
"keys",
")",
"-",
"1",
"]",
"\n",
"}",
"\n",
"keys",
"=",
"append",
"(",
"keys",
",",
"key",
")",
"\n",
"}",
"\n\n",
"// Some entries have a value.",
"hasValue",
":=",
"r",
".",
"readBoolean",
"(",
")",
"\n",
"if",
"hasValue",
"{",
"bitSize",
":=",
"uint32",
"(",
"0",
")",
"\n",
"if",
"userDataFixed",
"{",
"bitSize",
"=",
"uint32",
"(",
"userDataSize",
")",
"\n",
"}",
"else",
"{",
"if",
"(",
"flags",
"&",
"0x1",
")",
"!=",
"0",
"{",
"r",
".",
"readBoolean",
"(",
")",
"\n",
"}",
"\n",
"bitSize",
"=",
"r",
".",
"readBits",
"(",
"17",
")",
"*",
"8",
"\n",
"}",
"\n",
"value",
"=",
"r",
".",
"readBitsAsBytes",
"(",
"bitSize",
")",
"\n",
"}",
"\n\n",
"items",
"=",
"append",
"(",
"items",
",",
"&",
"stringTableItem",
"{",
"index",
",",
"key",
",",
"value",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"items",
"\n",
"}"
] | // Parse a string table data blob, returning a list of item updates. | [
"Parse",
"a",
"string",
"table",
"data",
"blob",
"returning",
"a",
"list",
"of",
"item",
"updates",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/string_table.go#L164-L267 |
5,853 | dotabuff/manta | lzss.go | unlzss | func unlzss(buf []byte) ([]byte, error) {
r := newReader(buf)
if s := r.readStringN(4); s != "LZSS" {
return nil, _errorf("expected LZSS header, got %s", s)
}
size := int(r.readLeUint32())
out := make([]byte, 0)
var cmdByte, getCmdByte byte
for {
if getCmdByte == 0 {
cmdByte = r.readByte()
}
getCmdByte = (getCmdByte + 1) & 0x07
if (cmdByte & 0x01) != 0 {
a := r.readByte()
b := r.readByte()
position := (int(a) << 4) | (int(b) >> 4)
count := int((b & 0x0F) + 1)
if count == 1 {
break
}
source := len(out) - int(position) - 1
for i := 0; i < count; i++ {
out = append(out, out[source+i])
}
} else {
out = append(out, r.readByte())
}
cmdByte = cmdByte >> 1
}
if len(out) != size {
return nil, _errorf("expected %d bytes, got %d", size, len(out))
}
return out, nil
} | go | func unlzss(buf []byte) ([]byte, error) {
r := newReader(buf)
if s := r.readStringN(4); s != "LZSS" {
return nil, _errorf("expected LZSS header, got %s", s)
}
size := int(r.readLeUint32())
out := make([]byte, 0)
var cmdByte, getCmdByte byte
for {
if getCmdByte == 0 {
cmdByte = r.readByte()
}
getCmdByte = (getCmdByte + 1) & 0x07
if (cmdByte & 0x01) != 0 {
a := r.readByte()
b := r.readByte()
position := (int(a) << 4) | (int(b) >> 4)
count := int((b & 0x0F) + 1)
if count == 1 {
break
}
source := len(out) - int(position) - 1
for i := 0; i < count; i++ {
out = append(out, out[source+i])
}
} else {
out = append(out, r.readByte())
}
cmdByte = cmdByte >> 1
}
if len(out) != size {
return nil, _errorf("expected %d bytes, got %d", size, len(out))
}
return out, nil
} | [
"func",
"unlzss",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"r",
":=",
"newReader",
"(",
"buf",
")",
"\n\n",
"if",
"s",
":=",
"r",
".",
"readStringN",
"(",
"4",
")",
";",
"s",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"_errorf",
"(",
"\"",
"\"",
",",
"s",
")",
"\n",
"}",
"\n\n",
"size",
":=",
"int",
"(",
"r",
".",
"readLeUint32",
"(",
")",
")",
"\n",
"out",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
")",
"\n\n",
"var",
"cmdByte",
",",
"getCmdByte",
"byte",
"\n\n",
"for",
"{",
"if",
"getCmdByte",
"==",
"0",
"{",
"cmdByte",
"=",
"r",
".",
"readByte",
"(",
")",
"\n",
"}",
"\n\n",
"getCmdByte",
"=",
"(",
"getCmdByte",
"+",
"1",
")",
"&",
"0x07",
"\n\n",
"if",
"(",
"cmdByte",
"&",
"0x01",
")",
"!=",
"0",
"{",
"a",
":=",
"r",
".",
"readByte",
"(",
")",
"\n",
"b",
":=",
"r",
".",
"readByte",
"(",
")",
"\n\n",
"position",
":=",
"(",
"int",
"(",
"a",
")",
"<<",
"4",
")",
"|",
"(",
"int",
"(",
"b",
")",
">>",
"4",
")",
"\n",
"count",
":=",
"int",
"(",
"(",
"b",
"&",
"0x0F",
")",
"+",
"1",
")",
"\n",
"if",
"count",
"==",
"1",
"{",
"break",
"\n",
"}",
"\n",
"source",
":=",
"len",
"(",
"out",
")",
"-",
"int",
"(",
"position",
")",
"-",
"1",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"out",
"[",
"source",
"+",
"i",
"]",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"r",
".",
"readByte",
"(",
")",
")",
"\n",
"}",
"\n",
"cmdByte",
"=",
"cmdByte",
">>",
"1",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"out",
")",
"!=",
"size",
"{",
"return",
"nil",
",",
"_errorf",
"(",
"\"",
"\"",
",",
"size",
",",
"len",
"(",
"out",
")",
")",
"\n",
"}",
"\n\n",
"return",
"out",
",",
"nil",
"\n",
"}"
] | // Decompress a Valve LZSS compressed buffer | [
"Decompress",
"a",
"Valve",
"LZSS",
"compressed",
"buffer"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/lzss.go#L4-L47 |
5,854 | dotabuff/manta | demo_packet.go | priority | func (m *pendingMessage) priority() int {
switch m.t {
case
// These messages provide context needed for the rest of the tick
// and should have the highest priority.
int32(dota.NET_Messages_net_Tick),
int32(dota.SVC_Messages_svc_CreateStringTable),
int32(dota.SVC_Messages_svc_UpdateStringTable),
int32(dota.NET_Messages_net_SpawnGroup_Load):
return -10
case
// These messages benefit from having context but may also need to
// provide context in terms of delta updates.
int32(dota.SVC_Messages_svc_PacketEntities):
return 5
case
// These messages benefit from having as much context as possible and
// should have the lowest priority.
int32(dota.EBaseGameEvents_GE_Source1LegacyGameEvent):
return 10
}
return 0
} | go | func (m *pendingMessage) priority() int {
switch m.t {
case
// These messages provide context needed for the rest of the tick
// and should have the highest priority.
int32(dota.NET_Messages_net_Tick),
int32(dota.SVC_Messages_svc_CreateStringTable),
int32(dota.SVC_Messages_svc_UpdateStringTable),
int32(dota.NET_Messages_net_SpawnGroup_Load):
return -10
case
// These messages benefit from having context but may also need to
// provide context in terms of delta updates.
int32(dota.SVC_Messages_svc_PacketEntities):
return 5
case
// These messages benefit from having as much context as possible and
// should have the lowest priority.
int32(dota.EBaseGameEvents_GE_Source1LegacyGameEvent):
return 10
}
return 0
} | [
"func",
"(",
"m",
"*",
"pendingMessage",
")",
"priority",
"(",
")",
"int",
"{",
"switch",
"m",
".",
"t",
"{",
"case",
"// These messages provide context needed for the rest of the tick",
"// and should have the highest priority.",
"int32",
"(",
"dota",
".",
"NET_Messages_net_Tick",
")",
",",
"int32",
"(",
"dota",
".",
"SVC_Messages_svc_CreateStringTable",
")",
",",
"int32",
"(",
"dota",
".",
"SVC_Messages_svc_UpdateStringTable",
")",
",",
"int32",
"(",
"dota",
".",
"NET_Messages_net_SpawnGroup_Load",
")",
":",
"return",
"-",
"10",
"\n\n",
"case",
"// These messages benefit from having context but may also need to",
"// provide context in terms of delta updates.",
"int32",
"(",
"dota",
".",
"SVC_Messages_svc_PacketEntities",
")",
":",
"return",
"5",
"\n\n",
"case",
"// These messages benefit from having as much context as possible and",
"// should have the lowest priority.",
"int32",
"(",
"dota",
".",
"EBaseGameEvents_GE_Source1LegacyGameEvent",
")",
":",
"return",
"10",
"\n",
"}",
"\n\n",
"return",
"0",
"\n",
"}"
] | // Calculates the priority of the message. Lower is more important. | [
"Calculates",
"the",
"priority",
"of",
"the",
"message",
".",
"Lower",
"is",
"more",
"important",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/demo_packet.go#L17-L42 |
5,855 | dotabuff/manta | demo_packet.go | onCDemoPacket | func (p *Parser) onCDemoPacket(m *dota.CDemoPacket) error {
// Create a slice to store pending mesages. Messages are read first as
// pending messages then sorted before dispatch.
ms := make(pendingMessages, 0, 2)
// Read all messages from the buffer. Messages are packed serially as
// {type, size, data}. We keep reading until until less than a byte remains.
r := newReader(m.GetData())
for r.remBytes() > 0 {
t := int32(r.readUBitVar())
size := r.readVarUint32()
buf := r.readBytes(size)
ms = append(ms, &pendingMessage{p.Tick, t, buf})
}
// Sort messages to ensure dependencies are met. For example, we need to
// process string tables before game events that may reference them.
sort.Sort(ms)
// Dispatch messages in order, returning on handler error.
for _, m := range ms {
if err := p.Callbacks.callByPacketType(m.t, m.buf); err != nil {
return err
}
}
return nil
} | go | func (p *Parser) onCDemoPacket(m *dota.CDemoPacket) error {
// Create a slice to store pending mesages. Messages are read first as
// pending messages then sorted before dispatch.
ms := make(pendingMessages, 0, 2)
// Read all messages from the buffer. Messages are packed serially as
// {type, size, data}. We keep reading until until less than a byte remains.
r := newReader(m.GetData())
for r.remBytes() > 0 {
t := int32(r.readUBitVar())
size := r.readVarUint32()
buf := r.readBytes(size)
ms = append(ms, &pendingMessage{p.Tick, t, buf})
}
// Sort messages to ensure dependencies are met. For example, we need to
// process string tables before game events that may reference them.
sort.Sort(ms)
// Dispatch messages in order, returning on handler error.
for _, m := range ms {
if err := p.Callbacks.callByPacketType(m.t, m.buf); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"onCDemoPacket",
"(",
"m",
"*",
"dota",
".",
"CDemoPacket",
")",
"error",
"{",
"// Create a slice to store pending mesages. Messages are read first as",
"// pending messages then sorted before dispatch.",
"ms",
":=",
"make",
"(",
"pendingMessages",
",",
"0",
",",
"2",
")",
"\n\n",
"// Read all messages from the buffer. Messages are packed serially as",
"// {type, size, data}. We keep reading until until less than a byte remains.",
"r",
":=",
"newReader",
"(",
"m",
".",
"GetData",
"(",
")",
")",
"\n",
"for",
"r",
".",
"remBytes",
"(",
")",
">",
"0",
"{",
"t",
":=",
"int32",
"(",
"r",
".",
"readUBitVar",
"(",
")",
")",
"\n",
"size",
":=",
"r",
".",
"readVarUint32",
"(",
")",
"\n",
"buf",
":=",
"r",
".",
"readBytes",
"(",
"size",
")",
"\n",
"ms",
"=",
"append",
"(",
"ms",
",",
"&",
"pendingMessage",
"{",
"p",
".",
"Tick",
",",
"t",
",",
"buf",
"}",
")",
"\n",
"}",
"\n\n",
"// Sort messages to ensure dependencies are met. For example, we need to",
"// process string tables before game events that may reference them.",
"sort",
".",
"Sort",
"(",
"ms",
")",
"\n\n",
"// Dispatch messages in order, returning on handler error.",
"for",
"_",
",",
"m",
":=",
"range",
"ms",
"{",
"if",
"err",
":=",
"p",
".",
"Callbacks",
".",
"callByPacketType",
"(",
"m",
".",
"t",
",",
"m",
".",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Internal parser for callback OnCDemoPacket, responsible for extracting
// multiple inner packets from a single CDemoPacket. This is the main structure
// that contains all other data types in the demo file. | [
"Internal",
"parser",
"for",
"callback",
"OnCDemoPacket",
"responsible",
"for",
"extracting",
"multiple",
"inner",
"packets",
"from",
"a",
"single",
"CDemoPacket",
".",
"This",
"is",
"the",
"main",
"structure",
"that",
"contains",
"all",
"other",
"data",
"types",
"in",
"the",
"demo",
"file",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/demo_packet.go#L62-L89 |
5,856 | dotabuff/manta | demo_packet.go | onCDemoFullPacket | func (p *Parser) onCDemoFullPacket(m *dota.CDemoFullPacket) error {
// Per Valve docs, parse the CDemoStringTables first.
if m.StringTable != nil {
if err := p.onCDemoStringTables(m.GetStringTable()); err != nil {
return err
}
}
// Then the CDemoPacket.
if m.Packet != nil {
if err := p.onCDemoPacket(m.GetPacket()); err != nil {
return err
}
}
return nil
} | go | func (p *Parser) onCDemoFullPacket(m *dota.CDemoFullPacket) error {
// Per Valve docs, parse the CDemoStringTables first.
if m.StringTable != nil {
if err := p.onCDemoStringTables(m.GetStringTable()); err != nil {
return err
}
}
// Then the CDemoPacket.
if m.Packet != nil {
if err := p.onCDemoPacket(m.GetPacket()); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"onCDemoFullPacket",
"(",
"m",
"*",
"dota",
".",
"CDemoFullPacket",
")",
"error",
"{",
"// Per Valve docs, parse the CDemoStringTables first.",
"if",
"m",
".",
"StringTable",
"!=",
"nil",
"{",
"if",
"err",
":=",
"p",
".",
"onCDemoStringTables",
"(",
"m",
".",
"GetStringTable",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Then the CDemoPacket.",
"if",
"m",
".",
"Packet",
"!=",
"nil",
"{",
"if",
"err",
":=",
"p",
".",
"onCDemoPacket",
"(",
"m",
".",
"GetPacket",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Internal parser for callback OnCDemoFullPacket. | [
"Internal",
"parser",
"for",
"callback",
"OnCDemoFullPacket",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/demo_packet.go#L92-L108 |
5,857 | dotabuff/manta | util.go | atoi32 | func atoi32(s string) (int32, error) {
n, err := strconv.ParseInt(s, 0, 32)
if err != nil {
return 0, err
}
return int32(n), nil
} | go | func atoi32(s string) (int32, error) {
n, err := strconv.ParseInt(s, 0, 32)
if err != nil {
return 0, err
}
return int32(n), nil
} | [
"func",
"atoi32",
"(",
"s",
"string",
")",
"(",
"int32",
",",
"error",
")",
"{",
"n",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"s",
",",
"0",
",",
"32",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"int32",
"(",
"n",
")",
",",
"nil",
"\n",
"}"
] | // Convert a string to an int32 | [
"Convert",
"a",
"string",
"to",
"an",
"int32"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/util.go#L37-L43 |
5,858 | dotabuff/manta | util.go | _debugf | func _debugf(format string, args ...interface{}) {
if v(1) {
args = append([]interface{}{_caller(2)}, args...)
fmt.Printf("%s: "+format+"\n", args...)
}
} | go | func _debugf(format string, args ...interface{}) {
if v(1) {
args = append([]interface{}{_caller(2)}, args...)
fmt.Printf("%s: "+format+"\n", args...)
}
} | [
"func",
"_debugf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"v",
"(",
"1",
")",
"{",
"args",
"=",
"append",
"(",
"[",
"]",
"interface",
"{",
"}",
"{",
"_caller",
"(",
"2",
")",
"}",
",",
"args",
"...",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\"",
"+",
"format",
"+",
"\"",
"\\n",
"\"",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"}"
] | // printf only if debugging | [
"printf",
"only",
"if",
"debugging"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/util.go#L51-L56 |
5,859 | dotabuff/manta | util.go | _dump | func _dump(label string, args ...interface{}) {
fmt.Printf("%s: %s", _caller(2), label)
spew.Dump(args...)
} | go | func _dump(label string, args ...interface{}) {
fmt.Printf("%s: %s", _caller(2), label)
spew.Dump(args...)
} | [
"func",
"_dump",
"(",
"label",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\"",
",",
"_caller",
"(",
"2",
")",
",",
"label",
")",
"\n",
"spew",
".",
"Dump",
"(",
"args",
"...",
")",
"\n",
"}"
] | // dump named object | [
"dump",
"named",
"object"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/util.go#L74-L77 |
5,860 | dotabuff/manta | util.go | _dump_fixture | func _dump_fixture(filename string, buf []byte) {
fmt.Printf("writing fixture %s...\n", filename)
if err := ioutil.WriteFile("./fixtures/"+filename, buf, 0644); err != nil {
panic(err)
}
} | go | func _dump_fixture(filename string, buf []byte) {
fmt.Printf("writing fixture %s...\n", filename)
if err := ioutil.WriteFile("./fixtures/"+filename, buf, 0644); err != nil {
panic(err)
}
} | [
"func",
"_dump_fixture",
"(",
"filename",
"string",
",",
"buf",
"[",
"]",
"byte",
")",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"filename",
")",
"\n",
"if",
"err",
":=",
"ioutil",
".",
"WriteFile",
"(",
"\"",
"\"",
"+",
"filename",
",",
"buf",
",",
"0644",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // dumps a given byte buffer to the given fixture filename | [
"dumps",
"a",
"given",
"byte",
"buffer",
"to",
"the",
"given",
"fixture",
"filename"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/util.go#L80-L85 |
5,861 | dotabuff/manta | util.go | _read_fixture | func _read_fixture(filename string) []byte {
buf, err := ioutil.ReadFile("./fixtures/" + filename)
if err != nil {
panic(err)
}
return buf
} | go | func _read_fixture(filename string) []byte {
buf, err := ioutil.ReadFile("./fixtures/" + filename)
if err != nil {
panic(err)
}
return buf
} | [
"func",
"_read_fixture",
"(",
"filename",
"string",
")",
"[",
"]",
"byte",
"{",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"\"",
"\"",
"+",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"buf",
"\n",
"}"
] | // reads a byte buffer from the given fixture filename | [
"reads",
"a",
"byte",
"buffer",
"from",
"the",
"given",
"fixture",
"filename"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/util.go#L88-L94 |
5,862 | dotabuff/manta | util.go | _proto_marshal | func _proto_marshal(obj proto.Message) []byte {
buf, err := proto.Marshal(obj)
if err != nil {
panic(err)
}
return buf
} | go | func _proto_marshal(obj proto.Message) []byte {
buf, err := proto.Marshal(obj)
if err != nil {
panic(err)
}
return buf
} | [
"func",
"_proto_marshal",
"(",
"obj",
"proto",
".",
"Message",
")",
"[",
"]",
"byte",
"{",
"buf",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"buf",
"\n",
"}"
] | // marshal a proto.Message to bytes | [
"marshal",
"a",
"proto",
".",
"Message",
"to",
"bytes"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/util.go#L97-L103 |
5,863 | dotabuff/manta | util.go | _caller | func _caller(n int) string {
if pc, _, _, ok := runtime.Caller(n); ok {
fns := strings.Split(runtime.FuncForPC(pc).Name(), "/")
return fns[len(fns)-1]
}
return "unknown"
} | go | func _caller(n int) string {
if pc, _, _, ok := runtime.Caller(n); ok {
fns := strings.Split(runtime.FuncForPC(pc).Name(), "/")
return fns[len(fns)-1]
}
return "unknown"
} | [
"func",
"_caller",
"(",
"n",
"int",
")",
"string",
"{",
"if",
"pc",
",",
"_",
",",
"_",
",",
"ok",
":=",
"runtime",
".",
"Caller",
"(",
"n",
")",
";",
"ok",
"{",
"fns",
":=",
"strings",
".",
"Split",
"(",
"runtime",
".",
"FuncForPC",
"(",
"pc",
")",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"return",
"fns",
"[",
"len",
"(",
"fns",
")",
"-",
"1",
"]",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // Returns the name of the calling function | [
"Returns",
"the",
"name",
"of",
"the",
"calling",
"function"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/util.go#L115-L122 |
5,864 | dotabuff/manta | sendtable.go | onCDemoSendTables | func (p *Parser) onCDemoSendTables(m *dota.CDemoSendTables) error {
r := newReader(m.GetData())
buf := r.readBytes(r.readVarUint32())
msg := &dota.CSVCMsg_FlattenedSerializer{}
if err := proto.Unmarshal(buf, msg); err != nil {
return err
}
patches := []fieldPatch{}
for _, h := range fieldPatches {
if h.shouldApply(p.GameBuild) {
patches = append(patches, h)
}
}
fields := map[int32]*field{}
fieldTypes := map[string]*fieldType{}
for _, s := range msg.GetSerializers() {
serializer := &serializer{
name: msg.GetSymbols()[s.GetSerializerNameSym()],
version: s.GetSerializerVersion(),
fields: []*field{},
}
for _, i := range s.GetFieldsIndex() {
if _, ok := fields[i]; !ok {
// create a new field
field := newField(msg, msg.GetFields()[i])
// patch parent name in builds <= 990
if p.GameBuild <= 990 {
field.parentName = serializer.name
}
// find or create a field type
if _, ok := fieldTypes[field.varType]; !ok {
fieldTypes[field.varType] = newFieldType(field.varType)
}
field.fieldType = fieldTypes[field.varType]
// find associated serializer
if field.serializerName != "" {
field.serializer = p.serializers[field.serializerName]
}
// apply any build-specific patches to the field
for _, h := range patches {
h.patch(field)
}
// determine field model
if field.serializer != nil {
if pointerTypes[field.fieldType.baseType] {
field.setModel(fieldModelFixedTable)
} else {
field.setModel(fieldModelVariableTable)
}
} else if field.fieldType.count > 0 && field.fieldType.baseType != "char" {
field.setModel(fieldModelFixedArray)
} else if field.fieldType.baseType == "CUtlVector" {
field.setModel(fieldModelVariableArray)
} else {
field.setModel(fieldModelSimple)
}
// store the field
fields[i] = field
}
// add the field to the serializer
serializer.fields = append(serializer.fields, fields[i])
}
// store the serializer for field reference
p.serializers[serializer.name] = serializer
if _, ok := p.classesByName[serializer.name]; ok {
p.classesByName[serializer.name].serializer = serializer
}
}
return nil
} | go | func (p *Parser) onCDemoSendTables(m *dota.CDemoSendTables) error {
r := newReader(m.GetData())
buf := r.readBytes(r.readVarUint32())
msg := &dota.CSVCMsg_FlattenedSerializer{}
if err := proto.Unmarshal(buf, msg); err != nil {
return err
}
patches := []fieldPatch{}
for _, h := range fieldPatches {
if h.shouldApply(p.GameBuild) {
patches = append(patches, h)
}
}
fields := map[int32]*field{}
fieldTypes := map[string]*fieldType{}
for _, s := range msg.GetSerializers() {
serializer := &serializer{
name: msg.GetSymbols()[s.GetSerializerNameSym()],
version: s.GetSerializerVersion(),
fields: []*field{},
}
for _, i := range s.GetFieldsIndex() {
if _, ok := fields[i]; !ok {
// create a new field
field := newField(msg, msg.GetFields()[i])
// patch parent name in builds <= 990
if p.GameBuild <= 990 {
field.parentName = serializer.name
}
// find or create a field type
if _, ok := fieldTypes[field.varType]; !ok {
fieldTypes[field.varType] = newFieldType(field.varType)
}
field.fieldType = fieldTypes[field.varType]
// find associated serializer
if field.serializerName != "" {
field.serializer = p.serializers[field.serializerName]
}
// apply any build-specific patches to the field
for _, h := range patches {
h.patch(field)
}
// determine field model
if field.serializer != nil {
if pointerTypes[field.fieldType.baseType] {
field.setModel(fieldModelFixedTable)
} else {
field.setModel(fieldModelVariableTable)
}
} else if field.fieldType.count > 0 && field.fieldType.baseType != "char" {
field.setModel(fieldModelFixedArray)
} else if field.fieldType.baseType == "CUtlVector" {
field.setModel(fieldModelVariableArray)
} else {
field.setModel(fieldModelSimple)
}
// store the field
fields[i] = field
}
// add the field to the serializer
serializer.fields = append(serializer.fields, fields[i])
}
// store the serializer for field reference
p.serializers[serializer.name] = serializer
if _, ok := p.classesByName[serializer.name]; ok {
p.classesByName[serializer.name].serializer = serializer
}
}
return nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"onCDemoSendTables",
"(",
"m",
"*",
"dota",
".",
"CDemoSendTables",
")",
"error",
"{",
"r",
":=",
"newReader",
"(",
"m",
".",
"GetData",
"(",
")",
")",
"\n",
"buf",
":=",
"r",
".",
"readBytes",
"(",
"r",
".",
"readVarUint32",
"(",
")",
")",
"\n\n",
"msg",
":=",
"&",
"dota",
".",
"CSVCMsg_FlattenedSerializer",
"{",
"}",
"\n",
"if",
"err",
":=",
"proto",
".",
"Unmarshal",
"(",
"buf",
",",
"msg",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"patches",
":=",
"[",
"]",
"fieldPatch",
"{",
"}",
"\n",
"for",
"_",
",",
"h",
":=",
"range",
"fieldPatches",
"{",
"if",
"h",
".",
"shouldApply",
"(",
"p",
".",
"GameBuild",
")",
"{",
"patches",
"=",
"append",
"(",
"patches",
",",
"h",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"fields",
":=",
"map",
"[",
"int32",
"]",
"*",
"field",
"{",
"}",
"\n",
"fieldTypes",
":=",
"map",
"[",
"string",
"]",
"*",
"fieldType",
"{",
"}",
"\n\n",
"for",
"_",
",",
"s",
":=",
"range",
"msg",
".",
"GetSerializers",
"(",
")",
"{",
"serializer",
":=",
"&",
"serializer",
"{",
"name",
":",
"msg",
".",
"GetSymbols",
"(",
")",
"[",
"s",
".",
"GetSerializerNameSym",
"(",
")",
"]",
",",
"version",
":",
"s",
".",
"GetSerializerVersion",
"(",
")",
",",
"fields",
":",
"[",
"]",
"*",
"field",
"{",
"}",
",",
"}",
"\n\n",
"for",
"_",
",",
"i",
":=",
"range",
"s",
".",
"GetFieldsIndex",
"(",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"fields",
"[",
"i",
"]",
";",
"!",
"ok",
"{",
"// create a new field",
"field",
":=",
"newField",
"(",
"msg",
",",
"msg",
".",
"GetFields",
"(",
")",
"[",
"i",
"]",
")",
"\n\n",
"// patch parent name in builds <= 990",
"if",
"p",
".",
"GameBuild",
"<=",
"990",
"{",
"field",
".",
"parentName",
"=",
"serializer",
".",
"name",
"\n",
"}",
"\n\n",
"// find or create a field type",
"if",
"_",
",",
"ok",
":=",
"fieldTypes",
"[",
"field",
".",
"varType",
"]",
";",
"!",
"ok",
"{",
"fieldTypes",
"[",
"field",
".",
"varType",
"]",
"=",
"newFieldType",
"(",
"field",
".",
"varType",
")",
"\n",
"}",
"\n",
"field",
".",
"fieldType",
"=",
"fieldTypes",
"[",
"field",
".",
"varType",
"]",
"\n\n",
"// find associated serializer",
"if",
"field",
".",
"serializerName",
"!=",
"\"",
"\"",
"{",
"field",
".",
"serializer",
"=",
"p",
".",
"serializers",
"[",
"field",
".",
"serializerName",
"]",
"\n",
"}",
"\n\n",
"// apply any build-specific patches to the field",
"for",
"_",
",",
"h",
":=",
"range",
"patches",
"{",
"h",
".",
"patch",
"(",
"field",
")",
"\n",
"}",
"\n\n",
"// determine field model",
"if",
"field",
".",
"serializer",
"!=",
"nil",
"{",
"if",
"pointerTypes",
"[",
"field",
".",
"fieldType",
".",
"baseType",
"]",
"{",
"field",
".",
"setModel",
"(",
"fieldModelFixedTable",
")",
"\n",
"}",
"else",
"{",
"field",
".",
"setModel",
"(",
"fieldModelVariableTable",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"field",
".",
"fieldType",
".",
"count",
">",
"0",
"&&",
"field",
".",
"fieldType",
".",
"baseType",
"!=",
"\"",
"\"",
"{",
"field",
".",
"setModel",
"(",
"fieldModelFixedArray",
")",
"\n",
"}",
"else",
"if",
"field",
".",
"fieldType",
".",
"baseType",
"==",
"\"",
"\"",
"{",
"field",
".",
"setModel",
"(",
"fieldModelVariableArray",
")",
"\n",
"}",
"else",
"{",
"field",
".",
"setModel",
"(",
"fieldModelSimple",
")",
"\n",
"}",
"\n\n",
"// store the field",
"fields",
"[",
"i",
"]",
"=",
"field",
"\n",
"}",
"\n\n",
"// add the field to the serializer",
"serializer",
".",
"fields",
"=",
"append",
"(",
"serializer",
".",
"fields",
",",
"fields",
"[",
"i",
"]",
")",
"\n",
"}",
"\n\n",
"// store the serializer for field reference",
"p",
".",
"serializers",
"[",
"serializer",
".",
"name",
"]",
"=",
"serializer",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"p",
".",
"classesByName",
"[",
"serializer",
".",
"name",
"]",
";",
"ok",
"{",
"p",
".",
"classesByName",
"[",
"serializer",
".",
"name",
"]",
".",
"serializer",
"=",
"serializer",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Internal callback for OnCDemoSendTables. | [
"Internal",
"callback",
"for",
"OnCDemoSendTables",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/sendtable.go#L25-L109 |
5,865 | dotabuff/manta | stream.go | newStream | func newStream(r io.Reader) *stream {
return &stream{r, make([]byte, buffer), buffer}
} | go | func newStream(r io.Reader) *stream {
return &stream{r, make([]byte, buffer), buffer}
} | [
"func",
"newStream",
"(",
"r",
"io",
".",
"Reader",
")",
"*",
"stream",
"{",
"return",
"&",
"stream",
"{",
"r",
",",
"make",
"(",
"[",
"]",
"byte",
",",
"buffer",
")",
",",
"buffer",
"}",
"\n",
"}"
] | // newStream creates a new stream from a given io.Reader | [
"newStream",
"creates",
"a",
"new",
"stream",
"from",
"a",
"given",
"io",
".",
"Reader"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/stream.go#L20-L22 |
5,866 | dotabuff/manta | stream.go | readBytes | func (s *stream) readBytes(n uint32) ([]byte, error) {
if n > s.size {
s.buf = make([]byte, n)
s.size = n
}
if _, err := io.ReadFull(s.Reader, s.buf[:n]); err != nil {
return nil, err
}
return s.buf[:n], nil
} | go | func (s *stream) readBytes(n uint32) ([]byte, error) {
if n > s.size {
s.buf = make([]byte, n)
s.size = n
}
if _, err := io.ReadFull(s.Reader, s.buf[:n]); err != nil {
return nil, err
}
return s.buf[:n], nil
} | [
"func",
"(",
"s",
"*",
"stream",
")",
"readBytes",
"(",
"n",
"uint32",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"n",
">",
"s",
".",
"size",
"{",
"s",
".",
"buf",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
")",
"\n",
"s",
".",
"size",
"=",
"n",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"s",
".",
"Reader",
",",
"s",
".",
"buf",
"[",
":",
"n",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"buf",
"[",
":",
"n",
"]",
",",
"nil",
"\n",
"}"
] | // readBytes reads the given number of bytes from the reader | [
"readBytes",
"reads",
"the",
"given",
"number",
"of",
"bytes",
"from",
"the",
"reader"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/stream.go#L25-L36 |
5,867 | dotabuff/manta | stream.go | readByte | func (s *stream) readByte() (byte, error) {
buf, err := s.readBytes(1)
if err != nil {
return 0, err
}
return buf[0], nil
} | go | func (s *stream) readByte() (byte, error) {
buf, err := s.readBytes(1)
if err != nil {
return 0, err
}
return buf[0], nil
} | [
"func",
"(",
"s",
"*",
"stream",
")",
"readByte",
"(",
")",
"(",
"byte",
",",
"error",
")",
"{",
"buf",
",",
"err",
":=",
"s",
".",
"readBytes",
"(",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"buf",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] | // readByte reads a single byte from the reader | [
"readByte",
"reads",
"a",
"single",
"byte",
"from",
"the",
"reader"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/stream.go#L39-L45 |
5,868 | dotabuff/manta | stream.go | readCommand | func (s *stream) readCommand() (dota.EDemoCommands, error) {
c, err := s.readVarUint32()
return dota.EDemoCommands(c), err
} | go | func (s *stream) readCommand() (dota.EDemoCommands, error) {
c, err := s.readVarUint32()
return dota.EDemoCommands(c), err
} | [
"func",
"(",
"s",
"*",
"stream",
")",
"readCommand",
"(",
")",
"(",
"dota",
".",
"EDemoCommands",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"s",
".",
"readVarUint32",
"(",
")",
"\n",
"return",
"dota",
".",
"EDemoCommands",
"(",
"c",
")",
",",
"err",
"\n",
"}"
] | // readCommand reads a varuint32 as an EDemoCommands | [
"readCommand",
"reads",
"a",
"varuint32",
"as",
"an",
"EDemoCommands"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/stream.go#L48-L51 |
5,869 | dotabuff/manta | stream.go | readVarUint32 | func (s *stream) readVarUint32() (uint32, error) {
var x, y uint32
for {
b, err := s.readByte()
if err != nil {
return 0, err
}
u := uint32(b)
x |= (u & 0x7F) << y
y += 7
if ((u & 0x80) == 0) || (y == 35) {
break
}
}
return x, nil
} | go | func (s *stream) readVarUint32() (uint32, error) {
var x, y uint32
for {
b, err := s.readByte()
if err != nil {
return 0, err
}
u := uint32(b)
x |= (u & 0x7F) << y
y += 7
if ((u & 0x80) == 0) || (y == 35) {
break
}
}
return x, nil
} | [
"func",
"(",
"s",
"*",
"stream",
")",
"readVarUint32",
"(",
")",
"(",
"uint32",
",",
"error",
")",
"{",
"var",
"x",
",",
"y",
"uint32",
"\n",
"for",
"{",
"b",
",",
"err",
":=",
"s",
".",
"readByte",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"u",
":=",
"uint32",
"(",
"b",
")",
"\n",
"x",
"|=",
"(",
"u",
"&",
"0x7F",
")",
"<<",
"y",
"\n",
"y",
"+=",
"7",
"\n",
"if",
"(",
"(",
"u",
"&",
"0x80",
")",
"==",
"0",
")",
"||",
"(",
"y",
"==",
"35",
")",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"x",
",",
"nil",
"\n",
"}"
] | // readVarUint32 reads an unsigned 32-bit varint | [
"readVarUint32",
"reads",
"an",
"unsigned",
"32",
"-",
"bit",
"varint"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/stream.go#L54-L70 |
5,870 | dotabuff/manta | class.go | onCSVCMsg_ServerInfo | func (p *Parser) onCSVCMsg_ServerInfo(m *dota.CSVCMsg_ServerInfo) error {
// This may be needed to parse PacketEntities.
p.classIdSize = uint32(math.Log(float64(m.GetMaxClasses()))/math.Log(2)) + 1
// Extract the build from the game dir.
matches := gameBuildRegexp.FindStringSubmatch(m.GetGameDir())
if len(matches) < 2 {
return fmt.Errorf("unable to determine game build from '%s'", m.GetGameDir())
}
build, err := strconv.ParseUint(matches[1], 10, 32)
if err != nil {
return err
}
p.GameBuild = uint32(build)
return nil
} | go | func (p *Parser) onCSVCMsg_ServerInfo(m *dota.CSVCMsg_ServerInfo) error {
// This may be needed to parse PacketEntities.
p.classIdSize = uint32(math.Log(float64(m.GetMaxClasses()))/math.Log(2)) + 1
// Extract the build from the game dir.
matches := gameBuildRegexp.FindStringSubmatch(m.GetGameDir())
if len(matches) < 2 {
return fmt.Errorf("unable to determine game build from '%s'", m.GetGameDir())
}
build, err := strconv.ParseUint(matches[1], 10, 32)
if err != nil {
return err
}
p.GameBuild = uint32(build)
return nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"onCSVCMsg_ServerInfo",
"(",
"m",
"*",
"dota",
".",
"CSVCMsg_ServerInfo",
")",
"error",
"{",
"// This may be needed to parse PacketEntities.",
"p",
".",
"classIdSize",
"=",
"uint32",
"(",
"math",
".",
"Log",
"(",
"float64",
"(",
"m",
".",
"GetMaxClasses",
"(",
")",
")",
")",
"/",
"math",
".",
"Log",
"(",
"2",
")",
")",
"+",
"1",
"\n\n",
"// Extract the build from the game dir.",
"matches",
":=",
"gameBuildRegexp",
".",
"FindStringSubmatch",
"(",
"m",
".",
"GetGameDir",
"(",
")",
")",
"\n",
"if",
"len",
"(",
"matches",
")",
"<",
"2",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"m",
".",
"GetGameDir",
"(",
")",
")",
"\n",
"}",
"\n",
"build",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"matches",
"[",
"1",
"]",
",",
"10",
",",
"32",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"p",
".",
"GameBuild",
"=",
"uint32",
"(",
"build",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Internal callback for OnCSVCMsg_ServerInfo. | [
"Internal",
"callback",
"for",
"OnCSVCMsg_ServerInfo",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/class.go#L42-L58 |
5,871 | dotabuff/manta | class.go | onCDemoClassInfo | func (p *Parser) onCDemoClassInfo(m *dota.CDemoClassInfo) error {
for _, c := range m.GetClasses() {
classId := c.GetClassId()
networkName := c.GetNetworkName()
class := &class{
classId: classId,
name: networkName,
serializer: p.serializers[networkName],
}
p.classesById[class.classId] = class
p.classesByName[class.name] = class
}
p.classInfo = true
p.updateInstanceBaseline()
return nil
} | go | func (p *Parser) onCDemoClassInfo(m *dota.CDemoClassInfo) error {
for _, c := range m.GetClasses() {
classId := c.GetClassId()
networkName := c.GetNetworkName()
class := &class{
classId: classId,
name: networkName,
serializer: p.serializers[networkName],
}
p.classesById[class.classId] = class
p.classesByName[class.name] = class
}
p.classInfo = true
p.updateInstanceBaseline()
return nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"onCDemoClassInfo",
"(",
"m",
"*",
"dota",
".",
"CDemoClassInfo",
")",
"error",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"m",
".",
"GetClasses",
"(",
")",
"{",
"classId",
":=",
"c",
".",
"GetClassId",
"(",
")",
"\n",
"networkName",
":=",
"c",
".",
"GetNetworkName",
"(",
")",
"\n\n",
"class",
":=",
"&",
"class",
"{",
"classId",
":",
"classId",
",",
"name",
":",
"networkName",
",",
"serializer",
":",
"p",
".",
"serializers",
"[",
"networkName",
"]",
",",
"}",
"\n",
"p",
".",
"classesById",
"[",
"class",
".",
"classId",
"]",
"=",
"class",
"\n",
"p",
".",
"classesByName",
"[",
"class",
".",
"name",
"]",
"=",
"class",
"\n",
"}",
"\n\n",
"p",
".",
"classInfo",
"=",
"true",
"\n\n",
"p",
".",
"updateInstanceBaseline",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Internal callback for OnCDemoClassInfo. | [
"Internal",
"callback",
"for",
"OnCDemoClassInfo",
"."
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/class.go#L61-L80 |
5,872 | dotabuff/manta | quantizedfloat.go | quantize | func (qfd *quantizedFloatDecoder) quantize(val float32) float32 {
if val < qfd.Low {
if (qfd.Flags & qff_roundup) == 0 {
_panicf("Field tried to quantize an out of range value")
}
return qfd.Low
} else if val > qfd.High {
if (qfd.Flags & qff_rounddown) == 0 {
_panicf("Field tried to quantize an out of range value")
}
return qfd.High
}
i := uint32((val - qfd.Low) * qfd.HighLowMul)
return qfd.Low + (qfd.High-qfd.Low)*(float32(i)*qfd.DecMul)
} | go | func (qfd *quantizedFloatDecoder) quantize(val float32) float32 {
if val < qfd.Low {
if (qfd.Flags & qff_roundup) == 0 {
_panicf("Field tried to quantize an out of range value")
}
return qfd.Low
} else if val > qfd.High {
if (qfd.Flags & qff_rounddown) == 0 {
_panicf("Field tried to quantize an out of range value")
}
return qfd.High
}
i := uint32((val - qfd.Low) * qfd.HighLowMul)
return qfd.Low + (qfd.High-qfd.Low)*(float32(i)*qfd.DecMul)
} | [
"func",
"(",
"qfd",
"*",
"quantizedFloatDecoder",
")",
"quantize",
"(",
"val",
"float32",
")",
"float32",
"{",
"if",
"val",
"<",
"qfd",
".",
"Low",
"{",
"if",
"(",
"qfd",
".",
"Flags",
"&",
"qff_roundup",
")",
"==",
"0",
"{",
"_panicf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"qfd",
".",
"Low",
"\n",
"}",
"else",
"if",
"val",
">",
"qfd",
".",
"High",
"{",
"if",
"(",
"qfd",
".",
"Flags",
"&",
"qff_rounddown",
")",
"==",
"0",
"{",
"_panicf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"qfd",
".",
"High",
"\n",
"}",
"\n\n",
"i",
":=",
"uint32",
"(",
"(",
"val",
"-",
"qfd",
".",
"Low",
")",
"*",
"qfd",
".",
"HighLowMul",
")",
"\n",
"return",
"qfd",
".",
"Low",
"+",
"(",
"qfd",
".",
"High",
"-",
"qfd",
".",
"Low",
")",
"*",
"(",
"float32",
"(",
"i",
")",
"*",
"qfd",
".",
"DecMul",
")",
"\n",
"}"
] | // Quantize a float | [
"Quantize",
"a",
"float"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/quantizedfloat.go#L110-L127 |
5,873 | dotabuff/manta | quantizedfloat.go | decode | func (qfd *quantizedFloatDecoder) decode(r *reader) float32 {
if (qfd.Flags&qff_rounddown) != 0 && r.readBoolean() {
return qfd.Low
}
if (qfd.Flags&qff_roundup) != 0 && r.readBoolean() {
return qfd.High
}
if (qfd.Flags&qff_encode_zero) != 0 && r.readBoolean() {
return 0.0
}
return qfd.Low + (qfd.High-qfd.Low)*float32(r.readBits(qfd.Bitcount))*qfd.DecMul
} | go | func (qfd *quantizedFloatDecoder) decode(r *reader) float32 {
if (qfd.Flags&qff_rounddown) != 0 && r.readBoolean() {
return qfd.Low
}
if (qfd.Flags&qff_roundup) != 0 && r.readBoolean() {
return qfd.High
}
if (qfd.Flags&qff_encode_zero) != 0 && r.readBoolean() {
return 0.0
}
return qfd.Low + (qfd.High-qfd.Low)*float32(r.readBits(qfd.Bitcount))*qfd.DecMul
} | [
"func",
"(",
"qfd",
"*",
"quantizedFloatDecoder",
")",
"decode",
"(",
"r",
"*",
"reader",
")",
"float32",
"{",
"if",
"(",
"qfd",
".",
"Flags",
"&",
"qff_rounddown",
")",
"!=",
"0",
"&&",
"r",
".",
"readBoolean",
"(",
")",
"{",
"return",
"qfd",
".",
"Low",
"\n",
"}",
"\n\n",
"if",
"(",
"qfd",
".",
"Flags",
"&",
"qff_roundup",
")",
"!=",
"0",
"&&",
"r",
".",
"readBoolean",
"(",
")",
"{",
"return",
"qfd",
".",
"High",
"\n",
"}",
"\n\n",
"if",
"(",
"qfd",
".",
"Flags",
"&",
"qff_encode_zero",
")",
"!=",
"0",
"&&",
"r",
".",
"readBoolean",
"(",
")",
"{",
"return",
"0.0",
"\n",
"}",
"\n\n",
"return",
"qfd",
".",
"Low",
"+",
"(",
"qfd",
".",
"High",
"-",
"qfd",
".",
"Low",
")",
"*",
"float32",
"(",
"r",
".",
"readBits",
"(",
"qfd",
".",
"Bitcount",
")",
")",
"*",
"qfd",
".",
"DecMul",
"\n",
"}"
] | // Actual float decoding | [
"Actual",
"float",
"decoding"
] | f51563b05e0e19c9ac19196e26455af1782ed3f0 | https://github.com/dotabuff/manta/blob/f51563b05e0e19c9ac19196e26455af1782ed3f0/quantizedfloat.go#L130-L144 |
5,874 | fsnotify/fsevents | fsevents.go | DeviceForPath | func DeviceForPath(path string) (int32, error) {
stat := syscall.Stat_t{}
if err := syscall.Lstat(path, &stat); err != nil {
return 0, err
}
return stat.Dev, nil
} | go | func DeviceForPath(path string) (int32, error) {
stat := syscall.Stat_t{}
if err := syscall.Lstat(path, &stat); err != nil {
return 0, err
}
return stat.Dev, nil
} | [
"func",
"DeviceForPath",
"(",
"path",
"string",
")",
"(",
"int32",
",",
"error",
")",
"{",
"stat",
":=",
"syscall",
".",
"Stat_t",
"{",
"}",
"\n",
"if",
"err",
":=",
"syscall",
".",
"Lstat",
"(",
"path",
",",
"&",
"stat",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"stat",
".",
"Dev",
",",
"nil",
"\n",
"}"
] | // DeviceForPath returns the device ID for the specified volume. | [
"DeviceForPath",
"returns",
"the",
"device",
"ID",
"for",
"the",
"specified",
"volume",
"."
] | f721bd2b045774a566e8f7f5fa2a9985e04c875d | https://github.com/fsnotify/fsevents/blob/f721bd2b045774a566e8f7f5fa2a9985e04c875d/fsevents.go#L84-L90 |
5,875 | fsnotify/fsevents | fsevents.go | Start | func (es *EventStream) Start() {
if es.Events == nil {
es.Events = make(chan []Event)
}
// register eventstream in the local registry for later lookup
// in C callback
cbInfo := registry.Add(es)
es.registryID = cbInfo
es.uuid = GetDeviceUUID(es.Device)
es.start(es.Paths, cbInfo)
} | go | func (es *EventStream) Start() {
if es.Events == nil {
es.Events = make(chan []Event)
}
// register eventstream in the local registry for later lookup
// in C callback
cbInfo := registry.Add(es)
es.registryID = cbInfo
es.uuid = GetDeviceUUID(es.Device)
es.start(es.Paths, cbInfo)
} | [
"func",
"(",
"es",
"*",
"EventStream",
")",
"Start",
"(",
")",
"{",
"if",
"es",
".",
"Events",
"==",
"nil",
"{",
"es",
".",
"Events",
"=",
"make",
"(",
"chan",
"[",
"]",
"Event",
")",
"\n",
"}",
"\n\n",
"// register eventstream in the local registry for later lookup",
"// in C callback",
"cbInfo",
":=",
"registry",
".",
"Add",
"(",
"es",
")",
"\n",
"es",
".",
"registryID",
"=",
"cbInfo",
"\n",
"es",
".",
"uuid",
"=",
"GetDeviceUUID",
"(",
"es",
".",
"Device",
")",
"\n",
"es",
".",
"start",
"(",
"es",
".",
"Paths",
",",
"cbInfo",
")",
"\n",
"}"
] | // Start listening to an event stream. | [
"Start",
"listening",
"to",
"an",
"event",
"stream",
"."
] | f721bd2b045774a566e8f7f5fa2a9985e04c875d | https://github.com/fsnotify/fsevents/blob/f721bd2b045774a566e8f7f5fa2a9985e04c875d/fsevents.go#L152-L163 |
5,876 | fsnotify/fsevents | fsevents.go | Stop | func (es *EventStream) Stop() {
if es.stream != nil {
stop(es.stream, es.rlref)
es.stream = nil
}
// Remove eventstream from the registry
registry.Delete(es.registryID)
es.registryID = 0
} | go | func (es *EventStream) Stop() {
if es.stream != nil {
stop(es.stream, es.rlref)
es.stream = nil
}
// Remove eventstream from the registry
registry.Delete(es.registryID)
es.registryID = 0
} | [
"func",
"(",
"es",
"*",
"EventStream",
")",
"Stop",
"(",
")",
"{",
"if",
"es",
".",
"stream",
"!=",
"nil",
"{",
"stop",
"(",
"es",
".",
"stream",
",",
"es",
".",
"rlref",
")",
"\n",
"es",
".",
"stream",
"=",
"nil",
"\n",
"}",
"\n\n",
"// Remove eventstream from the registry",
"registry",
".",
"Delete",
"(",
"es",
".",
"registryID",
")",
"\n",
"es",
".",
"registryID",
"=",
"0",
"\n",
"}"
] | // Stop listening to the event stream. | [
"Stop",
"listening",
"to",
"the",
"event",
"stream",
"."
] | f721bd2b045774a566e8f7f5fa2a9985e04c875d | https://github.com/fsnotify/fsevents/blob/f721bd2b045774a566e8f7f5fa2a9985e04c875d/fsevents.go#L171-L180 |
5,877 | fsnotify/fsevents | fsevents.go | Restart | func (es *EventStream) Restart() {
es.Stop()
es.Resume = true
es.Start()
} | go | func (es *EventStream) Restart() {
es.Stop()
es.Resume = true
es.Start()
} | [
"func",
"(",
"es",
"*",
"EventStream",
")",
"Restart",
"(",
")",
"{",
"es",
".",
"Stop",
"(",
")",
"\n",
"es",
".",
"Resume",
"=",
"true",
"\n",
"es",
".",
"Start",
"(",
")",
"\n",
"}"
] | // Restart listening. | [
"Restart",
"listening",
"."
] | f721bd2b045774a566e8f7f5fa2a9985e04c875d | https://github.com/fsnotify/fsevents/blob/f721bd2b045774a566e8f7f5fa2a9985e04c875d/fsevents.go#L183-L187 |
5,878 | fsnotify/fsevents | wrap.go | fsevtCallback | func fsevtCallback(stream C.FSEventStreamRef, info uintptr, numEvents C.size_t, cpaths **C.char, cflags *C.FSEventStreamEventFlags, cids *C.FSEventStreamEventId) {
l := int(numEvents)
events := make([]Event, l)
es := registry.Get(info)
if es == nil {
log.Printf("failed to retrieve registry %d", info)
return
}
// These slices are backed by C data. Ensure data is copied out
// if it expected to exist outside of this function.
paths := (*[1 << 30]*C.char)(unsafe.Pointer(cpaths))[:l:l]
ids := (*[1 << 30]C.FSEventStreamEventId)(unsafe.Pointer(cids))[:l:l]
flags := (*[1 << 30]C.FSEventStreamEventFlags)(unsafe.Pointer(cflags))[:l:l]
for i := range events {
events[i] = Event{
Path: C.GoString(paths[i]),
Flags: EventFlags(flags[i]),
ID: uint64(ids[i]),
}
es.EventID = uint64(ids[i])
}
es.Events <- events
} | go | func fsevtCallback(stream C.FSEventStreamRef, info uintptr, numEvents C.size_t, cpaths **C.char, cflags *C.FSEventStreamEventFlags, cids *C.FSEventStreamEventId) {
l := int(numEvents)
events := make([]Event, l)
es := registry.Get(info)
if es == nil {
log.Printf("failed to retrieve registry %d", info)
return
}
// These slices are backed by C data. Ensure data is copied out
// if it expected to exist outside of this function.
paths := (*[1 << 30]*C.char)(unsafe.Pointer(cpaths))[:l:l]
ids := (*[1 << 30]C.FSEventStreamEventId)(unsafe.Pointer(cids))[:l:l]
flags := (*[1 << 30]C.FSEventStreamEventFlags)(unsafe.Pointer(cflags))[:l:l]
for i := range events {
events[i] = Event{
Path: C.GoString(paths[i]),
Flags: EventFlags(flags[i]),
ID: uint64(ids[i]),
}
es.EventID = uint64(ids[i])
}
es.Events <- events
} | [
"func",
"fsevtCallback",
"(",
"stream",
"C",
".",
"FSEventStreamRef",
",",
"info",
"uintptr",
",",
"numEvents",
"C",
".",
"size_t",
",",
"cpaths",
"*",
"*",
"C",
".",
"char",
",",
"cflags",
"*",
"C",
".",
"FSEventStreamEventFlags",
",",
"cids",
"*",
"C",
".",
"FSEventStreamEventId",
")",
"{",
"l",
":=",
"int",
"(",
"numEvents",
")",
"\n",
"events",
":=",
"make",
"(",
"[",
"]",
"Event",
",",
"l",
")",
"\n\n",
"es",
":=",
"registry",
".",
"Get",
"(",
"info",
")",
"\n",
"if",
"es",
"==",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"info",
")",
"\n",
"return",
"\n",
"}",
"\n",
"// These slices are backed by C data. Ensure data is copied out",
"// if it expected to exist outside of this function.",
"paths",
":=",
"(",
"*",
"[",
"1",
"<<",
"30",
"]",
"*",
"C",
".",
"char",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"cpaths",
")",
")",
"[",
":",
"l",
":",
"l",
"]",
"\n",
"ids",
":=",
"(",
"*",
"[",
"1",
"<<",
"30",
"]",
"C",
".",
"FSEventStreamEventId",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"cids",
")",
")",
"[",
":",
"l",
":",
"l",
"]",
"\n",
"flags",
":=",
"(",
"*",
"[",
"1",
"<<",
"30",
"]",
"C",
".",
"FSEventStreamEventFlags",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"cflags",
")",
")",
"[",
":",
"l",
":",
"l",
"]",
"\n",
"for",
"i",
":=",
"range",
"events",
"{",
"events",
"[",
"i",
"]",
"=",
"Event",
"{",
"Path",
":",
"C",
".",
"GoString",
"(",
"paths",
"[",
"i",
"]",
")",
",",
"Flags",
":",
"EventFlags",
"(",
"flags",
"[",
"i",
"]",
")",
",",
"ID",
":",
"uint64",
"(",
"ids",
"[",
"i",
"]",
")",
",",
"}",
"\n",
"es",
".",
"EventID",
"=",
"uint64",
"(",
"ids",
"[",
"i",
"]",
")",
"\n",
"}",
"\n\n",
"es",
".",
"Events",
"<-",
"events",
"\n",
"}"
] | // arguments are released by C at the end of the callback. Ensure copies
// are made if data is expected to persist beyond this function ending.
//
//export fsevtCallback | [
"arguments",
"are",
"released",
"by",
"C",
"at",
"the",
"end",
"of",
"the",
"callback",
".",
"Ensure",
"copies",
"are",
"made",
"if",
"data",
"is",
"expected",
"to",
"persist",
"beyond",
"this",
"function",
"ending",
".",
"export",
"fsevtCallback"
] | f721bd2b045774a566e8f7f5fa2a9985e04c875d | https://github.com/fsnotify/fsevents/blob/f721bd2b045774a566e8f7f5fa2a9985e04c875d/wrap.go#L46-L70 |
5,879 | fsnotify/fsevents | wrap.go | GetStreamRefPaths | func GetStreamRefPaths(f FSEventStreamRef) []string {
arr := C.FSEventStreamCopyPathsBeingWatched(f)
l := cfArrayLen(arr)
ss := make([]string, l)
for i := range ss {
void := C.CFArrayGetValueAtIndex(arr, C.CFIndex(i))
ss[i] = cfStringToGoString(C.CFStringRef(void))
}
return ss
} | go | func GetStreamRefPaths(f FSEventStreamRef) []string {
arr := C.FSEventStreamCopyPathsBeingWatched(f)
l := cfArrayLen(arr)
ss := make([]string, l)
for i := range ss {
void := C.CFArrayGetValueAtIndex(arr, C.CFIndex(i))
ss[i] = cfStringToGoString(C.CFStringRef(void))
}
return ss
} | [
"func",
"GetStreamRefPaths",
"(",
"f",
"FSEventStreamRef",
")",
"[",
"]",
"string",
"{",
"arr",
":=",
"C",
".",
"FSEventStreamCopyPathsBeingWatched",
"(",
"f",
")",
"\n",
"l",
":=",
"cfArrayLen",
"(",
"arr",
")",
"\n\n",
"ss",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"l",
")",
"\n",
"for",
"i",
":=",
"range",
"ss",
"{",
"void",
":=",
"C",
".",
"CFArrayGetValueAtIndex",
"(",
"arr",
",",
"C",
".",
"CFIndex",
"(",
"i",
")",
")",
"\n",
"ss",
"[",
"i",
"]",
"=",
"cfStringToGoString",
"(",
"C",
".",
"CFStringRef",
"(",
"void",
")",
")",
"\n",
"}",
"\n",
"return",
"ss",
"\n",
"}"
] | // GetStreamRefPaths returns a copy of the paths being watched by
// this stream | [
"GetStreamRefPaths",
"returns",
"a",
"copy",
"of",
"the",
"paths",
"being",
"watched",
"by",
"this",
"stream"
] | f721bd2b045774a566e8f7f5fa2a9985e04c875d | https://github.com/fsnotify/fsevents/blob/f721bd2b045774a566e8f7f5fa2a9985e04c875d/wrap.go#L93-L103 |
5,880 | fsnotify/fsevents | wrap.go | copyCFString | func copyCFString(cfs C.CFStringRef) C.CFStringRef {
return C.CFStringCreateCopy(C.kCFAllocatorDefault, cfs)
} | go | func copyCFString(cfs C.CFStringRef) C.CFStringRef {
return C.CFStringCreateCopy(C.kCFAllocatorDefault, cfs)
} | [
"func",
"copyCFString",
"(",
"cfs",
"C",
".",
"CFStringRef",
")",
"C",
".",
"CFStringRef",
"{",
"return",
"C",
".",
"CFStringCreateCopy",
"(",
"C",
".",
"kCFAllocatorDefault",
",",
"cfs",
")",
"\n",
"}"
] | // copyCFString makes an immutable copy of a string with CFStringCreateCopy. | [
"copyCFString",
"makes",
"an",
"immutable",
"copy",
"of",
"a",
"string",
"with",
"CFStringCreateCopy",
"."
] | f721bd2b045774a566e8f7f5fa2a9985e04c875d | https://github.com/fsnotify/fsevents/blob/f721bd2b045774a566e8f7f5fa2a9985e04c875d/wrap.go#L139-L141 |
5,881 | fsnotify/fsevents | wrap.go | EventIDForDeviceBeforeTime | func EventIDForDeviceBeforeTime(dev int32, before time.Time) uint64 {
tm := C.CFAbsoluteTime(before.Unix())
return uint64(C.FSEventsGetLastEventIdForDeviceBeforeTime(C.dev_t(dev), tm))
} | go | func EventIDForDeviceBeforeTime(dev int32, before time.Time) uint64 {
tm := C.CFAbsoluteTime(before.Unix())
return uint64(C.FSEventsGetLastEventIdForDeviceBeforeTime(C.dev_t(dev), tm))
} | [
"func",
"EventIDForDeviceBeforeTime",
"(",
"dev",
"int32",
",",
"before",
"time",
".",
"Time",
")",
"uint64",
"{",
"tm",
":=",
"C",
".",
"CFAbsoluteTime",
"(",
"before",
".",
"Unix",
"(",
")",
")",
"\n",
"return",
"uint64",
"(",
"C",
".",
"FSEventsGetLastEventIdForDeviceBeforeTime",
"(",
"C",
".",
"dev_t",
"(",
"dev",
")",
",",
"tm",
")",
")",
"\n",
"}"
] | // EventIDForDeviceBeforeTime returns an event ID before a given time. | [
"EventIDForDeviceBeforeTime",
"returns",
"an",
"event",
"ID",
"before",
"a",
"given",
"time",
"."
] | f721bd2b045774a566e8f7f5fa2a9985e04c875d | https://github.com/fsnotify/fsevents/blob/f721bd2b045774a566e8f7f5fa2a9985e04c875d/wrap.go#L147-L150 |
5,882 | fsnotify/fsevents | wrap.go | createPaths | func createPaths(paths []string) (C.CFArrayRef, error) {
cPaths := C.ArrayCreateMutable(C.int(len(paths)))
var errs []error
for _, path := range paths {
p, err := filepath.Abs(path)
if err != nil {
// hack up some reporting errors, but don't prevent execution
// because of them
errs = append(errs, err)
}
str := makeCFString(p)
C.CFArrayAppendValue(C.CFMutableArrayRef(cPaths), unsafe.Pointer(str))
}
var err error
if len(errs) > 0 {
err = fmt.Errorf("%q", errs)
}
return cPaths, err
} | go | func createPaths(paths []string) (C.CFArrayRef, error) {
cPaths := C.ArrayCreateMutable(C.int(len(paths)))
var errs []error
for _, path := range paths {
p, err := filepath.Abs(path)
if err != nil {
// hack up some reporting errors, but don't prevent execution
// because of them
errs = append(errs, err)
}
str := makeCFString(p)
C.CFArrayAppendValue(C.CFMutableArrayRef(cPaths), unsafe.Pointer(str))
}
var err error
if len(errs) > 0 {
err = fmt.Errorf("%q", errs)
}
return cPaths, err
} | [
"func",
"createPaths",
"(",
"paths",
"[",
"]",
"string",
")",
"(",
"C",
".",
"CFArrayRef",
",",
"error",
")",
"{",
"cPaths",
":=",
"C",
".",
"ArrayCreateMutable",
"(",
"C",
".",
"int",
"(",
"len",
"(",
"paths",
")",
")",
")",
"\n",
"var",
"errs",
"[",
"]",
"error",
"\n",
"for",
"_",
",",
"path",
":=",
"range",
"paths",
"{",
"p",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// hack up some reporting errors, but don't prevent execution",
"// because of them",
"errs",
"=",
"append",
"(",
"errs",
",",
"err",
")",
"\n",
"}",
"\n",
"str",
":=",
"makeCFString",
"(",
"p",
")",
"\n",
"C",
".",
"CFArrayAppendValue",
"(",
"C",
".",
"CFMutableArrayRef",
"(",
"cPaths",
")",
",",
"unsafe",
".",
"Pointer",
"(",
"str",
")",
")",
"\n",
"}",
"\n",
"var",
"err",
"error",
"\n",
"if",
"len",
"(",
"errs",
")",
">",
"0",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"errs",
")",
"\n",
"}",
"\n",
"return",
"cPaths",
",",
"err",
"\n",
"}"
] | // createPaths accepts the user defined set of paths and returns FSEvents
// compatible array of paths | [
"createPaths",
"accepts",
"the",
"user",
"defined",
"set",
"of",
"paths",
"and",
"returns",
"FSEvents",
"compatible",
"array",
"of",
"paths"
] | f721bd2b045774a566e8f7f5fa2a9985e04c875d | https://github.com/fsnotify/fsevents/blob/f721bd2b045774a566e8f7f5fa2a9985e04c875d/wrap.go#L154-L172 |
5,883 | fsnotify/fsevents | wrap.go | makeCFString | func makeCFString(str string) C.CFStringRef {
s := C.CString(str)
defer C.free(unsafe.Pointer(s))
return C.CFStringCreateWithCString(C.kCFAllocatorDefault, s, C.kCFStringEncodingUTF8)
} | go | func makeCFString(str string) C.CFStringRef {
s := C.CString(str)
defer C.free(unsafe.Pointer(s))
return C.CFStringCreateWithCString(C.kCFAllocatorDefault, s, C.kCFStringEncodingUTF8)
} | [
"func",
"makeCFString",
"(",
"str",
"string",
")",
"C",
".",
"CFStringRef",
"{",
"s",
":=",
"C",
".",
"CString",
"(",
"str",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"s",
")",
")",
"\n",
"return",
"C",
".",
"CFStringCreateWithCString",
"(",
"C",
".",
"kCFAllocatorDefault",
",",
"s",
",",
"C",
".",
"kCFStringEncodingUTF8",
")",
"\n",
"}"
] | // makeCFString makes an immutable string with CFStringCreateWithCString. | [
"makeCFString",
"makes",
"an",
"immutable",
"string",
"with",
"CFStringCreateWithCString",
"."
] | f721bd2b045774a566e8f7f5fa2a9985e04c875d | https://github.com/fsnotify/fsevents/blob/f721bd2b045774a566e8f7f5fa2a9985e04c875d/wrap.go#L175-L179 |
5,884 | fsnotify/fsevents | wrap.go | flush | func flush(stream FSEventStreamRef, sync bool) {
if sync {
C.FSEventStreamFlushSync(stream)
} else {
C.FSEventStreamFlushAsync(stream)
}
} | go | func flush(stream FSEventStreamRef, sync bool) {
if sync {
C.FSEventStreamFlushSync(stream)
} else {
C.FSEventStreamFlushAsync(stream)
}
} | [
"func",
"flush",
"(",
"stream",
"FSEventStreamRef",
",",
"sync",
"bool",
")",
"{",
"if",
"sync",
"{",
"C",
".",
"FSEventStreamFlushSync",
"(",
"stream",
")",
"\n",
"}",
"else",
"{",
"C",
".",
"FSEventStreamFlushAsync",
"(",
"stream",
")",
"\n",
"}",
"\n",
"}"
] | // flush drains the event stream of undelivered events | [
"flush",
"drains",
"the",
"event",
"stream",
"of",
"undelivered",
"events"
] | f721bd2b045774a566e8f7f5fa2a9985e04c875d | https://github.com/fsnotify/fsevents/blob/f721bd2b045774a566e8f7f5fa2a9985e04c875d/wrap.go#L252-L258 |
5,885 | fsnotify/fsevents | wrap.go | stop | func stop(stream FSEventStreamRef, rlref CFRunLoopRef) {
C.FSEventStreamStop(stream)
C.FSEventStreamInvalidate(stream)
C.FSEventStreamRelease(stream)
C.CFRunLoopStop(C.CFRunLoopRef(rlref))
C.CFRelease(C.CFTypeRef(rlref))
} | go | func stop(stream FSEventStreamRef, rlref CFRunLoopRef) {
C.FSEventStreamStop(stream)
C.FSEventStreamInvalidate(stream)
C.FSEventStreamRelease(stream)
C.CFRunLoopStop(C.CFRunLoopRef(rlref))
C.CFRelease(C.CFTypeRef(rlref))
} | [
"func",
"stop",
"(",
"stream",
"FSEventStreamRef",
",",
"rlref",
"CFRunLoopRef",
")",
"{",
"C",
".",
"FSEventStreamStop",
"(",
"stream",
")",
"\n",
"C",
".",
"FSEventStreamInvalidate",
"(",
"stream",
")",
"\n",
"C",
".",
"FSEventStreamRelease",
"(",
"stream",
")",
"\n",
"C",
".",
"CFRunLoopStop",
"(",
"C",
".",
"CFRunLoopRef",
"(",
"rlref",
")",
")",
"\n",
"C",
".",
"CFRelease",
"(",
"C",
".",
"CFTypeRef",
"(",
"rlref",
")",
")",
"\n",
"}"
] | // stop requests fsevents stops streaming events | [
"stop",
"requests",
"fsevents",
"stops",
"streaming",
"events"
] | f721bd2b045774a566e8f7f5fa2a9985e04c875d | https://github.com/fsnotify/fsevents/blob/f721bd2b045774a566e8f7f5fa2a9985e04c875d/wrap.go#L261-L267 |
5,886 | cloudfoundry/bbs | db/sqldb/helpers/upsert.go | Upsert | func (h *sqlHelper) Upsert(
logger lager.Logger,
q Queryable,
table string,
attributes SQLAttributes,
wheres string,
whereBindings ...interface{},
) (bool, error) {
res, err := h.Update(
logger,
q,
table,
attributes,
wheres,
whereBindings...,
)
if err != nil {
return false, err
}
rowsAffected, err := res.RowsAffected()
if err != nil {
// this should never happen
logger.Error("failed-getting-rows-affected", err)
return false, err
}
if rowsAffected > 0 {
return false, nil
}
res, err = h.Insert(
logger,
q,
table,
attributes,
)
if err != nil {
return false, err
}
return true, nil
} | go | func (h *sqlHelper) Upsert(
logger lager.Logger,
q Queryable,
table string,
attributes SQLAttributes,
wheres string,
whereBindings ...interface{},
) (bool, error) {
res, err := h.Update(
logger,
q,
table,
attributes,
wheres,
whereBindings...,
)
if err != nil {
return false, err
}
rowsAffected, err := res.RowsAffected()
if err != nil {
// this should never happen
logger.Error("failed-getting-rows-affected", err)
return false, err
}
if rowsAffected > 0 {
return false, nil
}
res, err = h.Insert(
logger,
q,
table,
attributes,
)
if err != nil {
return false, err
}
return true, nil
} | [
"func",
"(",
"h",
"*",
"sqlHelper",
")",
"Upsert",
"(",
"logger",
"lager",
".",
"Logger",
",",
"q",
"Queryable",
",",
"table",
"string",
",",
"attributes",
"SQLAttributes",
",",
"wheres",
"string",
",",
"whereBindings",
"...",
"interface",
"{",
"}",
",",
")",
"(",
"bool",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"h",
".",
"Update",
"(",
"logger",
",",
"q",
",",
"table",
",",
"attributes",
",",
"wheres",
",",
"whereBindings",
"...",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"rowsAffected",
",",
"err",
":=",
"res",
".",
"RowsAffected",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// this should never happen",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"rowsAffected",
">",
"0",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"res",
",",
"err",
"=",
"h",
".",
"Insert",
"(",
"logger",
",",
"q",
",",
"table",
",",
"attributes",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] | // Upsert insert a record if it doesn't exist or update the record if one
// already exists. Returns true if a new record was inserted in the database. | [
"Upsert",
"insert",
"a",
"record",
"if",
"it",
"doesn",
"t",
"exist",
"or",
"update",
"the",
"record",
"if",
"one",
"already",
"exists",
".",
"Returns",
"true",
"if",
"a",
"new",
"record",
"was",
"inserted",
"in",
"the",
"database",
"."
] | 1978bb997cbd2527cc4fa52798b0af6f6d899698 | https://github.com/cloudfoundry/bbs/blob/1978bb997cbd2527cc4fa52798b0af6f6d899698/db/sqldb/helpers/upsert.go#L9-L51 |
5,887 | cloudfoundry/bbs | db/sqldb/helpers/transact.go | Transact | func (h *sqlHelper) Transact(logger lager.Logger, db QueryableDB, f func(logger lager.Logger, tx Tx) error) error {
var err error
for attempts := 0; attempts < 3; attempts++ {
err = func() error {
tx, err := db.Begin()
if err != nil {
logger.Error("failed-starting-transaction", err)
return err
}
defer tx.Rollback()
err = f(logger, tx)
if err != nil {
return err
}
err = tx.Commit()
if err != nil {
logger.Error("failed-committing-transaction", err)
}
return err
}()
convertedErr := h.ConvertSQLError(err)
// golang sql package does not always retry query on ErrBadConn, e.g. if it
// is in the middle of a transaction. This make sense since the package
// cannot retry the entire transaction and has to return control to the
// caller to initiate a retry
if attempts >= 2 || (convertedErr != ErrDeadlock && convertedErr != driver.ErrBadConn && convertedErr != mysql.ErrInvalidConn) {
break
} else {
logger.Error("deadlock-transaction", err, lager.Data{"attempts": attempts})
time.Sleep(500 * time.Millisecond)
}
}
return err
} | go | func (h *sqlHelper) Transact(logger lager.Logger, db QueryableDB, f func(logger lager.Logger, tx Tx) error) error {
var err error
for attempts := 0; attempts < 3; attempts++ {
err = func() error {
tx, err := db.Begin()
if err != nil {
logger.Error("failed-starting-transaction", err)
return err
}
defer tx.Rollback()
err = f(logger, tx)
if err != nil {
return err
}
err = tx.Commit()
if err != nil {
logger.Error("failed-committing-transaction", err)
}
return err
}()
convertedErr := h.ConvertSQLError(err)
// golang sql package does not always retry query on ErrBadConn, e.g. if it
// is in the middle of a transaction. This make sense since the package
// cannot retry the entire transaction and has to return control to the
// caller to initiate a retry
if attempts >= 2 || (convertedErr != ErrDeadlock && convertedErr != driver.ErrBadConn && convertedErr != mysql.ErrInvalidConn) {
break
} else {
logger.Error("deadlock-transaction", err, lager.Data{"attempts": attempts})
time.Sleep(500 * time.Millisecond)
}
}
return err
} | [
"func",
"(",
"h",
"*",
"sqlHelper",
")",
"Transact",
"(",
"logger",
"lager",
".",
"Logger",
",",
"db",
"QueryableDB",
",",
"f",
"func",
"(",
"logger",
"lager",
".",
"Logger",
",",
"tx",
"Tx",
")",
"error",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"for",
"attempts",
":=",
"0",
";",
"attempts",
"<",
"3",
";",
"attempts",
"++",
"{",
"err",
"=",
"func",
"(",
")",
"error",
"{",
"tx",
",",
"err",
":=",
"db",
".",
"Begin",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"tx",
".",
"Rollback",
"(",
")",
"\n\n",
"err",
"=",
"f",
"(",
"logger",
",",
"tx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"tx",
".",
"Commit",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"(",
")",
"\n\n",
"convertedErr",
":=",
"h",
".",
"ConvertSQLError",
"(",
"err",
")",
"\n",
"// golang sql package does not always retry query on ErrBadConn, e.g. if it",
"// is in the middle of a transaction. This make sense since the package",
"// cannot retry the entire transaction and has to return control to the",
"// caller to initiate a retry",
"if",
"attempts",
">=",
"2",
"||",
"(",
"convertedErr",
"!=",
"ErrDeadlock",
"&&",
"convertedErr",
"!=",
"driver",
".",
"ErrBadConn",
"&&",
"convertedErr",
"!=",
"mysql",
".",
"ErrInvalidConn",
")",
"{",
"break",
"\n",
"}",
"else",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
",",
"lager",
".",
"Data",
"{",
"\"",
"\"",
":",
"attempts",
"}",
")",
"\n",
"time",
".",
"Sleep",
"(",
"500",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // BEGIN TRANSACTION; f ... ; COMMIT; or
// BEGIN TRANSACTION; f ... ; ROLLBACK; if f returns an error. | [
"BEGIN",
"TRANSACTION",
";",
"f",
"...",
";",
"COMMIT",
";",
"or",
"BEGIN",
"TRANSACTION",
";",
"f",
"...",
";",
"ROLLBACK",
";",
"if",
"f",
"returns",
"an",
"error",
"."
] | 1978bb997cbd2527cc4fa52798b0af6f6d899698 | https://github.com/cloudfoundry/bbs/blob/1978bb997cbd2527cc4fa52798b0af6f6d899698/db/sqldb/helpers/transact.go#L14-L53 |
5,888 | cloudfoundry/bbs | models/actual_lrp.go | hasHigherPriority | func hasHigherPriority(lrp1, lrp2 *ActualLRP) bool {
if lrp1 == nil {
return false
}
if lrp2 == nil {
return true
}
if lrp1.Presence == ActualLRP_Ordinary {
switch lrp1.State {
case ActualLRPStateRunning:
return true
case ActualLRPStateClaimed:
return lrp2.State != ActualLRPStateRunning && lrp2.State != ActualLRPStateClaimed
}
} else if lrp1.Presence == ActualLRP_Suspect {
switch lrp1.State {
case ActualLRPStateRunning:
return lrp2.State != ActualLRPStateRunning
case ActualLRPStateClaimed:
return lrp2.State != ActualLRPStateRunning
}
}
// Cases where we are comparing two LRPs with the same presence have undefined behavior since it shouldn't happen
// with the way they're stored in the database
return false
} | go | func hasHigherPriority(lrp1, lrp2 *ActualLRP) bool {
if lrp1 == nil {
return false
}
if lrp2 == nil {
return true
}
if lrp1.Presence == ActualLRP_Ordinary {
switch lrp1.State {
case ActualLRPStateRunning:
return true
case ActualLRPStateClaimed:
return lrp2.State != ActualLRPStateRunning && lrp2.State != ActualLRPStateClaimed
}
} else if lrp1.Presence == ActualLRP_Suspect {
switch lrp1.State {
case ActualLRPStateRunning:
return lrp2.State != ActualLRPStateRunning
case ActualLRPStateClaimed:
return lrp2.State != ActualLRPStateRunning
}
}
// Cases where we are comparing two LRPs with the same presence have undefined behavior since it shouldn't happen
// with the way they're stored in the database
return false
} | [
"func",
"hasHigherPriority",
"(",
"lrp1",
",",
"lrp2",
"*",
"ActualLRP",
")",
"bool",
"{",
"if",
"lrp1",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"lrp2",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"if",
"lrp1",
".",
"Presence",
"==",
"ActualLRP_Ordinary",
"{",
"switch",
"lrp1",
".",
"State",
"{",
"case",
"ActualLRPStateRunning",
":",
"return",
"true",
"\n",
"case",
"ActualLRPStateClaimed",
":",
"return",
"lrp2",
".",
"State",
"!=",
"ActualLRPStateRunning",
"&&",
"lrp2",
".",
"State",
"!=",
"ActualLRPStateClaimed",
"\n",
"}",
"\n",
"}",
"else",
"if",
"lrp1",
".",
"Presence",
"==",
"ActualLRP_Suspect",
"{",
"switch",
"lrp1",
".",
"State",
"{",
"case",
"ActualLRPStateRunning",
":",
"return",
"lrp2",
".",
"State",
"!=",
"ActualLRPStateRunning",
"\n",
"case",
"ActualLRPStateClaimed",
":",
"return",
"lrp2",
".",
"State",
"!=",
"ActualLRPStateRunning",
"\n",
"}",
"\n",
"}",
"\n",
"// Cases where we are comparing two LRPs with the same presence have undefined behavior since it shouldn't happen",
"// with the way they're stored in the database",
"return",
"false",
"\n",
"}"
] | // hasHigherPriority returns true if lrp1 takes precendence over lrp2 | [
"hasHigherPriority",
"returns",
"true",
"if",
"lrp1",
"takes",
"precendence",
"over",
"lrp2"
] | 1978bb997cbd2527cc4fa52798b0af6f6d899698 | https://github.com/cloudfoundry/bbs/blob/1978bb997cbd2527cc4fa52798b0af6f6d899698/models/actual_lrp.go#L409-L436 |
5,889 | cloudfoundry/bbs | models/actual_lrp.go | ResolveActualLRPGroups | func ResolveActualLRPGroups(lrps []*ActualLRP) []*ActualLRPGroup {
mapOfGroups := map[ActualLRPKey]*ActualLRPGroup{}
result := []*ActualLRPGroup{}
for _, actualLRP := range lrps {
// Every actual LRP has potentially 2 rows in the database: one for the instance
// one for the evacuating. When building the list of actual LRP groups (where
// a group is the instance and corresponding evacuating), make sure we don't add the same
// actual lrp twice.
if mapOfGroups[actualLRP.ActualLRPKey] == nil {
mapOfGroups[actualLRP.ActualLRPKey] = &ActualLRPGroup{}
result = append(result, mapOfGroups[actualLRP.ActualLRPKey])
}
if actualLRP.Presence == ActualLRP_Evacuating {
mapOfGroups[actualLRP.ActualLRPKey].Evacuating = actualLRP
} else if hasHigherPriority(actualLRP, mapOfGroups[actualLRP.ActualLRPKey].Instance) {
mapOfGroups[actualLRP.ActualLRPKey].Instance = actualLRP
}
}
return result
} | go | func ResolveActualLRPGroups(lrps []*ActualLRP) []*ActualLRPGroup {
mapOfGroups := map[ActualLRPKey]*ActualLRPGroup{}
result := []*ActualLRPGroup{}
for _, actualLRP := range lrps {
// Every actual LRP has potentially 2 rows in the database: one for the instance
// one for the evacuating. When building the list of actual LRP groups (where
// a group is the instance and corresponding evacuating), make sure we don't add the same
// actual lrp twice.
if mapOfGroups[actualLRP.ActualLRPKey] == nil {
mapOfGroups[actualLRP.ActualLRPKey] = &ActualLRPGroup{}
result = append(result, mapOfGroups[actualLRP.ActualLRPKey])
}
if actualLRP.Presence == ActualLRP_Evacuating {
mapOfGroups[actualLRP.ActualLRPKey].Evacuating = actualLRP
} else if hasHigherPriority(actualLRP, mapOfGroups[actualLRP.ActualLRPKey].Instance) {
mapOfGroups[actualLRP.ActualLRPKey].Instance = actualLRP
}
}
return result
} | [
"func",
"ResolveActualLRPGroups",
"(",
"lrps",
"[",
"]",
"*",
"ActualLRP",
")",
"[",
"]",
"*",
"ActualLRPGroup",
"{",
"mapOfGroups",
":=",
"map",
"[",
"ActualLRPKey",
"]",
"*",
"ActualLRPGroup",
"{",
"}",
"\n",
"result",
":=",
"[",
"]",
"*",
"ActualLRPGroup",
"{",
"}",
"\n",
"for",
"_",
",",
"actualLRP",
":=",
"range",
"lrps",
"{",
"// Every actual LRP has potentially 2 rows in the database: one for the instance",
"// one for the evacuating. When building the list of actual LRP groups (where",
"// a group is the instance and corresponding evacuating), make sure we don't add the same",
"// actual lrp twice.",
"if",
"mapOfGroups",
"[",
"actualLRP",
".",
"ActualLRPKey",
"]",
"==",
"nil",
"{",
"mapOfGroups",
"[",
"actualLRP",
".",
"ActualLRPKey",
"]",
"=",
"&",
"ActualLRPGroup",
"{",
"}",
"\n",
"result",
"=",
"append",
"(",
"result",
",",
"mapOfGroups",
"[",
"actualLRP",
".",
"ActualLRPKey",
"]",
")",
"\n",
"}",
"\n",
"if",
"actualLRP",
".",
"Presence",
"==",
"ActualLRP_Evacuating",
"{",
"mapOfGroups",
"[",
"actualLRP",
".",
"ActualLRPKey",
"]",
".",
"Evacuating",
"=",
"actualLRP",
"\n",
"}",
"else",
"if",
"hasHigherPriority",
"(",
"actualLRP",
",",
"mapOfGroups",
"[",
"actualLRP",
".",
"ActualLRPKey",
"]",
".",
"Instance",
")",
"{",
"mapOfGroups",
"[",
"actualLRP",
".",
"ActualLRPKey",
"]",
".",
"Instance",
"=",
"actualLRP",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] | // DEPRECATED
// ResolveActualLRPGroups convert the given set of lrp instances into
// ActualLRPGroup. This conversion is lossy. A suspect LRP is given
// precendence over an Ordinary instance if it is Running. Otherwise, the
// Ordinary instance is returned in the Instance field of the ActualLRPGroup. | [
"DEPRECATED",
"ResolveActualLRPGroups",
"convert",
"the",
"given",
"set",
"of",
"lrp",
"instances",
"into",
"ActualLRPGroup",
".",
"This",
"conversion",
"is",
"lossy",
".",
"A",
"suspect",
"LRP",
"is",
"given",
"precendence",
"over",
"an",
"Ordinary",
"instance",
"if",
"it",
"is",
"Running",
".",
"Otherwise",
"the",
"Ordinary",
"instance",
"is",
"returned",
"in",
"the",
"Instance",
"field",
"of",
"the",
"ActualLRPGroup",
"."
] | 1978bb997cbd2527cc4fa52798b0af6f6d899698 | https://github.com/cloudfoundry/bbs/blob/1978bb997cbd2527cc4fa52798b0af6f6d899698/models/actual_lrp.go#L443-L463 |
5,890 | cloudfoundry/bbs | models/actual_lrp.go | ResolveActualLRPGroup | func ResolveActualLRPGroup(lrps []*ActualLRP) *ActualLRPGroup {
actualLRPGroups := ResolveActualLRPGroups(lrps)
switch len(actualLRPGroups) {
case 0:
return &ActualLRPGroup{}
case 1:
return actualLRPGroups[0]
default:
panic("shouldn't get here")
}
} | go | func ResolveActualLRPGroup(lrps []*ActualLRP) *ActualLRPGroup {
actualLRPGroups := ResolveActualLRPGroups(lrps)
switch len(actualLRPGroups) {
case 0:
return &ActualLRPGroup{}
case 1:
return actualLRPGroups[0]
default:
panic("shouldn't get here")
}
} | [
"func",
"ResolveActualLRPGroup",
"(",
"lrps",
"[",
"]",
"*",
"ActualLRP",
")",
"*",
"ActualLRPGroup",
"{",
"actualLRPGroups",
":=",
"ResolveActualLRPGroups",
"(",
"lrps",
")",
"\n",
"switch",
"len",
"(",
"actualLRPGroups",
")",
"{",
"case",
"0",
":",
"return",
"&",
"ActualLRPGroup",
"{",
"}",
"\n",
"case",
"1",
":",
"return",
"actualLRPGroups",
"[",
"0",
"]",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // DEPRECATED
// ResolveToActualLRPGroup calls ResolveActualLRPGroups and return the first
// LRP group. It panics if there are more than one group. If there no LRP
// groups were returned by ResolveActualLRPGroups, then an empty ActualLRPGroup
// is returned. | [
"DEPRECATED",
"ResolveToActualLRPGroup",
"calls",
"ResolveActualLRPGroups",
"and",
"return",
"the",
"first",
"LRP",
"group",
".",
"It",
"panics",
"if",
"there",
"are",
"more",
"than",
"one",
"group",
".",
"If",
"there",
"no",
"LRP",
"groups",
"were",
"returned",
"by",
"ResolveActualLRPGroups",
"then",
"an",
"empty",
"ActualLRPGroup",
"is",
"returned",
"."
] | 1978bb997cbd2527cc4fa52798b0af6f6d899698 | https://github.com/cloudfoundry/bbs/blob/1978bb997cbd2527cc4fa52798b0af6f6d899698/models/actual_lrp.go#L470-L480 |
5,891 | cloudfoundry/bbs | db/sqldb/task_db.go | ResolvingTask | func (db *SQLDB) ResolvingTask(logger lager.Logger, taskGuid string) (*models.Task, *models.Task, error) {
logger = logger.Session("resolving-task", lager.Data{"task_guid": taskGuid})
logger.Info("starting")
defer logger.Info("complete")
var beforeTask models.Task
var afterTask *models.Task
err := db.transact(logger, func(logger lager.Logger, tx helpers.Tx) error {
var err error
afterTask, err = db.fetchTaskForUpdate(logger, taskGuid, tx)
if err != nil {
logger.Error("failed-locking-task", err)
return err
}
beforeTask = *afterTask
if err = afterTask.ValidateTransitionTo(models.Task_Resolving); err != nil {
logger.Error("invalid-state-transition", err)
return err
}
now := db.clock.Now().UnixNano()
_, err = db.update(logger, tx, tasksTable,
helpers.SQLAttributes{
"state": models.Task_Resolving,
"updated_at": now,
},
"guid = ?", taskGuid,
)
if err != nil {
logger.Error("failed-updating-tasks", err)
return err
}
afterTask.State = models.Task_Resolving
afterTask.UpdatedAt = now
return nil
})
return &beforeTask, afterTask, err
} | go | func (db *SQLDB) ResolvingTask(logger lager.Logger, taskGuid string) (*models.Task, *models.Task, error) {
logger = logger.Session("resolving-task", lager.Data{"task_guid": taskGuid})
logger.Info("starting")
defer logger.Info("complete")
var beforeTask models.Task
var afterTask *models.Task
err := db.transact(logger, func(logger lager.Logger, tx helpers.Tx) error {
var err error
afterTask, err = db.fetchTaskForUpdate(logger, taskGuid, tx)
if err != nil {
logger.Error("failed-locking-task", err)
return err
}
beforeTask = *afterTask
if err = afterTask.ValidateTransitionTo(models.Task_Resolving); err != nil {
logger.Error("invalid-state-transition", err)
return err
}
now := db.clock.Now().UnixNano()
_, err = db.update(logger, tx, tasksTable,
helpers.SQLAttributes{
"state": models.Task_Resolving,
"updated_at": now,
},
"guid = ?", taskGuid,
)
if err != nil {
logger.Error("failed-updating-tasks", err)
return err
}
afterTask.State = models.Task_Resolving
afterTask.UpdatedAt = now
return nil
})
return &beforeTask, afterTask, err
} | [
"func",
"(",
"db",
"*",
"SQLDB",
")",
"ResolvingTask",
"(",
"logger",
"lager",
".",
"Logger",
",",
"taskGuid",
"string",
")",
"(",
"*",
"models",
".",
"Task",
",",
"*",
"models",
".",
"Task",
",",
"error",
")",
"{",
"logger",
"=",
"logger",
".",
"Session",
"(",
"\"",
"\"",
",",
"lager",
".",
"Data",
"{",
"\"",
"\"",
":",
"taskGuid",
"}",
")",
"\n",
"logger",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"defer",
"logger",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n\n",
"var",
"beforeTask",
"models",
".",
"Task",
"\n",
"var",
"afterTask",
"*",
"models",
".",
"Task",
"\n\n",
"err",
":=",
"db",
".",
"transact",
"(",
"logger",
",",
"func",
"(",
"logger",
"lager",
".",
"Logger",
",",
"tx",
"helpers",
".",
"Tx",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"afterTask",
",",
"err",
"=",
"db",
".",
"fetchTaskForUpdate",
"(",
"logger",
",",
"taskGuid",
",",
"tx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"beforeTask",
"=",
"*",
"afterTask",
"\n\n",
"if",
"err",
"=",
"afterTask",
".",
"ValidateTransitionTo",
"(",
"models",
".",
"Task_Resolving",
")",
";",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"now",
":=",
"db",
".",
"clock",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
"\n",
"_",
",",
"err",
"=",
"db",
".",
"update",
"(",
"logger",
",",
"tx",
",",
"tasksTable",
",",
"helpers",
".",
"SQLAttributes",
"{",
"\"",
"\"",
":",
"models",
".",
"Task_Resolving",
",",
"\"",
"\"",
":",
"now",
",",
"}",
",",
"\"",
"\"",
",",
"taskGuid",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"afterTask",
".",
"State",
"=",
"models",
".",
"Task_Resolving",
"\n",
"afterTask",
".",
"UpdatedAt",
"=",
"now",
"\n\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"return",
"&",
"beforeTask",
",",
"afterTask",
",",
"err",
"\n",
"}"
] | // The stager calls this when it wants to claim a completed task. This ensures that only one
// stager ever attempts to handle a completed task | [
"The",
"stager",
"calls",
"this",
"when",
"it",
"wants",
"to",
"claim",
"a",
"completed",
"task",
".",
"This",
"ensures",
"that",
"only",
"one",
"stager",
"ever",
"attempts",
"to",
"handle",
"a",
"completed",
"task"
] | 1978bb997cbd2527cc4fa52798b0af6f6d899698 | https://github.com/cloudfoundry/bbs/blob/1978bb997cbd2527cc4fa52798b0af6f6d899698/db/sqldb/task_db.go#L331-L374 |
5,892 | cloudfoundry/bbs | events/calculator/actual_lrp_event_calculator.go | EmitEvents | func (e ActualLRPEventCalculator) EmitEvents(beforeSet, afterSet []*models.ActualLRP) {
events := []models.Event{}
beforeGroup := models.ResolveActualLRPGroup(beforeSet)
afterGroup := models.ResolveActualLRPGroup(removeNilLRPs(afterSet))
for _, ev := range generateLRPGroupEvents(beforeGroup, afterGroup) {
e.ActualLRPGroupHub.Emit(ev)
}
// stretch the two slices to be of equal size. make sure we do this after
// emitting the group events, otherwise ResolveActualLRPGroup will panic if
// it encounters nil lrps.
stretchSlice(&beforeSet, &afterSet)
for i := range afterSet {
events = append(events, generateLRPInstanceEvents(beforeSet[i], afterSet[i])...)
}
sort.Slice(events, func(i, j int) bool {
return EventScore(events[i]) > EventScore(events[j])
})
for _, ev := range events {
e.ActualLRPInstanceHub.Emit(ev)
}
} | go | func (e ActualLRPEventCalculator) EmitEvents(beforeSet, afterSet []*models.ActualLRP) {
events := []models.Event{}
beforeGroup := models.ResolveActualLRPGroup(beforeSet)
afterGroup := models.ResolveActualLRPGroup(removeNilLRPs(afterSet))
for _, ev := range generateLRPGroupEvents(beforeGroup, afterGroup) {
e.ActualLRPGroupHub.Emit(ev)
}
// stretch the two slices to be of equal size. make sure we do this after
// emitting the group events, otherwise ResolveActualLRPGroup will panic if
// it encounters nil lrps.
stretchSlice(&beforeSet, &afterSet)
for i := range afterSet {
events = append(events, generateLRPInstanceEvents(beforeSet[i], afterSet[i])...)
}
sort.Slice(events, func(i, j int) bool {
return EventScore(events[i]) > EventScore(events[j])
})
for _, ev := range events {
e.ActualLRPInstanceHub.Emit(ev)
}
} | [
"func",
"(",
"e",
"ActualLRPEventCalculator",
")",
"EmitEvents",
"(",
"beforeSet",
",",
"afterSet",
"[",
"]",
"*",
"models",
".",
"ActualLRP",
")",
"{",
"events",
":=",
"[",
"]",
"models",
".",
"Event",
"{",
"}",
"\n\n",
"beforeGroup",
":=",
"models",
".",
"ResolveActualLRPGroup",
"(",
"beforeSet",
")",
"\n",
"afterGroup",
":=",
"models",
".",
"ResolveActualLRPGroup",
"(",
"removeNilLRPs",
"(",
"afterSet",
")",
")",
"\n\n",
"for",
"_",
",",
"ev",
":=",
"range",
"generateLRPGroupEvents",
"(",
"beforeGroup",
",",
"afterGroup",
")",
"{",
"e",
".",
"ActualLRPGroupHub",
".",
"Emit",
"(",
"ev",
")",
"\n",
"}",
"\n\n",
"// stretch the two slices to be of equal size. make sure we do this after",
"// emitting the group events, otherwise ResolveActualLRPGroup will panic if",
"// it encounters nil lrps.",
"stretchSlice",
"(",
"&",
"beforeSet",
",",
"&",
"afterSet",
")",
"\n\n",
"for",
"i",
":=",
"range",
"afterSet",
"{",
"events",
"=",
"append",
"(",
"events",
",",
"generateLRPInstanceEvents",
"(",
"beforeSet",
"[",
"i",
"]",
",",
"afterSet",
"[",
"i",
"]",
")",
"...",
")",
"\n",
"}",
"\n\n",
"sort",
".",
"Slice",
"(",
"events",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"EventScore",
"(",
"events",
"[",
"i",
"]",
")",
">",
"EventScore",
"(",
"events",
"[",
"j",
"]",
")",
"\n",
"}",
")",
"\n\n",
"for",
"_",
",",
"ev",
":=",
"range",
"events",
"{",
"e",
".",
"ActualLRPInstanceHub",
".",
"Emit",
"(",
"ev",
")",
"\n",
"}",
"\n",
"}"
] | // EmitEvents emits the events such as when the changes identified in the
// events are applied to the beforeSet the resulting state is equal to
// afterSet. The beforeSet and afterSet are assumed to have the same process
// guid and index. | [
"EmitEvents",
"emits",
"the",
"events",
"such",
"as",
"when",
"the",
"changes",
"identified",
"in",
"the",
"events",
"are",
"applied",
"to",
"the",
"beforeSet",
"the",
"resulting",
"state",
"is",
"equal",
"to",
"afterSet",
".",
"The",
"beforeSet",
"and",
"afterSet",
"are",
"assumed",
"to",
"have",
"the",
"same",
"process",
"guid",
"and",
"index",
"."
] | 1978bb997cbd2527cc4fa52798b0af6f6d899698 | https://github.com/cloudfoundry/bbs/blob/1978bb997cbd2527cc4fa52798b0af6f6d899698/events/calculator/actual_lrp_event_calculator.go#L85-L111 |
5,893 | cloudfoundry/bbs | events/calculator/actual_lrp_event_calculator.go | getEventLRP | func getEventLRP(e models.Event) (*models.ActualLRP, bool) {
switch x := e.(type) {
case *models.ActualLRPCreatedEvent:
lrp, _, _ := x.ActualLrpGroup.Resolve()
return lrp, false
case *models.ActualLRPChangedEvent:
lrp, _, _ := x.After.Resolve()
return lrp, false
case *models.ActualLRPInstanceCreatedEvent:
return x.ActualLrp, false
case *models.ActualLRPInstanceChangedEvent:
return x.After.ToActualLRP(x.ActualLRPKey, x.ActualLRPInstanceKey), false
case *models.ActualLRPCrashedEvent:
return nil, true
}
return nil, false
} | go | func getEventLRP(e models.Event) (*models.ActualLRP, bool) {
switch x := e.(type) {
case *models.ActualLRPCreatedEvent:
lrp, _, _ := x.ActualLrpGroup.Resolve()
return lrp, false
case *models.ActualLRPChangedEvent:
lrp, _, _ := x.After.Resolve()
return lrp, false
case *models.ActualLRPInstanceCreatedEvent:
return x.ActualLrp, false
case *models.ActualLRPInstanceChangedEvent:
return x.After.ToActualLRP(x.ActualLRPKey, x.ActualLRPInstanceKey), false
case *models.ActualLRPCrashedEvent:
return nil, true
}
return nil, false
} | [
"func",
"getEventLRP",
"(",
"e",
"models",
".",
"Event",
")",
"(",
"*",
"models",
".",
"ActualLRP",
",",
"bool",
")",
"{",
"switch",
"x",
":=",
"e",
".",
"(",
"type",
")",
"{",
"case",
"*",
"models",
".",
"ActualLRPCreatedEvent",
":",
"lrp",
",",
"_",
",",
"_",
":=",
"x",
".",
"ActualLrpGroup",
".",
"Resolve",
"(",
")",
"\n",
"return",
"lrp",
",",
"false",
"\n",
"case",
"*",
"models",
".",
"ActualLRPChangedEvent",
":",
"lrp",
",",
"_",
",",
"_",
":=",
"x",
".",
"After",
".",
"Resolve",
"(",
")",
"\n",
"return",
"lrp",
",",
"false",
"\n",
"case",
"*",
"models",
".",
"ActualLRPInstanceCreatedEvent",
":",
"return",
"x",
".",
"ActualLrp",
",",
"false",
"\n",
"case",
"*",
"models",
".",
"ActualLRPInstanceChangedEvent",
":",
"return",
"x",
".",
"After",
".",
"ToActualLRP",
"(",
"x",
".",
"ActualLRPKey",
",",
"x",
".",
"ActualLRPInstanceKey",
")",
",",
"false",
"\n",
"case",
"*",
"models",
".",
"ActualLRPCrashedEvent",
":",
"return",
"nil",
",",
"true",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"false",
"\n",
"}"
] | // return the resulting lrp of the given event, that is the lrp being created
// or the lrp in the new lrp in a ActualLRPChanged event. Returns nil for
// crashed and removed events. Returns true iff this is a crashed event. | [
"return",
"the",
"resulting",
"lrp",
"of",
"the",
"given",
"event",
"that",
"is",
"the",
"lrp",
"being",
"created",
"or",
"the",
"lrp",
"in",
"the",
"new",
"lrp",
"in",
"a",
"ActualLRPChanged",
"event",
".",
"Returns",
"nil",
"for",
"crashed",
"and",
"removed",
"events",
".",
"Returns",
"true",
"iff",
"this",
"is",
"a",
"crashed",
"event",
"."
] | 1978bb997cbd2527cc4fa52798b0af6f6d899698 | https://github.com/cloudfoundry/bbs/blob/1978bb997cbd2527cc4fa52798b0af6f6d899698/events/calculator/actual_lrp_event_calculator.go#L273-L290 |
5,894 | cloudfoundry/bbs | events/calculator/actual_lrp_event_calculator.go | EventScore | func EventScore(e models.Event) int {
lrp, crashed := getEventLRP(e)
// sort crashed events first to be backward compatible with the old
// event stream which emitted the crashed event before the
// remove/changed events.
if crashed {
return 2
}
// this is an event with a running instance, this should be emitted before
// any other event, such as removed ro changed event to non-running state.
if lrp != nil && lrp.State == models.ActualLRPStateRunning {
return 1
}
// The event is either a RemovedEvent or a ChangedEvent (to a non-RUNNING
// state). These are prioritized last, because those events cause loss of
// routability.
return 0
} | go | func EventScore(e models.Event) int {
lrp, crashed := getEventLRP(e)
// sort crashed events first to be backward compatible with the old
// event stream which emitted the crashed event before the
// remove/changed events.
if crashed {
return 2
}
// this is an event with a running instance, this should be emitted before
// any other event, such as removed ro changed event to non-running state.
if lrp != nil && lrp.State == models.ActualLRPStateRunning {
return 1
}
// The event is either a RemovedEvent or a ChangedEvent (to a non-RUNNING
// state). These are prioritized last, because those events cause loss of
// routability.
return 0
} | [
"func",
"EventScore",
"(",
"e",
"models",
".",
"Event",
")",
"int",
"{",
"lrp",
",",
"crashed",
":=",
"getEventLRP",
"(",
"e",
")",
"\n\n",
"// sort crashed events first to be backward compatible with the old",
"// event stream which emitted the crashed event before the",
"// remove/changed events.",
"if",
"crashed",
"{",
"return",
"2",
"\n",
"}",
"\n\n",
"// this is an event with a running instance, this should be emitted before",
"// any other event, such as removed ro changed event to non-running state.",
"if",
"lrp",
"!=",
"nil",
"&&",
"lrp",
".",
"State",
"==",
"models",
".",
"ActualLRPStateRunning",
"{",
"return",
"1",
"\n",
"}",
"\n\n",
"// The event is either a RemovedEvent or a ChangedEvent (to a non-RUNNING",
"// state). These are prioritized last, because those events cause loss of",
"// routability.",
"return",
"0",
"\n",
"}"
] | // Determine the score of an event. An event with higher score should be
// emitted before lower ones. The score based ordering ensures continuous
// routability, so events with running instances should be emitted first
// followed by remove events. | [
"Determine",
"the",
"score",
"of",
"an",
"event",
".",
"An",
"event",
"with",
"higher",
"score",
"should",
"be",
"emitted",
"before",
"lower",
"ones",
".",
"The",
"score",
"based",
"ordering",
"ensures",
"continuous",
"routability",
"so",
"events",
"with",
"running",
"instances",
"should",
"be",
"emitted",
"first",
"followed",
"by",
"remove",
"events",
"."
] | 1978bb997cbd2527cc4fa52798b0af6f6d899698 | https://github.com/cloudfoundry/bbs/blob/1978bb997cbd2527cc4fa52798b0af6f6d899698/events/calculator/actual_lrp_event_calculator.go#L296-L316 |
5,895 | cloudfoundry/bbs | events/calculator/actual_lrp_event_calculator.go | removeNilLRPs | func removeNilLRPs(lrps []*models.ActualLRP) []*models.ActualLRP {
newLRPs := []*models.ActualLRP{}
for _, l := range lrps {
if l == nil {
continue
}
newLRPs = append(newLRPs, l)
}
return newLRPs
} | go | func removeNilLRPs(lrps []*models.ActualLRP) []*models.ActualLRP {
newLRPs := []*models.ActualLRP{}
for _, l := range lrps {
if l == nil {
continue
}
newLRPs = append(newLRPs, l)
}
return newLRPs
} | [
"func",
"removeNilLRPs",
"(",
"lrps",
"[",
"]",
"*",
"models",
".",
"ActualLRP",
")",
"[",
"]",
"*",
"models",
".",
"ActualLRP",
"{",
"newLRPs",
":=",
"[",
"]",
"*",
"models",
".",
"ActualLRP",
"{",
"}",
"\n",
"for",
"_",
",",
"l",
":=",
"range",
"lrps",
"{",
"if",
"l",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"newLRPs",
"=",
"append",
"(",
"newLRPs",
",",
"l",
")",
"\n",
"}",
"\n",
"return",
"newLRPs",
"\n",
"}"
] | // A Helper function to remove null lrps that could be added to the set if an
// LRP is removed. | [
"A",
"Helper",
"function",
"to",
"remove",
"null",
"lrps",
"that",
"could",
"be",
"added",
"to",
"the",
"set",
"if",
"an",
"LRP",
"is",
"removed",
"."
] | 1978bb997cbd2527cc4fa52798b0af6f6d899698 | https://github.com/cloudfoundry/bbs/blob/1978bb997cbd2527cc4fa52798b0af6f6d899698/events/calculator/actual_lrp_event_calculator.go#L331-L340 |
5,896 | cloudfoundry/bbs | models/volume_mount.go | Validate | func (v *VolumeMount) Validate() error {
var ve ValidationError
if v.Driver == "" {
ve = ve.Append(errors.New("invalid volume_mount driver"))
}
if !(v.Mode == "r" || v.Mode == "rw") {
ve = ve.Append(errors.New("invalid volume_mount mode"))
}
if v.Shared != nil && v.Shared.VolumeId == "" {
ve = ve.Append(errors.New("invalid volume_mount volume id"))
}
if !ve.Empty() {
return ve
}
return nil
} | go | func (v *VolumeMount) Validate() error {
var ve ValidationError
if v.Driver == "" {
ve = ve.Append(errors.New("invalid volume_mount driver"))
}
if !(v.Mode == "r" || v.Mode == "rw") {
ve = ve.Append(errors.New("invalid volume_mount mode"))
}
if v.Shared != nil && v.Shared.VolumeId == "" {
ve = ve.Append(errors.New("invalid volume_mount volume id"))
}
if !ve.Empty() {
return ve
}
return nil
} | [
"func",
"(",
"v",
"*",
"VolumeMount",
")",
"Validate",
"(",
")",
"error",
"{",
"var",
"ve",
"ValidationError",
"\n",
"if",
"v",
".",
"Driver",
"==",
"\"",
"\"",
"{",
"ve",
"=",
"ve",
".",
"Append",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"if",
"!",
"(",
"v",
".",
"Mode",
"==",
"\"",
"\"",
"||",
"v",
".",
"Mode",
"==",
"\"",
"\"",
")",
"{",
"ve",
"=",
"ve",
".",
"Append",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"if",
"v",
".",
"Shared",
"!=",
"nil",
"&&",
"v",
".",
"Shared",
".",
"VolumeId",
"==",
"\"",
"\"",
"{",
"ve",
"=",
"ve",
".",
"Append",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"ve",
".",
"Empty",
"(",
")",
"{",
"return",
"ve",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // while volume mounts are experimental, we should never persist a "old" volume
// mount to the db layer, so the handler must convert old data models to the new ones
// when volume mounts are no longer experimental, this validation strategy must be reconsidered | [
"while",
"volume",
"mounts",
"are",
"experimental",
"we",
"should",
"never",
"persist",
"a",
"old",
"volume",
"mount",
"to",
"the",
"db",
"layer",
"so",
"the",
"handler",
"must",
"convert",
"old",
"data",
"models",
"to",
"the",
"new",
"ones",
"when",
"volume",
"mounts",
"are",
"no",
"longer",
"experimental",
"this",
"validation",
"strategy",
"must",
"be",
"reconsidered"
] | 1978bb997cbd2527cc4fa52798b0af6f6d899698 | https://github.com/cloudfoundry/bbs/blob/1978bb997cbd2527cc4fa52798b0af6f6d899698/models/volume_mount.go#L20-L37 |
5,897 | cloudfoundry/bbs | db/sqldb/desired_lrp_db.go | fetchDesiredLRPSchedulingInfoAndMore | func (db *SQLDB) fetchDesiredLRPSchedulingInfoAndMore(logger lager.Logger, scanner helpers.RowScanner, dest ...interface{}) (*models.DesiredLRPSchedulingInfo, error) {
schedulingInfo := &models.DesiredLRPSchedulingInfo{}
var routeData, volumePlacementData, placementTagData []byte
values := []interface{}{
&schedulingInfo.ProcessGuid,
&schedulingInfo.Domain,
&schedulingInfo.LogGuid,
&schedulingInfo.Annotation,
&schedulingInfo.Instances,
&schedulingInfo.MemoryMb,
&schedulingInfo.DiskMb,
&schedulingInfo.MaxPids,
&schedulingInfo.RootFs,
&routeData,
&volumePlacementData,
&schedulingInfo.ModificationTag.Epoch,
&schedulingInfo.ModificationTag.Index,
&placementTagData,
}
values = append(values, dest...)
err := scanner.Scan(values...)
if err == sql.ErrNoRows {
return nil, err
}
if err != nil {
logger.Error("failed-scanning", err)
return nil, err
}
var routes models.Routes
encodedData, err := db.encoder.Decode(routeData)
if err != nil {
logger.Error("failed-decrypting-routes", err)
return nil, err
}
err = json.Unmarshal(encodedData, &routes)
if err != nil {
logger.Error("failed-parsing-routes", err)
return nil, err
}
schedulingInfo.Routes = routes
var volumePlacement models.VolumePlacement
err = db.deserializeModel(logger, volumePlacementData, &volumePlacement)
if err != nil {
logger.Error("failed-parsing-volume-placement", err)
return nil, err
}
schedulingInfo.VolumePlacement = &volumePlacement
if placementTagData != nil {
err = json.Unmarshal(placementTagData, &schedulingInfo.PlacementTags)
if err != nil {
logger.Error("failed-parsing-placement-tags", err)
return nil, err
}
}
return schedulingInfo, nil
} | go | func (db *SQLDB) fetchDesiredLRPSchedulingInfoAndMore(logger lager.Logger, scanner helpers.RowScanner, dest ...interface{}) (*models.DesiredLRPSchedulingInfo, error) {
schedulingInfo := &models.DesiredLRPSchedulingInfo{}
var routeData, volumePlacementData, placementTagData []byte
values := []interface{}{
&schedulingInfo.ProcessGuid,
&schedulingInfo.Domain,
&schedulingInfo.LogGuid,
&schedulingInfo.Annotation,
&schedulingInfo.Instances,
&schedulingInfo.MemoryMb,
&schedulingInfo.DiskMb,
&schedulingInfo.MaxPids,
&schedulingInfo.RootFs,
&routeData,
&volumePlacementData,
&schedulingInfo.ModificationTag.Epoch,
&schedulingInfo.ModificationTag.Index,
&placementTagData,
}
values = append(values, dest...)
err := scanner.Scan(values...)
if err == sql.ErrNoRows {
return nil, err
}
if err != nil {
logger.Error("failed-scanning", err)
return nil, err
}
var routes models.Routes
encodedData, err := db.encoder.Decode(routeData)
if err != nil {
logger.Error("failed-decrypting-routes", err)
return nil, err
}
err = json.Unmarshal(encodedData, &routes)
if err != nil {
logger.Error("failed-parsing-routes", err)
return nil, err
}
schedulingInfo.Routes = routes
var volumePlacement models.VolumePlacement
err = db.deserializeModel(logger, volumePlacementData, &volumePlacement)
if err != nil {
logger.Error("failed-parsing-volume-placement", err)
return nil, err
}
schedulingInfo.VolumePlacement = &volumePlacement
if placementTagData != nil {
err = json.Unmarshal(placementTagData, &schedulingInfo.PlacementTags)
if err != nil {
logger.Error("failed-parsing-placement-tags", err)
return nil, err
}
}
return schedulingInfo, nil
} | [
"func",
"(",
"db",
"*",
"SQLDB",
")",
"fetchDesiredLRPSchedulingInfoAndMore",
"(",
"logger",
"lager",
".",
"Logger",
",",
"scanner",
"helpers",
".",
"RowScanner",
",",
"dest",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"models",
".",
"DesiredLRPSchedulingInfo",
",",
"error",
")",
"{",
"schedulingInfo",
":=",
"&",
"models",
".",
"DesiredLRPSchedulingInfo",
"{",
"}",
"\n",
"var",
"routeData",
",",
"volumePlacementData",
",",
"placementTagData",
"[",
"]",
"byte",
"\n",
"values",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"&",
"schedulingInfo",
".",
"ProcessGuid",
",",
"&",
"schedulingInfo",
".",
"Domain",
",",
"&",
"schedulingInfo",
".",
"LogGuid",
",",
"&",
"schedulingInfo",
".",
"Annotation",
",",
"&",
"schedulingInfo",
".",
"Instances",
",",
"&",
"schedulingInfo",
".",
"MemoryMb",
",",
"&",
"schedulingInfo",
".",
"DiskMb",
",",
"&",
"schedulingInfo",
".",
"MaxPids",
",",
"&",
"schedulingInfo",
".",
"RootFs",
",",
"&",
"routeData",
",",
"&",
"volumePlacementData",
",",
"&",
"schedulingInfo",
".",
"ModificationTag",
".",
"Epoch",
",",
"&",
"schedulingInfo",
".",
"ModificationTag",
".",
"Index",
",",
"&",
"placementTagData",
",",
"}",
"\n",
"values",
"=",
"append",
"(",
"values",
",",
"dest",
"...",
")",
"\n\n",
"err",
":=",
"scanner",
".",
"Scan",
"(",
"values",
"...",
")",
"\n",
"if",
"err",
"==",
"sql",
".",
"ErrNoRows",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"routes",
"models",
".",
"Routes",
"\n",
"encodedData",
",",
"err",
":=",
"db",
".",
"encoder",
".",
"Decode",
"(",
"routeData",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"encodedData",
",",
"&",
"routes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"schedulingInfo",
".",
"Routes",
"=",
"routes",
"\n\n",
"var",
"volumePlacement",
"models",
".",
"VolumePlacement",
"\n",
"err",
"=",
"db",
".",
"deserializeModel",
"(",
"logger",
",",
"volumePlacementData",
",",
"&",
"volumePlacement",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"schedulingInfo",
".",
"VolumePlacement",
"=",
"&",
"volumePlacement",
"\n",
"if",
"placementTagData",
"!=",
"nil",
"{",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"placementTagData",
",",
"&",
"schedulingInfo",
".",
"PlacementTags",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"schedulingInfo",
",",
"nil",
"\n",
"}"
] | // "rows" needs to have the columns defined in the schedulingInfoColumns constant | [
"rows",
"needs",
"to",
"have",
"the",
"columns",
"defined",
"in",
"the",
"schedulingInfoColumns",
"constant"
] | 1978bb997cbd2527cc4fa52798b0af6f6d899698 | https://github.com/cloudfoundry/bbs/blob/1978bb997cbd2527cc4fa52798b0af6f6d899698/db/sqldb/desired_lrp_db.go#L293-L353 |
5,898 | cloudfoundry/bbs | db/sqldb/lrp_convergence.go | staleUnclaimedActualLRPs | func (c *convergence) staleUnclaimedActualLRPs(logger lager.Logger, now time.Time) {
logger = logger.Session("stale-unclaimed-actual-lrps")
rows, err := c.selectStaleUnclaimedLRPs(logger, c.db, now)
if err != nil {
logger.Error("failed-query", err)
return
}
for rows.Next() {
var index int
schedulingInfo, err := c.fetchDesiredLRPSchedulingInfoAndMore(logger, rows, &index)
if err != nil {
continue
}
key := models.NewActualLRPKey(schedulingInfo.ProcessGuid, int32(index), schedulingInfo.Domain)
c.unstartedLRPKeys = append(c.unstartedLRPKeys, &models.ActualLRPKeyWithSchedulingInfo{
Key: &key,
SchedulingInfo: schedulingInfo,
})
logger.Info("creating-start-request",
lager.Data{"reason": "stale-unclaimed-lrp", "process_guid": schedulingInfo.ProcessGuid, "index": index})
}
if rows.Err() != nil {
logger.Error("failed-getting-next-row", rows.Err())
}
return
} | go | func (c *convergence) staleUnclaimedActualLRPs(logger lager.Logger, now time.Time) {
logger = logger.Session("stale-unclaimed-actual-lrps")
rows, err := c.selectStaleUnclaimedLRPs(logger, c.db, now)
if err != nil {
logger.Error("failed-query", err)
return
}
for rows.Next() {
var index int
schedulingInfo, err := c.fetchDesiredLRPSchedulingInfoAndMore(logger, rows, &index)
if err != nil {
continue
}
key := models.NewActualLRPKey(schedulingInfo.ProcessGuid, int32(index), schedulingInfo.Domain)
c.unstartedLRPKeys = append(c.unstartedLRPKeys, &models.ActualLRPKeyWithSchedulingInfo{
Key: &key,
SchedulingInfo: schedulingInfo,
})
logger.Info("creating-start-request",
lager.Data{"reason": "stale-unclaimed-lrp", "process_guid": schedulingInfo.ProcessGuid, "index": index})
}
if rows.Err() != nil {
logger.Error("failed-getting-next-row", rows.Err())
}
return
} | [
"func",
"(",
"c",
"*",
"convergence",
")",
"staleUnclaimedActualLRPs",
"(",
"logger",
"lager",
".",
"Logger",
",",
"now",
"time",
".",
"Time",
")",
"{",
"logger",
"=",
"logger",
".",
"Session",
"(",
"\"",
"\"",
")",
"\n\n",
"rows",
",",
"err",
":=",
"c",
".",
"selectStaleUnclaimedLRPs",
"(",
"logger",
",",
"c",
".",
"db",
",",
"now",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"index",
"int",
"\n",
"schedulingInfo",
",",
"err",
":=",
"c",
".",
"fetchDesiredLRPSchedulingInfoAndMore",
"(",
"logger",
",",
"rows",
",",
"&",
"index",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"key",
":=",
"models",
".",
"NewActualLRPKey",
"(",
"schedulingInfo",
".",
"ProcessGuid",
",",
"int32",
"(",
"index",
")",
",",
"schedulingInfo",
".",
"Domain",
")",
"\n",
"c",
".",
"unstartedLRPKeys",
"=",
"append",
"(",
"c",
".",
"unstartedLRPKeys",
",",
"&",
"models",
".",
"ActualLRPKeyWithSchedulingInfo",
"{",
"Key",
":",
"&",
"key",
",",
"SchedulingInfo",
":",
"schedulingInfo",
",",
"}",
")",
"\n",
"logger",
".",
"Info",
"(",
"\"",
"\"",
",",
"lager",
".",
"Data",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"schedulingInfo",
".",
"ProcessGuid",
",",
"\"",
"\"",
":",
"index",
"}",
")",
"\n",
"}",
"\n\n",
"if",
"rows",
".",
"Err",
"(",
")",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"rows",
".",
"Err",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // Adds stale UNCLAIMED Actual LRPs to the list of start requests. | [
"Adds",
"stale",
"UNCLAIMED",
"Actual",
"LRPs",
"to",
"the",
"list",
"of",
"start",
"requests",
"."
] | 1978bb997cbd2527cc4fa52798b0af6f6d899698 | https://github.com/cloudfoundry/bbs/blob/1978bb997cbd2527cc4fa52798b0af6f6d899698/db/sqldb/lrp_convergence.go#L81-L110 |
5,899 | cloudfoundry/bbs | db/sqldb/lrp_convergence.go | crashedActualLRPs | func (c *convergence) crashedActualLRPs(logger lager.Logger, now time.Time) {
logger = logger.Session("crashed-actual-lrps")
restartCalculator := models.NewDefaultRestartCalculator()
rows, err := c.selectCrashedLRPs(logger, c.db)
if err != nil {
logger.Error("failed-query", err)
return
}
for rows.Next() {
var index int
actual := &models.ActualLRP{}
schedulingInfo, err := c.fetchDesiredLRPSchedulingInfoAndMore(logger, rows, &index, &actual.Since, &actual.CrashCount)
if err != nil {
continue
}
actual.ActualLRPKey = models.NewActualLRPKey(schedulingInfo.ProcessGuid, int32(index), schedulingInfo.Domain)
actual.State = models.ActualLRPStateCrashed
if actual.ShouldRestartCrash(now, restartCalculator) {
c.unstartedLRPKeys = append(c.unstartedLRPKeys, &models.ActualLRPKeyWithSchedulingInfo{
Key: &actual.ActualLRPKey,
SchedulingInfo: schedulingInfo,
})
logger.Info("creating-start-request",
lager.Data{"reason": "crashed-instance", "process_guid": actual.ProcessGuid, "index": index})
}
}
if rows.Err() != nil {
logger.Error("failed-getting-next-row", rows.Err())
}
return
} | go | func (c *convergence) crashedActualLRPs(logger lager.Logger, now time.Time) {
logger = logger.Session("crashed-actual-lrps")
restartCalculator := models.NewDefaultRestartCalculator()
rows, err := c.selectCrashedLRPs(logger, c.db)
if err != nil {
logger.Error("failed-query", err)
return
}
for rows.Next() {
var index int
actual := &models.ActualLRP{}
schedulingInfo, err := c.fetchDesiredLRPSchedulingInfoAndMore(logger, rows, &index, &actual.Since, &actual.CrashCount)
if err != nil {
continue
}
actual.ActualLRPKey = models.NewActualLRPKey(schedulingInfo.ProcessGuid, int32(index), schedulingInfo.Domain)
actual.State = models.ActualLRPStateCrashed
if actual.ShouldRestartCrash(now, restartCalculator) {
c.unstartedLRPKeys = append(c.unstartedLRPKeys, &models.ActualLRPKeyWithSchedulingInfo{
Key: &actual.ActualLRPKey,
SchedulingInfo: schedulingInfo,
})
logger.Info("creating-start-request",
lager.Data{"reason": "crashed-instance", "process_guid": actual.ProcessGuid, "index": index})
}
}
if rows.Err() != nil {
logger.Error("failed-getting-next-row", rows.Err())
}
return
} | [
"func",
"(",
"c",
"*",
"convergence",
")",
"crashedActualLRPs",
"(",
"logger",
"lager",
".",
"Logger",
",",
"now",
"time",
".",
"Time",
")",
"{",
"logger",
"=",
"logger",
".",
"Session",
"(",
"\"",
"\"",
")",
"\n",
"restartCalculator",
":=",
"models",
".",
"NewDefaultRestartCalculator",
"(",
")",
"\n\n",
"rows",
",",
"err",
":=",
"c",
".",
"selectCrashedLRPs",
"(",
"logger",
",",
"c",
".",
"db",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"index",
"int",
"\n",
"actual",
":=",
"&",
"models",
".",
"ActualLRP",
"{",
"}",
"\n\n",
"schedulingInfo",
",",
"err",
":=",
"c",
".",
"fetchDesiredLRPSchedulingInfoAndMore",
"(",
"logger",
",",
"rows",
",",
"&",
"index",
",",
"&",
"actual",
".",
"Since",
",",
"&",
"actual",
".",
"CrashCount",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"actual",
".",
"ActualLRPKey",
"=",
"models",
".",
"NewActualLRPKey",
"(",
"schedulingInfo",
".",
"ProcessGuid",
",",
"int32",
"(",
"index",
")",
",",
"schedulingInfo",
".",
"Domain",
")",
"\n",
"actual",
".",
"State",
"=",
"models",
".",
"ActualLRPStateCrashed",
"\n\n",
"if",
"actual",
".",
"ShouldRestartCrash",
"(",
"now",
",",
"restartCalculator",
")",
"{",
"c",
".",
"unstartedLRPKeys",
"=",
"append",
"(",
"c",
".",
"unstartedLRPKeys",
",",
"&",
"models",
".",
"ActualLRPKeyWithSchedulingInfo",
"{",
"Key",
":",
"&",
"actual",
".",
"ActualLRPKey",
",",
"SchedulingInfo",
":",
"schedulingInfo",
",",
"}",
")",
"\n",
"logger",
".",
"Info",
"(",
"\"",
"\"",
",",
"lager",
".",
"Data",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"actual",
".",
"ProcessGuid",
",",
"\"",
"\"",
":",
"index",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"rows",
".",
"Err",
"(",
")",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"rows",
".",
"Err",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // Adds CRASHED Actual LRPs that can be restarted to the list of start requests
// and transitions them to UNCLAIMED. | [
"Adds",
"CRASHED",
"Actual",
"LRPs",
"that",
"can",
"be",
"restarted",
"to",
"the",
"list",
"of",
"start",
"requests",
"and",
"transitions",
"them",
"to",
"UNCLAIMED",
"."
] | 1978bb997cbd2527cc4fa52798b0af6f6d899698 | https://github.com/cloudfoundry/bbs/blob/1978bb997cbd2527cc4fa52798b0af6f6d899698/db/sqldb/lrp_convergence.go#L114-L151 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.