惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

drew's dev blog

Hunting a production-only proxy bug in SvelteKit Artisanal Handcrafted Git Repositories Everything you need to know about Python 3.13 – JIT and GIL went up the hill How Postgres stores oversized values – let's raise a TOAST How Postgres stores data on disk – this one's a page turner Bumper QuEST Rust Wrapper Dotfiles How long is a cucumber? 🥒 Jekyll KaTeX Block Using make and latexmk for easy LaTeX compilation Calculating the overlap of aerial photos Custom Jekyll plugins with GitHub Pages Calculating meters per pixel from aerial photographs Proper line numbers with Jekyll Compiling zsh without root Coding cheatsheet | drew's dev blog
Comtrade
Drew Silcock · 2024-07-15 · via drew's dev blog

· 4 min read ·3

About

This is a pure Rust parser for the COMTRADE signal file format. I wrote it a couple of years ago and management to get it working to a point where it has more functionality than most other parsers I’ve seen.

For the uninitiated, “comtrade” can mean 3 possible things:

  • A UN-maintained database of global trading data.
  • Your communist friend needs to work on his spelling.
  • A file format for signals from electrical power systems that is maintained by the IEEE.

This parser concerns the latter, namely the Common format for Transient Data Exchange for power systems. I’m gonna be honest, given the naming conflict and the poor quality of the acronym, I think it’s probably one of the worst technical acronym’s I’ve come across. (Let me know if you’ve got a worse one! I love to see them.)

COMTRADE files typically contains several channels which can be either analog or digital. Digital channels are typically used for things like statuses (e.g. breaker status) while analog channels are used for things like voltage, current, power, etc. For typical 3-phase systems, there will be at least one channel per phase.

If you’re interested about how to write a file format parser in Rust, take a look at src/parser.rust - it’s a very simple parser that’s mostly just based on regexp matching, there’s no fancy parsing libraries used.

COMTRADE file format specs

There are actually 3 different versions of the spec: IEEE C37.111-1991, IEEE C37.111-1999 and IEEE C37.111-2013.

The newer versions of the spec include additional useful functionality including things like different encoding mechanisms, combining multiple files into one, and more.

Motivation

COMTRADE is a fairly niche file format, andd there’s very few parsers available for it. The main one that everyone seems to use is the Python “comtrade” library (See PyPI package and GitHub repo). This library has pretty good support for the various COMTRADE spec features, although last time I used it I had a few issues with it using 32-bit floats and ints for all values when I needed 64-bit floating point precision - I put up a PR for implementing this which has since been merged, so this isn’t a problem anymore.

Mainly, I’d spent so much time understanding the minutiae of the COMTRADE spec for a project that I was working on at work that I thought it’d be fun to try to write a functioning parser, and I like writing Rust code, so I thought I’d give it a go.

The COMTRADE file format is really very simple - for the most part, it’s just a matter of knowing what values come after what other values, and what specific format they are stored in. There’s a few places which are slightly more difficult where you have to read one parameter before you can understand how many rows to expect in another part of the file, but on the whole it’s super simple. You certainly don’t need any of these proper parsing tools that people use for parsing programming languages, like GNU Bison.

Crate

This project is deployed on crates.io, check it out here: https://crates.io/crates/comtrade. Apparently it has 573 downloads at the time of writing, although they’re probably all bots.

To install comtrade to use in your project:

Current status

This project is in a working state and can be used, but it’s not been battle tested so there are bound to be a few bugs and areas for usability improvements. It’s got a few tests, but not as many as I’d like.