Annotation of nono/lib/memorystream.h, revision 1.1

1.1     ! root        1: //
        !             2: // nono
        !             3: // Copyright (C) 2019 [email protected]
        !             4: //
        !             5: 
        !             6: #pragma once
        !             7: 
        !             8: #include "header.h"
        !             9: 
        !            10: // ホストのメモリ領域に対するストリームクラスみたいなもの。
        !            11: // データの受け渡しはホストエンディアンで、
        !            12: // アクセスはビッグエンディアンになる。
        !            13: class MemoryStreamBE
        !            14: {
        !            15:  protected:
        !            16:        union union_ptr {
        !            17:                uint8 *b;
        !            18:                uint16 *w;
        !            19:                uint32 *l;
        !            20:        };
        !            21: 
        !            22:  public:
        !            23:        // コンストラクタ
        !            24:        MemoryStreamBE() {
        !            25:        }
        !            26:        MemoryStreamBE(void *p) {
        !            27:                SetPtr(p);
        !            28:        }
        !            29:        // デストラクタ不要
        !            30: 
        !            31:        // ポインタを設定する
        !            32:        void SetPtr(void *p) {
        !            33:                ptr.b = (uint8 *)p;
        !            34:        }
        !            35: 
        !            36:        // ポインタを取得する
        !            37:        void *GetPtr() const {
        !            38:                return (void *)ptr.b;
        !            39:        }
        !            40: 
        !            41:        // 1バイト読み込んでポインタを進める
        !            42:        uint32 Read8() {
        !            43:                uint32 data = *ptr.b++;
        !            44:                return data;
        !            45:        }
        !            46:        // BE で2バイト読み込んでポインタを進める
        !            47:        uint32 Read16() {
        !            48:                uint32 data = *ptr.w++;
        !            49:                return be16toh(data);
        !            50:        }
        !            51:        // BE で4バイト読み込んでポインタを進める
        !            52:        uint32 Read32() {
        !            53:                uint32 data = *ptr.l++;
        !            54:                return be32toh(data);
        !            55:        }
        !            56: 
        !            57:        // 1バイト書き込んでポインタを進める
        !            58:        void Write8(uint32 data) {
        !            59:                *ptr.b++ = data;
        !            60:        }
        !            61:        // BE で2バイト書き込んでポインタを進める
        !            62:        void Write16(uint32 data) {
        !            63:                *ptr.w++ = htobe16(data);
        !            64:        }
        !            65:        // BE で4バイト書き込んでポインタを進める
        !            66:        void Write32(uint32 data) {
        !            67:                *ptr.l++ = htobe32(data);
        !            68:        }
        !            69: 
        !            70:  private:
        !            71:        union_ptr ptr {};
        !            72: };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.