Coder Social home page Coder Social logo

Comments (2)

NotStatilko avatar NotStatilko commented on July 29, 2024

comment will be used for custom file attributes & types, so every developer may add own.

I suggest this standard:

  1. If comment is custom attributes, it must start from the one 0xFF byte. Otherwise this field will be determined as plain comment.
  2. Every custom attribute must have the Key and the Value, like dict(). Value can be b''.

As delimeters we may use length of Key (not to be confused with keys.Key) and the length of Value.
I.e we want to add to the RemoteBoxFile custom attribute key with value value. Then:

comment = b'\xff\x03key\x05value'

  1. We take \x03, convert it to int (3) and take three next bytes, receive Key;
  2. Take next byte from Key, convert it to int (5) and take next five bytes, receive Value;
  3. Repeat until bytestring will be empty.

So, for example, we may use this to store file hash or signatures, or whatever.
We can also use this to determine file types, if needed. Let's use type as Key.

Types can be combined, but there is limit in 255 bytes.

Example:

from tgbox.tools import CustomAttributes

# Some random types
cattr = CustomAttributes.make(
    sha256 = b'\x00'*32,
    never  = b'gonna give you up'
)
# Defining text message type
cattr = CustomAttributes.make(
    type = b'message'
)

Further will be list of types. You may suggest your own, if interested.

Key Value Description
sha256 hash May be used any hashfunc from hashlib
reply message.id Reply to the ID
type b'message' Text message type, can be another Value

from tgbox.

NotStatilko avatar NotStatilko commented on July 29, 2024

The CustomAttributes is now a PackedAttributes. This algorithm is used now for packing metadata attrs. comment attribute of prepare_file(...) is now replaced by a cattrs, user can present a dict with custom file attributes he wants, so all of the previous information on this issue isn't actual as per v1.0.

See new metadata: https://tgbox.readthedocs.io/en/latest/remotebox.html#remoteboxfile
See new cattrs attr: https://tgbox.readthedocs.io/en/latest/tgbox.html?highlight=prepare_file#tgbox.api.DecryptedLocalBox.prepare_file

Still, i want to make a standart for cattrs keys that different apps based on tgbox can share. Like "comment" key to define a file commentary or "type" to define a file type, e.g with a "message" value or even "sha256" / "md5" / "sha1" ... to define a file hash. You can propose your ideas here.

from tgbox.

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.