Coder Social home page Coder Social logo

Comments (2)

Samuelbella avatar Samuelbella commented on July 4, 2024

Here is the code I used to test:

import json
from idmefv2 import Message, SerializedMessage

#List of Dict
LDok = json.loads(Sok)
msg = Message()
#Dict
for Dok in LDok :

    payload = SerializedMessage('application/json', Dok)
    msg = Message.unserialize(payload)

With for example :
LDok[0] = {'Version': '2.0.3', 'ID': 'e5f9bbae-163e-42f9-a2f2-0daaf78fefb1', 'CreateTime': '2021-01-18T23:33:05.21Z', 'Analyzer': {'IP': '172.10.5.31', 'Name': 'Front door camera', 'Model': 'Netatmo 42B', 'Category': ['HAR'], 'Data': ['Images'], 'Method': ['Movement']}}

from python-idmefv2.

fpoirotte avatar fpoirotte commented on July 4, 2024

Hi,

Thank you for your report!

Disclaimer: I do not work on this project anymore.

The SerializedMessage class expects a serialized representation of the message as a sequence of bytes.
The call to Message.unserialize() will then unserialize the message for you (using knowledge about the serialization method in use it received as the first argument to SerializedMessage).
This makes the API more generic by decoupling it from a specific serialization method, so that new serialization methods can easily be plugged in later on (XML-based serialization, YAML-based serialization, binary serialization and so on).

Try out the following code:

import json
from idmefv2 import Message, SerializedMessage

# Notice how LDok[0] is now a byte sequence
LDok = [
  b'''
    {
      "Version": "2.0.3",
      "ID": "e5f9bbae-163e-42f9-a2f2-0daaf78fefb1",
      "CreateTime": "2021-01-18T23:33:05.21Z",
      "Analyzer": {
        "IP": "172.10.5.31",
        "Name": "Front door camera",
        "Model": "Netatmo 42B",
        "Category": ["HAR"],
        "Data": ["Images"],
        "Method": ["Movement"]
      }
    }
  '''
]

for Dok in LDok :
    payload = SerializedMessage('application/json', Dok)
    msg = Message.unserialize(payload)
    print(msg)

Regards,
François

from python-idmefv2.

Related Issues (1)

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.