Function donet_core::read_dc

source ·
pub fn read_dc<'a>(
    config: DCFileConfig,
    input: String,
) -> Result<DCFile<'a>, DCReadError>
Expand description

Front end to the donet-core DC parser pipeline.

§Example Usage

The following is an example of parsing a simple DC file string, printing its DC hash in hexadecimal notation, and accessing the elements of a defined Distributed Class:

use donet_core::dcfile::DCFile;
use donet_core::dclass::DClass;
use donet_core::dconfig::*;
use donet_core::read_dc;

let dc_file = "

from game.ai import AnonymousContact/UD
from game.ai import LoginManager/AI
from game.world import DistributedWorld/AI
from game.avatar import DistributedAvatar/AI/OV

typedef uint32 doId;
typedef uint32 zoneId;
typedef uint64 channel;

dclass AnonymousContact {
  login(string username, string password) clsend airecv;
};

dclass LoginManager {
  login(channel client, string username, string password) airecv;
};

dclass DistributedWorld {
  create_avatar(channel client) airecv;
};

dclass DistributedAvatar {
  set_xyzh(int16 x, int16 y, int16 z, int16 h) broadcast required;
  indicate_intent(int16 / 10, int16 / 10) ownsend airecv;
};

";

let dc_conf = DCFileConfig::default();
let dc_read = read_dc(dc_conf, dc_file.into());

if let Ok(dc_file) = dc_read {
    // Print the DC File's 32-bit hash in hexadecimal format.
    println!("{}", dc_file.get_pretty_hash());

    // TODO: Retrieve the `DistributedAvatar` dclass by ID.
    //let class: &DClass = dc_file.get_dclass_by_id(3);

    // TODO: Print the identifier of the dclass.
    //println!("{}", class.get_name());
}

The output of the program would be the following:

0x9c737148
DistributedAvatar