| 523 | |
| 524 | |
| 525 | class RealPayloadDecoder(AbstractSimplePayloadDecoder): |
| 526 | protoComponent = univ.Real() |
| 527 | |
| 528 | def valueDecoder(self, substrate, asn1Spec, |
| 529 | tagSet=None, length=None, state=None, |
| 530 | decodeFun=None, substrateFun=None, |
| 531 | **options): |
| 532 | if tagSet[0].tagFormat != tag.tagFormatSimple: |
| 533 | raise error.PyAsn1Error('Simple tag format expected') |
| 534 | |
| 535 | for chunk in readFromStream(substrate, length, options): |
| 536 | if isinstance(chunk, SubstrateUnderrunError): |
| 537 | yield chunk |
| 538 | |
| 539 | if not chunk: |
| 540 | yield self._createComponent(asn1Spec, tagSet, 0.0, **options) |
| 541 | return |
| 542 | |
| 543 | fo = chunk[0] |
| 544 | chunk = chunk[1:] |
| 545 | if fo & 0x80: # binary encoding |
| 546 | if not chunk: |
| 547 | raise error.PyAsn1Error("Incomplete floating-point value") |
| 548 | |
| 549 | if LOG: |
| 550 | LOG('decoding binary encoded REAL') |
| 551 | |
| 552 | n = (fo & 0x03) + 1 |
| 553 | |
| 554 | if n == 4: |
| 555 | n = chunk[0] |
| 556 | chunk = chunk[1:] |
| 557 | |
| 558 | eo, chunk = chunk[:n], chunk[n:] |
| 559 | |
| 560 | if not eo or not chunk: |
| 561 | raise error.PyAsn1Error('Real exponent screwed') |
| 562 | |
| 563 | e = eo[0] & 0x80 and -1 or 0 |
| 564 | |
| 565 | while eo: # exponent |
| 566 | e <<= 8 |
| 567 | e |= eo[0] |
| 568 | eo = eo[1:] |
| 569 | |
| 570 | b = fo >> 4 & 0x03 # base bits |
| 571 | |
| 572 | if b > 2: |
| 573 | raise error.PyAsn1Error('Illegal Real base') |
| 574 | |
| 575 | if b == 1: # encbase = 8 |
| 576 | e *= 3 |
| 577 | |
| 578 | elif b == 2: # encbase = 16 |
| 579 | e *= 4 |
| 580 | p = 0 |
| 581 | |
| 582 | while chunk: # value |
no outgoing calls
no test coverage detected