github.com/iDigitalFlame/xmt@v0.5.4/data/data.go (about) 1 // Copyright (C) 2020 - 2023 iDigitalFlame 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with this program. If not, see <https://www.gnu.org/licenses/>. 15 // 16 17 // Package data provides interfaces and helper methods that can be used for data 18 // writing and reading. This package exports the data Reader and Writer interfaces 19 // which are an extension of the standard io.Reader and io.Writer interfaces. 20 package data 21 22 const ( 23 // LimitSmall is the size value allowed for small strings using the WriteString 24 // and WriteBytes functions. 25 LimitSmall uint64 = 2 << 7 26 // LimitLarge is the size value allowed for large strings using the WriteString 27 // and WriteBytes functions. 28 LimitLarge uint64 = 2 << 31 29 // LimitMedium is the size value allowed for medium strings using the WriteString 30 // and WriteBytes functions. 31 LimitMedium uint64 = 2 << 15 32 ) 33 34 // Reader is a basic interface that supports all types of read functions of the 35 // core Golang builtin types. 36 // 37 // Pointer functions are available to allow for easier usage and fluid operation. 38 type Reader interface { 39 Close() error 40 Read([]byte) (int, error) 41 42 Int() (int, error) 43 Bool() (bool, error) 44 Int8() (int8, error) 45 Uint() (uint, error) 46 Int16() (int16, error) 47 Int32() (int32, error) 48 Int64() (int64, error) 49 Uint8() (uint8, error) 50 Bytes() ([]byte, error) 51 Uint16() (uint16, error) 52 Uint32() (uint32, error) 53 Uint64() (uint64, error) 54 Float32() (float32, error) 55 Float64() (float64, error) 56 StringVal() (string, error) 57 58 ReadInt(*int) error 59 ReadBool(*bool) error 60 ReadInt8(*int8) error 61 ReadUint(*uint) error 62 ReadInt16(*int16) error 63 ReadInt32(*int32) error 64 ReadInt64(*int64) error 65 ReadUint8(*uint8) error 66 ReadBytes(*[]byte) error 67 ReadUint16(*uint16) error 68 ReadUint32(*uint32) error 69 ReadUint64(*uint64) error 70 ReadString(*string) error 71 ReadFloat32(*float32) error 72 ReadFloat64(*float64) error 73 } 74 75 // Writer is a basic interface that supports writing of all core Golang builtin 76 // types. 77 type Writer interface { 78 Close() error 79 Flush() error 80 Write([]byte) (int, error) 81 82 WriteInt(int) error 83 WriteBool(bool) error 84 WriteInt8(int8) error 85 WriteUint(uint) error 86 WriteInt16(int16) error 87 WriteInt32(int32) error 88 WriteInt64(int64) error 89 WriteUint8(uint8) error 90 WriteBytes([]byte) error 91 WriteUint16(uint16) error 92 WriteUint32(uint32) error 93 WriteUint64(uint64) error 94 WriteString(string) error 95 WriteFloat32(float32) error 96 WriteFloat64(float64) error 97 }