├── .gitignore ├── BEST-PRACTICE.md ├── Go.md ├── LEGAL ├── LICENSE ├── README.md ├── adt ├── array │ └── protocol │ │ ├── associative.go │ │ └── dynamic.go ├── container │ └── protocol │ │ ├── container.go │ │ ├── element.go │ │ ├── index.go │ │ ├── iteration.go │ │ ├── length.go │ │ └── operations.go ├── graph │ └── protocol │ │ ├── dt-edge.go │ │ ├── dt-node-primary.go │ │ ├── dt-node-secondary.go │ │ └── graph.go ├── hash_table │ └── protocol │ │ └── hash-table.go ├── list │ └── protocol │ │ └── list.go ├── protocol │ ├── adt.go │ └── operations.go ├── queue │ ├── protocol │ │ ├── queue-priority.go │ │ └── queue.go │ ├── queue-codec.go │ └── queue.go ├── set │ └── protocol │ │ └── set.go └── stack │ └── protocol │ └── stack.go ├── audit ├── log │ ├── const.go │ ├── event-helpers.go │ ├── event-utf8.go │ ├── event.go │ ├── log-helpers.go │ ├── log.go │ ├── log_test.go │ ├── media-types.go │ ├── panic_handler.go │ ├── protocol │ │ ├── event.go │ │ ├── level.go │ │ └── log.go │ └── util.go └── request │ └── protocol │ └── dt-request-uuid.go ├── binary ├── README.md ├── be-in-be-cpu.go ├── be-in-le-cpu.go ├── be_bench_test.go ├── be_test.go ├── binary.go ├── binary_bench_test.go ├── binary_test.go ├── le-in-be-cpu.go ├── le-in-le-cpu.go ├── le_bench_test.go └── le_test.go ├── buffer ├── flat.go └── protocol │ └── buffer.go ├── codec ├── json │ ├── codec-runtime.go │ ├── codec.go │ ├── decode-minified-unsafe.go │ ├── decode-minified.go │ ├── decode-unsafe.go │ ├── decode.go │ ├── encode.go │ ├── errors │ │ ├── errors.go │ │ ├── locale.eng.go │ │ └── locale.per.go │ ├── media-types.go │ └── protocol │ │ └── json.go ├── protocol │ ├── codec.go │ └── marshalling.go └── syllab │ ├── codec-runtime.go │ ├── decode-safe.go │ ├── decode-unsafe.go │ ├── dynaimc-size-types.go │ ├── encode.go │ ├── encode_test.go │ ├── errors │ └── errors.go │ └── protocol │ └── syllab.go ├── compress-types ├── compress-types.go ├── compress-types_test.go ├── errors │ ├── init.go │ ├── locale.eng.go │ ├── locale.per.go │ ├── not_found.go │ └── not_found.locale.eng.go └── protocol │ └── compress-types.go ├── compress ├── errors │ ├── init.go │ ├── locale.eng.go │ ├── locale.per.go │ ├── source_not_changeable.go │ └── source_not_changeable.locale.eng.go ├── flate │ ├── compressor.go │ ├── decompressor.go │ ├── deflate.go │ ├── init.go │ ├── locale.eng.go │ └── locale.per.go ├── gzip │ ├── compressor.go │ ├── decompressor.go │ ├── gzip.go │ └── init.go └── protocol │ └── compress.go ├── computer ├── README.md ├── capsule │ └── protocol │ │ ├── accessor.go │ │ ├── life_cycle.go │ │ ├── object.go │ │ └── sync.go └── function │ └── protocol │ ├── access.go │ ├── function.go │ └── method.go ├── convert ├── array-slice-unsafe.go ├── bool-slice-unsafe.go ├── complex-slice-unsafe.go ├── float-slice-unsafe.go ├── integer-slice-unsafe.go ├── signed-integer-slice-unsafe.go └── string-unsafe.go ├── cpu ├── core.go └── core.s ├── crypto ├── aes-256.go ├── ccm.go ├── cipher-suites.go ├── gcm.go ├── hash.go ├── hash │ └── protocol │ │ └── hash.go └── protocol │ ├── cipher-suite.go │ └── cipher.go ├── datatype ├── data-type.go └── protocol │ ├── data-type.go │ ├── detail.go │ ├── id.go │ ├── life-cycle.go │ └── software-life_cycle.go ├── datatypes └── protocol │ └── data-types.go ├── error ├── chain-error.go ├── error-type.go ├── error.go ├── protocol │ ├── error.go │ ├── gui.go │ └── optional.go └── util.go ├── errors ├── error-duplicate_identifier.go ├── error-not_exist.go ├── error-not_exist.locale.eng.go ├── error-not_exist.locale.per.go ├── error-not_found.go ├── error-not_found.locale.eng.go ├── error-not_found.locale.per.go ├── error-not_provide_identifier.go ├── errors.go ├── errors_test.go ├── init.go ├── locale.eng.go ├── locale.per.go └── protocol │ └── errors.go ├── event ├── const.go ├── event.go ├── event_test.go ├── protocol │ ├── event-target.go │ └── event.go ├── target.go └── target_test.go ├── go.mod ├── go.sum ├── go └── parser │ ├── errors.go │ ├── package.go │ └── parse.go ├── gui ├── README.md ├── application.go ├── event-keyboard.go ├── event-scroll.go ├── event-touch.go ├── history.go ├── information.go ├── initialize.go ├── navigator.go ├── page-state.go ├── page.go ├── pages.go └── protocol │ ├── application.go │ ├── dom.go │ ├── element-status.go │ ├── element.go │ ├── event.go │ ├── history.go │ ├── information.go │ ├── navigator.go │ ├── page-state.go │ ├── page.go │ ├── screen.go │ ├── scroll.go │ └── som.go ├── identifier ├── 32byte │ ├── generated.go │ └── uuid.go ├── 8byte │ └── uuid.go ├── README.md ├── protocol │ ├── id.go │ ├── uuid-time.go │ └── uuid.go ├── rfc-4122 │ ├── utility.go │ └── uuid.go └── uuid-time-16byte │ └── uuid.go ├── main.go ├── math ├── boolean │ ├── boolean.go │ ├── const.go │ └── protocol │ │ └── boolean.go ├── decimal │ └── protocol │ │ └── decimal.go ├── errors │ └── errors.go ├── float │ ├── doc.go │ ├── float-32.go │ └── float-64.go ├── integer │ ├── const.go │ ├── doc.go │ ├── signed-64.go │ ├── signed-8.go │ ├── signed.go │ ├── unsigned-16.go │ ├── unsigned-16_test.go │ ├── unsigned-32.go │ ├── unsigned-32_test.go │ ├── unsigned-64.go │ ├── unsigned-64_test.go │ ├── unsigned-8.go │ └── unsigned-8_test.go ├── logic │ ├── conditional.go │ ├── logical-connective.go │ ├── operator-comparison.go │ └── protocol │ │ └── truth-functional.go ├── per │ ├── billion.go │ ├── cent-mille.go │ ├── cent.go │ ├── doc.go │ ├── mille.go │ ├── million.go │ ├── myriad.go │ ├── quadrillion.go │ ├── ten.go │ └── trillion.go └── protocol │ ├── math.go │ └── operations.go ├── mediatype ├── main-types.go ├── media-type.go └── protocol │ └── media-type.go ├── mediatypes ├── media-types.go ├── media-types_test.go └── protocol │ └── media-types.go ├── minify ├── css.go ├── html.go ├── minify.go └── protocol │ └── minify.go ├── modules ├── const.go ├── gui │ ├── module-cmd.go │ └── services │ │ ├── new-page │ │ ├── logic.go │ │ ├── request.go │ │ └── response.go │ │ └── splash-screen │ │ └── service-make-splash-screen.go └── syllab │ └── services │ └── go-methods │ └── generator.go ├── net ├── chapar │ ├── connection.go │ ├── connection_test.go │ ├── const.go │ ├── errors.go │ ├── frame-structure.go │ ├── frame.go │ ├── frame_test.go │ ├── locale.eng.go │ ├── locale.per.go │ ├── mux.go │ ├── path.go │ ├── port-bridge.go │ ├── port-bridge_test.go │ ├── port.go │ └── protocol.go ├── connection-status.go ├── connection-status_test.go ├── errors │ ├── guest_max_reached.go │ ├── guest_max_reached.locale.eng.go │ ├── guest_not_allow.go │ ├── guest_not_allow.locale.eng.go │ ├── init.go │ ├── locale.eng.go │ ├── locale.per.go │ ├── no_connection.go │ ├── no_connection.locale.eng.go │ ├── no_connection.locale.per.go │ ├── protocol_handler.go │ ├── protocol_handler.locale.eng.go │ ├── send_request.go │ └── send_request.locale.eng.go ├── frame.go ├── frames.go ├── gp │ ├── address.go │ ├── connection.go │ ├── connection_test.go │ ├── const.go │ ├── errors.go │ ├── frame-structure.go │ ├── frame.go │ ├── frame_test.go │ ├── init.go │ ├── locale.eng.go │ ├── locale.per.go │ ├── media-types.go │ └── protocol.go ├── http │ ├── README.md │ ├── body.go │ ├── const.go │ ├── errors │ │ ├── init.go │ │ ├── locale.eng.go │ │ └── locale.per.go │ ├── header.go │ ├── headers │ │ ├── accept.go │ │ ├── const.go │ │ ├── content-encoding.go │ │ ├── content-length.go │ │ ├── content-type.go │ │ ├── content-type_test.go │ │ ├── cookie.go │ │ ├── pragma.go │ │ ├── set-cookie.go │ │ └── transfer-encoding.go │ ├── locale.eng.go │ ├── locale.per.go │ ├── media-types.go │ ├── protocol │ │ ├── body.go │ │ ├── handler.go │ │ ├── header.go │ │ ├── http.go │ │ ├── method.go │ │ ├── pseudo_header.go │ │ ├── status.go │ │ └── version.go │ ├── request-pseudo_header.go │ ├── request.go │ ├── response-pseudo_header.go │ ├── response.go │ └── v1 │ │ ├── handler.go │ │ └── request_test.go ├── ipv4 │ ├── addr.go │ ├── const.go │ ├── errors.go │ ├── flag.go │ ├── locale.eng.go │ ├── locale.per.go │ ├── packet.go │ └── tcp.go ├── ipv6 │ ├── addr.go │ ├── const.go │ ├── errors.go │ ├── extension-headers-hop-by-hop.go │ ├── extension-routing.go │ ├── locale.eng.go │ ├── locale.per.go │ ├── packet-structure.go │ ├── packet.go │ └── tcp.go ├── l4 │ ├── frame-data.go │ ├── frame-packet-sequence-number.go │ └── frame-resend-broken-packet.go ├── l5 │ ├── frame-new-connection.go │ └── frame-reconnect.go ├── metric │ ├── connection.go │ └── connections-metric.go ├── packet-listener.go ├── packet-listener_test.go ├── packet-target.go ├── packet-target_test.go ├── protocol │ ├── address.go │ ├── frame-type.go │ ├── frame.go │ ├── osi_1-physical.go │ ├── osi_2-data_link.go │ ├── osi_3-network.go │ ├── osi_4-transport.go │ ├── osi_5-session.go │ ├── osi_6-presentation.go │ ├── osi_7-application.go │ ├── packet.go │ ├── socket.go │ └── status.go ├── sec │ ├── doc.go │ ├── frame-change-cipher-spec.go │ ├── frame-padding.go │ └── frame-signature.go ├── soap │ └── protocol │ │ └── soap.go ├── socket-buffer.go ├── socket-codec.go ├── socket-timing.go ├── socket.go ├── srpc │ ├── frame-call-service.go │ ├── frame-close-stream.go │ ├── frame-data-signature.go │ ├── frame-error.go │ ├── frame-open-stream.go │ ├── handler.go │ └── protocol │ │ └── srpc.go ├── std │ ├── io.go │ ├── net.go │ ├── net_test.go │ └── socket.go ├── stream-codec.go ├── tcp │ ├── README.md │ ├── cca.go │ ├── checksum.go │ ├── const.go │ ├── doc.go │ ├── ecn.go │ ├── errors │ │ └── errors.go │ ├── flag.go │ ├── header.go │ ├── locale.eng.go │ ├── locale.per.go │ ├── option-alt-checksum-data.go │ ├── option-alt-checksum.go │ ├── option-cc.go │ ├── option-ccecho.go │ ├── option-ccnew.go │ ├── option-delayed-acknowledgment.go │ ├── option-echo-reply.go │ ├── option-echo.go │ ├── option-mss.go │ ├── option-partial-order-connection-permitted.go │ ├── option-partial-order-service-profile.go │ ├── option-sack.go │ ├── option-stack-permited.go │ ├── option-timestamps.go │ ├── option-user_timeout.go │ ├── option-window-scale.go │ ├── option.go │ ├── port-number.go │ ├── port.go │ ├── segment.go │ ├── stream-firewall.go │ ├── stream-internal-syn-ack.go │ ├── stream-internal-syn.go │ ├── stream-internal.go │ ├── stream-metrics.go │ ├── stream-recv.go │ ├── stream-send.go │ ├── stream-status.go │ ├── stream-timing-delayed_acknowledgment.go │ ├── stream-timing-keep_alive.go │ ├── stream-timing-user_timeout.go │ ├── stream-timing.go │ ├── stream.go │ └── util.go ├── udp │ ├── const.go │ ├── errors │ │ ├── init.go │ │ ├── locale.eng.go │ │ ├── locale.per.go │ │ ├── packet_too_short.go │ │ ├── packet_too_short.locale.eng.go │ │ ├── packet_wrong_length.go │ │ └── packet_wrong_length.locale.eng.go │ └── packet.go └── uri │ ├── const.go │ ├── errors │ ├── errors.go │ ├── locale.eng.go │ └── locale.per.go │ ├── escape.go │ ├── media-types.go │ ├── protocol │ ├── authority.go │ ├── fragment.go │ ├── parsed.go │ ├── path.go │ ├── query.go │ ├── scheme.go │ ├── uri.go │ ├── url.go │ └── urn.go │ ├── uri-authority.go │ ├── uri-query.go │ ├── uri-user_Information.go │ ├── uri.go │ ├── uri_test.go │ └── urn.go ├── operation ├── README.md ├── command │ ├── README.md │ ├── cla.go │ ├── command.go │ ├── errors │ │ ├── flag_bad_syntax.go │ │ ├── flag_needs_an_arguments.go │ │ ├── flag_not_found.go │ │ ├── init.go │ │ ├── locale.eng.go │ │ ├── locale.per.go │ │ ├── service_call_by_alias.go │ │ ├── service_call_by_alias.locale.eng.go │ │ ├── service_not_accept_cli.go │ │ ├── service_not_accept_cli.locale.eng.go │ │ ├── service_not_accept_cli.locale.per.go │ │ └── service_not_found.go │ ├── flag.go │ ├── path.go │ ├── protocol │ │ ├── arguments.go │ │ └── command.go │ └── serve.go ├── protocol │ ├── action.go │ ├── action.locale.eng.go │ ├── action.locale.per.go │ ├── deadline.go │ ├── importance.go │ ├── priority.go │ ├── timeout.go │ └── weight.go ├── service │ ├── protocol │ │ ├── handlers.go │ │ ├── id.go │ │ └── service.go │ └── service.go └── services │ ├── errors │ ├── errors.go │ ├── locale.eng.go │ └── locale.per.go │ ├── protocol │ └── services.go │ ├── services.go │ └── services_test.go ├── os ├── default │ ├── file-directory.go │ ├── file-meta-data.go │ ├── file.go │ ├── network-transport-multiplexer.go │ ├── os.go │ └── sort.go ├── os_darwin.go ├── os_freebsd.go ├── os_linux.go ├── os_netbsd.go ├── os_openbsd.go ├── os_persiaos.go ├── os_windows.go ├── persiaos │ ├── errors-storage.go │ ├── network-transport-multiplexer.go │ └── os.go └── protocol │ ├── drivers.go │ ├── os.go │ ├── signal.go │ ├── storage.go │ └── users.go ├── picture └── protocol │ ├── color.go │ └── image.go ├── pool ├── bench_realloc-vs-empty_test.go ├── lifo.go └── status.go ├── runtime └── protocol │ ├── concurrency.go │ ├── runtime.go │ ├── scheduler.go │ └── stack.go ├── staticcheck.conf ├── storage ├── block │ └── protocol │ │ └── block.go ├── file │ ├── file.go │ ├── protocol │ │ ├── directory.go │ │ ├── file.go │ │ ├── metadata.go │ │ └── uri.go │ └── uri.go └── memory │ ├── protocol │ └── copy.go │ └── reference │ └── protocol │ └── reference.go ├── string ├── ascii │ └── protocol │ │ └── ascii.go ├── harf │ ├── charecters-tables.go │ ├── scripts.go │ └── string.go ├── protocol │ ├── character-encoding.go │ ├── character.go │ ├── string.go │ └── stringer.go └── utf8 │ └── protocol │ └── utf8.go ├── time ├── astronomy │ └── time.go ├── duration │ ├── const.go │ ├── micro-second.go │ ├── milli-second.go │ ├── nano-in-second.go │ ├── nano-second.go │ ├── nano-second_test.go │ ├── protocol │ │ └── duration.go │ └── second.go ├── earth │ ├── dayhour.go │ ├── duration-day.go │ ├── duration-hour.go │ ├── duration-minute.go │ ├── duration-month.go │ ├── duration-week.go │ └── duration-year.go ├── mars │ └── time.go ├── monotonic │ ├── atomic.go │ ├── epoch.go │ ├── now.go │ └── time.go ├── protocol │ ├── epoch.go │ └── time.go ├── unix │ ├── atomic.go │ ├── const.go │ ├── epoch.go │ ├── now.go │ ├── time.go │ └── time_test.go └── utc │ ├── dayhour.go │ ├── epoch.go │ ├── time.go │ ├── weekday.go │ ├── weekday.locale.en.go │ ├── weekday.locale.fa.go │ └── weekday_test.go ├── timer ├── const.go ├── doc.go ├── errors │ ├── init.go │ ├── locale.eng.go │ ├── locale.per.go │ ├── negative_duration.go │ ├── negative_duration.locale.eng.go │ ├── negative_period_number.go │ ├── negative_period_number.locale.eng.go │ ├── timer_already_init.go │ ├── timer_already_init.locale.eng.go │ ├── timer_already_started.go │ ├── timer_already_started.locale.eng.go │ ├── timer_bad_status.go │ ├── timer_bad_status.locale.eng.go │ ├── timer_not_init.go │ ├── timer_not_init.locale.eng.go │ ├── timer_racy_access.go │ └── timer_racy_access.locale.eng.go ├── init.go ├── protocol │ ├── listener.go │ ├── ticker.go │ ├── timer-status.go │ ├── timer.go │ └── timing.go ├── status.go ├── tick-limit.go ├── tick.go ├── timer-async.go ├── timer-async_test.go ├── timer-sync.go ├── timing-heap-bucket.go ├── timing-heap.go ├── timing-wheel │ └── timing-wheel.go ├── timing.go └── util.go ├── trash └── data-type-primitive.go ├── user ├── protocol │ ├── id.go │ └── type.go ├── user-type.go ├── user-type_test.go └── user.go └── validators ├── errors.go ├── locale.eng.go ├── locale.per.go ├── luhn-algorithm.go ├── protocol ├── specifications.go └── validation.go └── text.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | ____* 8 | _obj 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /adt/array/protocol/dynamic.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package array_p 4 | 5 | import ( 6 | container_p "memar/adt/container/protocol" 7 | ) 8 | 9 | // Slice is dynamically size array 10 | // https://en.wikipedia.org/wiki/Dynamic_array 11 | type Dynamic[ELEMENT container_p.Element] interface { 12 | container_p.Container[ELEMENT] 13 | } 14 | -------------------------------------------------------------------------------- /adt/container/protocol/element.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package container_p 4 | 5 | // Element is describe 6 | type Element any 7 | -------------------------------------------------------------------------------- /adt/container/protocol/index.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package container_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | // ElementIndex is related to `NumberOfElement` 10 | // ElementIndex can refer to any location of memory blocks in byte or 8bit number. 11 | type ElementIndex int 12 | 13 | type LastElementIndex interface { 14 | // LastElementIndex return the location of last element in the container. 15 | LastElementIndex() ElementIndex 16 | } 17 | 18 | type Index[ELEMENT Element] interface { 19 | // Index return the location of given element in the container. 20 | Index(el ELEMENT) (ei ElementIndex, err error_p.Error) 21 | } 22 | 23 | type LastIndex[ELEMENT Element] interface { 24 | // LastIndex return the location of given element in the container from end of container. 25 | LastIndex(el ELEMENT) (ei ElementIndex, err error_p.Error) 26 | } 27 | -------------------------------------------------------------------------------- /adt/container/protocol/iteration.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package container_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | // https://github.com/golang/go/discussions/54245 10 | 11 | type Iteration[ELEMENT Element] interface { 12 | Iterate(startIndex ElementIndex, iterator Iterate[ELEMENT]) (err error_p.Error) 13 | 14 | // TODO::: Stop() or return (breaking bool)?? 15 | // Stop() // break the iterate function 16 | } 17 | 18 | type Iterate[ELEMENT Element] interface { 19 | // Iterate or traverse 20 | // In each iteration if err != nil, iteration will be stopped 21 | Iterate(index ElementIndex, el ELEMENT) (err error_p.Error) 22 | } 23 | -------------------------------------------------------------------------------- /adt/graph/protocol/dt-edge.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package graph_p 4 | 5 | type Field_Edge[ID any] interface { 6 | // Edge usually is a label. 7 | // labelID. Edge in graph data type 8 | Edge() ID 9 | } 10 | -------------------------------------------------------------------------------- /adt/graph/protocol/dt-node-primary.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package graph_p 4 | 5 | type Field_PrimaryNode[ID any] interface { 6 | PrimaryNode() ID 7 | } 8 | -------------------------------------------------------------------------------- /adt/graph/protocol/dt-node-secondary.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package graph_p 4 | 5 | type Field_SecondaryNode[ID any] interface { 6 | SecondaryNode() ID 7 | } 8 | -------------------------------------------------------------------------------- /adt/graph/protocol/graph.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package graph_p 4 | 5 | // https://en.wikipedia.org/wiki/Graph_(abstract_data_type) 6 | type Graph[pID, sID, eID any] interface { 7 | Field_PrimaryNode[pID] 8 | Field_SecondaryNode[sID] 9 | Field_Edge[eID] 10 | } 11 | -------------------------------------------------------------------------------- /adt/protocol/adt.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package adt_p 4 | 5 | // Abstract data types are theoretical entities, used (among other things) to simplify the description of abstract algorithms, 6 | // to classify and evaluate data structures, and to formally describe the type systems of programming languages. 7 | // Primitive data types are a form of Abstract data type. It is just that they are provided by the language makers. 8 | // https://en.wikipedia.org/wiki/Abstract_data_type 9 | // It is a special DataType. So all ADT implementors MUST be a DataType too, But not reverse. 10 | // Means not all DataType need to implements ADT 11 | type ADT interface { 12 | Empty 13 | Nil 14 | Null 15 | } 16 | -------------------------------------------------------------------------------- /adt/protocol/operations.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package adt_p 4 | 5 | // Nil is for object pointers, NULL is for non pointers 6 | // TODO::: Is nil same as void?? 7 | type Empty interface { 8 | // an operation for testing whether or not a container is empty(Nil && Null). 9 | IsEmpty() bool 10 | } 11 | 12 | type Nil interface { 13 | // IsNil report is pointer to the Element valid or not. 14 | IsNil() bool 15 | } 16 | 17 | type Null interface { 18 | // IsNull report is the Element has value(data set before) or not. 19 | IsNull() bool 20 | } 21 | -------------------------------------------------------------------------------- /adt/queue/protocol/queue-priority.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package queue_p 4 | 5 | // https://en.wikipedia.org/wiki/Priority_queue 6 | -------------------------------------------------------------------------------- /adt/queue/queue-codec.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package queue 4 | 5 | import ( 6 | adt_p "memar/adt/protocol" 7 | buffer_p "memar/buffer/protocol" 8 | "memar/protocol" 9 | ) 10 | 11 | //memar:impl memar/codec/protocol.Codec 12 | func (q *Queue) Decode(source buffer_p.Buffer) (err protocol.Error) { return } 13 | func (q *Queue) Encode(destination buffer_p.Buffer) (err protocol.Error) { 14 | return 15 | } 16 | func (q *Queue) Marshal() (data []byte, err protocol.Error) { 17 | return 18 | } 19 | func (q *Queue) Unmarshal(source []byte) (n adt_p.NumberOfElement, err protocol.Error) { 20 | return 21 | } 22 | func (q *Queue) SerializationLength() (ln adt_p.NumberOfElement) { return q.totalLen } 23 | -------------------------------------------------------------------------------- /adt/set/protocol/set.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package set_p 4 | 5 | // https://en.wikipedia.org/wiki/Set_(abstract_data_type) 6 | -------------------------------------------------------------------------------- /adt/stack/protocol/stack.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package stack_p 4 | 5 | import ( 6 | container_p "memar/adt/container/protocol" 7 | ) 8 | 9 | // Stack is stack data structure. 10 | // https://en.wikipedia.org/wiki/Stack_(abstract_data_type) 11 | type Stack[ELEMENT container_p.Element] interface { 12 | container_p.Push[ELEMENT] 13 | container_p.Pop[ELEMENT] 14 | } 15 | -------------------------------------------------------------------------------- /audit/log/const.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package log 4 | 5 | // Application immutable runtime settings 6 | const ( 7 | 8 | // CNF_DevelopingMode use to indicate that app can do some more logic e.g. 9 | // - Save more logs 10 | // - Add more services like net/http/pprof for better debugging 11 | // - Add more pages that just need only for developers 12 | CNF_DevelopingMode = true 13 | ) 14 | -------------------------------------------------------------------------------- /audit/log/event-utf8.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package log 4 | 5 | import ( 6 | "runtime/debug" 7 | 8 | log_p "memar/log/protocol" 9 | "memar/protocol" 10 | "memar/string/utf8" 11 | ) 12 | 13 | // Event is a log event 14 | type Event_UTF8 struct { 15 | Event 16 | 17 | msgSTR utf8.String 18 | stackSTR utf8.ByteSlice 19 | } 20 | 21 | //memar:impl memar/protocol.ObjectLifeCycle 22 | func (e *Event_UTF8) Init(dt protocol.DataType, level log_p.Level, message string, stack bool) { 23 | e.msgSTR = utf8.String(message) 24 | if stack { 25 | e.stackSTR.Init(debug.Stack()) 26 | } 27 | 28 | e.Event.Init(dt, level, &e.msgSTR, &e.stackSTR) 29 | } 30 | -------------------------------------------------------------------------------- /audit/log/log.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package log 4 | 5 | import ( 6 | "memar/event" 7 | ) 8 | 9 | // Logger is default global like window.console.log global variable in browsers. 10 | // As suggested in protocol.Logger document, You can listen to notify about any log events occur. 11 | var Logger event.EventTarget[*Event] 12 | -------------------------------------------------------------------------------- /audit/log/log_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package log 4 | 5 | import ( 6 | log_p "memar/audit/log/protocol" 7 | ) 8 | 9 | var _ log_p.Logger[*Event] = &Logger 10 | -------------------------------------------------------------------------------- /audit/log/media-types.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package log 4 | 5 | import ( 6 | "memar/datatype" 7 | datatype_p "memar/datatype/protocol" 8 | ) 9 | 10 | var DT domainType 11 | 12 | type domainType struct { 13 | datatype.DataType 14 | } 15 | 16 | //memar:impl memar/protocol.MediaType 17 | func (dt *domainType) MediaType() string { return "domain/memar.scm.geniuses.group; package=log" } 18 | 19 | //memar:impl memar/datatype/protocol.DataType_Details 20 | func (dt *domainType) LifeCycle() datatype_p.LifeCycle { return datatype_p.LifeCycle_PreAlpha } 21 | func (dt *domainType) ReferenceURI() string { return "" } 22 | func (dt *domainType) IssueDate() string { return "" } 23 | func (dt *domainType) ExpiryDate() string { return "" } 24 | func (dt *domainType) ExpireInFavorOf() datatype_p.DataType { return nil } 25 | -------------------------------------------------------------------------------- /audit/log/util.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package log 4 | 5 | import ( 6 | "runtime" 7 | 8 | error_p "memar/error/protocol" 9 | ) 10 | 11 | func CallerInfo(calldepth int) (file string, line int) { 12 | var ok bool 13 | _, file, line, ok = runtime.Caller(calldepth) 14 | if !ok { 15 | file = "?" 16 | line = 0 17 | } 18 | return 19 | } 20 | 21 | // FatalError use as log.FatalError(function()) and not check return error from function. 22 | // It will just panic error not exit app and return to OS, Because all goroutine without any notify will terminate and can't recover in any way. 23 | // So we just panic it and wait to some logic recover it or let app close in main function. 24 | func FatalError(err error_p.Error) { 25 | if err != nil { 26 | // os.Exit(125) 27 | panic(err) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /audit/request/protocol/dt-request-uuid.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package request_p 4 | 5 | import ( 6 | record_p "memar/storage/record/protocol" 7 | ) 8 | 9 | // Field audit request (logging) is the process of documenting activity within the software systems used across your organization. 10 | // 11 | // Audit logs record the occurrence of an event, the time at which it occurred, the responsible user or service, 12 | // and the impacted entity. All of the devices in your network, your cloud services, 13 | // and your applications emit logs that may be used for auditing purposes. 14 | type Field_RequestID interface { 15 | RequestID() UUID 16 | } 17 | 18 | type Field_RequestIDs interface { 19 | RequestsID() []UUID 20 | } 21 | 22 | // Request RecordID to prove how domain objects created in the chain of other objects. 23 | type UUID record_p.UUID 24 | -------------------------------------------------------------------------------- /binary/README.md: -------------------------------------------------------------------------------- 1 | # Binary 2 | 3 | ## Little Endian vs Big Endian 4 | Go added library to compiler don't support [automatic endian detection](https://groups.google.com/g/golang-nuts/c/3GEzwKfRRQw), So we must have some mechanism to detect CPU architecture and do logics correctly. So by some [help](https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63) we can implement by compile time or runtime. 5 | 6 | Runtime mechanism suggestion like [x/net](https://github.com/golang/net/tree/master/internal/socket/sys.go) is not efficient enough for very low level tasks, So we implement this compile time logic package. 7 | 8 | ## [Conversions - Cast](https://go.dev/ref/spec#Conversions) 9 | Converting uint64 to int64 costs nothing: the bits don't change. Only the interpretation of them does. Just be careful about how large your uint64 is because it could end up becoming negative once it's converted to int64. 10 | 11 | ## Resources 12 | - https://groups.google.com/g/golang-nuts/c/Y95NNox15Ns 13 | -------------------------------------------------------------------------------- /binary/be_bench_test.go: -------------------------------------------------------------------------------- 1 | package binary 2 | 3 | import "testing" 4 | 5 | func BenchmarkBigEndian_PutUint16(b *testing.B) { 6 | for i := 0; i < b.N; i++ { 7 | BigEndian.PutUint16(putbuf[:2], uint16(i)) 8 | } 9 | } 10 | 11 | func BenchmarkBigEndian_PutUint32(b *testing.B) { 12 | for i := 0; i < b.N; i++ { 13 | BigEndian.PutUint32(putbuf[:4], uint32(i)) 14 | } 15 | } 16 | 17 | func BenchmarkBigEndian_PutUint64(b *testing.B) { 18 | for i := 0; i < b.N; i++ { 19 | BigEndian.PutUint64(putbuf, uint64(i)) 20 | } 21 | } 22 | 23 | func BenchmarkBigEndian_Uint16(b *testing.B) { 24 | for i := 0; i < b.N; i++ { 25 | u16 = BigEndian.Uint16(big[2:4]) 26 | } 27 | } 28 | 29 | func BenchmarkBigEndian_Uint32(b *testing.B) { 30 | for i := 0; i < b.N; i++ { 31 | u32 = BigEndian.Uint32(big[4:8]) 32 | } 33 | } 34 | 35 | func BenchmarkBigEndian_Uint64(b *testing.B) { 36 | for i := 0; i < b.N; i++ { 37 | u64 = BigEndian.Uint64(big[8:]) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /binary/binary.go: -------------------------------------------------------------------------------- 1 | // For license and copyright information please see the LEGAL file in the code repository 2 | 3 | package binary 4 | 5 | func Bool(b []byte) bool { return b[0] != 0 } 6 | func Uint8(b []byte) uint8 { return uint8(b[0]) } 7 | 8 | func PutBool(b []byte, v bool) { 9 | if v { 10 | b[0] = 1 11 | } else { 12 | b[0] = 0 13 | } 14 | } 15 | func PutUint8(b []byte, v uint8) { 16 | b[0] = v 17 | } 18 | -------------------------------------------------------------------------------- /binary/binary_test.go: -------------------------------------------------------------------------------- 1 | package binary 2 | 3 | import "testing" 4 | 5 | func TestUint8(t *testing.T) { 6 | var expected uint8 = 0x01 7 | if got := Uint8([]byte{0x01}); got != expected { 8 | t.Errorf("Uint8(): got %x, want %x", got, expected) 9 | } 10 | } 11 | 12 | func TestBool(t *testing.T) { 13 | var expected bool = true 14 | if got := Bool([]byte{0x01}); got != expected { 15 | t.Errorf("Bool(): got %t, want %t", got, expected) 16 | } 17 | } 18 | 19 | func TestPutUint8(t *testing.T) { 20 | var got = [1]byte{0x00} 21 | var expected = [1]byte{0x10} 22 | if PutUint8(got[:], 0x10); got != expected { 23 | t.Errorf("Uint8(): got %v, want %v", got, expected) 24 | } 25 | } 26 | 27 | func TestPutBool(t *testing.T) { 28 | var got = [1]byte{0x00} 29 | var expected = [1]byte{0x01} 30 | if PutBool(got[:], true); got != expected { 31 | t.Errorf("PutBool(): got %v, want %v", got, expected) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /codec/json/decode-minified-unsafe.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package json 4 | 5 | import ( 6 | "bytes" 7 | 8 | "libgo/convert" 9 | "libgo/protocol" 10 | ) 11 | 12 | // DecoderUnsafeMinified store data to decode data by each method. 13 | type DecoderUnsafeMinified struct { 14 | DecoderMinified 15 | } 16 | 17 | // DecodeString return string. pass d.buf start from after " and receive from from after " 18 | func (d *DecoderUnsafeMinified) DecodeString() (s string, err protocol.Error) { 19 | d.Offset(1) // due to have " at start 20 | 21 | var loc = bytes.IndexByte(d.buf, '"') 22 | if loc < 0 { 23 | err = &ErrEncodedStringCorrupted 24 | return 25 | } 26 | 27 | var slice []byte = d.buf[:loc] 28 | d.Offset(loc + 1) 29 | s = convert.UnsafeByteSliceToString(slice) 30 | return 31 | } 32 | -------------------------------------------------------------------------------- /codec/json/decode-unsafe.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package json 4 | 5 | import ( 6 | "bytes" 7 | 8 | "libgo/convert" 9 | "libgo/protocol" 10 | ) 11 | 12 | // DecoderUnsafe store data to decode data by each method! 13 | type DecoderUnsafe struct { 14 | Decoder 15 | } 16 | 17 | // DecodeString return string. pass d.buf start from after " and receive from from after " 18 | func (d *DecoderUnsafe) DecodeString() (s string, err protocol.Error) { 19 | if d.CheckNullValue() { 20 | return 21 | } 22 | 23 | var loc = bytes.IndexByte(d.buf, '"') 24 | d.buf = d.buf[loc+1:] // remove any byte before first " due to don't need them 25 | 26 | loc = bytes.IndexByte(d.buf, '"') 27 | if loc < 0 { 28 | err = &ErrEncodedStringCorrupted 29 | return 30 | } 31 | 32 | var slice []byte = d.buf[:loc] 33 | 34 | d.buf = d.buf[loc+1:] 35 | s = convert.UnsafeByteSliceToString(slice) 36 | return 37 | } 38 | -------------------------------------------------------------------------------- /codec/json/errors/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package json 6 | 7 | const domainPersian = "جیسون" 8 | 9 | func init() { 10 | } 11 | -------------------------------------------------------------------------------- /codec/syllab/codec-runtime.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see LEGAL file in repository */ 2 | 3 | package syllab 4 | 5 | /* 6 | ********************PAY ATTENTION:******************* 7 | We don't suggest use these 2 func instead use CompleteEncoderMethodSafe() to autogenerate needed code before compile time 8 | and reduce runtime proccess to improve performance of the app and gain max performance from this protocol! 9 | */ 10 | 11 | // Marshal encodes the value of s to the payload buffer in runtime. 12 | // offset add free space by given number at begging of return slice that almost just use in sRPC protocol! It can be 0!! 13 | func Marshal(s interface{}, offset int) (p []byte, err error) { 14 | return 15 | } 16 | 17 | // UnMarshal decode payload and stores the result in the value pointed to by s in runtime. 18 | func UnMarshal(p []byte, s interface{}) (err error) { 19 | return 20 | } 21 | -------------------------------------------------------------------------------- /compress-types/compress-types_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package cts 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | var _ protocol.CompressTypes = &cts 10 | -------------------------------------------------------------------------------- /compress-types/errors/init.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | const domainBaseMediatype = "domain/memar.scm.geniuses.group; package=compress-types; type=error; name=" 6 | 7 | func init() { 8 | ErrNotFound.Init() 9 | } 10 | -------------------------------------------------------------------------------- /compress-types/errors/locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errs 6 | 7 | const domainEnglish = "Compress-Types" 8 | -------------------------------------------------------------------------------- /compress-types/errors/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errs 6 | 7 | const domainPersian = "فشرده سازی ها" 8 | -------------------------------------------------------------------------------- /compress-types/errors/not_found.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ErrNotFound errNotFound 12 | 13 | type errNotFound struct{ er.Err } 14 | 15 | func (dt *errNotFound) Init() (err protocol.Error) { 16 | err = dt.Err.Init(domainBaseMediatype + "not-found") 17 | if err != nil { 18 | return 19 | } 20 | err = errors.Register(dt) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /compress-types/errors/not_found.locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errs 6 | 7 | //memar:impl memar/protocol.Detail 8 | func (d *errNotFound) Domain() string { return domainEnglish } 9 | func (d *errNotFound) Summary() string { return "Not Found" } 10 | func (d *errNotFound) Overview() string { 11 | return "Can't find requested compression||decompression algorithm" 12 | } 13 | func (d *errNotFound) UserNote() string { return "" } 14 | func (d *errNotFound) DevNote() string { return "" } 15 | func (d *errNotFound) TAGS() []string { return []string{} } 16 | 17 | //memar:impl memar/protocol.Quiddity 18 | func (d *errNotFound) Name() string { return "" } 19 | func (d *errNotFound) Abbreviation() string { return "" } 20 | func (d *errNotFound) Aliases() []string { return []string{} } 21 | -------------------------------------------------------------------------------- /compress-types/protocol/compress-types.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package cts_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | type CompressTypes interface { 10 | Register(ct CompressType) (err error_p.Error) 11 | GetByID(id ID) (ct CompressType, err error_p.Error) 12 | GetByMediaType(mt string) (ct CompressType, err error_p.Error) 13 | GetByFileExtension(ex string) (ct CompressType, err error_p.Error) 14 | GetByContentEncoding(ce string) (ct CompressType, err error_p.Error) 15 | 16 | ContentEncodings() []string 17 | } 18 | -------------------------------------------------------------------------------- /compress/errors/init.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | const domainBaseMediatype = "domain/memar.scm.geniuses.group; package=compress; type=error; name=" 6 | 7 | func init() { 8 | ErrSourceNotChangeable.Init() 9 | } 10 | -------------------------------------------------------------------------------- /compress/errors/locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errs 6 | 7 | const domainEnglish = "Compress" 8 | -------------------------------------------------------------------------------- /compress/errors/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errs 6 | 7 | const domainPersian = "فشرده سازی" 8 | -------------------------------------------------------------------------------- /compress/errors/source_not_changeable.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ErrSourceNotChangeable errSourceNotChangeable 12 | 13 | type errSourceNotChangeable struct{ er.Err } 14 | 15 | func (dt *errSourceNotChangeable) Init() (err protocol.Error) { 16 | err = dt.Err.Init(domainBaseMediatype + "source-not-changeable") 17 | if err != nil { 18 | return 19 | } 20 | err = errors.Register(dt) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /compress/flate/init.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package flate 4 | 5 | import ( 6 | cts "memar/compress-types" 7 | ) 8 | 9 | func init() { 10 | Deflate.Init() 11 | cts.Register(&Deflate) 12 | } 13 | -------------------------------------------------------------------------------- /compress/flate/locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package flate 6 | 7 | const domainEnglish = "Flate Compress" 8 | 9 | //memar:impl memar/protocol.Detail 10 | func (d *deflate) Domain() string { return domainEnglish } 11 | func (d *deflate) Summary() string { return "" } 12 | func (d *deflate) Overview() string { return "" } 13 | func (d *deflate) UserNote() string { return "" } 14 | func (d *deflate) DevNote() string { return "" } 15 | func (d *deflate) TAGS() []string { return []string{} } 16 | 17 | //memar:impl memar/protocol.Quiddity 18 | func (d *deflate) Name() string { return "" } 19 | func (d *deflate) Abbreviation() string { return "" } 20 | func (d *deflate) Aliases() []string { return []string{} } 21 | -------------------------------------------------------------------------------- /compress/flate/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package flate 6 | 7 | const domainPersian = "فشرده ساز فلیت" 8 | 9 | //memar:impl memar/protocol.Detail 10 | func (d *deflate) Domain() string { return domainPersian } 11 | func (d *deflate) Summary() string { return "" } 12 | func (d *deflate) Overview() string { return "" } 13 | func (d *deflate) UserNote() string { return "" } 14 | func (d *deflate) DevNote() string { return "" } 15 | func (d *deflate) TAGS() []string { return []string{} } 16 | 17 | //memar:impl memar/protocol.Quiddity 18 | func (d *deflate) Name() string { return "" } 19 | func (d *deflate) Abbreviation() string { return "" } 20 | func (d *deflate) Aliases() []string { return []string{} } 21 | -------------------------------------------------------------------------------- /compress/gzip/init.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gzip 4 | 5 | import ( 6 | cts "memar/compress-types" 7 | ) 8 | 9 | func init() { 10 | GZIP.Init() 11 | cts.Register(&GZIP) 12 | } 13 | -------------------------------------------------------------------------------- /computer/README.md: -------------------------------------------------------------------------------- 1 | # Computer 2 | 3 | ## Computer programs 4 | A [computer programs](https://en.wikipedia.org/wiki/Computer_program) is a sequence or set of instructions in a programming language for a computer to execute. It is one component of software, which also includes documentation and other intangible components. 5 | 6 | ## Programming language 7 | A [programming language](https://en.wikipedia.org/wiki/Programming_language) is a system of notation for writing computer programs. 8 | 9 | ## DSL 10 | A [domain-specific language (DSL)](https://en.wikipedia.org/wiki/Domain-specific_language) is a computer language specialized to a particular application domain. 11 | -------------------------------------------------------------------------------- /computer/capsule/protocol/object.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package capsule_p 4 | 5 | import ( 6 | function_p "memar/computer/function/protocol" 7 | datatype_p "memar/datatype/protocol" 8 | ) 9 | 10 | type Capsule interface { 11 | Fields() []datatype_p.DataType 12 | Methods() []function_p.Method 13 | 14 | // datatype_p.DataType 15 | // LifeCycle 16 | } 17 | -------------------------------------------------------------------------------- /computer/capsule/protocol/sync.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package capsule_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | type Locker interface { 10 | Lock() (err error_p.Error) 11 | Unlock() (err error_p.Error) 12 | } 13 | -------------------------------------------------------------------------------- /computer/function/protocol/function.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package function_p 4 | 5 | import ( 6 | datatype_p "memar/datatype/protocol" 7 | ) 8 | 9 | // Function 10 | type Function interface { 11 | // We believe fields MUST always access from inside the object, 12 | // So we MUST have this method just in methods not fields. 13 | Access() Access 14 | 15 | WhenToExecuted() // runtime, compile time 16 | 17 | Blocking() bool // TODO::: be method or as type?? 18 | // TODO::: add more 19 | 20 | datatype_p.DataType 21 | } 22 | -------------------------------------------------------------------------------- /computer/function/protocol/method.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package function_p 4 | 5 | import ( 6 | datatype_p "memar/datatype/protocol" 7 | ) 8 | 9 | // Method 10 | type Method interface { 11 | Function 12 | 13 | Receiver() datatype_p.DataType // std/go/ast.FuncType.TypeParams 14 | } 15 | -------------------------------------------------------------------------------- /convert/bool-slice-unsafe.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see LEGAL file in repository */ 2 | 3 | package convert 4 | 5 | import ( 6 | "reflect" 7 | "unsafe" 8 | ) 9 | 10 | // UnsafeBoolSliceToByteSlice returns ... 11 | func UnsafeBoolSliceToByteSlice(req []bool) (res []byte) { 12 | var reqStruct = (*reflect.SliceHeader)(unsafe.Pointer(&req)) 13 | var resStruct = (*reflect.SliceHeader)(unsafe.Pointer(&res)) 14 | resStruct.Data = reqStruct.Data 15 | resStruct.Len = reqStruct.Len 16 | resStruct.Cap = reqStruct.Cap 17 | return 18 | } 19 | 20 | // UnsafeByteSliceToBoolSlice returns ... 21 | func UnsafeByteSliceToBoolSlice(req []byte) (res []bool) { 22 | var reqStruct = (*reflect.SliceHeader)(unsafe.Pointer(&req)) 23 | var resStruct = (*reflect.SliceHeader)(unsafe.Pointer(&res)) 24 | resStruct.Data = reqStruct.Data 25 | resStruct.Len = reqStruct.Len 26 | resStruct.Cap = reqStruct.Cap 27 | return 28 | } 29 | -------------------------------------------------------------------------------- /convert/string-unsafe.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see LEGAL file in repository */ 2 | 3 | package convert 4 | 5 | import ( 6 | "reflect" 7 | "unsafe" 8 | ) 9 | 10 | // UnsafeStringToByteSlice returns ... 11 | func UnsafeStringToByteSlice(req string) (res []byte) { 12 | var reqStruct = (*reflect.StringHeader)(unsafe.Pointer(&req)) 13 | var resStruct = (*reflect.SliceHeader)(unsafe.Pointer(&res)) 14 | resStruct.Data = reqStruct.Data 15 | resStruct.Len = reqStruct.Len 16 | resStruct.Cap = reqStruct.Len 17 | return 18 | } 19 | 20 | // UnsafeByteSliceToString returns ... 21 | func UnsafeByteSliceToString(req []byte) (res string) { 22 | var reqStruct = (*reflect.SliceHeader)(unsafe.Pointer(&req)) 23 | var resStruct = (*reflect.StringHeader)(unsafe.Pointer(&res)) 24 | resStruct.Data = reqStruct.Data 25 | resStruct.Len = reqStruct.Len 26 | return 27 | } 28 | -------------------------------------------------------------------------------- /cpu/core.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright info please see LEGAL file in repository */ 2 | 3 | package cpu 4 | 5 | import "runtime" 6 | 7 | type CoreID uint64 8 | 9 | func (id *CoreID) Active() { 10 | *id = CoreID(activeCoreID()) 11 | } 12 | 13 | // activeCoreID or WhichCoreAmIOn return active core id that thread(goroutine) run on it. 14 | func activeCoreID() uint64 15 | 16 | // LogicalCount returns the number of logical CPUs usable by the current process. 17 | func LogicalCount() uint { return uint(runtime.NumCPU()) } 18 | 19 | // PhysicalCount returns the number of physical CPUs usable by the current process. 20 | func PhysicalCount() uint { return uint(runtime.NumCPU()) } 21 | -------------------------------------------------------------------------------- /cpu/core.s: -------------------------------------------------------------------------------- 1 | // func activeCoreID() uint64 2 | TEXT ·activeCoreID(SB),7,$0 3 | MOVQ $0xB,AX 4 | XORQ CX,CX 5 | CPUID 6 | MOVQ DX,ret+0(FP) 7 | RET 8 | -------------------------------------------------------------------------------- /crypto/aes-256.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see LEGAL file in repository */ 2 | 3 | package crypto 4 | 5 | // AESBlockSize is block size in bytes. 6 | const AESBlockSize = 16 7 | 8 | // A aes256 is an instance of AES-256 encryption using a particular key. 9 | type aes256 struct { 10 | enc [60]uint32 11 | dec [60]uint32 12 | } 13 | 14 | // NewAES256 use to create the aes256 that implement BlockCipher128 interface! 15 | func NewAES256(key [32]byte) BlockCipher128 { 16 | var c = aes256{} 17 | return &c 18 | } 19 | 20 | // Encrypt encrypts the buf. 21 | // If original buf needed for any other proccess, must clone it before pass it!! 22 | func (aes *aes256) Encrypt(block *[16]byte) {} 23 | 24 | // Decrypt decrypts the buf. 25 | // If original buf needed for any other proccess, must clone it before pass it!! 26 | func (aes *aes256) Decrypt(block *[16]byte) {} 27 | -------------------------------------------------------------------------------- /crypto/ccm.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see LEGAL file in repository */ 2 | 3 | package crypto 4 | 5 | // CCM cipher mode 6 | type ccm struct { 7 | b BlockCipher128 8 | } 9 | 10 | // NewCCM use to create the ccm that implement Cipher interface! 11 | func NewCCM(b BlockCipher128) Cipher { 12 | var c = ccm{ 13 | b: b, 14 | } 15 | return &c 16 | } 17 | 18 | // Encrypt encrypts the buf. 19 | // If original buf needed for any other proccess, must clone it before pass it!! 20 | func (c *ccm) Encrypt(buf []byte) (err error) { 21 | return 22 | } 23 | 24 | // Decrypt decrypts the buf. 25 | // If original buf needed for any other proccess, must clone it before pass it!! 26 | func (c *ccm) Decrypt(buf []byte) (err error) { 27 | return 28 | } 29 | -------------------------------------------------------------------------------- /crypto/cipher-suites.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see LEGAL file in repository */ 2 | 3 | package crypto -------------------------------------------------------------------------------- /crypto/gcm.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see LEGAL file in repository */ 2 | 3 | package crypto 4 | 5 | // GCM cipher mode 6 | type gcm struct { 7 | b BlockCipher128 8 | } 9 | 10 | // NewGCM use to create the gcm that implement Cipher interface! 11 | func NewGCM(b BlockCipher128) Cipher { 12 | var g = gcm{ 13 | b: b, 14 | } 15 | return &g 16 | } 17 | 18 | // Encrypt encrypts the buf. 19 | // If original buf needed for any other proccess, must clone it before pass it!! 20 | func (g *gcm) Encrypt(buf []byte) (err error) { 21 | return 22 | } 23 | 24 | // Decrypt decrypts the buf. 25 | // If original buf needed for any other proccess, must clone it before pass it!! 26 | func (g *gcm) Decrypt(buf []byte) (err error) { 27 | return 28 | } -------------------------------------------------------------------------------- /crypto/hash.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see LEGAL file in repository */ 2 | 3 | package crypto 4 | 5 | // Hash32 represents an implementation for a 32 bit hash! 6 | type Hash32 interface { 7 | Generate(buf []byte) (hash uint32) 8 | } 9 | 10 | // Hash64 represents an implementation for a 64 bit hash! 11 | type Hash64 interface { 12 | Generate(buf []byte) (hash uint64) 13 | } 14 | 15 | // Hash128 represents an implementation for a 128 bit hash! 16 | type Hash128 interface { 17 | Generate(buf []byte) (hash [16]byte) 18 | } 19 | 20 | // Hash256 represents an implementation for a 256 bit hash! 21 | type Hash256 interface { 22 | Generate(buf []byte) (hash [32]byte) 23 | } 24 | -------------------------------------------------------------------------------- /datatype/protocol/id.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package datatype_p 4 | 5 | type Field_ID interface { 6 | DataTypeID() ID 7 | } 8 | 9 | // ID use as a way to distinguish data-types as domains. 10 | // It MUST fill by any UUID mechanism that guaranty it will be globally unique. 11 | // Suggest use first 64bit of Hash of MediaType() 12 | type ID uint64 13 | -------------------------------------------------------------------------------- /datatype/protocol/software-life_cycle.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package datatype_p 4 | 5 | // SoftwareLifeCycle indicate methods any apps or object should have. 6 | type SoftwareLifeCycle interface { 7 | } 8 | -------------------------------------------------------------------------------- /datatypes/protocol/data-types.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package protocol 4 | 5 | import ( 6 | datatype_p "memar/datatype/protocol" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | type DataTypes interface { 11 | Register(dt datatype_p.DataType) (err error_p.Error) 12 | GetByID(id datatype_p.ID) (dt datatype_p.DataType, err error_p.Error) 13 | } 14 | -------------------------------------------------------------------------------- /error/error-type.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package error 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | //memar:impl memar/error/protocol.Internal 10 | func IsInternal(err error_p.Error) bool { 11 | var interErr, ok = err.(error_p.Internal) 12 | return ok && interErr.Internal() 13 | } 14 | 15 | //memar:impl memar/error/protocol.Temporary 16 | func IsTemporary(err error_p.Error) bool { 17 | var tempErr, ok = err.(error_p.Temporary) 18 | return ok && tempErr.Temporary() 19 | } 20 | 21 | //memar:impl memar/error/protocol.Timeout 22 | func IsTimeout(err error_p.Error) bool { 23 | var timeErr, ok = err.(error_p.Timeout) 24 | return ok && timeErr.Timeout() 25 | } 26 | -------------------------------------------------------------------------------- /error/error.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package error 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | // IsEqual compare two Error. 10 | // Suggest to add more logic to Error.Equal() logic such as chain situation! 11 | func IsEqual(base, with error_p.Error) bool { 12 | if base == nil && with == nil { 13 | return true 14 | } 15 | if base != nil && 16 | with != nil && 17 | base.MediaType() == with.MediaType() && 18 | base.DataTypeID() == with.DataTypeID() { 19 | return true 20 | } 21 | return false 22 | } 23 | -------------------------------------------------------------------------------- /error/protocol/gui.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package error_p 4 | 5 | // GUI indicate how Error capsule must act in GUI applications. 6 | // 7 | // GUI can use also in CLI apps by e.g. use `//go:build gui` tag, 8 | // But strongly suggest DON'T think in this way and just use `Log` concept 9 | type GUI interface { 10 | // Notify error to user by graphic, sound and vibration (Haptic Feedback) 11 | Notify() 12 | } 13 | -------------------------------------------------------------------------------- /error/util.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package error 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | func ToGoError(err error_p.Error) error { 10 | if err == nil { 11 | return nil 12 | } 13 | 14 | var errStr errorString 15 | errStr.msg = err.Summary() 16 | return &errStr 17 | } 18 | 19 | // errorString is a trivial implementation of error. 20 | type errorString struct { 21 | msg string 22 | } 23 | 24 | func (e *errorString) Error() string { return e.msg } 25 | 26 | func ToError(err error) error_p.Error { 27 | if err == nil { 28 | return nil 29 | } 30 | 31 | var exErr = err.(error_p.Error) 32 | if exErr != nil { 33 | return exErr 34 | } 35 | 36 | // TODO::: 37 | return nil 38 | } 39 | -------------------------------------------------------------------------------- /errors/error-not_exist.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errors 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/protocol" 8 | ) 9 | 10 | var ErrNotExist errNotExist 11 | 12 | type errNotExist struct{ er.Err } 13 | 14 | func (dt *errNotExist) Init() (err protocol.Error) { 15 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=errors; type=error; name=not_exist") 16 | if err != nil { 17 | return 18 | } 19 | err = Register(dt) 20 | return 21 | } 22 | -------------------------------------------------------------------------------- /errors/error-not_found.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errors 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/protocol" 8 | ) 9 | 10 | var ( 11 | ErrNotFound errNotFound 12 | ) 13 | 14 | type errNotFound struct{ er.Err } 15 | 16 | func (dt *errNotFound) Init() (err protocol.Error) { 17 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=errors; type=error; name=not_found") 18 | if err != nil { 19 | return 20 | } 21 | err = Register(dt) 22 | return 23 | } 24 | -------------------------------------------------------------------------------- /errors/error-not_provide_identifier.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errors 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/protocol" 8 | ) 9 | 10 | var ErrNotProvideIdentifier errNotProvideIdentifier 11 | 12 | type errNotProvideIdentifier struct{ er.Err } 13 | 14 | func (dt *errNotProvideIdentifier) Init() (err protocol.Error) { 15 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=errors; type=error; name=not_provide_identifier") 16 | if err != nil { 17 | return 18 | } 19 | err = Register(dt) 20 | return 21 | } 22 | -------------------------------------------------------------------------------- /errors/errors_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errors 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | var _ protocol.Errors = &errors 10 | -------------------------------------------------------------------------------- /errors/init.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errors 4 | 5 | func init() { 6 | ErrNotFound.Init() 7 | ErrNotExist.Init() 8 | 9 | // This conditions must be true just in the dev phase. 10 | ErrNotProvideIdentifier.Init() 11 | ErrDuplicateIdentifier.Init() 12 | } 13 | -------------------------------------------------------------------------------- /errors/locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errors 6 | 7 | const domainEnglish = "Errors" 8 | -------------------------------------------------------------------------------- /errors/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errors 6 | 7 | const domainPersian = "خطاها" 8 | -------------------------------------------------------------------------------- /errors/protocol/errors.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errors_p 4 | 5 | import ( 6 | datatype_p "memar/datatype/protocol" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | // Errors use to register errors to get them in a desire way e.g. ErrorID in http headers. 11 | type Errors interface { 12 | Register(errorToRegister error_p.Error) (err error_p.Error) 13 | GetByID(id datatype_p.ID) (err error_p.Error) 14 | GetByMediaType(mt string) (err error_p.Error) 15 | } 16 | -------------------------------------------------------------------------------- /event/const.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package event 4 | 5 | const ( 6 | CNF_InitialListenersLength = 8 7 | ) 8 | -------------------------------------------------------------------------------- /event/event_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package event 4 | 5 | import ( 6 | event_p "memar/event/protocol" 7 | ) 8 | 9 | var _ event_p.Event = &Event{} 10 | -------------------------------------------------------------------------------- /event/target_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package event 4 | 5 | import ( 6 | event_p "memar/event/protocol" 7 | ) 8 | 9 | var _ event_p.Target[*Event] = &Target[*Event]{} 10 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module memar 2 | // module github.com/GeniusesGroup/memar-go 3 | 4 | go 1.23 5 | 6 | require ( 7 | github.com/tdewolff/minify v2.3.6+incompatible 8 | github.com/tdewolff/parse v2.3.4+incompatible 9 | golang.org/x/crypto v0.15.0 10 | golang.org/x/tools v0.15.0 11 | ) 12 | 13 | require ( 14 | golang.org/x/sys v0.14.0 // indirect 15 | ) 16 | 17 | // replace ( 18 | // memar => ./ 19 | // ) 20 | -------------------------------------------------------------------------------- /go/parser/errors.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package parser 4 | 5 | import "errors" 6 | 7 | //Declare Errors Details 8 | var ( 9 | ErrEmptyPackageFolder = errors.New("You can't have empty logic folder or logic package contain no compatible function") 10 | ErrBadServiceName = errors.New("Each service file must start with ServiceID") 11 | ErrBadServiceParameters = errors.New("Service functions must have just one struct as parameters") 12 | ) 13 | -------------------------------------------------------------------------------- /gui/README.md: -------------------------------------------------------------------------------- 1 | # GUI - Graphical User Interface 2 | 3 | ## Resources 4 | - https://developer.mozilla.org/en-US/docs/Web/API/Window 5 | - https://github.com/gopherjs/gopherjs 6 | - https://webvision.mozilla.org/full/ 7 | - https://extensiblewebmanifesto.org/ 8 | - https://open-ui.org/ 9 | - https://www.chromium.org/teams/web-capabilities-fugu/ 10 | - https://fugu-tracker.web.app/ 11 | 12 | ## Related Projects 13 | All below projects have many problems. 14 | - [Flutter](https://docs.flutter.dev/) mix content(HTML) and style(CSS) in to logic(JS, Dart, Go, ...) language 15 | - https://github.com/maxence-charriere/go-app/blob/master/pkg/ui/scroll.go >> indicate scroll as a content not behavior of elements 16 | - https://github.com/gioui/gio 17 | - https://github.com/asticode/go-astilectron 18 | - https://github.com/zserge/lorca 19 | - https://github.com/wailsapp/wails 20 | - https://github.com/sciter-sdk/go-sciter 21 | -------------------------------------------------------------------------------- /gui/application.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gui 4 | 5 | // Application store the data to run a GUI application 6 | // Such to implement phase 1 (compile go to js) to run in webview. 7 | // https://github.com/webview/webview 8 | type Application struct { 9 | Domain string // full domain name use for gui app like gui.geniuses.group 10 | Icon []byte 11 | Info []Information 12 | LocaleInfo Information 13 | ContentPreferences string 14 | PresentationPreferences string 15 | 16 | UserPreferences UserPreferences 17 | DesignLanguageStyles string 18 | 19 | Pages 20 | Navigator 21 | History 22 | } 23 | 24 | // UserPreferences : 25 | type UserPreferences struct { 26 | UsersState UsersState 27 | } 28 | 29 | // UsersState : 30 | type UsersState struct { 31 | usersID []string 32 | activeUserID string 33 | } 34 | -------------------------------------------------------------------------------- /gui/event-scroll.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gui 4 | 5 | type ScrollEvent uint8 6 | 7 | const ( 8 | ScrollEvent_Unset ScrollEvent = iota 9 | ScrollEvent_HOME 10 | ScrollEvent_END 11 | ScrollEvent_STEP_PLUS 12 | ScrollEvent_STEP_MINUS 13 | ScrollEvent_PAGE_PLUS 14 | ScrollEvent_PAGE_MINUS 15 | ScrollEvent_POS 16 | ScrollEvent_SLIDER_RELEASED 17 | ScrollEvent_CORNER_PRESSED 18 | ScrollEvent_CORNER_RELEASED 19 | ) 20 | -------------------------------------------------------------------------------- /gui/event-touch.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gui 4 | 5 | // https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent 6 | type TouchEvent interface { 7 | // Event 8 | 9 | Type() string 10 | } 11 | 12 | // https://developer.mozilla.org/en-US/docs/Web/API/Touch 13 | -------------------------------------------------------------------------------- /gui/history.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gui 4 | 5 | type History struct { 6 | } 7 | -------------------------------------------------------------------------------- /gui/information.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gui 4 | 5 | // Information : 6 | type Information struct { 7 | language string 8 | name string 9 | shortName string 10 | tagline string 11 | slogan string 12 | description string 13 | tags []string 14 | } 15 | 16 | func (i *Information) Language() string { return i.language } 17 | func (i *Information) Name() string { return i.name } 18 | func (i *Information) ShortName() string { return i.shortName } 19 | func (i *Information) Tagline() string { return i.tagline } 20 | func (i *Information) Slogan() string { return i.slogan } 21 | func (i *Information) Description() string { return i.description } 22 | func (i *Information) Tags() []string { return i.tags } 23 | -------------------------------------------------------------------------------- /gui/initialize.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gui 4 | 5 | // Initialize use to initialize application object 6 | func (a *Application) Initialize() { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /gui/navigator.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gui 4 | 5 | import ( 6 | gui_p "memar/gui/protocol" 7 | ) 8 | 9 | type Navigator struct { 10 | switcherPage Page 11 | homePage Page 12 | activePage Page 13 | pages []Page 14 | } 15 | 16 | // Active a page like alt+tab in windows to show Pages() and their states 17 | func (n *Navigator) SwitcherPage() {} 18 | 19 | func (n *Navigator) HomePage() (page gui_p.Page) { 20 | return 21 | } 22 | func (n *Navigator) ActivePage() (page gui_p.Page) { 23 | return 24 | } 25 | 26 | // It must reorder by recently active page be last item in the array 27 | func (n *Navigator) Pages() (page []gui_p.Page) { 28 | return 29 | } 30 | 31 | func (n *Navigator) ActivatePage(url string) {} // Navigate(url string) 32 | -------------------------------------------------------------------------------- /gui/page-state.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gui 4 | 5 | // PageState : 6 | type PageState struct { 7 | Title string 8 | Description string 9 | } 10 | -------------------------------------------------------------------------------- /gui/pages.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gui 4 | 5 | import gui_p "memar/gui/protocol" 6 | 7 | // Pages implements gui_p.Pages interface 8 | type Pages struct { 9 | poolByTimeAdded []gui_p.Page 10 | poolByPath map[string]gui_p.Page 11 | } 12 | 13 | func (p *Pages) RegisterPage(page gui_p.Page) { 14 | p.poolByTimeAdded = append(p.poolByTimeAdded, page) 15 | p.poolByPath[page.Path()] = page 16 | } 17 | func (p *Pages) GetPageByPath(path string) (page gui_p.Page) { 18 | return p.poolByPath[path] 19 | } 20 | func (p *Pages) Pages() (pages []gui_p.Page) { 21 | return p.poolByTimeAdded 22 | } 23 | -------------------------------------------------------------------------------- /gui/protocol/application.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gui_p 4 | 5 | // GUI is default global protocol.Application like window global variable in browsers. 6 | // You must assign to it by any object implement protocol.Application on your main.go file. Suggestion: 7 | // - GUI App >> gui_p.GUI = &gui.Application 8 | var GUI Application 9 | 10 | // Application is UI (GUI, VUI, ...) specific protocols that include in Application interface 11 | type Application interface { 12 | Pages 13 | Navigator 14 | History 15 | } 16 | -------------------------------------------------------------------------------- /gui/protocol/dom.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gui_p 4 | 5 | type DOM interface{} 6 | -------------------------------------------------------------------------------- /gui/protocol/history.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gui_p 4 | 5 | type History interface { 6 | PreviousPageState() PageState 7 | FollowingPageState() PageState 8 | 9 | // Find states by PageID, Title, ... 10 | } 11 | -------------------------------------------------------------------------------- /gui/protocol/information.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gui_p 4 | 5 | // Information store application, page, widget locale details 6 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl 7 | type Information interface { 8 | Language() string 9 | Name() string 10 | ShortName() string 11 | Tagline() string 12 | Slogan() string 13 | Description() string 14 | Tags() []string 15 | } 16 | -------------------------------------------------------------------------------- /gui/protocol/navigator.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gui_p 4 | 5 | type Navigator interface { 6 | // Active a page like alt+tab in windows to show Pages() and their states 7 | SwitcherPage() 8 | 9 | HomePage() (page Page) 10 | ActivePage() (page Page) 11 | // It must reorder by recently active page be last item in the array 12 | ActivePages() (pages []Page) 13 | 14 | ActivatePage(url string) // Navigate(url string) 15 | } 16 | -------------------------------------------------------------------------------- /gui/protocol/som.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gui_p 4 | 5 | // SOM as Style-Object-Model 6 | // same in many way to CSSOM as Cascading-Style-Sheets-Object-Model https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model 7 | type SOM interface { 8 | } 9 | -------------------------------------------------------------------------------- /identifier/32byte/generated.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package uuid 4 | 5 | import "memar/protocol" 6 | 7 | type Generated struct { 8 | UID 9 | id protocol.DataTypeID 10 | idAsString string 11 | } 12 | 13 | func (g *Generated) NewHashString(data string) { 14 | g.NewHash((unsafeStringToByteSlice(data))) 15 | g.id = g.UID.ID() 16 | g.idAsString = g.UID.IDasString() 17 | } 18 | 19 | func (g *Generated) ID() protocol.DataTypeID { return g.id } 20 | func (g *Generated) IDasString() string { return g.idAsString } 21 | -------------------------------------------------------------------------------- /identifier/README.md: -------------------------------------------------------------------------------- 1 | # ID or Identifier 2 | An [identifier](https://en.wikipedia.org/wiki/Identifier) is a name that identifies (that is, labels the identity of) either a unique object or a unique class of objects, where the "object" or class may be an idea, person, physical countable object (or class thereof), or physical noncountable substance (or class thereof). 3 | 4 | ## UID 5 | The [unique identifier (UID)](https://en.wikipedia.org/wiki/Unique_identifier) is an identifier that refers to only one instance—only one particular object in the universe. 6 | 7 | ## UUID 8 | A [Universally Unique Identifier (UUID)](https://en.wikipedia.org/wiki/Universally_unique_identifier) is a 128-bit label used for information in computer systems. The term Globally Unique Identifier (GUID) is also used, mostly in Microsoft systems. 9 | -------------------------------------------------------------------------------- /identifier/protocol/id.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package identifier_p 4 | 5 | type ID uint64 6 | -------------------------------------------------------------------------------- /identifier/protocol/uuid-time.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package identifier_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | time_p "memar/time/protocol" 8 | ) 9 | 10 | type UUID_Time interface { 11 | ExistenceTime() time_p.Time 12 | 13 | string_p.Stringer[string_p.String] 14 | } 15 | -------------------------------------------------------------------------------- /identifier/protocol/uuid.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package identifier_p 4 | 5 | type UUID_Hash interface { 6 | UUID() [32]byte // Hash of a record data 7 | ID() ID // first 64bit of UUID 8 | } 9 | -------------------------------------------------------------------------------- /identifier/rfc-4122/utility.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package uuid 4 | 5 | import ( 6 | "bytes" 7 | "encoding/hex" 8 | ) 9 | 10 | // Equal returns true if uuid1 and uuid2 equals 11 | func Equal(uuid1, uuid2 [16]byte) bool { 12 | return bytes.Equal(uuid1[:], uuid2[:]) 13 | } 14 | 15 | // ToString returns canonical string representation of UUID: 16 | // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. 17 | func ToString(uuid [16]byte) string { 18 | buf := make([]byte, 36) 19 | hex.Encode(buf[0:8], uuid[0:4]) 20 | buf[8] = '-' 21 | hex.Encode(buf[9:13], uuid[4:6]) 22 | buf[13] = '-' 23 | hex.Encode(buf[14:18], uuid[6:8]) 24 | buf[18] = '-' 25 | hex.Encode(buf[19:23], uuid[8:10]) 26 | buf[23] = '-' 27 | hex.Encode(buf[24:], uuid[10:]) 28 | 29 | return string(buf) 30 | } 31 | 32 | // FromString will parsing UUID from string input 33 | func FromString(s string) (uuid [16]byte) { 34 | return 35 | } 36 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package main 4 | 5 | import ( 6 | "os" 7 | 8 | "memar/modules" 9 | ) 10 | 11 | // TODO::: act as a server?? 12 | 13 | func init() { 14 | modules.RootCommand.Init() 15 | } 16 | 17 | func main() { 18 | // remove app binary path from os args 19 | var args = os.Args[1:] 20 | var err = modules.RootCommand.ServeCLA(args) 21 | if err != nil { 22 | os.Exit(1) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /math/boolean/const.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package boolean 4 | 5 | const ( 6 | True Boolean = true // 1 7 | False Boolean = false // 0 8 | ) 9 | -------------------------------------------------------------------------------- /math/boolean/protocol/boolean.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package boolean_p 4 | 5 | import ( 6 | logic_p "memar/math/logic/protocol" 7 | ) 8 | 9 | // Boolean algebra is a branch of mathematics that deals with operations on logical values with binary variables. 10 | // The Boolean variables are represented as binary numbers to represent truths: 1 = true and 0 = false. 11 | // https://en.wikipedia.org/wiki/Boolean_datatype 12 | // https://en.wikipedia.org/wiki/Boolean_algebra 13 | // https://en.wikipedia.org/wiki/Boolean_algebra_(structure) 14 | // 15 | // Some other languages: 16 | // - https://doc.rust-lang.org/stable/std/primitive.bool.html 17 | type Boolean[B any /*Boolean*/] interface { 18 | logic_p.Conjunction[B, B] 19 | logic_p.Disjunction[B, B] 20 | logic_p.Equivalence[B] 21 | logic_p.Negation[B] 22 | } 23 | -------------------------------------------------------------------------------- /math/decimal/protocol/decimal.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package decimal_p 4 | 5 | import ( 6 | math_p "memar/math/protocol" 7 | ) 8 | 9 | // https://docs.microsoft.com/en-us/dotnet/api/system.decimal?view=net-6.0#methods 10 | // https://github.com/shopspring/decimal 11 | type Decimal /*[I Integer, D Signed]*/ interface { 12 | Integer() int64 // "-123456" of the number "-123456.235689" 13 | Decimal() uint64 // "235689" of the number "-123456.235689" 14 | 15 | math_p.Operations[Decimal] 16 | } 17 | -------------------------------------------------------------------------------- /math/errors/errors.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | ) 8 | 9 | // Errors 10 | var ( 11 | ErrEmptyValue er.Error 12 | ErrValueOutOfRange er.Error 13 | ErrBadValue er.Error 14 | ) 15 | 16 | func init() { 17 | ErrEmptyValue.Init("domain/memar.scm.geniuses.group; package=convert; type=error; name=empty-value") 18 | ErrValueOutOfRange.Init("domain/memar.scm.geniuses.group; package=convert; type=error; name=value-out-of-range") 19 | ErrBadValue.Init("domain/memar.scm.geniuses.group; package=convert; type=error; name=bad-value") 20 | } 21 | -------------------------------------------------------------------------------- /math/float/doc.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | // https://en.wikipedia.org/wiki/Floating-point_arithmetic 4 | package float 5 | -------------------------------------------------------------------------------- /math/float/float-32.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package float 4 | 5 | import ( 6 | "strconv" 7 | 8 | "memar/math/boolean" 9 | "memar/protocol" 10 | ) 11 | 12 | // F32 is 32-bit floating point number. 13 | type F32 float32 14 | 15 | //memar:impl memar/protocol.DataType_Equal 16 | func (f *F32) Equal(with F32) boolean.Boolean { 17 | return *f == with 18 | } 19 | 20 | //memar:impl memar/protocol.Stringer 21 | func (f *F32) ToString() (str string, err protocol.Error) { 22 | str = strconv.FormatFloat(float64(*f), 'g', -1, f.bitSize()) 23 | return 24 | } 25 | func (f *F32) FromString(str string) (err protocol.Error) { 26 | // TODO::: error handling 27 | var f32, _ = strconv.ParseFloat(str, f.bitSize()) 28 | *f = F32(f32) 29 | return 30 | } 31 | 32 | func (f *F32) bitSize() int { return 32 } 33 | -------------------------------------------------------------------------------- /math/float/float-64.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package float 4 | 5 | import ( 6 | "strconv" 7 | 8 | "memar/math/boolean" 9 | "memar/protocol" 10 | ) 11 | 12 | // F64 is 64-bit floating point number. 13 | type F64 float64 14 | 15 | //memar:impl memar/protocol.DataType_Equal 16 | func (f *F64) Equal(with F64) boolean.Boolean { 17 | return *f == with 18 | } 19 | 20 | //memar:impl memar/protocol.Stringer 21 | func (f *F64) ToString() (str string, err protocol.Error) { 22 | str = strconv.FormatFloat(float64(*f), 'g', -1, f.bitSize()) 23 | return 24 | } 25 | func (f *F64) FromString(str string) (err protocol.Error) { 26 | // TODO::: error handling 27 | var f64, _ = strconv.ParseFloat(str, f.bitSize()) 28 | *f = F64(f64) 29 | return 30 | } 31 | 32 | func (f *F64) bitSize() int { return 64 } 33 | -------------------------------------------------------------------------------- /math/integer/const.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package integer 4 | 5 | const ( 6 | maxUint8Value uint8 = 255 7 | maxUint16Value uint16 = 65535 8 | maxUint32Value uint32 = 4294967295 9 | ) 10 | -------------------------------------------------------------------------------- /math/integer/doc.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | // https://en.wikipedia.org/wiki/Integer_(computer_science) 4 | package integer 5 | -------------------------------------------------------------------------------- /math/integer/signed-64.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package integer 4 | 5 | import ( 6 | "strconv" 7 | 8 | "memar/math/boolean" 9 | "memar/protocol" 10 | ) 11 | 12 | // S64 is signed 64 bit integer 13 | type S64 int64 14 | 15 | //memar:impl memar/protocol.DataType_Equal 16 | func (s *S64) Equal(with S64) boolean.Boolean { 17 | return *s == with 18 | } 19 | 20 | //memar:impl memar/protocol.Stringer 21 | func (s *S64) ToString() (str string, err protocol.Error) { 22 | str = strconv.FormatInt(int64(*s), 10) 23 | return 24 | } 25 | func (s *S64) FromString(str string) (err protocol.Error) { 26 | strconv.ParseInt(str, 10, s.bitSize()) 27 | return 28 | } 29 | 30 | func (s *S64) bitSize() int { return 64 } 31 | -------------------------------------------------------------------------------- /math/integer/signed-8.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package integer 4 | 5 | import ( 6 | "strconv" 7 | 8 | "memar/math/boolean" 9 | "memar/protocol" 10 | ) 11 | 12 | // S8 is signed 8 bit integer 13 | type S8 int8 14 | 15 | //memar:impl memar/protocol.DataType_Equal 16 | func (s *S8) Equal(with S8) boolean.Boolean { 17 | return *s == with 18 | } 19 | 20 | // TODO::: not efficient enough code 21 | // 22 | //memar:impl memar/protocol.Stringer 23 | func (s *S8) ToString() (str string, err protocol.Error) { 24 | str = strconv.FormatInt(int64(*s), 10) 25 | return 26 | } 27 | func (s *S8) FromString(str string) (err protocol.Error) { 28 | strconv.ParseInt(str, 10, s.bitSize()) 29 | return 30 | } 31 | 32 | func (s *S8) bitSize() int { return 8 } 33 | -------------------------------------------------------------------------------- /math/integer/signed.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package integer 4 | 5 | import ( 6 | "strconv" 7 | 8 | "memar/math/boolean" 9 | "memar/protocol" 10 | ) 11 | 12 | // https://en.wikipedia.org/wiki/Integer_(computer_science) 13 | type Signed struct { 14 | number int64 15 | bitSize int 16 | } 17 | 18 | //memar:impl memar/protocol.DataType_Equal 19 | func (s *Signed) Equal(with Signed) boolean.Boolean { 20 | return *s == with 21 | } 22 | 23 | //memar:impl memar/protocol.Stringer 24 | func (s *Signed) ToString() (str string, err protocol.Error) { 25 | str = strconv.FormatInt(int64(s.number), 10) 26 | return 27 | } 28 | func (s *Signed) FromString(str string) (err protocol.Error) { 29 | strconv.ParseInt(str, 10, s.bitSize) 30 | return 31 | } 32 | -------------------------------------------------------------------------------- /math/logic/conditional.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package cl 4 | 5 | type Field_Conditional interface { 6 | Conditional() Conditional 7 | } 8 | 9 | // 10 | // https://en.wikipedia.org/wiki/Conditional_(computer_programming) 11 | type Conditional uint64 12 | 13 | const ( 14 | Conditional_Unset Conditional = iota 15 | Conditional_Then 16 | Conditional_ActionAndContinue 17 | Conditional_Continue 18 | Conditional_Break 19 | Conditional_Return 20 | ) 21 | -------------------------------------------------------------------------------- /math/per/billion.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package per 4 | 5 | // Billion equal to per billion(1,000,000,000) with (ppm) sign 6 | type Billion uint32 7 | 8 | // Calculate return PerBillion of given number. 9 | func (b Billion) Calculate(num uint64) (per uint64) { 10 | return (num * uint64(b)) / 1000000000 11 | } 12 | -------------------------------------------------------------------------------- /math/per/cent-mille.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package per 4 | 5 | // CentMille equal to per Hundred Thousand(100,000) with (pcm) sign 6 | type CentMille uint32 7 | 8 | // Calculate return PerCentMille of given number. 9 | func (b CentMille) Calculate(num uint64) (per uint64) { 10 | return (num * uint64(b)) / 100000 11 | } 12 | -------------------------------------------------------------------------------- /math/per/cent.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package per 4 | 5 | // Cent equal to per hundred(100) with % sign 6 | type Cent uint8 7 | 8 | // Calculate return PerCent of given number. 9 | func (b Cent) Calculate(num uint64) (per uint64) { 10 | return (num * uint64(b)) / 100 11 | } 12 | -------------------------------------------------------------------------------- /math/per/doc.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | /* 4 | Use in calculate proportion that means a part, share, or number considered in comparative relation to a whole. 5 | */ 6 | package per 7 | -------------------------------------------------------------------------------- /math/per/mille.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package per 4 | 5 | // Mille equal to per thousand(1000) with ‰ sign 6 | type Mille uint16 7 | 8 | // Calculate return PerMille of given number. 9 | func (b Mille) Calculate(num uint64) (per uint64) { 10 | return (num * uint64(b)) / 1000 11 | } 12 | -------------------------------------------------------------------------------- /math/per/million.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package per 4 | 5 | // Million equal to per million(1,000,000) with (ppm) sign 6 | type Million uint32 7 | 8 | // Calculate return PerMillion of given number. 9 | func (b Million) Calculate(num uint64) (per uint64) { 10 | return (num * uint64(b)) / 1000000 11 | } 12 | -------------------------------------------------------------------------------- /math/per/myriad.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package per 4 | 5 | // Myriad equal to per ten-thousand(10,000) with ‱ sign 6 | type Myriad uint16 7 | 8 | // Calculate return PerMyriad of given number. 9 | func (b Myriad) Calculate(num uint64) (per uint64) { 10 | return (num * uint64(b)) / 10000 11 | } 12 | -------------------------------------------------------------------------------- /math/per/quadrillion.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package per 4 | 5 | // Quadrillion equal to per quadrillion(1,000,000,000,000,000) with (ppm) sign 6 | type Quadrillion uint64 7 | 8 | // Calculate return PerQuadrillion of given number. 9 | func (b Quadrillion) Calculate(num uint64) (per uint64) { 10 | return (num * uint64(b)) / 1000000 11 | } 12 | -------------------------------------------------------------------------------- /math/per/ten.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package per 4 | 5 | // Ten equal to per ten(10) 6 | type Ten uint8 7 | 8 | // Calculate return PerTen of given number. 9 | func (pt Ten) Calculate(num uint64) (per uint64) { 10 | return (num * uint64(pt)) / 10 11 | } 12 | -------------------------------------------------------------------------------- /math/per/trillion.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package per 4 | 5 | // Trillion equal to per trillion(1,000,000,000,000) with (ppm) sign 6 | type Trillion uint64 7 | 8 | // Calculate return PerTrillion of given number. 9 | func (b Trillion) Calculate(num uint64) (per uint64) { 10 | return (num * uint64(b)) / 1000000 11 | } 12 | -------------------------------------------------------------------------------- /mediatype/main-types.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package mediatype 4 | 5 | // The currently registered types 6 | const ( 7 | MainType_Domain = "domain" 8 | MainType_Application = "application" 9 | MainType_Audio = "audio" 10 | MainType_Font = "font" 11 | MainType_Example = "example" 12 | MainType_Image = "image" 13 | MainType_Message = "message" 14 | MainType_Model = "model" 15 | MainType_Multipart = "multipart" 16 | MainType_Text = "text" 17 | MainType_Video = "video" 18 | ) 19 | -------------------------------------------------------------------------------- /mediatype/protocol/media-type.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package mediatype_p 4 | 5 | // MediaType or MimeType protocol is the shape of any coding media-type. 6 | // It is a special way to naming a DataType. So all MediaType implementors MUST be a DataType too, But not reverse. 7 | // Means not all DataType need to implements MediaType 8 | // It also implement our RFC details on https://github.com/GeniusesGroup/memar/blob/main/media-type.md 9 | // https://en.wikipedia.org/wiki/Media_type 10 | type MediaType /*[STR string_p.String]*/ interface { 11 | // Never change MediaType due to it adds unnecessary complicated troubleshooting on SDK. 12 | MediaType() /*STR*/ string // must "maintype "/" [tree "."] subtype ["+" suffix]* [";" parameters]" 13 | } 14 | -------------------------------------------------------------------------------- /mediatypes/media-types_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package mediatypes 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | var _ protocol.MediaTypes = &mts 10 | -------------------------------------------------------------------------------- /mediatypes/protocol/media-types.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package mts_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | mediatype_p "memar/mediatype/protocol" 8 | string_p "memar/string/protocol" 9 | ) 10 | 11 | type MediaTypes interface { 12 | Register(mt mediatype_p.MediaType) (err error_p.Error) 13 | GetByMediaType(mediaType string_p.String) (mt mediatype_p.MediaType, err error_p.Error) 14 | GetByFileExtension(ex string_p.String) (mt mediatype_p.MediaType, err error_p.Error) 15 | } 16 | -------------------------------------------------------------------------------- /minify/protocol/minify.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package minify_p 4 | 5 | import ( 6 | codec_p "memar/codec/protocol" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | // Minify replace given data with minify of them if possible. 11 | type Minifier interface { 12 | Minify(data codec_p.Codec) (err error_p.Error) 13 | MinifyBytes(data []byte) (minified []byte, err error_p.Error) 14 | } 15 | -------------------------------------------------------------------------------- /modules/const.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see LEGAL file in repository */ 2 | 3 | package modules 4 | 5 | const ( 6 | // it is better to update version in each release. 7 | version = "v0.0.1" 8 | ) 9 | -------------------------------------------------------------------------------- /modules/gui/services/new-page/request.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package np 4 | 5 | type Request struct { 6 | Domain string 7 | ScopeName string 8 | PageVarName string 9 | } 10 | -------------------------------------------------------------------------------- /modules/gui/services/new-page/response.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package np 4 | 5 | type Response struct { 6 | JS, HTML, CSS, JSON []byte 7 | } 8 | -------------------------------------------------------------------------------- /net/chapar/connection_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package chapar 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | var _ protocol.OSI_DataLink = &Connection{} 10 | -------------------------------------------------------------------------------- /net/chapar/const.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package chapar 4 | 5 | const ( 6 | // MinFrameLen is minimum Chapar frame length 7 | MinFrameLen = int(frameFixedLength + minHopCount) 8 | // MaxFrameLen is maximum Chapar frame length 9 | MaxFrameLen = int(frameFixedLength) + int(maxHopCount) 10 | 11 | // AcceptLastHop indicate that package must accept frames in last hop or not. 12 | AcceptLastHop = true 13 | 14 | // 256 is max ports that Chapar protocol support directly in one hop. 15 | defaultPortNumber = 256 16 | 17 | frameFixedLength byte = 3 // without path part 18 | minHopCount byte = 1 19 | maxHopCount byte = 255 20 | broadcastHopCount byte = 0 21 | ) 22 | -------------------------------------------------------------------------------- /net/chapar/frame-structure.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package chapar 4 | 5 | // frameFormat represents Chapar frame structure. 6 | // It is just to show protocol in better way, we never use this type. 7 | // Read more about this protocol : https://github.com/GeniusesGroup/memar/blob/main/networking-osi_2-Chapar.md 8 | // It is just to show protocol in better way, we never use this type. 9 | // up-to 255 switch port number can be in a frame header. 10 | // First hopNum is hopNum==1 not hopNum==0. Don't read hopNum==0 due to it is use for broadcast frame. 11 | type frameFormat struct { 12 | FrameType byte // 13 | HopCount byte // the number of intermediate network devices indicate in frame. 14 | NextHop byte // next hop number. 15 | FirstHopPortNum byte // 16 | // SecondHopPortNum byte 17 | // ... byte 18 | } 19 | -------------------------------------------------------------------------------- /net/chapar/frame_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package chapar 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | var _ protocol.Network_Frame = &Frame{} 10 | -------------------------------------------------------------------------------- /net/chapar/port-bridge_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package chapar 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | var _ protocol.OSI_Physical = &BridgePort{} 10 | -------------------------------------------------------------------------------- /net/chapar/protocol.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package chapar 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | type Connections interface { 10 | GetConnectionByPath(path []byte) (conn *Connection, err protocol.Error) 11 | 12 | RegisterConnection(conn *Connection) (err protocol.Error) 13 | DeregisterConnection(conn *Connection) (err protocol.Error) 14 | 15 | protocol.ObjectLifeCycle 16 | } 17 | -------------------------------------------------------------------------------- /net/connection-status_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package net 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | var _ protocol.Network_Status = &STATUS{} 10 | -------------------------------------------------------------------------------- /net/errors/guest_max_reached.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ( 12 | ErrGuestMaxReached errGuestMaxReached 13 | ) 14 | 15 | type ( 16 | errGuestMaxReached struct{ er.Err } 17 | ) 18 | 19 | func (dt *errGuestMaxReached) Init() (err protocol.Error) { 20 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=connection; type=error; name=guest-max-reached") 21 | if err != nil { 22 | return 23 | } 24 | err = errors.Register(dt) 25 | return 26 | } 27 | -------------------------------------------------------------------------------- /net/errors/guest_not_allow.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ( 12 | ErrGuestNotAllow errGuestNotAllow 13 | ) 14 | 15 | type ( 16 | errGuestNotAllow struct{ er.Err } 17 | ) 18 | 19 | func (dt *errGuestNotAllow) Init() (err protocol.Error) { 20 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=connection; type=error; name=guest-not-allow") 21 | if err != nil { 22 | return 23 | } 24 | err = errors.Register(dt) 25 | return 26 | } 27 | 28 | // memar error make guest-not-allowed ./errors -langs="eng,per" -------------------------------------------------------------------------------- /net/errors/init.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | func init() { 6 | ErrNoConnection.Init() 7 | ErrSendRequest.Init() 8 | ErrProtocolHandler.Init() 9 | ErrGuestNotAllow.Init() 10 | ErrGuestMaxReached.Init() 11 | } 12 | -------------------------------------------------------------------------------- /net/errors/locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errs 6 | 7 | const domainEnglish = "network" 8 | -------------------------------------------------------------------------------- /net/errors/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errs 6 | 7 | const domainPersian = "شبکه" 8 | -------------------------------------------------------------------------------- /net/errors/no_connection.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ( 12 | ErrNoConnection errNoConnection 13 | ) 14 | 15 | type ( 16 | errNoConnection struct{ er.Err } 17 | ) 18 | 19 | func (dt *errNoConnection) Init() (err protocol.Error) { 20 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=net; type=error; name=no-connection") 21 | if err != nil { 22 | return 23 | } 24 | err = errors.Register(dt) 25 | return 26 | } 27 | -------------------------------------------------------------------------------- /net/errors/protocol_handler.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ( 12 | ErrProtocolHandler errProtocolHandler 13 | ) 14 | 15 | type ( 16 | errProtocolHandler struct{ er.Err } 17 | ) 18 | 19 | func (dt *errProtocolHandler) Init() (err protocol.Error) { 20 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=connection; type=error; name=protocol-handler") 21 | if err != nil { 22 | return 23 | } 24 | err = errors.Register(dt) 25 | return 26 | } 27 | -------------------------------------------------------------------------------- /net/errors/send_request.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ( 12 | ErrSendRequest errSendRequest 13 | ) 14 | 15 | type ( 16 | errSendRequest struct{ er.Err } 17 | ) 18 | 19 | func (dt *errSendRequest) Init() (err protocol.Error) { 20 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=connection; type=error; name=send-request") 21 | if err != nil { 22 | return 23 | } 24 | err = errors.Register(dt) 25 | return 26 | } 27 | -------------------------------------------------------------------------------- /net/frame.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package net 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | /* 10 | type frame struct { 11 | Type byte 12 | Payload []byte 13 | } 14 | */ 15 | type frame []byte 16 | 17 | //memar:impl memar/protocol.Network_Framer 18 | func (f frame) FrameType() protocol.Network_FrameType { return protocol.Network_FrameType(f[0]) } 19 | 20 | func (f frame) Payload() []byte { return f[1:] } 21 | -------------------------------------------------------------------------------- /net/gp/connection_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gp 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | var _ protocol.OSI_Network = &Connection{} 10 | -------------------------------------------------------------------------------- /net/gp/const.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gp 4 | 5 | import ( 6 | "memar/protocol" 7 | "memar/time/earth" 8 | ) 9 | 10 | const ( 11 | // AddrLen address lengths 32 bit equal 4 byte. 12 | AddrLen = 16 13 | 14 | // FrameLen is GP frame length. 15 | FrameLen = protocol.Network_FrameType_Length + AddrLen + AddrLen // 33 = 1+16+16 16 | ) 17 | 18 | const ( 19 | ConnectionIdleTimeout = 24 * earth.Hour // 24 hour 20 | ) 21 | -------------------------------------------------------------------------------- /net/gp/errors.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gp 4 | 5 | import ( 6 | er "memar/error" 7 | ) 8 | 9 | // Errors 10 | var ( 11 | ErrFrameLength er.Error 12 | ErrBadFrameType er.Error 13 | ErrFrameArrivedAnterior er.Error 14 | ErrFrameArrivedPosterior er.Error 15 | ) 16 | 17 | func init() { 18 | ErrFrameLength.Init("domain/gp.scm.geniuses.group; type=error; name=frame-length") 19 | ErrBadFrameType.Init("domain/gp.scm.geniuses.group; type=error; name=bad-frame-type") 20 | ErrFrameArrivedAnterior.Init("domain/gp.scm.geniuses.group; type=error; name=frame-arrived-anterior") 21 | ErrFrameArrivedPosterior.Init("domain/gp.scm.geniuses.group; type=error; name=frame-arrived-posterior") 22 | } 23 | -------------------------------------------------------------------------------- /net/gp/frame-structure.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gp 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | // frameStructure is represent protocol frame structure. 10 | // It is just to show protocol in better way, we never use this type. 11 | // Read more about this protocol : https://github.com/GeniusesGroup/memar/blob/main/networking-osi_3-Giti-Network.md 12 | type frameStructure struct { 13 | FrameType protocol.Network_FrameType // 14 | 15 | // DestinationGPAddr Addr 16 | DestinationPlanet [2]byte // uint16 17 | DestinationSociety [4]byte // uint32 18 | DestinationRouter [4]byte // uint32 19 | DestinationUser [4]byte // uint32 20 | DestinationApp [2]byte // uint16 21 | 22 | //SourceGPAddr Addr 23 | SourcePlanet [2]byte // uint16 24 | SourceSociety [4]byte // uint32 25 | SourceRouter [4]byte // uint32 26 | SourceUser [4]byte // uint32 27 | SourceApp [2]byte // uint16 28 | } 29 | -------------------------------------------------------------------------------- /net/gp/frame_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gp 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | var _ protocol.Network_Frame = &Frame{} 10 | -------------------------------------------------------------------------------- /net/gp/init.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gp 4 | 5 | import ( 6 | "memar/log" 7 | "memar/protocol" 8 | ) 9 | 10 | // must assign before use the package 11 | var conns Connections 12 | 13 | //memar:impl memar/protocol.ObjectLifeCycle 14 | func Init(cs Connections) (err protocol.Error) { 15 | if conns != nil { 16 | // err = 17 | return 18 | } 19 | log.Info(&Package_MediaType, "GP network begin listening...") 20 | conns = cs 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /net/gp/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package gp 6 | 7 | import ( 8 | "memar/detail" 9 | "memar/protocol" 10 | ) 11 | 12 | const domainPersian = "شبکه گیتی" 13 | 14 | func init() { 15 | } 16 | -------------------------------------------------------------------------------- /net/gp/media-types.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package gp 4 | 5 | import ( 6 | "memar/datatype" 7 | "memar/mediatype" 8 | "memar/protocol" 9 | ) 10 | 11 | var ( 12 | Package_MediaType mediaType 13 | ) 14 | 15 | func init() { 16 | Package_MediaType.Init("domain/memar.scm.geniuses.group; package=gp") 17 | } 18 | 19 | type mediaType struct { 20 | datatype.DataType 21 | mediatype.MT 22 | } 23 | 24 | //memar:impl memar/protocol.DataType_Details 25 | func (m *mediaType) Status() protocol.SoftwareStatus { return protocol.Software_PreAlpha } 26 | func (m *mediaType) ReferenceURI() string { 27 | return "" 28 | } 29 | func (m *mediaType) IssueDate() protocol.Time { return nil } 30 | func (m *mediaType) ExpiryDate() protocol.Time { return nil } 31 | func (m *mediaType) ExpireInFavorOf() protocol.DataType { return nil } 32 | -------------------------------------------------------------------------------- /net/http/headers/pragma.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package http 4 | 5 | // FixPragmaCacheControl do as RFC 7234, section 5.4: Treat [Pragma: no-cache] as [Cache-Control: no-cache] 6 | func (h *Header) FixPragmaCacheControl() { 7 | if h.Header_Get(HeaderKey_Pragma) == "no-cache" { 8 | if h.Header_Get(HeaderKey_CacheControl) == "" { 9 | h.Header_Add(HeaderKey_CacheControl, "no-cache") 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /net/http/locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package http 6 | 7 | import ( 8 | "memar/detail" 9 | "memar/protocol" 10 | ) 11 | 12 | const domainEnglish = "HTTP" 13 | 14 | func init() { 15 | MediaType.SetDetail(protocol.LanguageEnglish, domainEnglish, 16 | "Hypertext Transfer Protocol", 17 | "An application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information", 18 | "", 19 | "", 20 | []string{}) 21 | 22 | MediaTypeRequest.SetDetail(protocol.LanguageEnglish, domainEnglish, "Hypertext Transfer Protocol Request", "", "", "", []string{}) 23 | 24 | MediaTypeResponse.SetDetail(protocol.LanguageEnglish, domainEnglish, "Hypertext Transfer Protocol Response", "", "", "", []string{}) 25 | } 26 | -------------------------------------------------------------------------------- /net/http/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package http 6 | 7 | import ( 8 | "memar/detail" 9 | "memar/protocol" 10 | ) 11 | 12 | const domainPersian = "HTTP" 13 | -------------------------------------------------------------------------------- /net/http/protocol/body.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package http_p 4 | 5 | import ( 6 | codec_p "memar/codec/protocol" 7 | ) 8 | 9 | // HTTP Body Semantic that USUALLY use in responses. 10 | // In requests ALMOST ALWAYS each service HTTPHandler use [SK Socket] Buffer to decode to desire data type. 11 | type Body interface { 12 | Body() codec_p.Codec 13 | SetBody(codec codec_p.Codec) 14 | } 15 | -------------------------------------------------------------------------------- /net/http/protocol/header.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package http_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | // Header indicate HTTP header semantic. 10 | // STR MUST just include ASCII characters. 11 | type Header[STR string_p.String] interface { 12 | Header_Get(key STR) (value STR) 13 | Header_Add(key, value STR) 14 | // Header_Set is same as Header_Del() >> Header_Add() 15 | Header_Set(key, value STR) 16 | Header_Del(key STR) 17 | } 18 | 19 | // some header fields such as "Set-Cookie", "WWW-Authenticate", "Proxy-Authenticate" break multiple values 20 | // separate by comma and use multi line same key! implementations MUST provide iteration mechanism over all header fields. 21 | // type Header_Iteration[STR String] array_p.Iteration_KV[STR, STR] 22 | -------------------------------------------------------------------------------- /net/http/protocol/http.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package http_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | // Other languages: 10 | // - https://www.php-fig.org/psr/psr-7/ 11 | // - https://nodejs.org/api/http.html#requestgetheaders 12 | 13 | // Request indicate HTTP request semantic. 14 | type Request /*[STR String]*/ interface { 15 | PseudoHeader_Request[string_p.String] 16 | Header[string_p.String] 17 | Body 18 | } 19 | 20 | // Response indicate HTTP response semantic. 21 | type Response /*[STR String]*/ interface { 22 | PseudoHeader_Response[string_p.String] 23 | Header[string_p.String] 24 | Body 25 | } 26 | -------------------------------------------------------------------------------- /net/http/protocol/method.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package http_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | type Method[STR string_p.String] interface { 10 | Method() STR 11 | } 12 | -------------------------------------------------------------------------------- /net/http/protocol/status.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package http_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | type Status[STR string_p.String] interface { 10 | StatusCode() STR 11 | 12 | // The Reason-Phrase is indeed optional. 13 | // HTTP/2 and HTTP/3 even dropped it entirely. 14 | ReasonPhrase() STR 15 | 16 | // TODO::: How can we made reasonPhrase optional? below is good? 17 | // If pass just one status, it means status code. 18 | // If pass two args, means code and phrase. 19 | // It will ignore more than two args. 20 | // SetStatus(status ...STR) 21 | SetStatus(statusCode, reasonPhrase STR) 22 | } 23 | -------------------------------------------------------------------------------- /net/http/protocol/version.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package http_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | type Version[STR string_p.String] interface { 10 | Version() STR 11 | } 12 | -------------------------------------------------------------------------------- /net/ipv4/const.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package ipv4 4 | 5 | import ( 6 | "memar/time/monotonic" 7 | ) 8 | 9 | // https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers 10 | const ( 11 | protocolNumber_tcp byte = 0x06 12 | ) 13 | 14 | const ( 15 | // Version of protocol 16 | Version = 4 17 | 18 | // AddrLen address lengths 32 bit equal 4 byte. 19 | AddrLen = 4 20 | 21 | // MinHeaderLen is minimum header length of IPv4 header 22 | MinHeaderLen = 40 23 | ) 24 | 25 | const ( 26 | // Indicate max number of packet bundle in one buffer and processed 27 | maxEvents = 0 28 | 29 | // Max wait time a buffer fill 30 | timeout = 10 * monotonic.Millisecond 31 | 32 | // handle constants indicate IP must support their packets or drop them 33 | handleMode_Listener = false 34 | ) 35 | -------------------------------------------------------------------------------- /net/ipv4/errors.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package ipv4 4 | 5 | import ( 6 | er "memar/error" 7 | ) 8 | 9 | // Errors 10 | var ( 11 | ErrPacketTooShort er.Error 12 | ErrPacketWrongLength er.Error 13 | ) 14 | 15 | func init() { 16 | ErrPacketTooShort.Init("domain/ipv4.wg.ietf.org; type=error; name=packet-too-short") 17 | ErrPacketWrongLength.Init("domain/ipv4.wg.ietf.org; type=error; name=packet-wrong-length") 18 | } 19 | -------------------------------------------------------------------------------- /net/ipv4/flag.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package ipv4 4 | 5 | const ( 6 | flag_Reserved byte = 0b10000000 7 | flag_DF byte = 0b01000000 8 | flag_MF byte = 0b00100000 9 | 10 | // 00 – Non ECN-Capable Transport, Non-ECT 11 | flag_ECT0 byte = 0b00000010 // ECN Capable Transport 12 | flag_ECT1 byte = 0b00000001 // ECN Capable Transport 13 | flag_CE byte = 0b00000011 // Congestion Encountered 14 | ) 15 | -------------------------------------------------------------------------------- /net/ipv4/locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package ipv4 6 | 7 | import ( 8 | "memar/detail" 9 | "memar/protocol" 10 | ) 11 | 12 | const domainEnglish = "IPv4" 13 | 14 | func init() { 15 | ErrPacketTooShort.SetDetail(protocol.LanguageEnglish, domainEnglish, 16 | "Packet Too Short", 17 | "IPv4 packet is empty or too short than standard minimum size. It must include at least 20Byte header", 18 | "", 19 | "", 20 | nil) 21 | ErrPacketWrongLength.SetDetail(protocol.LanguageEnglish, domainEnglish, 22 | "Packet Wrong Length", 23 | "Data offset set in IPv4 packet header is not set correctly", 24 | "", 25 | "", 26 | nil) 27 | } 28 | -------------------------------------------------------------------------------- /net/ipv4/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package ipv4 6 | 7 | import ( 8 | "memar/detail" 9 | "memar/protocol" 10 | ) 11 | 12 | const domainPersian = "IPv4" 13 | 14 | func init() { 15 | } 16 | -------------------------------------------------------------------------------- /net/ipv6/const.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package ipv6 4 | 5 | import "memar/time/monotonic" 6 | 7 | const ( 8 | // Indicate max number of packet bundle in one buffer and processed 9 | maxEvents = 0 10 | 11 | // Max wait time a buffer fill 12 | timeout = 10 * monotonic.Millisecond 13 | 14 | // handle constants indicate IP must support their packets or drop them 15 | handleMode_Listener = false 16 | ) 17 | 18 | const ( 19 | // Version of protocol 20 | Version = 6 21 | 22 | // AddrLen address lengths 128 bit || 16 byte. 23 | AddrLen = 16 24 | 25 | // HeaderLen is minimum header length of IPv6 header 26 | HeaderLen = 40 27 | ) 28 | -------------------------------------------------------------------------------- /net/ipv6/errors.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package ipv6 4 | 5 | import ( 6 | er "memar/error" 7 | ) 8 | 9 | // Errors 10 | var ( 11 | ErrPacketTooShort er.Error 12 | ) 13 | 14 | func init() { 15 | ErrPacketTooShort.Init("domain/ipv6.wg.ietf.org; type=error; name=packet-too-short") 16 | } 17 | -------------------------------------------------------------------------------- /net/ipv6/extension-headers-hop-by-hop.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package ipv6 4 | 5 | // HopByHop is IPv6 extension header with NextHeader==0 6 | type HopByHop struct { 7 | NextHeader uint8 8 | HdrExtLen uint8 9 | Options []byte 10 | } 11 | -------------------------------------------------------------------------------- /net/ipv6/locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package ipv6 6 | 7 | import ( 8 | "memar/detail" 9 | "memar/protocol" 10 | ) 11 | 12 | const domainEnglish = "IPv6" 13 | 14 | func init() { 15 | ErrPacketTooShort.SetDetail(protocol.LanguageEnglish, domainEnglish, 16 | "Packet Too Short", 17 | "IPv6 packet is empty or too short than standard minimum size. It must include at least 40Byte header", 18 | "", 19 | "", 20 | nil) 21 | } 22 | -------------------------------------------------------------------------------- /net/ipv6/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package ipv6 6 | 7 | import ( 8 | "memar/detail" 9 | "memar/protocol" 10 | ) 11 | 12 | const domainPersian = "IPv6" 13 | 14 | func init() { 15 | } 16 | -------------------------------------------------------------------------------- /net/l4/frame-packet-sequence-number.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package l4 4 | 5 | /* 6 | type PacketSequenceNumber struct { 7 | SequenceNumber [8]byte // or PacketNumber / or uint64 8 | } 9 | */ 10 | -------------------------------------------------------------------------------- /net/l5/frame-new-connection.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package l5 4 | 5 | // Three way to make new connection 6 | // - Guest: provide some data like cipher-suite to open the connection 7 | // - New: Ask peer to get authentication data from given society 8 | // - Load: Ask to load exiting connection by provide some detail like UserID+DelegateUserID 9 | 10 | // This frame must not to encrypt?? 11 | // Must be the first frame in the first Packet and not mean PacketID==0 to improve the connection to know the state?? 12 | -------------------------------------------------------------------------------- /net/l5/frame-reconnect.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package l5 4 | 5 | // Three way to make new connection 6 | // - Guest: provide some data like cipher-suite to open the connection 7 | // - New: Ask peer to get authentication data from given society 8 | // - Load: Ask to load exiting connection by provide some detail like UserID+DelegateUserID 9 | 10 | // This frame must not to encrypt?? 11 | // Must be the first frame in the first Packet and not mean PacketID==0 to improve the connection to know the state?? 12 | -------------------------------------------------------------------------------- /net/packet-listener.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package net 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | type PacketListener struct { 10 | } 11 | 12 | //memar:impl memar/protocol.ObjectLifeCycle 13 | func (pl *PacketListener) Init() (err protocol.Error) { 14 | // TODO::: 15 | return 16 | } 17 | func (pl *PacketListener) Reinit() (err protocol.Error) { 18 | // TODO::: 19 | return 20 | } 21 | func (pl *PacketListener) Deinit() (err protocol.Error) { 22 | // TODO::: 23 | return 24 | } 25 | 26 | func (pl *PacketListener) NetworkPacketHandler(np protocol.Network_Packet) { 27 | var err = HandleFrames(np) 28 | if err != nil { 29 | // TODO::: 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /net/packet-listener_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package net 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | var _ protocol.Network_PacketListener = &PacketListener{} 10 | -------------------------------------------------------------------------------- /net/packet-target.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package net 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | type PacketTarget struct { 10 | } 11 | 12 | //memar:impl memar/protocol.ObjectLifeCycle 13 | func (pt *PacketTarget) Init() (err protocol.Error) { 14 | // TODO::: 15 | return 16 | } 17 | func (pt *PacketTarget) Reinit() (err protocol.Error) { 18 | // TODO::: 19 | return 20 | } 21 | func (pt *PacketTarget) Deinit() (err protocol.Error) { 22 | // TODO::: 23 | return 24 | } 25 | 26 | //memar:impl memar/protocol.PacketTarget 27 | func (pt *PacketTarget) AddPacketListener(fID protocol.Network_FrameType, callback protocol.Network_PacketListener) (err protocol.Error) { 28 | // TODO::: 29 | return 30 | } 31 | 32 | func (pt *PacketTarget) RemovePacketListener(fID protocol.Network_FrameType, callback protocol.Network_PacketListener) (err protocol.Error) { 33 | // TODO::: 34 | return 35 | } 36 | -------------------------------------------------------------------------------- /net/packet-target_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package net 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | var _ protocol.PacketTarget = &PacketTarget{} 10 | -------------------------------------------------------------------------------- /net/protocol/address.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package net_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | // Addr represents a network end point address. 10 | // They can be any layer 2 or 3 or even 4. 11 | type NetworkAddress interface { 12 | LocalAddr() string_p.Stringer[string_p.String] 13 | RemoteAddr() string_p.Stringer[string_p.String] 14 | } 15 | -------------------------------------------------------------------------------- /net/protocol/frame-type.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package net_p 4 | 5 | const ( 6 | FrameType_Length = 1 // byte get on byte space 7 | ) 8 | 9 | // FrameType is Frame type ID like service ID but fixed ID with 8bit length. Just some few services get one byte length service ID 10 | // Common services must register by 64bit unsigned integer. 11 | type FrameType byte 12 | 13 | // https://github.com/GeniusesGroup/memar/blob/main/networking.md#frames-number 14 | const ( 15 | FrameType_Unset FrameType = iota 16 | 17 | // e.g. A way to process all old protocols e.g. Ethernet, ATM, IPv4, IPv6, 18 | FrameType_OldProtocols 19 | 20 | FrameType_Asb 21 | FrameType_Chapar 22 | FrameType_GP 23 | 24 | FrameType_Padding // FrameType = 128 + iota 25 | FrameType_CallService 26 | FrameType_OpenStream 27 | FrameType_CloseStream 28 | FrameType_Data 29 | FrameType_Error 30 | FrameType_Signature 31 | ) 32 | -------------------------------------------------------------------------------- /net/protocol/frame.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package net_p 4 | 5 | import ( 6 | container_p "memar/adt/container/protocol" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | type Frame interface { 11 | // TODO::: due to method need custom args in each frame type, we can't uncomment bellow easily. 12 | // StaticFrameLen(args) int 13 | 14 | // FrameLen or FrameLength 15 | FrameLength() container_p.NumberOfElement 16 | NextFrame() []byte // Frame 17 | // Buffer 18 | 19 | Process(sk Socket) (err error_p.Error) 20 | Do(sk Socket) (err error_p.Error) 21 | } 22 | 23 | type Framer interface { 24 | FrameType() FrameType 25 | } 26 | type FrameWriter interface { 27 | WriteFrame(packet Packet) (n container_p.NumberOfElement, err error_p.Error) 28 | } 29 | -------------------------------------------------------------------------------- /net/protocol/osi_2-data_link.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package net_p 4 | 5 | import ( 6 | capsule_p "memar/computer/capsule/protocol" 7 | ) 8 | 9 | /* 10 | ********************************************************************************** 11 | Link - (OSI Layer 2: Data Link) - Device to Device Connection 12 | 13 | https://en.wikipedia.org/wiki/Data_link_layer 14 | ********************************************************************************** 15 | */ 16 | 17 | // OSI_DataLink use to network hardware devices in a computers or connect two or more computers. 18 | type OSI_DataLink interface { 19 | capsule_p.LifeCycle 20 | Framer 21 | NetworkAddress // string form of address (for example, "MAC://aa:bb:cc:dd:ee:ff", "Chapar://[1:242:20]") 22 | FrameWriter 23 | } 24 | -------------------------------------------------------------------------------- /net/protocol/packet.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package net_p 4 | 5 | import ( 6 | buffer_p "memar/buffer/protocol" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | // Receiver must release Packet and don't use it after return. 11 | // So almost in most cases dev must copy Packet payload to the socket. 12 | type Packet = buffer_p.Buffer 13 | 14 | type PacketTarget interface { 15 | // TODO::: just accept FrameType? other conditions? some thing like Regex?? 16 | AddPacketListener(fID FrameType, callback PacketListener) (err error_p.Error) 17 | RemovePacketListener(fID FrameType, callback PacketListener) (err error_p.Error) 18 | } 19 | 20 | // PacketListener 21 | // It isn't just for hardware network packet, It is use for any requirements e.g. IPC, D-Bus, ... 22 | type PacketListener interface { 23 | // Non-Blocking, means It must not block the caller in any ways. 24 | NetworkPacketHandler(np Packet) 25 | } 26 | -------------------------------------------------------------------------------- /net/sec/doc.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | // a cryptographic protocol designed to provide communications security over a computer network. 4 | package sec 5 | -------------------------------------------------------------------------------- /net/sec/frame-change-cipher-spec.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package sec 4 | 5 | // ChangeCipherSpec use to change cipher use in encryption||decryption process by connection! 6 | // func ChangeCipherSpec() {} 7 | 8 | // type changeCipherSpecReq struct { 9 | // cipherSuite uint16 // Ciphersuite negotiated for the session 10 | // } 11 | -------------------------------------------------------------------------------- /net/sec/frame-padding.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package sec 4 | 5 | import ( 6 | "memar/binary" 7 | ) 8 | 9 | /* 10 | type PaddingFrame struct { 11 | Length [2]byte // including the header fields 12 | Padding []byte 13 | } 14 | */ 15 | type PaddingFrame []byte 16 | 17 | func (f PaddingFrame) Length() uint16 { return binary.BigEndian(f[0:]).Uint16() } 18 | func (f PaddingFrame) Payload() []byte { return f[2:f.Length()] } 19 | 20 | //memar:impl memar/protocol.Network_Frame 21 | func (f PaddingFrame) NextFrame() []byte { return f[f.Length():] } 22 | -------------------------------------------------------------------------------- /net/sec/frame-signature.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package sec 4 | 5 | import ( 6 | "memar/protocol" 7 | "memar/syllab" 8 | ) 9 | 10 | /* 11 | registerStreamSignature 12 | 13 | type SignatureFrame struct { 14 | Length [2]byte // including the header fields 15 | StreamID [4]byte // uint32 16 | Signature []byte // Checksum, MAC, Tag, ... 17 | } 18 | */ 19 | type SignatureFrame []byte 20 | 21 | func (f SignatureFrame) ID() int64 { return syllab.GetInt64(f, 0) } 22 | 23 | //memar:impl memar/protocol.Network_Frame 24 | func (f SignatureFrame) NextFrame() []byte { return f[8:] } 25 | 26 | func (f SignatureFrame) Do(sk protocol.Socket) (err protocol.Error) { 27 | return 28 | } 29 | 30 | func checkSignature() {} 31 | -------------------------------------------------------------------------------- /net/socket-buffer.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package net 4 | 5 | import ( 6 | "memar/buffer" 7 | "memar/protocol" 8 | ) 9 | 10 | type buf struct { 11 | buf buffer.Queue 12 | } 13 | 14 | //memar:impl memar/protocol.ObjectLifeCycle 15 | func (b *buf) Init() (err protocol.Error) { 16 | // TODO::: 17 | return 18 | } 19 | func (b *buf) Reinit() (err protocol.Error) { 20 | // TODO::: 21 | return 22 | } 23 | func (b *buf) Deinit() (err protocol.Error) { 24 | // TODO::: 25 | return 26 | } 27 | -------------------------------------------------------------------------------- /net/srpc/frame-data-signature.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package srpc 4 | 5 | import ( 6 | "memar/protocol" 7 | "memar/syllab" 8 | ) 9 | 10 | /* 11 | registerStreamSignature 12 | 13 | type DataSignatureFrame struct { 14 | Length [2]byte // including the header fields 15 | StreamID [4]byte // uint32 16 | Signature []byte // Checksum, MAC, Tag, ... 17 | } 18 | */ 19 | type DataSignatureFrame []byte 20 | 21 | func (f DataSignatureFrame) ID() int64 { return syllab.GetInt64(f, 0) } 22 | 23 | //memar:impl memar/protocol.Network_Frame 24 | func (f DataSignatureFrame) NextFrame() []byte { return f[8:] } 25 | 26 | func (f DataSignatureFrame) Do(sk protocol.Socket) (err protocol.Error) { 27 | return 28 | } 29 | -------------------------------------------------------------------------------- /net/srpc/protocol/srpc.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package srpc_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | net_p "memar/net/protocol" 8 | ) 9 | 10 | // Handler is any object to be sRPC service handler. 11 | type Handler interface { 12 | // ServeSRPC method is sRPC handler of the service with Syllab codec data in the payload. 13 | ServeSRPC(sk net_p.Socket) (err error_p.Error) 14 | 15 | // Call service remotely by sRPC protocol 16 | // doSRPC(req any) (res any, err error_p.Error) Due to specific sign for each service, we can't have it here. 17 | } 18 | -------------------------------------------------------------------------------- /net/std/io.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package std 4 | 5 | import ( 6 | "io" 7 | ) 8 | 9 | /* 10 | ********** protocol.Buffer interface ********** 11 | */ 12 | 13 | func (sk *Socket) ReadFrom(reader io.Reader) (n int64, err error) { return } 14 | func (sk *Socket) WriteTo(w io.Writer) (totalWrite int64, err error) { 15 | var writeLen int 16 | var data, _ = sk.Marshal() 17 | writeLen, err = w.Write(data) 18 | totalWrite = int64(writeLen) 19 | return 20 | } 21 | -------------------------------------------------------------------------------- /net/std/socket.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package std 4 | 5 | import ( 6 | "memar/net" 7 | "memar/protocol" 8 | // "memar/uuid/16byte" 9 | ) 10 | 11 | type Socket struct { 12 | net.Socket 13 | } 14 | 15 | //libgo:impl libgo/protocol.ObjectLifeCycle 16 | func (sk *Socket) Init(timeout protocol.Duration) (err protocol.Error) { 17 | return 18 | } 19 | func (sk *Socket) Reinit() (err protocol.Error) { return } 20 | func (sk *Socket) Deinit() (err protocol.Error) { return } 21 | -------------------------------------------------------------------------------- /net/tcp/checksum.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | const ( 6 | // https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers 7 | tcpProtocolNumberOverIP byte = 0x06 8 | ) 9 | 10 | // TODO::: impelemenet checksums over IPv4, IPv6, standalone 11 | // https://github.com/google/gopacket/blob/master/layers/tcpip.go 12 | // https://github.com/tass-belgium/picotcp/blob/master/modules/pico_tcp.c 13 | -------------------------------------------------------------------------------- /net/tcp/ecn.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | // ECN is RFC 3168 Explicit Congestion Notification 6 | type ECN uint8 7 | 8 | const ( 9 | ExplicitCongestionNotification_Unset ECN = iota 10 | 11 | // Disable ECN Neither initiate nor accept ECN. 12 | // This was the default up to and including Linux 13 | // 2.6.30. 14 | ExplicitCongestionNotification_Disabled 15 | // Enable ECN when requested by incoming connections 16 | // and also request ECN on outgoing connection 17 | // attempts. 18 | ExplicitCongestionNotification_Enabled 19 | // Enable ECN when requested by incoming connections, 20 | // but do not request ECN on outgoing connections. 21 | // This value is supported, and is the default, since 22 | // Linux 2.6.31. 23 | ExplicitCongestionNotification_EnabledOnRequested 24 | ) 25 | -------------------------------------------------------------------------------- /net/tcp/errors/errors.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | ) 8 | 9 | // Errors 10 | var ( 11 | SegmentTooShort er.Error 12 | SegmentWrongLength er.Error 13 | ) 14 | 15 | func init() { 16 | SegmentTooShort.Init("domain/tcp.wg.ietf.org; type=error; name=packet-too-short") 17 | SegmentWrongLength.Init("domain/tcp.wg.ietf.org; type=error; name=packet-wrong-length") 18 | } 19 | -------------------------------------------------------------------------------- /net/tcp/flag.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | // TODO::: byte is not enough here to distinguish between flags in first byte or second one 6 | type flag byte 7 | 8 | const ( 9 | flag_Reserved1 flag = 0b00001000 10 | flag_Reserved2 flag = 0b00000100 11 | flag_Reserved3 flag = 0b00000010 12 | flag_NS flag = 0b00000001 13 | flag_CWR flag = 0b10000000 14 | flag_ECE flag = 0b01000000 15 | flag_URG flag = 0b00100000 16 | flag_ACK flag = 0b00010000 17 | flag_PSH flag = 0b00001000 18 | flag_RST flag = 0b00000100 19 | flag_SYN flag = 0b00000010 20 | flag_FIN flag = 0b00000001 21 | ) 22 | -------------------------------------------------------------------------------- /net/tcp/locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package tcp 6 | 7 | import ( 8 | "memar/detail" 9 | "memar/protocol" 10 | ) 11 | 12 | const domainEnglish = "TCP" 13 | 14 | func init() { 15 | ErrSegmentTooShort.SetDetail(protocol.LanguageEnglish, domainEnglish, 16 | "Segment Too Short", 17 | "TCP packet is empty or too short than standard header. It must include at least 20Byte header", 18 | "", 19 | "", 20 | nil) 21 | ErrSegmentWrongLength.SetDetail(protocol.LanguageEnglish, domainEnglish, 22 | "Segment Wrong Length", 23 | "Data offset set in TCP packet header is not set correctly", 24 | "", 25 | "", 26 | nil) 27 | } 28 | -------------------------------------------------------------------------------- /net/tcp/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package tcp 6 | 7 | import ( 8 | "memar/detail" 9 | "memar/protocol" 10 | ) 11 | 12 | const domainPersian = "TCP" 13 | 14 | func init() { 15 | } 16 | -------------------------------------------------------------------------------- /net/tcp/option-alt-checksum-data.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | "memar/binary" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | type optionAltChecksumData []byte 11 | 12 | func (o optionAltChecksumData) Length() byte { return o[0] } 13 | func (o optionAltChecksumData) AltChecksumData() uint16 { return binary.BigEndian(o[1:]).Uint16() } // unrecognised 14 | func (o optionAltChecksumData) NextOption() []byte { return o[3:] } 15 | 16 | func (o optionAltChecksumData) Process(s *Stream) (err error_p.Error) { 17 | return 18 | } 19 | -------------------------------------------------------------------------------- /net/tcp/option-alt-checksum.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | "memar/binary" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | type optionAltChecksum []byte 11 | 12 | func (o optionAltChecksum) Length() byte { return o[0] } 13 | func (o optionAltChecksum) AltChecksum() uint16 { return binary.BigEndian(o[1:]).Uint16() } 14 | func (o optionAltChecksum) NextOption() []byte { return o[3:] } 15 | 16 | func (o optionAltChecksum) Process(s *Stream) (err error_p.Error) { 17 | return 18 | } 19 | -------------------------------------------------------------------------------- /net/tcp/option-cc.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | "memar/binary" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | type optionCC []byte 11 | 12 | func (o optionCC) Length() byte { return o[0] } 13 | func (o optionCC) CC() uint16 { return binary.BigEndian(o[1:]).Uint16() } 14 | func (o optionCC) NextOption() []byte { return o[5:] } 15 | 16 | func (o optionCC) Process(s *Stream) (err error_p.Error) { 17 | return 18 | } 19 | -------------------------------------------------------------------------------- /net/tcp/option-ccecho.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | "memar/binary" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | type optionCCEcho []byte 11 | 12 | func (o optionCCEcho) Length() byte { return o[0] } 13 | func (o optionCCEcho) CCEcho() uint16 { return binary.BigEndian(o[1:]).Uint16() } 14 | func (o optionCCEcho) NextOption() []byte { return o[5:] } 15 | 16 | func (o optionCCEcho) Process(s *Stream) (err error_p.Error) { 17 | return 18 | } 19 | -------------------------------------------------------------------------------- /net/tcp/option-ccnew.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | "memar/binary" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | type optionCCNew []byte 11 | 12 | func (o optionCCNew) Length() byte { return o[0] } 13 | func (o optionCCNew) CCNew() uint16 { return binary.BigEndian(o[1:]).Uint16() } 14 | func (o optionCCNew) NextOption() []byte { return o[5:] } 15 | 16 | func (o optionCCNew) Process(s *Stream) (err error_p.Error) { 17 | return 18 | } 19 | -------------------------------------------------------------------------------- /net/tcp/option-delayed-acknowledgment.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | // https://en.wikipedia.org/wiki/TCP_delayed_acknowledgment 6 | // http://tools.ietf.org/html/rfc1122#page-96 7 | -------------------------------------------------------------------------------- /net/tcp/option-echo-reply.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | "memar/binary" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | type optionEchoReply []byte 11 | 12 | func (o optionEchoReply) Length() byte { return o[0] } 13 | func (o optionEchoReply) EchoReply() uint16 { return binary.BigEndian(o[1:]).Uint16() } 14 | func (o optionEchoReply) NextOption() []byte { return o[5:] } 15 | 16 | func (o optionEchoReply) Process(s *Stream) (err error_p.Error) { 17 | return 18 | } 19 | -------------------------------------------------------------------------------- /net/tcp/option-echo.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | "memar/binary" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | type optionEcho []byte 11 | 12 | func (o optionEcho) Length() byte { return o[0] } 13 | func (o optionEcho) Echo() uint16 { return binary.BigEndian(o[1:]).Uint16() } 14 | func (o optionEcho) NextOption() []byte { return o[5:] } 15 | 16 | func (o optionEcho) Process(s *Stream) (err error_p.Error) { 17 | return 18 | } 19 | -------------------------------------------------------------------------------- /net/tcp/option-mss.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | "memar/binary" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | /* 11 | type optionMSS struct { 12 | Length byte 13 | MSS uint16 // Max Segment Length 14 | } 15 | */ 16 | type optionMSS []byte 17 | 18 | func (o optionMSS) Length() byte { return o[0] } 19 | func (o optionMSS) MSS() uint16 { return binary.BigEndian(o[1:]).Uint16() } 20 | func (o optionMSS) NextOption() []byte { return o[3:] } 21 | 22 | func (o optionMSS) Process(s *Stream) (err error_p.Error) { 23 | return 24 | } 25 | -------------------------------------------------------------------------------- /net/tcp/option-partial-order-connection-permitted.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | type optionPartialOrderConnectionPermitted []byte 10 | 11 | func (o optionPartialOrderConnectionPermitted) Length() byte { return o[0] } 12 | 13 | // func (o optionPartialOrderConnectionPermitted) PartialOrderConnectionPermitted() uint16 { 14 | // return binary.BigEndian(o[1:]).Uint16() 15 | // } 16 | func (o optionPartialOrderConnectionPermitted) NextOption() []byte { return o[3:] } 17 | 18 | func (o optionPartialOrderConnectionPermitted) Process(s *Stream) (err error_p.Error) { 19 | return 20 | } 21 | -------------------------------------------------------------------------------- /net/tcp/option-sack.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | // TCP Selective Acknowledgment Options 6 | // https://datatracker.ietf.org/doc/html/rfc2018 7 | -------------------------------------------------------------------------------- /net/tcp/option-stack-permited.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | type optionSACKPermitted []byte 10 | 11 | func (o optionSACKPermitted) Length() byte { return o[0] } 12 | 13 | // func (o optionSACKPermitted) SACKPermitted() uint16 { return binary.BigEndian(o[1:]).Uint16() } 14 | func (o optionSACKPermitted) NextOption() []byte { return o[1:] } 15 | 16 | func (o optionSACKPermitted) Process(s *Stream) (err error_p.Error) { 17 | return 18 | } 19 | -------------------------------------------------------------------------------- /net/tcp/option-timestamps.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | "memar/binary" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | type optionTimestamps []byte 11 | 12 | func (o optionTimestamps) Length() byte { return o[0] } 13 | func (o optionTimestamps) Timestamps() uint16 { return binary.BigEndian(o[1:]).Uint16() } 14 | func (o optionTimestamps) NextOption() []byte { return o[8:] } 15 | 16 | func (o optionTimestamps) Process(s *Stream) (err error_p.Error) { 17 | return 18 | } 19 | -------------------------------------------------------------------------------- /net/tcp/option-user_timeout.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | // https://www.rfc-editor.org/rfc/rfc5482 6 | type optionUserTimeout struct { 7 | } 8 | -------------------------------------------------------------------------------- /net/tcp/option-window-scale.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | "memar/binary" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | type optionWindowScale []byte 11 | 12 | func (o optionWindowScale) Length() byte { return o[0] } 13 | func (o optionWindowScale) WindowScale() uint16 { return binary.BigEndian(o[1:]).Uint16() } 14 | func (o optionWindowScale) NextOption() []byte { return o[2:] } 15 | 16 | // handler options -> stream 17 | func (o optionWindowScale) Process(s *Stream) (err error_p.Error) { 18 | return 19 | } 20 | -------------------------------------------------------------------------------- /net/tcp/port-number.go: -------------------------------------------------------------------------------- 1 | // For license and copyright information please see the LEGAL file in the code repository 2 | 3 | package tcp 4 | 5 | type PortNumber uint16 6 | -------------------------------------------------------------------------------- /net/tcp/stream-firewall.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | func (s *Stream) checkPushFlag() (err error_p.Error) { 10 | // TODO::: 11 | return 12 | } 13 | -------------------------------------------------------------------------------- /net/tcp/stream-internal-syn-ack.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | type synAck struct { 10 | maxSynAckRetry uint8 11 | retrySynAck uint8 12 | } 13 | 14 | func (s *synAck) Init() (err error_p.Error) { 15 | s.maxSynAckRetry = CNF_SynAck_Retries 16 | return 17 | } 18 | func (s *synAck) Reinit() (err error_p.Error) { 19 | s.maxSynAckRetry = CNF_SynAck_Retries 20 | return 21 | } 22 | func (s *synAck) Deinit() (err error_p.Error) { 23 | return 24 | } 25 | 26 | func (s *synAck) ReachMaxSynACK() (max bool) { 27 | if s.retrySynAck > s.maxSynAckRetry { 28 | return true 29 | } 30 | return false 31 | } 32 | 33 | func (s *synAck) ReceiveNewSynAck() { 34 | s.retrySynAck++ 35 | } 36 | -------------------------------------------------------------------------------- /net/tcp/stream-metrics.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | "memar/time/duration" 8 | ) 9 | 10 | type StreamMetrics struct { 11 | TotalPacket uint32 // Expected packets count that must received! 12 | PacketReceived uint32 // Count of packets received! 13 | LastPacketID uint32 // Last send or received Packet use to know order of packets! 14 | PacketDropCount uint8 // Count drop packets to prevent some attacks type! 15 | } 16 | 17 | // memar/computer/language/object/protocol.LifeCycle 18 | func (sm *StreamMetrics) Init(timeout duration.NanoSecond) (err error_p.Error) { 19 | return 20 | } 21 | func (sm *StreamMetrics) Reinit() (err error_p.Error) { 22 | // TODO::: 23 | return 24 | } 25 | func (sm *StreamMetrics) Deinit() (err error_p.Error) { 26 | return 27 | } 28 | -------------------------------------------------------------------------------- /net/tcp/stream-recv.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | // recv is receive sequence space 10 | type recv struct { 11 | next uint32 // receive next 12 | wnd uint16 // receive window 13 | up bool // receive urgent pointer 14 | irs uint32 // initial receive sequence number 15 | recvPushFlag bool 16 | recvUrgFlag bool 17 | // TODO::: not in order segments 18 | } 19 | 20 | // memar/computer/language/object/protocol.LifeCycle 21 | func (r *recv) Init() (err error_p.Error) { 22 | // TODO::: 23 | return 24 | } 25 | func (r *recv) Reinit() (err error_p.Error) { 26 | // TODO::: 27 | return 28 | } 29 | func (r *recv) Deinit() (err error_p.Error) { 30 | // TODO::: 31 | return 32 | } 33 | -------------------------------------------------------------------------------- /net/tcp/util.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package tcp 4 | -------------------------------------------------------------------------------- /net/udp/const.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package udp 4 | 5 | // ATTENTION:::: Don't changed below settings without any good reason 6 | const ( 7 | MinPacketLen = 8 8 | OptionDefault_MSS = 536 9 | ) 10 | -------------------------------------------------------------------------------- /net/udp/errors/init.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errors 4 | 5 | func init() { 6 | ErrPacketTooShort.Init() 7 | ErrPacketWrongLength.Init() 8 | } 9 | -------------------------------------------------------------------------------- /net/udp/errors/locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errors 6 | 7 | const domainEnglish = "UDP" 8 | -------------------------------------------------------------------------------- /net/udp/errors/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errors 6 | 7 | const domainPersian = "UDP" 8 | -------------------------------------------------------------------------------- /net/udp/errors/packet_too_short.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errors 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/protocol" 8 | ) 9 | 10 | var ErrPacketTooShort errPacketTooShort 11 | 12 | type errPacketTooShort struct{ er.Err } 13 | 14 | func (dt *errPacketTooShort) Init() (err protocol.Error) { 15 | err = dt.Err.Init("domain/udp.wg.ietf.org; type=error; name=packet-too-short") 16 | if err != nil { 17 | return 18 | } 19 | err = protocol.App.RegisterError(dt) 20 | return 21 | } 22 | -------------------------------------------------------------------------------- /net/udp/errors/packet_wrong_length.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errors 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/protocol" 8 | ) 9 | 10 | var ErrPacketWrongLength errPacketWrongLength 11 | 12 | type errPacketWrongLength struct{ er.Err } 13 | 14 | func (dt *errPacketWrongLength) Init() (err protocol.Error) { 15 | err = dt.Err.Init("domain/udp.wg.ietf.org; type=error; name=packet-wrong-length") 16 | if err != nil { 17 | return 18 | } 19 | err = protocol.App.RegisterError(dt) 20 | return 21 | } 22 | -------------------------------------------------------------------------------- /net/uri/const.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package uri 4 | 5 | // Some default signs 6 | const ( 7 | sign_SP byte = ' ' // 8 | sign_Equal byte = '=' 9 | sign_Colon byte = ':' 10 | sign_Semicolon byte = ':' 11 | sign_AtSign byte = '@' 12 | sign_NumberSign byte = '#' 13 | sign_Comma byte = ',' 14 | sign_Question byte = '?' 15 | sign_And byte = '&' 16 | sign_Slash byte = '/' 17 | sign_Asterisk byte = '*' 18 | ) 19 | -------------------------------------------------------------------------------- /net/uri/errors/errors.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | ) 8 | 9 | // Errors 10 | var ( 11 | ErrParse er.Error 12 | ErrQueryBadKey er.Error 13 | ErrInvalidURLEscape er.Error 14 | ErrInvalidHostEscape er.Error 15 | ) 16 | 17 | func init() { 18 | ErrParse.Init("domain/uri.wg.ietf.org; type=error; name=parse-uri") 19 | ErrQueryBadKey.Init("domain/uri.wg.ietf.org; type=error; name=query-bad-key") 20 | ErrInvalidURLEscape.Init("domain/uri.wg.ietf.org; type=error; name=invalid-url-escape ") 21 | ErrInvalidHostEscape.Init("domain/uri.wg.ietf.org; type=error; name=invalid-host-escape ") 22 | } 23 | -------------------------------------------------------------------------------- /net/uri/errors/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errs 6 | 7 | import ( 8 | "memar/detail" 9 | "memar/protocol" 10 | ) 11 | 12 | const domainPersian = "URI" 13 | 14 | func init() { 15 | } 16 | -------------------------------------------------------------------------------- /net/uri/protocol/authority.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package uri_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | type Username[STR string_p.String] interface { 10 | Username() STR 11 | } 12 | 13 | type Password[STR string_p.String] interface { 14 | Password() STR 15 | } 16 | 17 | type Host[STR string_p.String] interface { 18 | Host() STR 19 | } 20 | 21 | type Port[STR string_p.String] interface { 22 | Port() STR 23 | } -------------------------------------------------------------------------------- /net/uri/protocol/fragment.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package uri_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | type Fragment[STR string_p.String] interface { 10 | Fragment() STR 11 | } 12 | -------------------------------------------------------------------------------- /net/uri/protocol/parsed.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package uri_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | type Parsed[STR string_p.String] interface { 10 | Scheme[STR] 11 | 12 | // URI Authority >> [ userinfo "@" ] host [ ":" port ] 13 | // URI Userinfo >> "username[:password]" 14 | Username[STR] 15 | Password[STR] 16 | Host[STR] 17 | Port[STR] 18 | 19 | Path[STR] 20 | Query[STR] 21 | Fragment[STR] 22 | } 23 | -------------------------------------------------------------------------------- /net/uri/protocol/path.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package uri_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | type Path[STR string_p.String] interface { 10 | Path() STR 11 | } 12 | -------------------------------------------------------------------------------- /net/uri/protocol/query.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package uri_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | type Query[STR string_p.String] interface { 10 | Query() STR 11 | } 12 | -------------------------------------------------------------------------------- /net/uri/protocol/scheme.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package uri_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | type Scheme[STR string_p.String] interface { 10 | Scheme() STR 11 | } 12 | -------------------------------------------------------------------------------- /net/uri/protocol/url.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package uri_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | // URL indicate "Uniform Resource Locators". 10 | // https://datatracker.ietf.org/doc/html/rfc1738 11 | type URL[STR string_p.String] URI[STR] 12 | -------------------------------------------------------------------------------- /net/uri/protocol/urn.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package uri_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | // https://en.wikipedia.org/wiki/Uniform_Resource_Name 10 | type URN[STR string_p.String] interface { 11 | URI[STR] // e.g. "urn:isbn:0451450523" 12 | Scheme[STR] // always return "urn" 13 | 14 | URN_NID[STR] 15 | URN_NSS[STR] 16 | } 17 | 18 | type URN_NID[STR string_p.String] interface { 19 | NID() STR // NID is the namespace identifier e.g. "isbn" 20 | } 21 | type URN_NSS[STR string_p.String] interface { 22 | NSS() STR // NSS is the namespace-specific e.g. "0451450523" 23 | } 24 | -------------------------------------------------------------------------------- /net/uri/urn.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package uri 4 | 5 | // URN implement protocol.URN interface 6 | type URN struct { 7 | uri string 8 | nid string 9 | nss string 10 | } 11 | 12 | // SetDetail add error text details to existing error and return it. 13 | func (u *URN) Init(urn string) { 14 | u.uri = urn 15 | // TODO::: 16 | } 17 | 18 | func (u *URN) URI() string { return u.uri } 19 | func (u *URN) Scheme() string { return "urn" } 20 | func (u *URN) NID() string { return u.nid } 21 | func (u *URN) NSS() string { return u.nss } 22 | -------------------------------------------------------------------------------- /operation/README.md: -------------------------------------------------------------------------------- 1 | # Operation 2 | we categorize service, command, and query as items in the operation category. 3 | 4 | Here's a breakdown of why: 5 | - Service: A service is a function or action provided by a system or organization. It often involves a series of steps or processes. 6 | - Command: A command is an instruction or order given to a system or device to perform a specific action. 7 | - Query: A query is a request for information or data from a system. 8 | 9 | All of these terms imply a specific action or request being performed, which aligns with the concept of an operation. Therefore, they can be effectively categorized under the operation category. 10 | -------------------------------------------------------------------------------- /operation/command/errors/flag_bad_syntax.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ErrFlagBadSyntax errFlagBadSyntax 12 | 13 | type errFlagBadSyntax struct{ er.Err } 14 | 15 | func (dt *errFlagBadSyntax) Init() (err protocol.Error) { 16 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=command; type=error; name=flag_bad_syntax") 17 | if err != nil { 18 | return 19 | } 20 | err = errors.Register(dt) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /operation/command/errors/flag_needs_an_arguments.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ErrFlagNeedsAnArgument errFlagNeedsAnArgument 12 | 13 | type errFlagNeedsAnArgument struct{ er.Err } 14 | 15 | func (dt *errFlagNeedsAnArgument) Init() (err protocol.Error) { 16 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=command; type=error; name=flag_needs_an_arguments") 17 | if err != nil { 18 | return 19 | } 20 | err = errors.Register(dt) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /operation/command/errors/flag_not_found.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ErrFlagNotFound errFlagNotFound 12 | 13 | type errFlagNotFound struct{ er.Err } 14 | 15 | func (dt *errFlagNotFound) Init() (err protocol.Error) { 16 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=command; type=error; name=flag-not_found") 17 | if err != nil { 18 | return 19 | } 20 | err = errors.Register(dt) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /operation/command/errors/init.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | func init() { 6 | ErrServiceNotFound.Init() 7 | ErrServiceCallByAlias.Init() 8 | ErrServiceNotAcceptCLI.Init() 9 | 10 | ErrFlagNotFound.Init() 11 | ErrFlagBadSyntax.Init() 12 | ErrFlagNeedsAnArgument.Init() 13 | } 14 | -------------------------------------------------------------------------------- /operation/command/errors/locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errs 6 | 7 | const domainEnglish = "Command" 8 | -------------------------------------------------------------------------------- /operation/command/errors/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errs 6 | 7 | const domainPersian = "فرمان" 8 | -------------------------------------------------------------------------------- /operation/command/errors/service_call_by_alias.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ErrServiceCallByAlias errServiceCallByAlias 12 | 13 | type errServiceCallByAlias struct{ er.Err } 14 | 15 | func (dt *errServiceCallByAlias) Init() (err protocol.Error) { 16 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=command; type=error; name=service-call-by-alias") 17 | if err != nil { 18 | return 19 | } 20 | err = errors.Register(dt) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /operation/command/errors/service_not_accept_cli.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ErrServiceNotAcceptCLI errServiceNotAcceptCLI 12 | 13 | type errServiceNotAcceptCLI struct{ er.Err } 14 | 15 | func (dt *errServiceNotAcceptCLI) Init() (err protocol.Error) { 16 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=command; type=error; name=service-not-accept-cli") 17 | if err != nil { 18 | return 19 | } 20 | err = errors.Register(dt) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /operation/command/errors/service_not_found.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ErrServiceNotFound errServiceNotFound 12 | 13 | type errServiceNotFound struct{ er.Err } 14 | 15 | func (dt *errServiceNotFound) Init() (err protocol.Error) { 16 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=command; type=error; name=service-not-found") 17 | if err != nil { 18 | return 19 | } 20 | err = errors.Register(dt) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /operation/command/protocol/arguments.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package command_p 4 | 5 | // Arguments 6 | type Arguments []string 7 | -------------------------------------------------------------------------------- /operation/protocol/action.locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package operation 6 | 7 | // String return name of crud in app language. 8 | func (at *ActionType) String() string { 9 | switch at { 10 | case ActionType_None: 11 | return "None" 12 | case ActionType_Create: 13 | return "Create" 14 | case ActionType_Read: 15 | return "Read" 16 | case ActionType_Update: 17 | return "Update" 18 | case ActionType_Delete: 19 | return "Delete" 20 | case ActionType_All: 21 | return "All" 22 | } 23 | return "" 24 | } 25 | -------------------------------------------------------------------------------- /operation/protocol/action.locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package operation 6 | 7 | // String return name of crud in app language. 8 | func (at *ActionType) String() string { 9 | switch at { 10 | case ActionType_None: 11 | return "هیچ کدام" 12 | case ActionType_Create: 13 | return "ایجاد کردن" 14 | case ActionType_Read: 15 | return "خواندن" 16 | case ActionType_Update: 17 | return "بروزرسانی" 18 | case ActionType_Delete: 19 | return "حذف" 20 | case ActionType_All: 21 | return "همه" 22 | } 23 | return "" 24 | } 25 | -------------------------------------------------------------------------------- /operation/protocol/deadline.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package operation_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | time_p "memar/time/protocol" 8 | ) 9 | 10 | // Deadline is the interface to show how an operation must implement deadline e.g. network socket, ... 11 | type Deadline interface { 12 | // SetDeadline sets the read and write deadlines associated with the connection. 13 | // It is equivalent to calling both SetReadDeadline and SetWriteDeadline. 14 | SetDeadline(t time_p.Time) error_p.Error 15 | 16 | Deadline_Read 17 | Deadline_Write 18 | } 19 | type Deadline_Read interface { 20 | SetReadDeadline(t time_p.Time) error_p.Error 21 | } 22 | type Deadline_Write interface { 23 | SetWriteDeadline(t time_p.Time) error_p.Error 24 | } 25 | -------------------------------------------------------------------------------- /operation/protocol/importance.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package operation_p 4 | 5 | type Importance interface { 6 | // TODO::: need both of below items??!! 7 | Priority() Priority // Use to queue requests by its priority 8 | Weight() Weight // Use to queue requests by its weights in the same priority 9 | } 10 | -------------------------------------------------------------------------------- /operation/protocol/priority.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package operation_p 4 | 5 | // Priority indicate to use by any queue systems like network sockets to implement priority/weight mechanism. 6 | type Priority uint8 7 | 8 | // Priorities 9 | const ( 10 | Priority_Unset Priority = iota 11 | Priority_TimeSensitive // Call related service in each received packet. VoIP, IPTV, Sensors data, ... 12 | Priority_Normal 13 | Priority_Low 14 | Priority_Lower 15 | // TODO::: add more priorities 16 | Priority_Lowest Priority = 255 17 | ) 18 | -------------------------------------------------------------------------------- /operation/protocol/timeout.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package operation_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | "memar/time/duration" 8 | ) 9 | 10 | // Timeout is the interface to show how an operation must implement timeout e.g. network socket, ... 11 | type Timeout interface { 12 | // SetTimeout sets the read and write deadlines associated with the connection. 13 | // It is equivalent to calling both SetReadTimeout and SetWriteTimeout. 14 | SetTimeout(d duration.NanoSecond) error_p.Error 15 | 16 | Timeout_Read 17 | Timeout_Write 18 | } 19 | type Timeout_Read interface { 20 | SetReadTimeout(d duration.NanoSecond) error_p.Error 21 | } 22 | type Timeout_Write interface { 23 | SetWriteTimeout(d duration.NanoSecond) error_p.Error 24 | } 25 | -------------------------------------------------------------------------------- /operation/protocol/weight.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package operation_p 4 | 5 | // Weight indicate to use by any queue systems like network sockets to implement priority/weight mechanism. 6 | type Weight uint8 7 | 8 | // Weights 9 | const ( 10 | Weight_Unset Weight = iota 11 | Weight_Lowest 12 | Weight_Lower 13 | Weight_Low 14 | Weight_Normal 15 | // TODO::: add more queue for priority weights 16 | Weight_TimeSensitive Weight = 255 // Call related service in each received packet. VoIP, IPTV, Sensors data, ... 17 | ) 18 | -------------------------------------------------------------------------------- /operation/service/protocol/handlers.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package service_p 4 | 5 | import ( 6 | datatype_p "memar/datatype/protocol" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | // Handlers is just test (approver) interface and MUST NOT use directly in any signature. 11 | // Due to Golang import cycle problem we can't use `net_p.Socket` 12 | type Handlers[SK any /*net_p.Socket*/, ReqT, ResT datatype_p.DataType] interface { 13 | // Call service locally by import service package to other one 14 | Process(sk SK, req ReqT) (res ResT, err error_p.Error) 15 | // 16 | // Call service remotely by preferred(SDK generator choose) protocol. 17 | Do(req ReqT) (res ResT, err error_p.Error) 18 | } 19 | -------------------------------------------------------------------------------- /operation/service/protocol/id.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package service_p 4 | 5 | import ( 6 | datatype_p "memar/datatype/protocol" 7 | ) 8 | 9 | type Field_ServiceID interface { 10 | // Usually easily return s.DataTypeID() 11 | // or it can return some old manual way numbering like HTTP:80, HTTPS:443, ... 12 | ServiceID() ID 13 | } 14 | 15 | type ID = datatype_p.ID 16 | -------------------------------------------------------------------------------- /operation/services/errors/errors.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | ) 8 | 9 | var ( 10 | ErrNotFound er.Error 11 | 12 | // This conditions must be checked just in the dev phase. 13 | ErrServiceNotProvideIdentifier er.Error 14 | ErrServiceDuplicateIdentifier er.Error 15 | ) 16 | 17 | func init() { 18 | ErrNotFound.Init("domain/memar.scm.geniuses.group; type=error; package=service; name=not_found") 19 | 20 | ErrServiceNotProvideIdentifier.Init("domain/memar.scm.geniuses.group; type=error; package=service; name=service_not_provide_identifier") 21 | ErrServiceDuplicateIdentifier.Init("domain/memar.scm.geniuses.group; type=error; package=service; name=service_duplicate_identifier") 22 | } 23 | -------------------------------------------------------------------------------- /operation/services/errors/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errs 6 | 7 | import ( 8 | "memar/detail" 9 | "memar/protocol" 10 | ) 11 | 12 | const domainPersian = "سرویس" 13 | 14 | func init() { 15 | ErrNotFound.SetDetail(detail.New(protocol.LanguagePersian, domainPersian). 16 | SetName(""). 17 | SetAbbreviation(""). 18 | SetAliases([]string{}). 19 | SetSummary("یافت نشد"). 20 | SetOverview("سرویس درخواست شده برای پردازش یافت نشد"). 21 | SetUserNote("سرور دیگر را امتحان کنید یا با پشتیبانی نرم افزار تماس بگیرید"). 22 | SetDevNote(""). 23 | SetTAGS([]string{}) 24 | ) 25 | } 26 | -------------------------------------------------------------------------------- /operation/services/protocol/services.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package services_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | service_p "memar/operation/service/protocol" 8 | ) 9 | 10 | // Services use to register services to get them in a desire way e.g. sid in http query. 11 | type Services interface { 12 | // Register use to register application services. 13 | // Due to minimize performance impact, This method isn't safe to use concurrently and 14 | // must register all service before use GetService methods. 15 | Register(s service_p.Service) (err error_p.Error) 16 | Delete(s service_p.Service) (err error_p.Error) 17 | 18 | Services() []service_p.Service 19 | GetByID(sID service_p.ID) (ser service_p.Service, err error_p.Error) 20 | GetByMediaType(mt string) (ser service_p.Service, err error_p.Error) 21 | } 22 | -------------------------------------------------------------------------------- /operation/services/services_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package services 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | var _ protocol.Services = &services 10 | -------------------------------------------------------------------------------- /os/default/network-transport-multiplexer.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see LEGAL file in repository */ 2 | 3 | package dos 4 | 5 | import ( 6 | "../../protocol" 7 | ) 8 | 9 | type netTransMux struct { 10 | transportsMux []protocol.NetworkTransportAppMultiplexer 11 | } 12 | 13 | // RegisterUDPNetwork use to register a established udp network! 14 | func (n *netTransMux) RegisterNetworkTransportMultiplexer(tMux protocol.NetworkTransportAppMultiplexer) { 15 | // TODO::: register in OS 16 | n.transportsMux = append(n.transportsMux, tMux) 17 | } 18 | 19 | func (n *netTransMux) shutdown() { 20 | for i := 0; i < len(n.transportsMux); i++ { 21 | n.transportsMux[i].Shutdown() 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /os/default/sort.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see LEGAL file in repository */ 2 | 3 | package dos 4 | 5 | import ( 6 | goos "os" 7 | "sort" 8 | ) 9 | 10 | // ByModTime use to 11 | type ByModTime []goos.FileInfo 12 | 13 | func (fis ByModTime) Len() int { 14 | return len(fis) 15 | } 16 | 17 | func (fis ByModTime) Swap(i, j int) { 18 | fis[i], fis[j] = fis[j], fis[i] 19 | } 20 | 21 | func (fis ByModTime) Less(i, j int) bool { 22 | return fis[i].ModTime().Before(fis[j].ModTime()) 23 | } 24 | 25 | // SortFilesDec sort given slice in dec 26 | func SortFilesDec(repoFiles []goos.FileInfo) { 27 | sort.Sort(ByModTime(repoFiles)) 28 | } 29 | -------------------------------------------------------------------------------- /os/os_darwin.go: -------------------------------------------------------------------------------- 1 | //go:build darwin 2 | 3 | /* For license and copyright information please see LEGAL file in repository */ 4 | 5 | package os 6 | 7 | import ( 8 | "../protocol" 9 | "./darwin" 10 | ) 11 | 12 | func init() { 13 | protocol.OS = &darwin.OS 14 | } 15 | -------------------------------------------------------------------------------- /os/os_freebsd.go: -------------------------------------------------------------------------------- 1 | //go:build freebsd 2 | 3 | /* For license and copyright information please see LEGAL file in repository */ 4 | 5 | package os 6 | 7 | import ( 8 | "../freebsd" 9 | "../protocol" 10 | ) 11 | 12 | func init() { 13 | protocol.OS = &freebsd.OS 14 | } 15 | -------------------------------------------------------------------------------- /os/os_linux.go: -------------------------------------------------------------------------------- 1 | //go:build linux 2 | 3 | /* For license and copyright information please see LEGAL file in repository */ 4 | 5 | package os 6 | 7 | import ( 8 | "../protocol" 9 | "./linux" 10 | ) 11 | 12 | func init() { 13 | protocol.OS = &linux.OS 14 | } 15 | -------------------------------------------------------------------------------- /os/os_netbsd.go: -------------------------------------------------------------------------------- 1 | //go:build netbsd 2 | 3 | /* For license and copyright information please see LEGAL file in repository */ 4 | 5 | package os 6 | 7 | import ( 8 | "../protocol" 9 | "./netbsd" 10 | ) 11 | 12 | func init() { 13 | protocol.OS = &netbsd.OS 14 | } 15 | -------------------------------------------------------------------------------- /os/os_openbsd.go: -------------------------------------------------------------------------------- 1 | //go:build openbsd 2 | 3 | /* For license and copyright information please see LEGAL file in repository */ 4 | 5 | package os 6 | 7 | import ( 8 | "../openbsd" 9 | "../protocol" 10 | ) 11 | 12 | func init() { 13 | protocol.OS = &openbsd.OS 14 | } 15 | -------------------------------------------------------------------------------- /os/os_persiaos.go: -------------------------------------------------------------------------------- 1 | //go:build persiaos 2 | 3 | /* For license and copyright information please see LEGAL file in repository */ 4 | 5 | package os 6 | 7 | import ( 8 | "../protocol" 9 | "./persiaos" 10 | ) 11 | 12 | func init() { 13 | protocol.OS = &persiaos.OS 14 | } 15 | -------------------------------------------------------------------------------- /os/os_windows.go: -------------------------------------------------------------------------------- 1 | //go:build windows 2 | 3 | /* For license and copyright information please see LEGAL file in repository */ 4 | 5 | package os 6 | 7 | import ( 8 | "../protocol" 9 | "./windows" 10 | ) 11 | 12 | func init() { 13 | protocol.OS = &windows.OS 14 | } 15 | -------------------------------------------------------------------------------- /os/persiaos/network-transport-multiplexer.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see LEGAL file in repository */ 2 | 3 | package persiaos 4 | 5 | // RegisterNetworkTransportMultiplexer will register multiplexer only if it is GP multiplexer. 6 | func (os *os) RegisterNetworkTransportMultiplexer(appMux protocol.NetworkTransportMultiplexer) { 7 | switch appMux.HeaderID() { 8 | case protocol.NetworkLinkNextHeaderGP: 9 | os.gp.RegisterAppMultiplexer(appMux) 10 | case protocol.NetworkLinkNextHeaderIPv4: 11 | os.ipv4.RegisterAppMultiplexer(appMux) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /os/protocol/os.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package os_p 4 | 5 | // OperatingSystem is the interface that must implement by any OS object 6 | type OperatingSystem interface { 7 | Screens() []GUIScreen 8 | 9 | OperatingSystem_User 10 | OperatingSystem_Storage 11 | net_p.PacketTarget 12 | } 13 | -------------------------------------------------------------------------------- /os/protocol/storage.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package os_p 4 | 5 | import ( 6 | storage_p "memar/storage/protocol" 7 | ) 8 | 9 | // OperatingSystem_Storage is the interface that must implement by any OS object 10 | type OperatingSystem_Storage interface { 11 | Storage() storage_p.Block 12 | // Any data transfer between host and drive will be in multiples of logical block size (PhysicalSectorSize) 13 | StorageDevices() []StorageBlockDetails 14 | } 15 | -------------------------------------------------------------------------------- /os/protocol/users.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package os_p 4 | 5 | import ( 6 | user_p "memar/user/protocol" 7 | ) 8 | 9 | // OperatingSystem_User introduce all data about an applications 10 | type OperatingSystem_User interface { 11 | ActiveUser() User 12 | Users() []User 13 | } 14 | 15 | type User interface { 16 | ID() user_p.UserID 17 | SocietyID() SocietyID 18 | } 19 | -------------------------------------------------------------------------------- /picture/protocol/color.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package picture_p 4 | 5 | // True color (24-bit) 2^24 gives 16,777,216 color variations. 6 | // The human eye can discriminate up to ten million colors, and since the gamut of a display is smaller than the range of human vision, 7 | // this means this should cover that range with more detail than can be perceived. 8 | // https://en.wikipedia.org/wiki/Color_depth 9 | type RGB struct { 10 | Red uint32 11 | Green uint32 12 | Blue uint32 13 | } 14 | 15 | // type ColorHex [6]byte 16 | -------------------------------------------------------------------------------- /picture/protocol/image.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package picture_p 4 | 5 | import ( 6 | buffer_p "memar/buffer/protocol" 7 | ) 8 | 9 | type Image interface { 10 | Format() 11 | Image() buffer_p.Buffer 12 | } 13 | -------------------------------------------------------------------------------- /pool/status.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see LEGAL file in repository */ 2 | 3 | package pool 4 | 5 | type PoolStatus int32 6 | 7 | const ( 8 | PoolStatus_Unset PoolStatus = iota 9 | PoolStatus_Running 10 | PoolStatus_Stopping 11 | PoolStatus_Stopped 12 | ) 13 | -------------------------------------------------------------------------------- /runtime/protocol/concurrency.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package runtime_p 4 | 5 | // Async indicate any object need to run in a new thread, 6 | // due to have blocking mechanism in its logic. 7 | type Async interface { 8 | DoAsync() 9 | } 10 | -------------------------------------------------------------------------------- /runtime/protocol/runtime.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package runtime_p 4 | 5 | type Runtime interface { 6 | } 7 | -------------------------------------------------------------------------------- /runtime/protocol/scheduler.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package runtime_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | type Thread interface { 10 | // Defer(where ??, v any) 11 | 12 | // Thread_Execution_Exception 13 | Thread_SchedulerWaiting 14 | 15 | Runtime 16 | } 17 | 18 | type Thread_SchedulerWaiting interface { 19 | AddToWaitList(id int) (err error_p.Error) 20 | NotifyWaitList(id int) (err error_p.Error) 21 | Wait() (id int, er error_p.Error) 22 | } 23 | 24 | // Even when a package uses panic internally, its external API still presents explicit error return values. 25 | // TODO::: Is it good idea to have these logics? Why not just Errors?? 26 | // type Thread_Execution_Exception interface { 27 | // Panic(e Event) 28 | // Recover() (e Event) 29 | // } 30 | -------------------------------------------------------------------------------- /runtime/protocol/stack.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package runtime_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | type Stack interface { 10 | // if log need to trace, specially in panic situation. 11 | // In Go USUALLY fill by `debug.Stack()` 12 | RuntimeStack() string_p.String 13 | } 14 | 15 | type Existence interface { 16 | Heap() bool // Pointer 17 | } 18 | -------------------------------------------------------------------------------- /staticcheck.conf: -------------------------------------------------------------------------------- 1 | checks = ["all", "-ST1000", "-ST1003", "-ST1006", "-ST1021"] 2 | 3 | # https://staticcheck.dev/docs/checks/ 4 | # ST1000 ::: at least one file in a package should have a package comment 5 | # ST1003 ::: should not use underscores in Go names; method DataTypeID_Base64 should be DataTypeIDBase64 6 | # ST1006 ::: receiver name should be a reflection of its identity; don't use generic names such as "this" or "self" 7 | # ST1021 ::: comment on exported type Buffer should be of the form "Buffer ..." (with optional leading article) -------------------------------------------------------------------------------- /storage/file/protocol/file.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package file_p 4 | 5 | import ( 6 | buffer_p "memar/buffer/protocol" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | // File is the descriptor interface that must implement by any to be an file. 11 | // File owner is one app so it must handle concurrent protection internally not by file it self. 12 | type File interface { 13 | Metadata() Metadata 14 | Data() buffer_p.Buffer 15 | 16 | File_Methods 17 | } 18 | 19 | type File_Methods interface { 20 | // Depend on OS, file data can be cache on ram until Save() called. 21 | Save() (err error_p.Error) 22 | 23 | Rename(newName string) 24 | } 25 | -------------------------------------------------------------------------------- /storage/file/protocol/metadata.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package file_p 4 | 5 | import ( 6 | container_p "memar/adt/container/protocol" 7 | string_p "memar/string/protocol" 8 | time_p "memar/time/protocol" 9 | ) 10 | 11 | // Metadata is the interface that must implement by any file and directory. 12 | type Metadata interface { 13 | ParentDirectory() Directory 14 | URI[string_p.String] 15 | Size() container_p.NumberOfElement // in Byte?? 16 | Created() time_p.Time 17 | Accessed() time_p.Time 18 | Modified() time_p.Time 19 | } 20 | -------------------------------------------------------------------------------- /storage/memory/reference/protocol/reference.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package reference_p 4 | 5 | import ( 6 | capsule_p "memar/computer/capsule/protocol" 7 | error_p "memar/error/protocol" 8 | ) 9 | 10 | type Reference[T any] interface { 11 | // Returns a copy of the type itself 12 | Dereference() (t T, err error_p.Error) 13 | 14 | // TODO::: we need out of scope mechanism like RUST, how to implement this in the library instead of language syntax?? 15 | capsule_p.LifeCycle 16 | } 17 | -------------------------------------------------------------------------------- /string/ascii/protocol/ascii.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package ascii_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | string_p "memar/string/protocol" 8 | ) 9 | 10 | // ASCII abbreviated from American Standard Code for Information Interchange, 11 | // is a character encoding standard for electronic communication. 12 | // https://en.wikipedia.org/wiki/ASCII 13 | type ASCII interface { 14 | string_p.String 15 | 16 | // TODO::: 17 | } 18 | 19 | // Stringer code the data to/from human readable format. 20 | type Stringer interface { 21 | Stringer_To 22 | Stringer_From 23 | } 24 | 25 | // Stringer code the data to human readable format. 26 | type Stringer_To interface { 27 | ToASCII() (str ASCII, err error_p.Error) 28 | } 29 | 30 | // Stringer_From code the data from human readable format. 31 | type Stringer_From interface { 32 | FromASCII(str ASCII) (err error_p.Error) 33 | } 34 | -------------------------------------------------------------------------------- /string/protocol/character-encoding.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package string_p 4 | 5 | import ( 6 | datatype_p "memar/datatype/protocol" 7 | ) 8 | 9 | // character encoding used for electronic communication. 10 | type CharacterEncoding datatype_p.ID 11 | -------------------------------------------------------------------------------- /string/protocol/character.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package string_p 4 | 5 | import ( 6 | logic_p "memar/math/logic/protocol" 7 | memory_p "memar/storage/memory/protocol" 8 | ) 9 | 10 | // Character is base of any character encoding 11 | type Character interface { 12 | logic_p.Equivalence[Character] 13 | memory_p.Clone[Character] 14 | memory_p.Copy[Character] 15 | } 16 | -------------------------------------------------------------------------------- /string/protocol/stringer.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package string_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | // Stringer code the data to/from human readable format. It can be any other format like JSON(not recommended). 10 | type Stringer[STR String] interface { 11 | Stringer_To[STR] 12 | Stringer_From[STR] 13 | } 14 | 15 | type Stringer_To[STR String] interface { 16 | ToString() (str STR, err error_p.Error) 17 | } 18 | type Stringer_From[STR String] interface { 19 | FromString(str STR) (err error_p.Error) 20 | } 21 | 22 | // Stringer_GO is same as `fmt.Stringer` 23 | // It just exist to prevent protocol package not couple to a implementation package(fmt). 24 | type Stringer_GO interface { 25 | // It will clone the underlying buffer and return standalone string. 26 | String() string 27 | } 28 | -------------------------------------------------------------------------------- /string/utf8/protocol/utf8.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package string_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | string_p "memar/string/protocol" 8 | ) 9 | 10 | // UTF-8 is a variable-length character encoding standard used for electronic communication. 11 | // Defined by the Unicode Standard, the name is derived from Unicode Transformation Format – 8-bit. 12 | // UTF-8 is capable of encoding all 1,112,064 valid character code points in Unicode using one to four one-byte code units. 13 | // https://en.wikipedia.org/wiki/UTF-8 14 | type UTF8 interface { 15 | string_p.String 16 | 17 | // TODO::: 18 | } 19 | 20 | // Stringer code the data to/from human readable format. 21 | type Stringer interface { 22 | ToUTF8() (str UTF8, err error_p.Error) 23 | FromUTF8(str UTF8) (err error_p.Error) 24 | } 25 | -------------------------------------------------------------------------------- /time/astronomy/time.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package astronomy 4 | 5 | // https://en.wikipedia.org/wiki/Julian_year_(astronomy) 6 | // https://en.wikipedia.org/wiki/Epoch_(astronomy) 7 | // https://en.wikipedia.org/wiki/Terrestrial_Time 8 | -------------------------------------------------------------------------------- /time/duration/const.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package duration 4 | 5 | const ( 6 | // coefficientUnit_1000 is the metric base unit for many unit of measure such as mass, length, ... 7 | coefficientUnit_1000 = 1000 8 | coefficientUnit_100 = 100 9 | coefficientUnit_10 = 10 10 | ) 11 | -------------------------------------------------------------------------------- /time/duration/micro-second.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package duration 4 | 5 | // A MicroSecond duration represents the elapsed time between two instants as an int64 micro-second count. 6 | // The representation limits the largest representable duration to approximately 290 earth years. 7 | type MicroSecond int64 8 | 9 | // Common durations. 10 | const ( 11 | OneMicroSecond MicroSecond = 1 12 | 13 | NanoSecondInMicroSecond NanoSecond = coefficientUnit_1000 * OneNanosecond // 1e3 14 | ) 15 | 16 | func (d *MicroSecond) FromSecAndNano(sec Second, nsec NanoInSecond) { 17 | *d = (MicroSecond(sec) * 1e6) + MicroSecond(nsec/1e3) 18 | } 19 | -------------------------------------------------------------------------------- /time/duration/milli-second.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package duration 4 | 5 | // A MilliSecond duration represents the elapsed time between two instants as an int64 milli-second count. 6 | // The representation limits the largest representable duration to approximately 290 earth years. 7 | type MilliSecond int64 8 | 9 | // Common durations. 10 | const ( 11 | OneMilliSecond MilliSecond = 1 12 | 13 | NanoSecondInMilliSecond NanoSecond = coefficientUnit_1000 * NanoSecondInMicroSecond // 1e6 14 | 15 | MicroSecondInMilliSecond MicroSecond = coefficientUnit_1000 * OneMicroSecond // 1e6 16 | ) 17 | 18 | func (d *MilliSecond) FromSecAndNano(sec Second, nsec NanoInSecond) { 19 | *d = (MilliSecond(sec) * 1e3) + MilliSecond(nsec/1e6) 20 | } 21 | -------------------------------------------------------------------------------- /time/duration/nano-in-second.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package duration 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | "memar/math/integer" 8 | ) 9 | 10 | // A NanoInSecond represents the elapsed time between two seconds in nano-second count. 11 | type NanoInSecond integer.S32 12 | 13 | func (d *NanoInSecond) FromSec(nsec NanoSecond) { 14 | var sec Second 15 | sec.FromNanoSecond(nsec) 16 | *d = NanoInSecond(int64(nsec) % int64(sec)) 17 | } 18 | 19 | //memar:impl memar/string/protocol.Stringer 20 | func (d *NanoInSecond) ToString() (str string, err error_p.Error) { 21 | // Go doesn't support to access derived type methods, So we MUST hack it this way! 22 | // var s32 = integer.S32(*d) 23 | // return s32.ToString() 24 | return (*integer.S32)(d).ToString() 25 | } 26 | -------------------------------------------------------------------------------- /time/duration/protocol/duration.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package duration_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | ) 8 | 9 | // A Duration represents the elapsed time between two instants as an int64 nanosecond count. 10 | // The representation limits the largest representable duration to approximately 290 earth years. 11 | type Duration[STR string_p.String] interface { 12 | string_p.Stringer_To[STR] 13 | } 14 | -------------------------------------------------------------------------------- /time/earth/duration-day.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package earth 4 | 5 | import ( 6 | "memar/math/integer" 7 | "memar/time/duration" 8 | ) 9 | 10 | // Day show number of days pass from specific epoch. 11 | // e.g. `unix.Now().DayElapsed()` return number of days from unix epoch. 12 | type Day integer.S64 13 | 14 | // Common day durations 15 | const ( 16 | NanoSecondInDay duration.NanoSecond = 24 * NanoSecondInHour 17 | SecondInDay duration.Second = 24 * SecondInHour 18 | MinuteInDay Minute = 24 * MinuteInHour 19 | HourInDay Hour = 24 20 | ) 21 | 22 | func (day *Day) FromNanoSecond(d duration.NanoSecond) { 23 | // TODO::: any bad situation? 24 | *day = Day(d / NanoSecondInDay) 25 | } 26 | 27 | func (day *Day) FromSecond(d duration.Second) { 28 | // TODO::: any bad situation? 29 | *day = Day(d / SecondInDay) 30 | } 31 | -------------------------------------------------------------------------------- /time/earth/duration-hour.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package earth 4 | 5 | import ( 6 | "memar/math/integer" 7 | "memar/time/duration" 8 | ) 9 | 10 | type Hour integer.S64 11 | 12 | // Common durations. 13 | const ( 14 | NanoSecondInHour duration.NanoSecond = 60 * NanoSecondInMinute 15 | SecondInHour duration.Second = 60 * SecondInMinute 16 | MinuteInHour Minute = 60 17 | ) 18 | 19 | func (h *Hour) FromNanoSecond(d duration.NanoSecond) { 20 | // TODO::: any bad situation? 21 | *h = Hour(d / NanoSecondInHour) 22 | } 23 | 24 | func (h *Hour) FromSecond(d duration.Second) { 25 | // TODO::: any bad situation? 26 | *h = Hour(d / SecondInHour) 27 | } 28 | -------------------------------------------------------------------------------- /time/earth/duration-minute.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package earth 4 | 5 | import ( 6 | "memar/math/integer" 7 | "memar/time/duration" 8 | ) 9 | 10 | type Minute integer.S64 11 | 12 | // Common durations. 13 | const ( 14 | NanoSecondInMinute duration.NanoSecond = 60 * duration.NanoSecondInSecond 15 | SecondInMinute duration.Second = 60 16 | ) 17 | 18 | func (m *Minute) FromNanoSecond(d duration.NanoSecond) { 19 | // TODO::: any bad situation? 20 | *m = Minute(d / NanoSecondInMinute) 21 | } 22 | 23 | func (m *Minute) FromSecond(d duration.Second) { 24 | // TODO::: any bad situation? 25 | *m = Minute(d / SecondInMinute) 26 | } 27 | -------------------------------------------------------------------------------- /time/earth/duration-month.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package earth 4 | 5 | import ( 6 | "memar/math/integer" 7 | "memar/time/duration" 8 | ) 9 | 10 | type Month integer.S64 11 | 12 | // Common durations. 13 | const ( 14 | NanoSecondInMonth duration.NanoSecond = 2629743 * duration.NanoSecondInSecond 15 | SecondInMonth duration.Second = 2629743 // 30.44 days 16 | ) 17 | 18 | func (m *Month) FromNanoSecond(d duration.NanoSecond) { 19 | // TODO::: any bad situation? 20 | *m = Month(d / NanoSecondInMonth) 21 | } 22 | 23 | func (m *Month) FromSecond(d duration.Second) { 24 | // TODO::: any bad situation? 25 | *m = Month(d / SecondInMonth) 26 | } 27 | -------------------------------------------------------------------------------- /time/earth/duration-week.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package earth 4 | 5 | import ( 6 | "memar/math/integer" 7 | "memar/time/duration" 8 | ) 9 | 10 | type Week integer.S64 11 | 12 | // Common durations. 13 | const ( 14 | NanoSecondInWeek duration.NanoSecond = 7 * NanoSecondInDay 15 | SecondInWeek duration.Second = 7 * SecondInDay 16 | MinuteInWeek Minute = 7 * MinuteInDay 17 | HourInWeek Hour = 7 * HourInDay 18 | DayInWeek Day = 7 19 | ) 20 | 21 | func (w *Week) FromNanoSecond(d duration.NanoSecond) { 22 | // TODO::: any bad situation? 23 | *w = Week(d / NanoSecondInWeek) 24 | } 25 | 26 | func (w *Week) FromSecond(d duration.Second) { 27 | // TODO::: any bad situation? 28 | *w = Week(d / SecondInWeek) 29 | } 30 | -------------------------------------------------------------------------------- /time/mars/time.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package mars 4 | 5 | // https://en.wikipedia.org/wiki/Timekeeping_on_Mars 6 | -------------------------------------------------------------------------------- /time/monotonic/now.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package monotonic 4 | 5 | import ( 6 | _ "unsafe" // for go:linkname 7 | ) 8 | 9 | // TODO::: move assembly logic from go/src/runtime to this package to prevent use unsafe package 10 | // TODO::: Is duration include sleep time or without it?? 11 | 12 | // now returns the current value of the runtime monotonic clock in nanoseconds. 13 | // It isn't not wall clock, Use in tasks like timeout, ... 14 | // 15 | //go:linkname now runtime.nanotime 16 | func now() int64 17 | -------------------------------------------------------------------------------- /time/protocol/epoch.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package time_p 4 | 5 | import ( 6 | datatype_p "memar/datatype/protocol" 7 | string_p "memar/string/protocol" 8 | ) 9 | 10 | // Epoch is the interface that must implement by any time capsule. 11 | // It is base on Epoch and Second terms to work anywhere (in any planet in the universe). 12 | // https://en.wikipedia.org/wiki/Epoch 13 | type Epoch interface { 14 | datatype_p.DataType 15 | string_p.Stringer_To[string_p.String] 16 | } 17 | -------------------------------------------------------------------------------- /time/protocol/time.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package time_p 4 | 5 | import ( 6 | string_p "memar/string/protocol" 7 | "memar/time/duration" 8 | ) 9 | 10 | // Time is the interface that must implement by any time capsule. 11 | // It is base on Epoch and Second terms to work anywhere (in any planet in the universe). 12 | type Time interface { 13 | Epoch() Epoch 14 | SecondElapsed() duration.Second // From Epoch 15 | NanoInSecondElapsed() duration.NanoInSecond // From second 16 | } 17 | 18 | // Time_Stringer is base on other factor than Time like timezone, ... 19 | type Time_Stringer[STR string_p.String] interface { 20 | string_p.Stringer[STR] 21 | } 22 | -------------------------------------------------------------------------------- /time/unix/const.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | /* 4 | Unix time specifies time(second) elapsed of January 1 of the absolute year. 5 | January 1 of the absolute year(1970), like January 1 of 2001, was a Monday. 6 | */ 7 | package unix 8 | 9 | const Base = "00:00:00 UTC on 1 January 1970" // Thursday 10 | -------------------------------------------------------------------------------- /time/unix/now.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package unix 4 | 5 | import ( 6 | _ "unsafe" // for go:linkname 7 | ) 8 | 9 | // Provided by package runtime. 10 | // TODO::: move assembly logic from go/src/runtime to this package to prevent use unsafe package 11 | // 12 | //go:linkname now time.now 13 | func now() (sec int64, nsec int32, mono int64) 14 | -------------------------------------------------------------------------------- /time/utc/dayhour.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see LEGAL file in repository */ 2 | 3 | package utc 4 | 5 | // A DayHours specifies a hour of a day. 6 | type DayHours uint32 7 | 8 | // Hours 9 | const ( 10 | DayHours_None DayHours = 0 11 | DayHours_0 DayHours = (1 << iota) 12 | DayHours_1 13 | DayHours_2 14 | DayHours_3 15 | DayHours_4 16 | DayHours_5 17 | DayHours_6 18 | DayHours_7 19 | DayHours_8 20 | DayHours_9 21 | DayHours_10 22 | DayHours_11 23 | DayHours_12 24 | DayHours_13 25 | DayHours_14 26 | DayHours_15 27 | DayHours_16 28 | DayHours_17 29 | DayHours_18 30 | DayHours_19 31 | DayHours_20 32 | DayHours_21 33 | DayHours_22 34 | DayHours_23 35 | DayHours_All DayHours = 0b11111111111111111111111111111111 36 | ) 37 | 38 | // Check given hour exist in given day hours 39 | func (dh DayHours) Check(hour DayHours) (exist bool) { return hour&dh != 0 } 40 | -------------------------------------------------------------------------------- /time/utc/weekday.locale.en.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package utc 6 | 7 | // Check given day exist in desire Weekdays. 8 | func (wd Weekdays) String() (day string) { 9 | switch wd { 10 | case Weekdays_Monday: 11 | return "Monday" 12 | case Weekdays_Tuesday: 13 | return "Tuesday" 14 | case Weekdays_Wednesday: 15 | return "Wednesday" 16 | case Weekdays_Thursday: 17 | return "Thursday" 18 | case Weekdays_Friday: 19 | return "Friday" 20 | case Weekdays_Saturday: 21 | return "Saturday" 22 | case Weekdays_Sunday: 23 | return "Sunday" 24 | } 25 | return 26 | } 27 | -------------------------------------------------------------------------------- /time/utc/weekday.locale.fa.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package utc 6 | 7 | // Check given day exist in desire Weekdays. 8 | func (wd Weekdays) String() (day string) { 9 | switch wd { 10 | case Weekdays_Monday: 11 | return "دوشنبه" 12 | case Weekdays_Tuesday: 13 | return "سه شنبه" 14 | case Weekdays_Wednesday: 15 | return "چهارشنبه" 16 | case Weekdays_Thursday: 17 | return "پنچ شنبه" 18 | case Weekdays_Friday: 19 | return "جمعه" 20 | case Weekdays_Saturday: 21 | return "شنبه" 22 | case Weekdays_Sunday: 23 | return "یکشنبه" 24 | } 25 | return 26 | } 27 | -------------------------------------------------------------------------------- /timer/const.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package timer 4 | 5 | import ( 6 | "memar/time/monotonic" 7 | ) 8 | 9 | // maxWhen is the maximum value for timer's when field. 10 | const maxWhen monotonic.Time = 1<<63 - 1 // math.MaxInt64 11 | 12 | // verifyTimers can be set to true to add debugging checks that the 13 | // timer heaps are valid. 14 | const verifyTimers = false 15 | 16 | // The default heap ary is 4-ary. See siftUpTimer and siftDownTimer. 17 | // It MUST be even number. 18 | const heapAry = 4 19 | -------------------------------------------------------------------------------- /timer/errors/init.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | func init() { 6 | ErrTimerNotInit.Init() 7 | ErrTimerAlreadyInit.Init() 8 | ErrTimerAlreadyStarted.Init() 9 | ErrNegativeDuration.Init() 10 | ErrNegativePeriodNumber.Init() 11 | 12 | ErrTimerBadStatus.Init() 13 | ErrTimerRacyAccess.Init() 14 | } 15 | -------------------------------------------------------------------------------- /timer/errors/locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errs 6 | 7 | const domainEnglish = "Timer" 8 | -------------------------------------------------------------------------------- /timer/errors/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errs 6 | 7 | const domainPersian = "زمان سنج" 8 | -------------------------------------------------------------------------------- /timer/errors/negative_duration.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ErrNegativeDuration errNegativeDuration 12 | 13 | type errNegativeDuration struct{ er.Err } 14 | 15 | func (dt *errNegativeDuration) Init() (err protocol.Error) { 16 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=timer; type=error; name=negative-duration") 17 | if err != nil { 18 | return 19 | } 20 | err = errors.Register(dt) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /timer/errors/negative_duration.locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errs 6 | 7 | //memar:impl memar/protocol.Detail 8 | func (d *errNegativeDuration) Domain() string { return domainEnglish } 9 | func (d *errNegativeDuration) Summary() string { return "Negative Duration" } 10 | func (d *errNegativeDuration) Overview() string { 11 | return "Timer or Ticker must have positive duration or interval." 12 | } 13 | func (d *errNegativeDuration) UserNote() string { return "" } 14 | func (d *errNegativeDuration) DevNote() string { return "" } 15 | func (d *errNegativeDuration) TAGS() []string { return []string{} } 16 | 17 | //memar:impl memar/protocol.Quiddity 18 | func (d *errNegativeDuration) Name() string { return "" } 19 | func (d *errNegativeDuration) Abbreviation() string { return "" } 20 | func (d *errNegativeDuration) Aliases() []string { return []string{} } 21 | -------------------------------------------------------------------------------- /timer/errors/negative_period_number.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ErrNegativePeriodNumber errNegativePeriodNumber 12 | 13 | type errNegativePeriodNumber struct{ er.Err } 14 | 15 | func (dt *errNegativePeriodNumber) Init() (err protocol.Error) { 16 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=timer; type=error; name=negative-period-number") 17 | if err != nil { 18 | return 19 | } 20 | err = errors.Register(dt) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /timer/errors/timer_already_init.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ErrTimerAlreadyInit errTimerAlreadyInit 12 | 13 | type errTimerAlreadyInit struct{ er.Err } 14 | 15 | func (dt *errTimerAlreadyInit) Init() (err protocol.Error) { 16 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=timer; type=error; name=timer-already-initialized") 17 | if err != nil { 18 | return 19 | } 20 | err = errors.Register(dt) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /timer/errors/timer_already_started.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ErrTimerAlreadyStarted errTimerAlreadyStarted 12 | 13 | type errTimerAlreadyStarted struct{ er.Err } 14 | 15 | func (dt *errTimerAlreadyStarted) Init() (err protocol.Error) { 16 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=timer; type=error; name=timer-already-started") 17 | if err != nil { 18 | return 19 | } 20 | err = errors.Register(dt) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /timer/errors/timer_bad_status.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ErrTimerBadStatus errTimerBadStatus 12 | 13 | type errTimerBadStatus struct{ er.Err } 14 | 15 | func (dt *errTimerBadStatus) Init() (err protocol.Error) { 16 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=timer; type=error; name=timer-bad-status") 17 | if err != nil { 18 | return 19 | } 20 | err = errors.Register(dt) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /timer/errors/timer_not_init.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ErrTimerNotInit errTimerNotInit 12 | 13 | type errTimerNotInit struct{ er.Err } 14 | 15 | func (dt *errTimerNotInit) Init() (err protocol.Error) { 16 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=timer; type=error; name=timer-not-initialize") 17 | if err != nil { 18 | return 19 | } 20 | err = errors.Register(dt) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /timer/errors/timer_not_init.locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package errs 6 | 7 | //memar:impl memar/protocol.Detail 8 | func (d *errTimerNotInit) Domain() string { return domainEnglish } 9 | func (d *errTimerNotInit) Summary() string { return "Timer Not Initialized" } 10 | func (d *errTimerNotInit) Overview() string { 11 | return "Timer must initialized before Start(), Reset() or Stop()" 12 | } 13 | func (d *errTimerNotInit) UserNote() string { return "" } 14 | func (d *errTimerNotInit) DevNote() string { return "" } 15 | func (d *errTimerNotInit) TAGS() []string { return []string{} } 16 | 17 | //memar:impl memar/protocol.Quiddity 18 | func (d *errTimerNotInit) Name() string { return "" } 19 | func (d *errTimerNotInit) Abbreviation() string { return "" } 20 | func (d *errTimerNotInit) Aliases() []string { return []string{} } 21 | -------------------------------------------------------------------------------- /timer/errors/timer_racy_access.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package errs 4 | 5 | import ( 6 | er "memar/error" 7 | "memar/errors" 8 | "memar/protocol" 9 | ) 10 | 11 | var ErrTimerRacyAccess errTimerRacyAccess 12 | 13 | type errTimerRacyAccess struct{ er.Err } 14 | 15 | func (dt *errTimerRacyAccess) Init() (err protocol.Error) { 16 | err = dt.Err.Init("domain/memar.scm.geniuses.group; package=timer; type=error; name=timer-racy-access") 17 | if err != nil { 18 | return 19 | } 20 | err = errors.Register(dt) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /timer/init.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package timer 4 | 5 | import ( 6 | "memar/cpu" 7 | "runtime" 8 | ) 9 | 10 | var poolByCores = make(timing, cpu.LogicalCount()) 11 | 12 | func init() { 13 | var coreNumbers = runtime.GOMAXPROCS(0) 14 | for id := 0; id < coreNumbers; id++ { 15 | poolByCores[id].Init() 16 | } 17 | } 18 | 19 | func getActiveTiming() *Timing { return poolByCores.activeTiming() } 20 | 21 | type timing []Timing 22 | 23 | func (tg timing) activeTiming() *Timing { 24 | return &tg[cpu.ActiveCoreID()] 25 | } 26 | -------------------------------------------------------------------------------- /timer/protocol/listener.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package timer_p 4 | 5 | // TimerListener or TimerCallBack 6 | type TimerListener interface { 7 | // Non-Blocking, means It must not block the caller in any ways. 8 | // Be aware that given callback must not be closure too. TODO::: Why?? 9 | TimerHandler() 10 | } 11 | -------------------------------------------------------------------------------- /timer/protocol/ticker.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package timer_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | "memar/time/duration" 8 | ) 9 | 10 | // Ticker is the interface that must implement by any ticker. 11 | // Implement object of Timer can also be a ticker, 12 | // just Start() method of timer is same as Tick(d, 0). 13 | // Reset() just change the interval not first tick duration. 14 | type Ticker /*[DUR duration_p.Duration]*/ interface { 15 | // Tick will add timer to default timing mechanism like TimingHeap, TimingWheel, ... 16 | Tick(first, interval duration.NanoSecond) (err error_p.Error) 17 | } 18 | -------------------------------------------------------------------------------- /timer/protocol/timer-status.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package timer_p 4 | 5 | type TimerStatus interface { 6 | } -------------------------------------------------------------------------------- /timer/protocol/timing.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package timer_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | time_p "memar/time/protocol" 8 | ) 9 | 10 | // Timing observe Timers or Tickers and call TimerHandler() methods of them in desire time. 11 | // All package provide default Timing mechanism for easily usage, 12 | // But they should provide some other algorithms for other use-cases too. 13 | // Packages can also break Init() methods of Timer or Ticker if they can't provide default Timing mechanism e.g. on TimingWheel 14 | type Timing[ /*DUR duration_p.Duration,*/ TIME time_p.Time, ST TimerStatus] interface { 15 | // Depend on implementation but in most cases t can be a Ticker too. 16 | AddTimer(t Timer[ /*DUR,*/ TIME, ST]) (err error_p.Error) 17 | } 18 | -------------------------------------------------------------------------------- /timer/timer-async_test.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package timer 4 | 5 | import ( 6 | "memar/protocol" 7 | ) 8 | 9 | var _ protocol.Timer = &Async{} 10 | -------------------------------------------------------------------------------- /timer/timing-heap-bucket.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package timer 4 | 5 | import ( 6 | "memar/protocol" 7 | "memar/time/monotonic" 8 | ) 9 | 10 | type timerBucketHeap struct { 11 | timer *Async 12 | // Two reason to have timer when here: 13 | // - hot cache to prevent dereference timer to get when field 14 | // - It can be difference with timer when filed in timerModifiedXX status. 15 | when monotonic.Time 16 | } 17 | 18 | //memar:impl memar/protocol.SoftwareLifeCycle 19 | func (tb *timerBucketHeap) Init() (err protocol.Error) { return } 20 | func (tb *timerBucketHeap) Reinit() (err protocol.Error) { return } 21 | func (tb *timerBucketHeap) Deinit() (err protocol.Error) { tb.timer = nil; tb.when = 0; return } 22 | -------------------------------------------------------------------------------- /timer/util.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package timer 4 | 5 | import ( 6 | "memar/time/duration" 7 | "memar/time/monotonic" 8 | ) 9 | 10 | // when is a helper function for setting the 'when' field of a Timer. 11 | // It returns what the time will be, in nanoseconds, Duration d in the future. 12 | // If d is negative, it is ignored. If the returned value would be less than 13 | // zero because of an overflow, MaxInt64 is returned. 14 | func when(d duration.NanoSecond) (t monotonic.Time) { 15 | t.Now() 16 | if d <= 0 { 17 | return 18 | } 19 | t.Add(d) 20 | // check for overflow. 21 | if t < 0 { 22 | // monotonic.Now() and d are always positive, so addition 23 | // (including overflow) will never result in t == 0. 24 | t = maxWhen 25 | } 26 | return 27 | } 28 | -------------------------------------------------------------------------------- /user/protocol/id.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package user_p 4 | 5 | import ( 6 | ut16 "memar/identifier/uuid-time-16byte" 7 | time_p "memar/time/protocol" 8 | ) 9 | 10 | type UUID = ut16.UUID 11 | 12 | type ID interface { 13 | UUID() UUID 14 | 15 | // Below fields extract from(part of) above UUID 16 | ExistenceTime() time_p.Time 17 | Type() Type 18 | ID() [3]byte 19 | } 20 | -------------------------------------------------------------------------------- /user/user-type.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see LEGAL file in repository */ 2 | 3 | package user 4 | 5 | import "../protocol" 6 | 7 | // CheckUserType check and return error if user not exist in base users 8 | func CheckUserType(baseUsers, user protocol.UserType) (exist bool) { 9 | return user&baseUsers == user 10 | // err = ErrUserNotAllow 11 | } 12 | -------------------------------------------------------------------------------- /validators/errors.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package validators 4 | 5 | import ( 6 | er "libgo/error" 7 | ) 8 | 9 | // Declare package errors 10 | var ( 11 | ErrTextOverFlow er.Error 12 | ErrTextLack er.Error 13 | ErrTextIllegalCharacter er.Error 14 | ) 15 | 16 | func init() { 17 | ErrTextOverFlow.Init("domain/libgo.scm.geniuses.group; package=validators; type=error; name=text-over-flow") 18 | ErrTextLack.Init("domain/libgo.scm.geniuses.group; package=validators; type=error; name=text-lack") 19 | ErrTextIllegalCharacter.Init("domain/libgo.scm.geniuses.group; package=validators; type=error; name=text-illegal-character") 20 | } 21 | -------------------------------------------------------------------------------- /validators/locale.eng.go: -------------------------------------------------------------------------------- 1 | //go:build lang_eng 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package validators 6 | 7 | import ( 8 | "libgo/protocol" 9 | ) 10 | 11 | const domainEnglish = "Validation" 12 | 13 | func init() { 14 | ErrTextOverFlow.SetDetail(protocol.LanguageEnglish, domainEnglish, 15 | "Text OverFlow", 16 | "Given text size is more than it must be", 17 | "", 18 | "", 19 | nil) 20 | ErrTextLack.SetDetail(protocol.LanguageEnglish, domainEnglish, 21 | "Text Lack", 22 | "Given text size is less than it must be", 23 | "", 24 | "", 25 | nil) 26 | ErrTextIllegalCharacter.SetDetail(protocol.LanguageEnglish, domainEnglish, 27 | "Text Illegal Character", 28 | "Given text include illegal character or text!", 29 | "", 30 | "", 31 | nil) 32 | } 33 | -------------------------------------------------------------------------------- /validators/locale.per.go: -------------------------------------------------------------------------------- 1 | //go:build lang_per 2 | 3 | /* For license and copyright information please see the LEGAL file in the code repository */ 4 | 5 | package validators 6 | 7 | import ( 8 | "libgo/protocol" 9 | ) 10 | 11 | const domainPersian = "اعتبارسنجی" 12 | 13 | func init() { 14 | } 15 | -------------------------------------------------------------------------------- /validators/protocol/specifications.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package validation_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | // TODO::: why not validate per field?? 10 | 11 | // https://martinfowler.com/apsupp/spec.pdf 12 | // https://github.com/nullexp/specp/blob/main/example/basic.go 13 | type Satisfier[T any] interface { 14 | IsSatisfiedBy(value T) error_p.Error 15 | } 16 | 17 | type Specification[T any] interface { 18 | Satisfier[T] 19 | And(other Specification[T]) Specification[T] 20 | AndNot(other Specification[T]) Specification[T] 21 | Not() Specification[T] 22 | OrNot(other Specification[T]) Specification[T] 23 | Or(other Specification[T]) Specification[T] 24 | } 25 | -------------------------------------------------------------------------------- /validators/protocol/validation.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package validation_p 4 | 5 | import ( 6 | error_p "memar/error/protocol" 7 | ) 8 | 9 | // **ATTENTION**::: strongly suggest use capsule_p.Accessor to prevent invalid state at first place. 10 | type Validation interface { 11 | Validate() (err error_p.Error) 12 | } 13 | -------------------------------------------------------------------------------- /validators/text.go: -------------------------------------------------------------------------------- 1 | /* For license and copyright information please see the LEGAL file in the code repository */ 2 | 3 | package validators 4 | 5 | import ( 6 | "libgo/protocol" 7 | ) 8 | 9 | func ValidateTextLength(t string, min, max int) (err protocol.Error) { 10 | if len(t) < min { 11 | return &ErrTextLack 12 | } 13 | if max != 0 && len(t) > max { 14 | return &ErrTextOverFlow 15 | } 16 | return 17 | } 18 | --------------------------------------------------------------------------------