separate public types and private utils

This commit is contained in:
jangko 2020-10-22 12:09:34 +07:00 committed by zah
parent 4304251b09
commit 1e1ba43af2
6 changed files with 31 additions and 28 deletions

View File

@ -1,7 +1,7 @@
import
tables, strutils, typetraits, options,
tables, typetraits, options,
serialization/[object_serialization, errors],
./utils
./utils, ./types
type
WinregReader* = object
@ -32,8 +32,7 @@ proc init*(T: type WinregReader,
template getUnderlyingType*[T](_: Option[T]): untyped = T
proc readValue*[T](r: var WinregReader, value: var T)
{.raises: [SerializationError, IOError, Defect].} =
proc readValue*[T](r: var WinregReader, value: var T) =
mixin readValue
# TODO: reduce allocation
@ -65,8 +64,6 @@ proc readValue*[T](r: var WinregReader, value: var T)
var expectedFieldPos = 0
r.key.add ""
value.enumInstanceSerializedFields(fieldName, field):
type FieldType = type field
when T is tuple:
r.key[^1] = $expectedFieldPos
var reader = fields[][expectedFieldPos].reader

View File

@ -0,0 +1,21 @@
import
serialization/errors
type
HKEY* = distinct uint
RegType* = distinct int32
WinregError* = object of SerializationError
const
HKEY_CLASSES_ROOT* = HKEY(0x80000000'u)
HKEY_CURRENT_USER* = HKEY(0x80000001'u)
HKEY_LOCAL_MACHINE* = HKEY(0x80000002'u)
HKEY_USERS* = HKEY(0x80000003'u)
HKLM* = HKEY_LOCAL_MACHINE
HKCU* = HKEY_CURRENT_USER
HKCR* = HKEY_CLASSES_ROOT
HKU* = HKEY_USERS
proc `==`*(a, b: HKEY): bool {.borrow.}
proc `==`*(a, b: RegType): bool {.borrow.}

View File

@ -1,24 +1,11 @@
import
strutils,
serialization/errors
./types
type
HKEY* = distinct uint
RegType* = distinct int32
WinregError* = object of SerializationError
SomePrimitives* = SomeInteger | enum | bool | SomeFloat | char
const
HKEY_CLASSES_ROOT* = HKEY(0x80000000'u)
HKEY_CURRENT_USER* = HKEY(0x80000001'u)
HKEY_LOCAL_MACHINE* = HKEY(0x80000002'u)
HKEY_USERS* = HKEY(0x80000003'u)
HKLM* = HKEY_LOCAL_MACHINE
HKCU* = HKEY_CURRENT_USER
HKCR* = HKEY_CLASSES_ROOT
HKU* = HKEY_USERS
REG_SZ* = RegType(1)
REG_BINARY* = RegType(3)
REG_DWORD* = RegType(4)
@ -30,9 +17,6 @@ const
RT_QWORD* = 0x00000040
RT_ANY* = 0x0000ffff
proc `==`*(a, b: HKEY): bool {.borrow.}
proc `==`*(a, b: RegType): bool {.borrow.}
proc regGetValue(hKey: HKEY, lpSubKey, lpValue: cstring,
dwFlags: int32, pdwType: ptr RegType,
pvData: pointer, pcbData: ptr int32): int32 {.

View File

@ -1,9 +1,9 @@
import
stew/shims/macros,
serialization, ./reader, ./writer, ./utils
serialization, ./reader, ./writer, ./utils, ./types
export
serialization, reader, writer, utils
serialization, reader, writer, types
serializationFormat Winreg,
Reader = WinregReader,

View File

@ -1,7 +1,7 @@
import
typetraits, options, strutils, tables,
typetraits, options, tables,
serialization,
./utils
./utils, ./types
type
WinregWriter* = object

View File

@ -1,6 +1,7 @@
import
unittest, options,
../confutils/winreg/winreg_serialization
../confutils/winreg/winreg_serialization,
../confutils/winreg/utils
type
Fruit = enum