Daniel Willmann | 7423728 | 2020-08-12 12:44:04 +0200 | [diff] [blame] | 1 | module StatsD_Types { |
| 2 | |
| 3 | /* Definition of abstract types for the StatsD protocol. USes the TITAN "TEXT" |
| 4 | * codec to auto-generate encoder/decoder functions |
| 5 | * |
| 6 | * (C) 2020 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Author: Daniel Willmann <dwillmann@sysmocom.de> |
| 10 | * |
| 11 | * Released under the terms of GNU General Public License, Version 2 or |
| 12 | * (at your option) any later version. |
| 13 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 14 | */ |
| 15 | |
| 16 | type charstring MetricName with { |
| 17 | variant "END(':')"; |
| 18 | }; |
| 19 | |
| 20 | type integer MetricValue with { |
| 21 | variant "END('|', '\|#(1)')"; |
| 22 | }; |
| 23 | |
| 24 | type charstring MetricType (pattern "(g|c|ms|h|m)"); |
| 25 | |
| 26 | type charstring MetricSampleRate (pattern "\d.\d+") with { |
| 27 | variant "BEGIN('|@')" |
| 28 | }; |
| 29 | |
| 30 | type record StatsDMetric { |
| 31 | MetricName name, |
| 32 | MetricValue val, |
| 33 | MetricType mtype, |
| 34 | MetricSampleRate srate optional |
| 35 | }; |
| 36 | |
| 37 | type record of StatsDMetric StatsDMessage with { |
| 38 | variant "SEPARATOR('\n')"; |
| 39 | }; |
| 40 | |
| 41 | external function enc_StatsDMessage(in StatsDMessage id) return charstring |
| 42 | with { extension "prototype(convert) encode(TEXT)"}; |
| 43 | |
| 44 | external function dec_StatsDMessage(in charstring id) return StatsDMessage |
| 45 | with { extension "prototype(convert) decode(TEXT)"}; |
| 46 | |
| 47 | template StatsDMessage tr_StatsDMsg1(template StatsDMetric metric) := { |
| 48 | [0] := metric |
| 49 | } |
| 50 | |
| 51 | template StatsDMetric tr_StatsDMetric(template MetricName name, template MetricValue val := ?, template MetricType mtype) := { |
| 52 | name := name, |
| 53 | val := val, |
| 54 | mtype := mtype |
| 55 | } |
| 56 | |
| 57 | template StatsDMetric tr_StatsDMetricCounter(template MetricName name, template MetricValue val := ?) := { |
| 58 | name := name, |
| 59 | val := val, |
| 60 | mtype := "c" |
| 61 | } |
| 62 | |
| 63 | template StatsDMetric tr_StatsDMetricGauge(template MetricName name, template MetricValue val := ?) := { |
| 64 | name := name, |
| 65 | val := val, |
| 66 | mtype := "g" |
| 67 | } |
| 68 | |
| 69 | } with { encode "TEXT" } |