Coder Social home page Coder Social logo

Comments (6)

ChristianTremblay avatar ChristianTremblay commented on June 28, 2024

@JoelBender

Just to be sure I understand it right. Is this code would need to raise the error ?

from bacpypes.primitivedata import Tag, Enumerated
from bacpypes.debugging import bacpypes_debugging, ModuleLogger, xtob

tag = Tag(Tag.applicationTagClass, Tag.enumeratedAppTag, 1, xtob(''))
obj = Enumerated(tag)
# ! Bang -> Decoding Error

Is a specific call to decode() necessary ?

from bacpypes.

JoelBender avatar JoelBender commented on June 28, 2024

That's one form that will generate an error. Your example shows a tag that is inconsistent because the LVT field (in this case interpreted as "length") is one (1) but the length of the tag data is zero (0). The current code doesn't have test for this error, so adding something like this is a good idea:

if (tag.tagLVT != len(tag.tagData)):
    raise DecodingError("inconsistent tag")

The sample test is equivalent to this, which should also raise an error:

tag = Tag(Tag.applicationTagClass, Tag.enumeratedAppTag, 0, xtob(''))

because there must be at least one octet of data (and four octets for Real, Date, and Time, etc.) The test code is already in tests/test_primitive_data/test_enumerated.py, it's just commented out:

#       with self.assertRaises(DecodingError):
#           obj = Enumerated(enumerated_tag(''))

Your mission, now that this is assigned to you :-), is to uncomment the test and fix the decode() function.

It's not necessary to explicitly call decode() because having it implicitly called by __init__() is part of the "signature" of the function.

from bacpypes.

JoelBender avatar JoelBender commented on June 28, 2024

You are going to be making (or you have already made) a new branch issue-50 from stage, correct? If I'm thinking correctly, it should contain the 49f990c commit and go forward from there.

from bacpypes.

JoelBender avatar JoelBender commented on June 28, 2024

After reviewing 18.9 Reject Reason in the standard, perhaps the exception should be called InvalidTag:

INVALID_TAG - While parsing a message, an invalid tag was encountered. Since an invalid tag could confuse the parsing logic, any of the following Reject Reasons may also be generated in response to a confirmed request containing an invalid tag: INCONSISTENT_PARAMETERS, INVALID_PARAMETER_DATA_TYPE, MISSING_REQUIRED_PARAMETER, and TOO_MANY_ARGUMENTS.

When this exception is raised during the decoding of an APDU before it is sent upstream for processing, it will need to be trapped and a RejectPDU sent to the client (I'll make a separate issue).

from bacpypes.

ChristianTremblay avatar ChristianTremblay commented on June 28, 2024

Create an InvalidTagError exception that inherit from DecodingError (to be confirmed... if ok, if not, just change it to inherit from ValueError

This line is added to primitivedata encode function :

    if tag.tagData == b'':
        raise InvalidTagError('empty tag')

Did it for :

  • Enumerated
  • Date
  • Double
  • Integer
  • object_identifier
  • object_type
  • real
  • time
  • unsigned

Seems not appropriate for :

  • Null
  • Boolean
  • BitString
  • octet_string

from bacpypes.

JoelBender avatar JoelBender commented on June 28, 2024

This has been subsumed by #58, which has all the reject and abort exceptions, includes all three distributions, and I included the updates to the tests as well. I'm closing this issue and abandoning the branch.

from bacpypes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.