Function libdonet::read_dc

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

Front end to the libdonet 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 libdonet::dcfile::DCFile;
use libdonet::dclass::DClass;
use libdonet::globals::DCReadError;
use libdonet::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_read: Result<DCFile, DCReadError> = read_dc(dc_file.to_owned());

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