1 // Written in the D programming language. 2 3 /** 4 A type for representing the iounit 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.iounit; 12 13 private { 14 import std.string : format; 15 16 import styx2000.lowlevel.endianness; 17 18 import styx2000.protobj.styxobject; 19 } 20 21 /** 22 A class that provides a type for the iounit field in some Styx messages. Inherits methods from StyxObject class. 23 See_Also: 24 https://web.archive.org/web/20201029184954/https://powerman.name/Inferno/man/5/0intro.html 25 */ 26 class Iounit : StyxObject 27 { 28 protected { 29 uint _iounit; 30 31 ubyte[] _representation; 32 } 33 34 /** 35 A constructor that creates an object of the Iounit class with the given parameter in the form of unsigned value. 36 If called without parameters, then the default parameter is zero. 37 Params: 38 iounit = Maximal size for atomic I/O operations. 39 40 Typical usage: 41 ---- 42 Iounit unit = new Iounit(0); 43 ---- 44 */ 45 this(uint iounit = 0) 46 { 47 _iounit = iounit; 48 _representation = toLEBytes!uint(iounit); 49 } 50 51 /// Get value from Iounit object 52 uint getUnit() 53 { 54 return _iounit; 55 } 56 57 /// Set value for Iounit from value 58 void setUnit(uint iounit) 59 { 60 _iounit = iounit; 61 _representation = toLEBytes!uint(iounit); 62 } 63 64 /// Convenient aliases for set/get 65 alias getIounit = getUnit; 66 alias setIounit = setUnit; 67 68 /// Pack to bytes array 69 ubyte[] pack() 70 { 71 return _representation; 72 } 73 74 /// Unpack from bytes array 75 void unpack(ubyte[] bytes...) 76 { 77 _representation = bytes[0..4]; 78 _iounit = fromLEBytes!uint(bytes[0..4]); 79 } 80 81 /// Convenient string representation of an object for printing 82 override string toString() 83 { 84 return format( 85 `IOunit(iounit=%d)`, 86 _iounit 87 ); 88 } 89 90 /// An alias for easier packing into a byte array without having to manually call the pack() method 91 alias pack this; 92 }