{"action":"created","issue":{"url":"https://api.github.com/repos/Datomic/fressian/issues/5","labels_url":"https://api.github.com/repos/Datomic/fressian/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/Datomic/fressian/issues/5/comments","events_url":"https://api.github.com/repos/Datomic/fressian/issues/5/events","html_url":"https://github.com/Datomic/fressian/issues/5","id":37684577,"number":5,"title":"Writing an open list and then a footer causes an off by one error","user":{"login":"spinningtopsofdoom","id":6473652,"avatar_url":"https://avatars.githubusercontent.com/u/6473652?v=3","gravatar_id":"","url":"https://api.github.com/users/spinningtopsofdoom","html_url":"https://github.com/spinningtopsofdoom","followers_url":"https://api.github.com/users/spinningtopsofdoom/followers","following_url":"https://api.github.com/users/spinningtopsofdoom/following{/other_user}","gists_url":"https://api.github.com/users/spinningtopsofdoom/gists{/gist_id}","starred_url":"https://api.github.com/users/spinningtopsofdoom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spinningtopsofdoom/subscriptions","organizations_url":"https://api.github.com/users/spinningtopsofdoom/orgs","repos_url":"https://api.github.com/users/spinningtopsofdoom/repos","events_url":"https://api.github.com/users/spinningtopsofdoom/events{/privacy}","received_events_url":"https://api.github.com/users/spinningtopsofdoom/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-07-11T18:22:47Z","updated_at":"2015-03-15T23:56:38Z","closed_at":null,"body":"If you write an open list, end it, and then write a footer the validation logic for the number of bytes fails.  The length reported in the footer and the calculated length are off by one.  Here is a example that produces the error\r\n\r\n```clojure\r\n(require '[clojure.data.fressian :as fress])\r\n(import '[org.fressian.impl ByteBufferInputStream BytesOutputStream InheritanceLookup])\r\n(let [my-os (BytesOutputStream.)\r\n      fw (fress/create-writer my-os) ]\r\n  (do\r\n   (fress/begin-open-list fw)\r\n   (fress/end-list fw)\r\n   (fress/write-footer fw)\r\n   (fress/write-object fw nil)\r\n   (let [ my-is (fress/to-input-stream (.internalBuffer my-os))\r\n         fr (fress/create-reader my-is)]\r\n     [(fress/read-object fr) (fress/read-object fr)])))\r\n````\r\n\r\nI believe the cause is in the beginOpenList method of FressianWriter\r\n\r\n```java\r\npublic Writer beginOpenList() throws IOException {\r\n        if (0 != rawOut.getBytesWritten())\r\n            throw new IllegalStateException(\"openList must be called from the top level, outside any footer context.\");\r\n        writeCode(Codes.BEGIN_OPEN_LIST);\r\n        rawOut.reset();\r\n        return this;\r\n    }\r\n```\r\n\r\nThe byte code for the open list is written, then the stream is reset making the reported number of bytes written zero, not one."},"comment":{"url":"https://api.github.com/repos/Datomic/fressian/issues/comments/81304854","html_url":"https://github.com/Datomic/fressian/issues/5#issuecomment-81304854","issue_url":"https://api.github.com/repos/Datomic/fressian/issues/5","id":81304854,"user":{"login":"rschmitt","id":3725049,"avatar_url":"https://avatars.githubusercontent.com/u/3725049?v=3","gravatar_id":"","url":"https://api.github.com/users/rschmitt","html_url":"https://github.com/rschmitt","followers_url":"https://api.github.com/users/rschmitt/followers","following_url":"https://api.github.com/users/rschmitt/following{/other_user}","gists_url":"https://api.github.com/users/rschmitt/gists{/gist_id}","starred_url":"https://api.github.com/users/rschmitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rschmitt/subscriptions","organizations_url":"https://api.github.com/users/rschmitt/orgs","repos_url":"https://api.github.com/users/rschmitt/repos","events_url":"https://api.github.com/users/rschmitt/events{/privacy}","received_events_url":"https://api.github.com/users/rschmitt/received_events","type":"User","site_admin":false},"created_at":"2015-03-15T23:56:38Z","updated_at":"2015-03-15T23:56:38Z","body":"Speaking as a member of the peanut gallery, this is an outstanding bug report and I'm surprised that you haven't gotten any kind of response."}}