2828
2929// Decoder wraps a Section method for decoding a section of a given size.
3030type Decoder interface {
31+ // RepFormat returns the replay format
32+ RepFormat () RepFormat
33+
3134 // NewSection must be called between sections.
3235 // ErrNoMoreSections is returned if the replay has no more sections.
3336 NewSection () error
@@ -63,7 +66,7 @@ func NewFromFile(name string) (d Decoder, err error) {
6366 return nil , fmt .Errorf ("not a file: %s" , name )
6467 }
6568
66- var rf repFormat
69+ var rf RepFormat
6770 if stat .Size () >= 30 {
6871 fileHeader := make ([]byte , 30 )
6972 if _ , err = io .ReadFull (f , fileHeader ); err != nil {
@@ -81,23 +84,23 @@ func NewFromFile(name string) (d Decoder, err error) {
8184// New creates a new Decoder that reads and decompresses data from the
8285// given byte slice.
8386func New (repData []byte ) Decoder {
84- rf := repFormatUnknown
87+ rf := RepFormatUnknown
8588 if len (repData ) >= 30 {
8689 rf = detectRepFormat (repData [:30 ])
8790 }
8891
8992 return newDecoder (bytes .NewBuffer (repData ), rf )
9093}
9194
92- // repFormat identifies the replay format
93- type repFormat int
95+ // RepFormat identifies the replay format
96+ type RepFormat int
9497
9598// Possible values of repFormat
9699const (
97- repFormatUnknown repFormat = iota // Unknown replay format
98- repFormatLegacy // Legacy replay format (pre 1.18)
99- repFormatModern // Modern replay format (1.18 - 1.20)
100- repFormatModern121 // Modern 1.21 replay format (starting from 1.21)
100+ RepFormatUnknown RepFormat = iota // Unknown replay format
101+ RepFormatLegacy // Legacy replay format (pre 1.18)
102+ RepFormatModern // Modern replay format (1.18 - 1.20)
103+ RepFormatModern121 // Modern 1.21 replay format (starting from 1.21)
101104)
102105
103106// detectRepFormat detects the replay format based on the file header
@@ -107,15 +110,15 @@ const (
107110// data block of the Header section (which starts at offset 28).
108111// If the compressed data block starts with the magic of the valid zlib header,
109112// it is modern. If it is modern, the replay ID data decides which version.
110- func detectRepFormat (fileHeader []byte ) repFormat {
113+ func detectRepFormat (fileHeader []byte ) RepFormat {
111114 if len (fileHeader ) < 30 {
112- return repFormatUnknown
115+ return RepFormatUnknown
113116 }
114117
115118 // legacy and pre 1.21 modern replays have replay ID data "reRS".
116119 // Starting from 1.21, replay ID data is "seRS".
117120 if fileHeader [12 ] == 's' {
118- return repFormatModern121
121+ return RepFormatModern121
119122 }
120123
121124 // It's pre 1.21, check if legacy:
@@ -127,16 +130,16 @@ func detectRepFormat(fileHeader []byte) repFormat {
127130 // 0x9C level 6 (default compression?)
128131 // 0xDA level 7..9
129132 if fileHeader [28 ] != 0x78 {
130- return repFormatLegacy
133+ return RepFormatLegacy
131134 }
132135
133- return repFormatModern
136+ return RepFormatModern
134137}
135138
136139// newDecoder creates a new Decoder that reads and decompresses data from the given Reader.
137140// The source is treated as a modern replay if modern is true, else as a
138141// legacy replay.
139- func newDecoder (r io.Reader , rf repFormat ) Decoder {
142+ func newDecoder (r io.Reader , rf RepFormat ) Decoder {
140143 dec := decoder {
141144 r : r ,
142145 rf : rf ,
@@ -145,7 +148,7 @@ func newDecoder(r io.Reader, rf repFormat) Decoder {
145148 }
146149
147150 switch rf {
148- case repFormatModern , repFormatModern121 :
151+ case RepFormatModern , RepFormatModern121 :
149152 return & modernDecoder {
150153 decoder : dec ,
151154 }
@@ -163,7 +166,7 @@ type decoder struct {
163166 r io.Reader
164167
165168 // rf identifiers the rep format
166- rf repFormat
169+ rf RepFormat
167170
168171 // sectionsCounter tells how many sections have been read
169172 sectionsCounter int
@@ -175,6 +178,10 @@ type decoder struct {
175178 buf []byte
176179}
177180
181+ func (d * decoder ) RepFormat () RepFormat {
182+ return d .rf
183+ }
184+
178185// readInt32 reads an int32 from the underlying Reader.
179186func (d * decoder ) readInt32 () (n int32 , err error ) {
180187 if _ , err = io .ReadFull (d .r , d .int32Buf ); err != nil {
@@ -191,11 +198,11 @@ func (d *decoder) NewSection() (err error) {
191198 d .sectionsCounter ++
192199
193200 switch d .rf {
194- case repFormatLegacy :
201+ case RepFormatLegacy :
195202 if d .sectionsCounter == 5 {
196203 return ErrNoMoreSections // Legacy replays only have 4 sections
197204 }
198- case repFormatModern121 :
205+ case RepFormatModern121 :
199206 // There is a 4-byte encoded length between sections:
200207 if d .sectionsCounter == 2 {
201208 if _ , err = d .readInt32 (); err != nil {
0 commit comments