Repository: markus-wa/demoinfocs-golang
Pull request #288 (2021-05-14 18:57:32)

sendtables: make property type public via Property.Type()

codecov[bot]: # [Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/288?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) Report
> Merging [#288](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/288?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) (16395e3) into [master](https://codecov.io/gh/markus-wa/demoinfocs-golang/commit/9190856f2d2fd310465eebb4dd925ef0eda2ca74?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) (9190856) will **decrease** coverage by `0.03%`.
> The diff coverage is `0.00%`.

[![Impacted file tree graph](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/288/graphs/tree.svg?width=650&height=150&src=pr&token=20emCaZRHz&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus)](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/288?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus)

```diff
@@            Coverage Diff             @@
##           master     #288      +/-   ##
==========================================
- Coverage   92.06%   92.02%   -0.04%     
==========================================
  Files          29       29              
  Lines        2470     2471       +1     
==========================================
  Hits         2274     2274              
- Misses        144      145       +1     
  Partials       52       52              
```


| [Impacted Files](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/288?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) | Coverage Δ | |
|---|---|---|
| [pkg/demoinfocs/sendtables/entity.go](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/288/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus#diff-cGtnL2RlbW9pbmZvY3Mvc2VuZHRhYmxlcy9lbnRpdHkuZ28=) | `87.87% <0.00%> (-0.68%)` | :arrow_down: |
| [pkg/demoinfocs/sendtables/propdecoder.go](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/288/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus#diff-cGtnL2RlbW9pbmZvY3Mvc2VuZHRhYmxlcy9wcm9wZGVjb2Rlci5nbw==) | `75.00% <ø> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/288?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/288?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus). Last update [9190856...16395e3](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/288?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus).


Patch:
diff --git a/pkg/demoinfocs/events/events.go b/pkg/demoinfocs/events/events.go
index ac7f69d..ae9a5b9 100644
--- a/pkg/demoinfocs/events/events.go
+++ b/pkg/demoinfocs/events/events.go
@@ -488,7 +488,7 @@ type ItemDrop struct {
 }
 
 // DataTablesParsed signals that the datatables were parsed.
-// You can use the Parser.SendTableParser() after this event to register update notification on entities & properties.
+// You can use the Parser.ServerClasses() after this event to register update notification on entities & properties.
 type DataTablesParsed struct{}
 
 // StringTableCreated signals that a string table was created via net message.
diff --git a/pkg/demoinfocs/sendtables/entity.go b/pkg/demoinfocs/sendtables/entity.go
index 4eafc84..1dfe4b9 100644
--- a/pkg/demoinfocs/sendtables/entity.go
+++ b/pkg/demoinfocs/sendtables/entity.go
@@ -314,11 +314,16 @@ func (pe *property) Name() string {
 	return pe.entry.name
 }
 
-// Value returns current value of the property.
+// Value returns the current value of the property.
 func (pe *property) Value() PropertyValue {
 	return pe.value
 }
 
+// Type returns the data type of the property.
+func (pe *property) Type() PropertyType {
+	return PropertyType(pe.entry.prop.rawType)
+}
+
 // PropertyValueType specifies the type of a PropertyValue
 type PropertyValueType int
 
diff --git a/pkg/demoinfocs/sendtables/fake/property.go b/pkg/demoinfocs/sendtables/fake/property.go
index b8ca7a6..2882c5a 100644
--- a/pkg/demoinfocs/sendtables/fake/property.go
+++ b/pkg/demoinfocs/sendtables/fake/property.go
@@ -23,6 +23,11 @@ func (p *Property) Value() st.PropertyValue {
 	return p.Called().Get(0).(st.PropertyValue)
 }
 
+// Type is a mock-implementation of Property.Type().
+func (p *Property) Type() st.PropertyType {
+	return p.Called().Get(0).(st.PropertyType)
+}
+
 // OnUpdate is a mock-implementation of Property.OnUpdate().
 func (p *Property) OnUpdate(handler st.PropertyUpdateHandler) {
 	p.Called(handler)
diff --git a/pkg/demoinfocs/sendtables/propdecoder.go b/pkg/demoinfocs/sendtables/propdecoder.go
index cd68bf2..a3307e4 100644
--- a/pkg/demoinfocs/sendtables/propdecoder.go
+++ b/pkg/demoinfocs/sendtables/propdecoder.go
@@ -21,6 +21,22 @@ const (
 	propTypeInt64
 )
 
+// PropertyType identifies the data type of a property.
+type PropertyType int
+
+// PropType constants are duplicated as publics so we don't have to convert ints to PropertyType for normal use.
+
+const (
+	PropTypeInt PropertyType = iota
+	PropTypeFloat
+	PropTypeVector
+	PropTypeVectorXY
+	PropTypeString
+	PropTypeArray
+	PropTypeDataTable
+	PropTypeInt64
+)
+
 const (
 	coordFractionalBitsMp             = 5
 	coordFractionalBitsMpLowPrecision = 3
diff --git a/pkg/demoinfocs/sendtables/property_interface.go b/pkg/demoinfocs/sendtables/property_interface.go
index 713404d..61edcfb 100644
--- a/pkg/demoinfocs/sendtables/property_interface.go
+++ b/pkg/demoinfocs/sendtables/property_interface.go
@@ -8,8 +8,10 @@ package sendtables
 type Property interface {
 	// Name returns the property's name.
 	Name() string
-	// Value returns current value of the property.
+	// Value returns the current value of the property.
 	Value() PropertyValue
+	// Type returns the data type of the property.
+	Type() PropertyType
 	// OnUpdate registers a handler for updates of the property's value.
 	//
 	// The handler will be called with the current value upon registration.


Test patch:
diff --git a/pkg/demoinfocs/sendtables/entity_test.go b/pkg/demoinfocs/sendtables/entity_test.go
index f840135..90303bb 100644
--- a/pkg/demoinfocs/sendtables/entity_test.go
+++ b/pkg/demoinfocs/sendtables/entity_test.go
@@ -68,3 +68,9 @@ func TestProperty_Name(t *testing.T) {
 
 	assert.Equal(t, "test", prop.Name())
 }
+
+func TestProperty_Type(t *testing.T) {
+	prop := property{entry: &flattenedPropEntry{prop: &sendTableProperty{rawType: 1}}}
+
+	assert.Equal(t, PropTypeFloat, prop.Type())
+}