Skip to content

Commit

Permalink
docs typos and embedding warns
Browse files Browse the repository at this point in the history
  • Loading branch information
arekbulski committed Jan 17, 2020
1 parent 11dc7bb commit c522be2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Bytes and bits

Python 3 known problem:

Unprefixed string literals like "data" are on Python 3 interpreted as unicode. This casues failures when using fields like `Bytes`.
Unprefixed string literals like "data" are on Python 3 interpreted as unicode. This causes failures when using fields like `Bytes`.

"Strings" of bytes (`str` in PY2 and `bytes` in PY3) can be moved around as-is. Bits are discussed in a later chapter.

Expand Down Expand Up @@ -92,7 +92,7 @@ b'\x08\xd0\x90\xd1\x84\xd0\xbe\xd0\xbd'

CString is another string representation, that always ends with a null \\0 terminating byte at the end. This scheme was invented in C language and is known in the computer science community very well. One of the authors, Kernighan or Ritchie, admitted that it was one of the most regretable design decisions in history.

>>> CString("utf8").build(b"hello")
>>> CString("utf8").build(u"hello")
b'hello\x00'

Last would be GreedyString which does the same thing as GreedyBytes, plus encoding. It reads until the end of stream and then decodes data using specified encoding. Greedy* classes are usually used with tunneling constructs, which are discussed in a later chapter.
Expand Down
3 changes: 2 additions & 1 deletion docs/meta.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ The Context
===========


Meta constructs are the key to the declarative power of Construct. Meta constructs are constructs which are affected by the context of the construction (during parsing and building). The context is a dictionary that is created during the parsing and building process by Structs and Sequences, and is "propagated" down and up to all constructs along the way, so that other members can access other members parsing or building resuslts. It basically represents a mirror image of the construction tree, as it is altered by the different constructs. Nested structs create nested contexts, just as they create nested containers.
Meta constructs are the key to the declarative power of Construct. Meta constructs are constructs which are affected by the context of the construction (during parsing and building). The context is a dictionary that is created during the parsing and building process by Structs and Sequences, and is "propagated" down and up to all constructs along the way, so that other members can access other members parsing or building results. It basically represents a mirror image of the construction tree, as it is altered by the different constructs. Nested structs create nested contexts, just as they create nested containers.

In order to see the context, let's try this snippet:

Expand Down Expand Up @@ -82,6 +82,7 @@ Embedding also complicates using the context. Notice that `count` is on same lev
>>> outer.parse(b"\x041234")
Container(count=4, data=b'1234')

I cannot stress it enough: embedding is just plain doing-it-wrong and should not be used, unless really really needed.


Refering to inlined constructs
Expand Down

0 comments on commit c522be2

Please sign in to comment.