Struct sameold::MessageHeader

source ·
pub struct MessageHeader { /* private fields */ }
Expand description

Event, area, time, and originator information

Implementations§

source§

impl MessageHeader

source

pub fn new<S>(message: S) -> Result<Self, MessageDecodeErr>where S: Into<String>,

Try to construct a SAME header from String

The message string must match the general format of a SAME header. If it does not, an error is returned.

source

pub fn new_with_errors<S>( message: S, error_counts: &[u8] ) -> Result<Self, MessageDecodeErr>where S: Into<String>,

Try to construct a SAME header from String, with error counts

The message string must match the general format of a SAME header. If it does not, an error is returned.

The error_counts slice counts the number of bit errors corrected in byte of message. The slice must have the same length as message.

source

pub fn message(&self) -> &str

Message text

Returns UTF-8 string representation of a SAME/EAS message. Use the release() method to obtain an owned String.

source

pub fn as_str(&self) -> &str

Message text

Returns UTF-8 string representation of a SAME/EAS message. Use the release() method to obtain an owned String.

source

pub fn originator(&self) -> Originator

Originator code

The ultimate source of the message, such as Originator::WeatherService for the National Weather Service

source

pub fn originator_str(&self) -> &str

Originator code (as string)

A three-character string that is usually one of the following:

  • PEP: Primary Entry Point Station. Generally only used for national activations, which are very rare.

  • CIV: Civil authorities (usu. state and local government)

  • WXR: National Weather Service or Environment Canada

  • EAS: EAS Participant. Usually a broadcast station.

The originator code returned is three characters but is not guaranteed to be one of the above.

source

pub fn event(&self) -> Result<EventCode, UnrecognizedEventCode>

Event code

Decodes the event code into an enumerated type. For example, messages which contain an event_str() of “RWT” will decode as EventCode::RequiredWeeklyTest.

If the event code is unrecognized, an error is returned. An error here does NOT mean that the message is invalid or should be discarded. Instead, if the error is WithSignificance, then you should treat it as a valid (but unknown) message at the given significance level. This will help your application react correctly if new codes are added in the future.

Event codes can be converted to human-readable strings.

use sameold::EventCode;

assert_eq!("Required Weekly Test", (EventCode::RequiredWeeklyTest).as_display_str());
assert_eq!(
    "Required Weekly Test",
    format!("{}", EventCode::RequiredWeeklyTest)
);

All EventCode are mapped to a significance level. This may be useful when deciding how to handle the event.


let lvl = (EventCode::RequiredWeeklyTest).to_significance_level();
assert_eq!(lvl, SignificanceLevel::Test);
source

pub fn event_str(&self) -> &str

Event code

A three-character code which is generally formatted according to severity level.

  • xxT: Test
  • xxS: Statement / Advisory
  • xxA: Watch
  • xxW: Warning (generally most severe events)

Major exceptions to this are the codes SVR (“Severe Thunderstorm Warning”) and TOR (“Tornado Warning”), which are among the most common messages in the United States. Plenty of other codes also do not adhere to this standard.

The event code returned is three characters but is not guaranteed to be one of the above.

source

pub fn location_str_iter<'m>(&'m self) -> Split<'m, char>

Iterator over location codes

Returns an iterator over the location codes in the message. Location codes are six-digit strings of the form PSSCCC:

  • P: part of county, or zero for entire county
  • SS: FIPS State code
  • CCC: FIPS County code

Locations are returned in the order listed in the message. Iterator values are guaranteed to be six-digit strings.

Per the SAME standard, a message can have up to 31 location codes.

source

pub fn valid_duration(&self) -> Duration

Message validity duration (Duration)

Returns the message validity duration. The message is valid until

msg.issue_datetime().unwrap() + msg.valid_duration()

After this time elapses, the message is no longer valid and should not be relayed or alerted to anymore.

This field represents the validity time of the message and not the expected duration of the severe condition. Severe conditions may persist after the message expires! (And might be the subject of future messages.)

The valid duration is relative to the issue_datetime() and not the current time.

Requires chrono.

source

pub fn valid_duration_fields(&self) -> (u8, u8)

Message validity duration

Returns the message validity duration or “purge time.” This is a tuple of (hours, minutes).

This field represents the validity time of the message and not the expected duration of the severe condition. Severe conditions may persist after the message expires! (And might be the subject of future messages.)

The valid duration is relative to the issue_daytime_fields().

source

pub fn issue_datetime( &self, received: &DateTime<Utc> ) -> Result<DateTime<Utc>, InvalidDateErr>

Estimated message issuance datetime (UTC)

Computes the datetime that the SAME message was issued from the time that the message was received, which must be provided.

SAME headers do not include the year of issuance. This makes it impossible to calculate the full datetime of issuance without a rough idea of the message’s true UTC time. It is unnecessary for the received time to be a precision timestamp. As long as the provided value is within ±90 days of true UTC, the output time will be correct.

An error is returned if we are unable to calculate a valid timestamp. This can happen, for example, if we project a message sent on Julian/Ordinal Day 366 into a year that is not a leap year.

The returned datetime is always in one minute increments with the seconds field set to zero.

Requires chrono.

source

pub fn is_expired_at(&self, now: &DateTime<Utc>) -> bool

Is the message expired?

Given the current time, determine if this message has expired. It is assumed that now is within twelve hours of the message issuance time. Twelve hours is the maximum duration of a SAME message.

An expired message may still refer to an ongoing hazard or event! Expiration merely indicates that the message should not be relayed or alerted to anymore.

Requires chrono.

source

pub fn issue_daytime_fields(&self) -> (u16, u8, u8)

Mesage issuance day/time (fields)

Returns the message issue day and time, as the string JJJHHMM,

  • JJJ: Ordinal day of the year. 001 represents 1 Jan., and 365 represents 31 Dec. in non leap-years. During leap-years, 366 represents 31 Dec. 000 is not used. It is up to the receiving station to have some notion of what the current year is and to detect calendar rollovers.

  • HHMM: UTC time of day, using a 24-hour time scale. Times are UTC and are NOT local times.

source

pub fn callsign(&self) -> &str

Sending station callsign

The FCC or other regulatory body-assigned callsign of the sending station. Minus signs (-) in the callsign are replaced with slashes (/).

source

pub fn parity_error_count(&self) -> usize

Count of parity errors

The number of bit errors which were corrected by the 2-of-3 parity correction algorithm. High parity error counts indicate a high bit error rate in the receiving system.

source

pub fn release(self) -> String

Obtain the owned message String

Destroys this object and releases the message contained within

Trait Implementations§

source§

impl AsRef<[u8]> for MessageHeader

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<str> for MessageHeader

source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for MessageHeader

source§

fn clone(&self) -> MessageHeader

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for MessageHeader

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for MessageHeader

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<MessageHeader> for String

source§

fn from(msg: MessageHeader) -> String

Converts to this type from the input type.
source§

impl Hash for MessageHeader

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq<MessageHeader> for MessageHeader

source§

fn eq(&self, other: &MessageHeader) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<(String, &[u8])> for MessageHeader

§

type Error = MessageDecodeErr

The type returned in the event of a conversion error.
source§

fn try_from(inp: (String, &[u8])) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<String> for MessageHeader

§

type Error = MessageDecodeErr

The type returned in the event of a conversion error.
source§

fn try_from(inp: String) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for MessageHeader

source§

impl StructuralEq for MessageHeader

source§

impl StructuralPartialEq for MessageHeader

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.