1 // Written in the D programming language.
2 
3 /**
4 A type for representing the version object of the 9P / Styx protocol. 
5 
6 Copyright: LightHouse Software, 2021
7 License:   $(HTTP https://github.com/aquaratixc/ESL-License, Experimental Software License 1.0).
8 Authors:   Oleg Bakharev,
9 		   Ilya Pertsev
10 */
11 module styx2000.protobj.styxversion;
12 
13 private {
14 	import std..string : format;
15 	
16 	import styx2000.lowlevel.endianness;
17 	import styx2000.lowlevel.vls;
18 	
19 	import styx2000.protoconst.base : STYX_VERSION;
20 	
21 	import styx2000.protobj.name;
22 	import styx2000.protobj.styxobject;
23 }
24 
25 /**
26 	A class that provides a type for the version field in some Styx messages. Inherits methods from the Name class and the StyxObject class. 
27 	See_Also:
28 		https://web.archive.org/web/20201029184954/https://powerman.name/Inferno/man/5/0intro.html
29 */
30 class Version : Name
31 {
32 	/**
33 	A constructor that creates an object of the Version class with the given parameter in the form of some string value representing protocol version. 
34 	If called without parameters, then the default parameter is empty string value. 
35     Params:
36     name = String value for protocol version.
37     
38     Typical usage:
39     ----
40     Version vers = new Version(`9P2000`);
41     ----
42     */
43 	this(string name = "")
44 	{
45 		if (name == "")
46 		{
47 			_name = STYX_VERSION;
48 			_representation = cast(ubyte[]) [6, 0] ~ cast(ubyte[]) STYX_VERSION;
49 		}
50 		else
51 		{
52 			_name = name;
53 			_representation = VariableLengthSequence.pack(cast(ubyte[]) name);
54 		}
55 	}
56 	
57 	/// An alias that allows you to call a setter method without accessing the base Name class
58 	alias setVersion = setName;
59 	/// An alias that allows you to call a getter method without accessing the base Name class
60 	alias getVersion = getName;
61 		
62 	/// Convenient string representation of an object for printing 	
63 	override string toString()
64 	{
65 		return format(
66 			`Version(version="%s")`, 
67 			_name == "" ? `""` : _name
68 		);
69 	}
70 	
71 	/// An alias for easier packing into a byte array without having to manually call the pack() method
72 	alias pack this;
73 }