… | |
… | |
147 | -- decode UCS-2 string of length <xsl:value-of select="@length"/> |
147 | -- decode UCS-2 string of length <xsl:value-of select="@length"/> |
148 | -- the first 0 terminates the string, but not the field |
148 | -- the first 0 terminates the string, but not the field |
149 | |
149 | |
150 | enc<xsl:value-of select="@name"/> = |
150 | enc<xsl:value-of select="@name"/> = |
151 | -- likewise, encode as UCS-2, fill space with 0 |
151 | -- likewise, encode as UCS-2, fill space with 0 |
|
|
152 | |
152 | </xsl:template> |
153 | </xsl:template> |
153 | |
154 | |
154 | <xsl:template match="type[@type = 'A']"> |
155 | <xsl:template match="type[@type = 'A']"> |
155 | dec<xsl:value-of select="@name"/> :: State [Word8] [Char] |
156 | dec<xsl:value-of select="@name"/> :: State [Word8] [Char] |
156 | dec<xsl:value-of select="@name"/> = do |
157 | dec<xsl:value-of select="@name"/> = do |
157 | -- decode ASCII string of length <xsl:value-of select="@length"/> |
158 | -- decode ASCII string of length <xsl:value-of select="@length"/> |
158 | -- the first 0 terminates the string, but not the field |
159 | -- the first 0 terminates the string, but not the field |
159 | |
160 | |
160 | enc<xsl:value-of select="@name"/> = |
161 | enc<xsl:value-of select="@name"/> = |
161 | -- likewise, encode as ASCII, fill space with 0 |
162 | -- likewise, encode as ASCII, fill space with 0 |
|
|
163 | |
162 | </xsl:template> |
164 | </xsl:template> |
163 | |
165 | |
164 | <xsl:template match="type[@multiplier]"> |
166 | <xsl:template match="type[@multiplier]"> |
165 | dec<xsl:value-of select="@name"/> = do |
167 | dec<xsl:value-of select="@name"/> = do |
166 | n <- dec<xsl:value-of select="@type"/> |
168 | n <- dec<xsl:value-of select="@type"/> |
167 | return n * (1 / <xsl:value-of select="@multiplier"/>) |
169 | return n * (1 / <xsl:value-of select="@multiplier"/>) |
168 | |
170 | |
169 | enc<xsl:value-of select="@name"/> = |
171 | enc<xsl:value-of select="@name"/> n = |
170 | <xsl:value-of select="@multiplier"/> * enc<xsl:value-of select="@type"/> |
172 | enc<xsl:value-of select="@type"/> $ n * <xsl:value-of select="@multiplier"/> |
|
|
173 | |
171 | </xsl:template> |
174 | </xsl:template> |
172 | |
175 | |
173 | <xsl:template match="member[@array = 'yes']" mode="dec"> |
176 | <xsl:template match="member[@array = 'yes']" mode="dec"> |
174 | $r->{<xsl:value-of select="@name"/>} = (my $array = []); |
177 | $r->{<xsl:value-of select="@name"/>} = (my $array = []); |
175 | while (length $data) { |
178 | while (length $data) { |
… | |
… | |
179 | } |
182 | } |
180 | </xsl:template> |
183 | </xsl:template> |
181 | |
184 | |
182 | <xsl:template match="member" mode="dec"> |
185 | <xsl:template match="member" mode="dec"> |
183 | <xsl:if test="@guard-cond"> |
186 | <xsl:if test="@guard-cond"> |
184 | if ($r->{<xsl:value-of select="@guard-member"/>} <xsl:value-of select="@guard-cond"/>)</xsl:if> |
187 | -- decode next only when <xsl:value-of select="@guard-member"/> <xsl:value-of select="@guard-cond"/> -- |
185 | <xsl:text>;</xsl:text> |
188 | </xsl:if> |
186 | dec<xsl:value-of select="@type"/> -- default <xsl:value-of select="@default"/> -- |
189 | dec<xsl:value-of select="@type"/> -- default <xsl:value-of select="@default"/> -- |
187 | </xsl:template> |
190 | </xsl:template> |
188 | |
191 | |
189 | <xsl:template match="member" mode="enc"> |
192 | <xsl:template match="member" mode="enc"> |
190 | enc<xsl:value-of select="@type"/> defined $_[0]{<xsl:value-of select="@name"/>} ? $_[0]{<xsl:value-of select="@name"/> |
193 | enc<xsl:value-of select="@type"/> defined $_[0]{<xsl:value-of select="@name"/>} ? $_[0]{<xsl:value-of select="@name"/> s |
191 | <xsl:text>} : (</xsl:text> |
194 | <xsl:text>} : (</xsl:text> |
192 | <xsl:value-of select="@default"/> |
195 | <xsl:value-of select="@default"/> |
193 | <xsl:text>);</xsl:text> |
196 | <xsl:text>);</xsl:text> |
194 | </xsl:template> |
197 | </xsl:template> |
195 | |
198 | |
196 | <xsl:template match="struct"> |
199 | <xsl:template match="struct"> |
197 | sub dec_<xsl:value-of select="@name"/> { |
200 | dec<xsl:value-of select="@name"/> = do |
198 | my $r = {}; |
|
|
199 | <xsl:apply-templates select="member" mode="dec"/> |
201 | <xsl:apply-templates select="member" mode="dec"/> |
200 | <xsl:if test="@class"> |
202 | <xsl:if test="@class"> |
201 | bless $r, <xsl:value-of select="@class"/>::; |
203 | -- result has class <xsl:value-of select="@class"/> -- |
202 | </xsl:if> |
204 | </xsl:if> |
203 | $r; |
|
|
204 | } |
|
|
205 | |
205 | |
206 | sub enc_<xsl:value-of select="@name"/> { |
206 | enc<xsl:value-of select="@name"/> s = |
207 | <xsl:apply-templates select="member" mode="enc"/> |
207 | <xsl:apply-templates select="member" mode="enc"/> |
208 | } |
208 | |
209 | </xsl:template> |
209 | </xsl:template> |
210 | |
210 | |
211 | <xsl:template match="message"> |
211 | <xsl:template match="message"> |
212 | # <xsl:value-of select="@name"/> |
212 | # <xsl:value-of select="@name"/> |
213 | $dec_<xsl:value-of select="@src"/>{0x<xsl:value-of select="@type"/>} = sub { |
213 | dec<xsl:value-of select="@src"/>_<xsl:value-of select="@type"/> = do |
214 | $data = $_[0]; |
|
|
215 | my $r; |
|
|
216 | $r->{type} = "<xsl:value-of select="@name"/>"; |
214 | -- type "<xsl:value-of select="@name"/>" -- |
217 | <xsl:apply-templates select="member" mode="dec"/> |
215 | <xsl:apply-templates select="member" mode="dec"/> |
218 | $r; |
216 | |
219 | }; |
|
|
220 | $enc_<xsl:value-of select="@src"/>{<xsl:value-of select="@name"/>} = sub { |
217 | enc<xsl:value-of select="@src"/>_<xsl:value-of select="@name"/> = |
221 | $data = ""; |
|
|
222 | enc_U16 0x<xsl:value-of select="@type"/>; |
218 | encU16 0x<xsl:value-of select="@type"/> |
223 | <xsl:apply-templates select="member" mode="enc"/> |
219 | <xsl:apply-templates select="member" mode="enc"/> |
224 | $data; |
220 | |
225 | }; |
|
|
226 | </xsl:template> |
221 | </xsl:template> |
227 | |
222 | |
228 | <xsl:template match="member"> |
223 | <xsl:template match="member"> |
229 | [<xsl:value-of select="@name"/> |
224 | [<xsl:value-of select="@name"/> |
230 | <xsl:text>=> "</xsl:text> |
225 | <xsl:text>=> "</xsl:text> |