Skip to content

Commit c582c6b

Browse files
committed
Add country kwarg to aiscat Decoder; bump 0.68.2 -> 0.68.3
1 parent af8c5ee commit c582c6b

4 files changed

Lines changed: 16 additions & 9 deletions

File tree

python/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,21 @@ For perspective: a busy AIS shore station produces ~50 msg/s. Throughput matters
4949

5050
```python
5151
class Decoder:
52-
def __init__(self, *, annotated: bool = False) -> None: ...
52+
def __init__(self, *, annotated: bool = False, country: bool = False) -> None: ...
5353
def feed(self, data: bytes | bytearray | str) -> int: ...
5454
def next(self) -> dict | None: ...
5555
def pending(self) -> int: ...
5656

57-
def iter_decode(chunks: Iterable[bytes | str], *, annotated: bool = False) -> Iterator[dict]: ...
57+
def iter_decode(
58+
chunks: Iterable[bytes | str], *, annotated: bool = False, country: bool = False
59+
) -> Iterator[dict]: ...
5860
```
5961

6062
- `feed(data)` parses NMEA AIVDM/AIVDO sentences out of the buffer. Multipart messages are reassembled internally; partial chunks are buffered until completed. Returns the number of decoded messages waiting.
6163
- `next()` pops one decoded message as a `dict`, or `None` if the queue is empty. Pop in a loop after each `feed()`.
6264
- The queue is unbounded — drain it after each feed, or memory grows.
6365
- `annotated=True` wraps every scalar as `{"value": x, "unit": ..., "description": ..., "text": ...}` (the latter three included only when defined for that key) — useful for self-describing displays and field reference. See [Annotated mode](#annotated-mode) below.
66+
- `country=True` adds `country` and `country_code` to every message, derived from the MMSI prefix (ITU-R M.585 MID table).
6467

6568
```python
6669
# Streaming pattern

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"
44

55
[project]
66
name = "aiscat"
7-
version = "0.68.2"
7+
version = "0.68.3"
88
description = "Fast Python bindings for AIS-catcher's NMEA-to-JSON AIS decoder"
99
readme = "README.md"
1010
license = "GPL-3.0-or-later"

python/src/aiscat/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
from ._core import Decoder
44
from .types import AISMessage
55

6-
__version__ = "0.68.2"
6+
__version__ = "0.68.3"
77
__all__ = ["Decoder", "iter_decode", "AISMessage"]
88

99

10-
def iter_decode(chunks, *, annotated=False):
10+
def iter_decode(chunks, *, annotated=False, country=False):
1111
"""Yield decoded AIS messages (as dicts) from an iterable of bytes/str chunks.
1212
1313
If ``annotated`` is True, every scalar value is wrapped as
1414
``{"value": x, "unit": ..., "description": ..., "text": ...}`` (the latter
1515
three fields included only when defined for that key).
16+
17+
If ``country`` is True, every message gets ``country`` and ``country_code``
18+
fields derived from the MMSI prefix.
1619
"""
17-
dec = Decoder(annotated=annotated)
20+
dec = Decoder(annotated=annotated, country=country)
1821
for chunk in chunks:
1922
dec.feed(chunk)
2023
msg = dec.next()

python/src/aiscat/_core.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ typedef struct {
177177
} DecoderObject;
178178

179179
static int Decoder_init(DecoderObject *self, PyObject *args, PyObject *kwds) {
180-
static const char *kwlist[] = {"annotated", nullptr};
181-
int annotated = 0;
182-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|p", (char **)kwlist, &annotated))
180+
static const char *kwlist[] = {"annotated", "country", nullptr};
181+
int annotated = 0, country = 0;
182+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|pp", (char **)kwlist, &annotated, &country))
183183
return -1;
184184

185185
self->nmea = new AIS::NMEA();
@@ -188,6 +188,7 @@ static int Decoder_init(DecoderObject *self, PyObject *args, PyObject *kwds) {
188188
self->sink->annotated = (annotated != 0);
189189
self->tag = new TAG();
190190
self->tag->clear();
191+
if (country) self->tag->mode |= 4; // enables JSONAIS::COUNTRY (MMSI prefix → country, country_code)
191192
self->nmea->out.Connect(self->jsonais);
192193
self->jsonais->out.Connect(self->sink);
193194
return 0;

0 commit comments

Comments
 (0)