{"id":18515266,"url":"https://github.com/chokobole/data_view","last_synced_at":"2025-04-09T06:34:54.279Z","repository":{"id":143979104,"uuid":"230494377","full_name":"chokobole/data_view","owner":"chokobole","description":"c++ version of js DataView","archived":false,"fork":false,"pushed_at":"2024-04-11T20:43:42.000Z","size":9,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-07T09:35:52.831Z","etag":null,"topics":["bazel-support","cpp","cpp-library","cpp14","cpp14-library","dataview","endian"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chokobole.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-27T18:21:10.000Z","updated_at":"2024-04-11T20:43:45.000Z","dependencies_parsed_at":"2024-04-11T21:40:58.325Z","dependency_job_id":null,"html_url":"https://github.com/chokobole/data_view","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chokobole%2Fdata_view","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chokobole%2Fdata_view/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chokobole%2Fdata_view/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chokobole%2Fdata_view/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chokobole","download_url":"https://codeload.github.com/chokobole/data_view/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247993669,"owners_count":21030043,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bazel-support","cpp","cpp-library","cpp14","cpp14-library","dataview","endian"],"created_at":"2024-11-06T15:47:11.399Z","updated_at":"2025-04-09T06:34:49.258Z","avatar_url":"https://github.com/chokobole.png","language":"C++","readme":"# DataView\n\n`DataView` is similar to javascript [DataView](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/DataView). It can read or write by from `uint8` to `double`.\n\n## Contents\n- [DataView](#dataview)\n  - [Contents](#contents)\n  - [How to use](#how-to-use)\n  - [Examples](#examples)\n  - [Usages](#usages)\n    - [DataView](#dataview-1)\n    - [Read](#read)\n    - [Write](#write)\n\n## How to use\n\nTo use `data_view`, add the followings to your `WORKSPACE` file.\n\n```python\nload(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\")\n\nhttp_archive(\n    name = \"data_view\",\n    sha256 = \"\u003csha256\u003e\",\n    strip_prefix = \"data_view-\u003ccommit\u003e\",\n    urls = [\n        \"https://github.com/chokobole/data_view/archive/\u003ccommit\u003e.tar.gz\",\n    ],\n)\n```\n\nThen, in your `BUILD` files, import and use the rules.\n\n```python\nload(\"@data_view//bazel:data_view_cc.bzl\", \"data_view_copts\")\n\ncc_library(\n    name = \"...\",\n    copts = data_view_copts(),\n    deps = [\n      \"@data_view\",\n    ]\n)\n```\n\n## Examples\n\nBuild example.\n\n```bash\nbazel run //examples:example\n```\n\n```c++\n#include \u003ciostream\u003e\n\n#include \"data_view/data_view.h\"\n\nint main() {\n  const char buf[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};\n  size_t buf_len = sizeof(buf);\n  data_view::ConstDataView data_view(buf, buf_len);\n\n  uint16_t v;\n  data_view.Read(0, \u0026v, true);\n  std::cout \u003c\u003c v \u003c\u003c std::endl;  // 256\n  data_view.Read(0, \u0026v, false);\n  std::cout \u003c\u003c v \u003c\u003c std::endl;  // 1\n\n  return 0;\n}\n```\n\n## Usages\n\n### DataView\n\nIf you want to just read bytes, then use `ConstDataView`. If you want to modify bytes, then use `DataView`.\n\n### Read\n\nSignature of `Read` is like below.\n\n```c++\n// Returns true if succeeded to read. (offset + sizeof(T) \u003c= |length_|)\ntemplate \u003ctypename T\u003e\nbool Read(size_t offset, T* value, bool little_endian) const;\n```\n\n* `offset`: byte offset to read from.\n* `value`\n* `little_endian`: If set true, read as little endian, Otherwise read as big endian.\n\nFor example,\n\n```c++\ndata_view::ConstDataView data_view;\nuint16_t v;\ndata_view.Read(0, \u0026v, true);\n```\n\n### Write\n\nSignature of `Write` is like below.\n\n```c++\n// Returns true if succeeded to write. (offset + sizeof(T) \u003c= |length_|)\ntemplate \u003ctypename T\u003e\nbool Write(size_t offset, T value, bool little_endian);\n```\n\n* `offset`: byte offset to write to.\n* `value`\n* `little_endian`: If set true, write as little endian, Otherwise write as big endian.\n\nFor example,\n\n```c++\nchar buf[16] = {0,};\nsize_t buf_len = sizeof(buf);\ndata_view::DataView data_view(buf, buf_len);\ndata_view.Write(0, 127, true);\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchokobole%2Fdata_view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchokobole%2Fdata_view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchokobole%2Fdata_view/lists"}