Skip to content

Commit 6fda173

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 5f4fa9e + 3023373 commit 6fda173

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

cookbook/c06/p12_var_binary.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
import struct
88
import itertools
99

10+
polys = [
11+
[ (1.0, 2.5), (3.5, 4.0), (2.5, 1.5) ],
12+
[ (7.0, 1.2), (5.1, 3.0), (0.5, 7.5), (0.8, 9.0) ],
13+
[ (3.4, 6.3), (1.2, 0.5), (4.6, 9.2) ],
14+
]
1015

1116
def write_polys(filename, polys):
1217
# Determine bounding box

source/c06/p12_read_nested_and_variable_sized_binary_structures.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
``struct`` 模块可被用来编码/解码几乎所有类型的二进制的数据结构。为了解释清楚这种数据,假设你用下面的Python数据结构
1616
来表示一个组成一系列多边形的点的集合:
1717

18-
.. code-block::python
18+
.. code-block:: python
1919
2020
polys = [
2121
[ (1.0, 2.5), (3.5, 4.0), (2.5, 1.5) ],
@@ -30,17 +30,17 @@
3030
+------+--------+------------------------------------+
3131
|Byte | Type | Description |
3232
+======+========+====================================+
33-
|0 | int | File code (0x1234, little endian) |
33+
|0 | int | 文件代码(0x1234,小端) |
3434
+------+--------+------------------------------------+
35-
|4 | double | Minimum x (little endian) |
35+
|4 | double | x 的最小值(小端) |
3636
+------+--------+------------------------------------+
37-
|12 | double | Minimum y (little endian) |
37+
|12 | double | y 的最小值(小端) |
3838
+------+--------+------------------------------------+
39-
|20 | double | Maximum x (little endian) |
39+
|20 | double | x 的最大值(小端) |
4040
+------+--------+------------------------------------+
41-
|28 | double | Maximum y (little endian) |
41+
|28 | double | y 的最大值(小端) |
4242
+------+--------+------------------------------------+
43-
|36 | int | Number of polygons (little endian)|
43+
|36 | int | 三角形数量(小端) |
4444
+------+--------+------------------------------------+
4545
4646
紧跟着头部是一系列的多边形记录,编码格式如下:
@@ -50,9 +50,9 @@
5050
+------+--------+-------------------------------------------+
5151
|Byte | Type | Description |
5252
+======+========+===========================================+
53-
|0 | int | Record length including length (N bytes) |
53+
|0 | int | 记录长度(N字节) |
5454
+------+--------+-------------------------------------------+
55-
|4-N | Points | Pairs of (X,Y) coords as doubles |
55+
|4-N | Points | (X,Y) 坐标,以浮点数表示 |
5656
+------+--------+-------------------------------------------+
5757
5858
为了写这样的文件,你可以使用如下的Python代码:
@@ -104,7 +104,7 @@
104104
那未免也太繁杂了点。因此很显然应该有另一种解决方法可以简化这些步骤,让程序员只关注自最重要的事情。
105105

106106
在本小节接下来的部分,我会逐步演示一个更加优秀的解析字节数据的方案。
107-
目标是可以给程序员提供一个高级的文件格式化方法,并简化读取和解包数据的细节。但是我要先提醒习啊你
107+
目标是可以给程序员提供一个高级的文件格式化方法,并简化读取和解包数据的细节。但是我要先提醒你
108108
本小节接下来的部分代码应该是整本书中最复杂最高级的例子,使用了大量的面向对象编程和元编程技术。
109109
一定要仔细的阅读我们的讨论部分,另外也要参考下其他章节内容。
110110

0 commit comments

Comments
 (0)